• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Create a new numeric Datapoints from alphanumeric datapoint

    How-To
    3
    7
    1.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      Jorge Gonzalez
      last edited by

      There are 110 controller, where every data come with the units, I mean for example starting voltage battery: 13.7V, engine temperature 47,0celsius, etc
      • All data are SNMP
      • The type of data is OctectString (it from MIB File)
      • In Mango Scada every data points is configured as Alphanumeric type and Not Settable
      • All information is getting with out problema.

      The problem is that with this kind of data (Alphanumeric), is not possible to get a graph also is not possible to configure limits alarms maximum or minimum. (Event detector)

      Question, If I have and get all information, ¿could I have any way to change all this information from Alphanumeric to Numeric??
      Im thinking or guess is possible to use some virtual datasources where datapoint values will be obtained from this alphanumeric information… 0_1544013662101_Alphanumeric Value.png

      1 Reply Last reply Reply Quote 0
      • JoelHaggarJ
        JoelHaggar
        last edited by

        You will need to change the Data Type on the Data Point to Numeric if you want to chart and use statistics. Other things in Mango are also affected by the data type such as the types of event detectors.

        1 Reply Last reply Reply Quote 0
        • phildunlapP
          phildunlap
          last edited by

          Hi Jorge,

          Joel's suggestion would work if the value didn't have the unit encoded in the alphanumeric value, and if your locale is set for Double.parseDouble to expect commas for number formatting. One could create a meta point and parse out the value that way, i.e.

          where p is the variable name for a alphanumeric context point,

          var pieces = /(-?\d+?),(\d+).*/.exec(p.value);
          return parseFloat( pieces[1] + "." + pieces[2] );
          

          Then you could generate history and whatnot for your existing data. That may not be exactly what you need (you may need to change the decimal delimiter on the second line back to a comma (if so, you could also just capture it all together in the first line)) but it's close.

          1 Reply Last reply Reply Quote 0
          • J
            Jorge Gonzalez
            last edited by

            Thanks so much Phil, I will check Your sugestion, I guess that it may work... thanks again

            I will keep in touch about it

            1 Reply Last reply Reply Quote 0
            • J
              Jorge Gonzalez
              last edited by

              Dear Phil, I made some tests with some values and it work.. even it must be done one by one value. (i think there are more than 800 different values).

              Phil. please what we need now to add something to the script to multiplying the final value x20. It is because the value is %, I think that will be better, if it is shown as a number i.e. 70% = 20x70=1400

              1 Reply Last reply Reply Quote 0
              • phildunlapP
                phildunlap
                last edited by

                Phil. please what we need now to add something to the script to multiplying the final value x20. It is because the value is %, I think that will be better, if it is shown as a number i.e. 70% = 20x70=1400

                If I'm understanding right, that's a simple modification to the script,

                var pieces = /(-?\d+?),(\d+).*/.exec(p.value);
                return parseFloat( pieces[1] + "." + pieces[2] ) * 20; //multiply it by 20
                

                You could automate creating the meta points by doing something like I did in this thread, https://forum.infiniteautomation.com/topic/2473/how-to-bulk-import-event-detectors

                It's probably possible and perhaps easier through CSV export/import, but I would do it with a script like,

                var xidPrefix = "N_"; //used to create a unique XID from the XID of the data point, chose N for numeric
                var snmpDataSourceXid = "DS_c4248bb3-9877-4ed7-b228-0bd08c3f77b6"; //Identify the points to add to, change to your SNMP DS's
                var metaDataSourceXid = "DS_b9d9db6b-49f3-4c92-820d-7f2a65c39ea4"; //change to your meta DS
                
                var dataPoints = JSON.parse(JsonEmport.getConfiguration("dataPoints")).dataPoints;
                var snmpPoints = DataPointQuery.query('eq(dataSourceXid,'+snmpDataSourceXid+')&limit(1000)');
                var createdMetaPoints = [];
                
                function findByXid(list, xid) {
                    for( var k = 0; k < list.length; k+=1 )
                        if( list[k].xid === xid )
                            return list[k];
                    return undefined;
                }
                
                function createMetaPointForDataPoint(dp) {
                    if(findByXid(dataPoints, xidPrefix + dp.xid) !== undefined)
                		return; //ensure we don't create the meta point twice
                                        // but it would just import and save again, no biggie
                    
                    var meta = { //Gotten by configuring one and exporting it
                         "xid":xidPrefix + dp.xid,
                         "name": dp.name,
                         "enabled":true,
                         "loggingType":"ALL",
                         "intervalLoggingPeriodType":"MINUTES",
                         "intervalLoggingType":"AVERAGE",
                         "purgeType":"YEARS",
                         "pointLocator":{
                            "dataType":"NUMERIC",
                            "updateEvent":"NONE",
                            "contextUpdateEvent":"CONTEXT_UPDATE",
                            "context":[
                               {
                                  "varName":"p",
                                  "dataPointXid":dp.xid,
                                  "updateContext":true
                               }
                            ],
                            "logLevel":"NONE",
                            "variableName":"my",
                            "executionDelaySeconds":0,
                            "logCount":5,
                            "logSize":1.0,
                            "script":"var pieces = \/(-?\\d+?),(\\d+).*\/.exec(p.value);\r\nreturn parseFloat( pieces[1] + \".\" + pieces[2] ) * 20;",
                            "scriptPermissions":{
                               "customPermissions":"",
                               "dataPointReadPermissions":"superadmin, edit-ui-menus, edit-ui-pages, edit-ui-settings",
                               "dataPointSetPermissions":"superadmin, edit-ui-menus, edit-ui-pages, edit-ui-settings",
                               "dataSourcePermissions":"superadmin, edit-ui-menus, edit-ui-pages, edit-ui-settings"
                            },
                            "settable":false,
                            "updateCronPattern":""
                         },
                         "eventDetectors":[
                         ],
                         "plotType":"SPLINE",
                         "rollup":"NONE",
                         "unit":"",
                         "simplifyType":"NONE",
                         "chartColour":"",
                         "chartRenderer":{
                            "type":"IMAGE",
                            "timePeriodType":"DAYS",
                            "numberOfPeriods":1
                         },
                         "dataSourceXid":metaDataSourceXid,
                         "defaultCacheSize":1,
                         "deviceName":"Parsed " + dp.deviceName,
                         "discardExtremeValues":false,
                         "discardHighLimit":1.7976931348623157E307,
                         "discardLowLimit":-1.7976931348623157E307,
                         "intervalLoggingPeriod":1,
                         "intervalLoggingSampleWindowSize":0,
                         "overrideIntervalLoggingSamples":false,
                         "preventSetExtremeValues":false,
                         "purgeOverride":false,
                         "purgePeriod":1,
                         "readPermission":"",
                         "setExtremeHighLimit":1.7976931348623157E307,
                         "setExtremeLowLimit":-1.7976931348623157E307,
                         "setPermission":"",
                         "tags":{
                         },
                         "textRenderer":{
                            "type":"ANALOG",
                            "useUnitAsSuffix":true,
                            "unit":"",
                            "renderedUnit":"",
                            "format":"0.0"
                         },
                         "tolerance":0.0
                      };
                            
                    createdMetaPoints.push(meta);
                }
                
                for(var k in snmpPoints) {
                	var dpWrapper = snmpPoints[k];
                	createMetaPointForDataPoint(dpWrapper);
                }
                
                
                //The next line allows this import to happen even if we're just clicking the validate checkbox on a script
                JsonEmport.setImportDuringValidation( true );
                
                JsonEmport.doImport(JSON.stringify({"dataPoints":createdMetaPoints}));
                
                1 Reply Last reply Reply Quote 0
                • J
                  Jorge Gonzalez
                  last edited by

                  Thanks so much, You are right, we check it and it work. Thank You
                  The other script... will be for the oficial integration.
                  till now we are showing to the customer that the platform can work with their controller

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post