What issue did you foresee with the POP3 points? Multiple values per point per email?
Here's the script I came up with,
//JsonEmport.setImportDuringValidation(true);
var pointIndexes = this.pointIndexes;
var timezone = this.timezone;
if(typeof pointIndexes === 'undefined') {
pointIndexes = this.pointIndexes = pointIndexes = {
windDirection: 2,
windSpeed: 3,
barometer: 4,
rh: 5,
temperature: 6,
dewPoint: 7,
sensorPower: 8
}; //Create points on the scripting data source with those variable names
}
var lines = p.value.replace(/\r/g, "").split("\n");
for( var k = 0; k < lines.length; k+=1 ) {
var line = lines[k];
var dateMatch = /^.*?(\d\d)\/(\d\d)\/(\d\d)\s*\|\s*(\d\d):(\d\d):(\d\d).*/.exec(line);
if(dateMatch !== null) {
//Assume times are in server timezone, if UTC use next line, else manual offset
var date = new Date(parseInt("20" + dateMatch[3]), parseInt(dateMatch[2])-1, parseInt(dateMatch[1]),
parseInt(dateMatch[4]), parseInt(dateMatch[5]), parseInt(dateMatch[6]));
// var utcDate = new Date(Date.UTC(parseInt("20" + dateMatch[3]), parseInt(dateMatch[2])-1, parseInt(dateMatch[1]),
// parseInt(dateMatch[4]), parseInt(dateMatch[5]), parseInt(dateMatch[6])))
var lineData = line.split("|");
for(var point in pointIndexes) {
var nextValue = lineData[pointIndexes[point]];
nextValue = nextValue.replace(/\s+/g, "");
if(typeof this[point] === 'undefined') {
//Create a data point using our base point,
var newDp = JSON.parse(JsonEmport.dataPointQuery("eq(xid,DP_EmailParser_BasePoint)")).dataPoints[0];
newDp.name = point;
newDp.pointLocator.varName = point;
newDp.enabled = true;
delete newDp.xid; //get a randomly generated xid
JsonEmport.doImportGetStatus(JSON.stringify({"dataPoints":[newDp]}));
RuntimeManager.sleep(1000);
}
this[point].set(parseFloat(nextValue), date.getTime());
}
}
}
Where for a similar email you would only need to change the pointIndexes object to be the names you want the points in those columns to be created with. I did it with the formatting still in the email (just add \s* all around some regex!) Here's the JSON for the data source with the base point:
{
"dataSources":[
{
"xid":"DS_8ffb2983-dd50-42e1-9b43-706bc0a10eb2",
"name":"Email Parser",
"enabled":false,
"type":"SCRIPTING",
"alarmLevels":{
"SCRIPT_ERROR":"URGENT",
"DATA_TYPE_ERROR":"URGENT",
"POLL_ABORTED":"URGENT",
"LOG_ERROR":"URGENT"
},
"purgeType":"YEARS",
"updateEvent":"CONTEXT_UPDATE",
"context":[
{
"varName":"p",
"dataPointXid":"DP_f4a4b495-f7a8-4ddc-a619-5172835ebe30",
"updateContext":true
}
],
"logLevel":"NONE",
"cronPattern":"",
"executionDelaySeconds":0,
"historicalSetting":false,
"logCount":5,
"logSize":1.0,
"script":"\/\/JsonEmport.setImportDuringValidation(true);\nvar pointIndexes = this.pointIndexes;\nvar timezone = this.timezone;\nif(typeof pointIndexes === 'undefined') {\n pointIndexes = this.pointIndexes = pointIndexes = {\n windDirection: 2,\n windSpeed: 3,\n barometer: 4,\n rh: 5,\n temperature: 6,\n dewPoint: 7,\n sensorPower: 8\n }; \/\/Create points on the scripting data source with those variable names\n}\n\nvar lines = p.value.replace(\/\\r\/g, \"\").split(\"\\n\");\nfor( var k = 0; k < lines.length; k+=1 ) {\n var line = lines[k];\n var dateMatch = \/^.*?(\\d\\d)\\\/(\\d\\d)\\\/(\\d\\d)\\s*\\|\\s*(\\d\\d):(\\d\\d):(\\d\\d).*\/.exec(line);\n if(dateMatch !== null) {\n \/\/Assume times are in server timezone, if UTC use next line, else manual offset\n var date = new Date(parseInt(\"20\" + dateMatch[3]), parseInt(dateMatch[2])-1, parseInt(dateMatch[1]),\n parseInt(dateMatch[4]), parseInt(dateMatch[5]), parseInt(dateMatch[6]));\n\/\/ var utcDate = new Date(Date.UTC(parseInt(\"20\" + dateMatch[3]), parseInt(dateMatch[2])-1, parseInt(dateMatch[1]),\n\/\/ parseInt(dateMatch[4]), parseInt(dateMatch[5]), parseInt(dateMatch[6])))\n var lineData = line.split(\"|\");\n for(var point in pointIndexes) {\n var nextValue = lineData[pointIndexes[point]];\n nextValue = nextValue.replace(\/\\s+\/g, \"\");\n if(typeof this[point] === 'undefined') {\n \/\/Create a data point using our base point,\n var newDp = JSON.parse(JsonEmport.dataPointQuery(\"eq(xid,DP_EmailParser_BasePoint)\")).dataPoints[0];\n newDp.name = point;\n newDp.pointLocator.varName = point;\n newDp.enabled = true;\n delete newDp.xid; \/\/get a randomly generated xid\n JsonEmport.doImportGetStatus(JSON.stringify({\"dataPoints\":[newDp]}));\n RuntimeManager.sleep(1000);\n }\n this[point].set(parseFloat(nextValue), date.getTime());\n }\n }\n}",
"scriptPermissions":{
"customPermissions":"",
"dataPointReadPermissions":"superadmin",
"dataPointSetPermissions":"superadmin",
"dataSourcePermissions":"superadmin"
},
"editPermission":"",
"purgeOverride":false,
"purgePeriod":1
}
],
"dataPoints":[
{
"xid":"DP_EmailParser_BasePoint",
"name":"BasePoint",
"enabled":false,
"loggingType":"ALL",
"intervalLoggingPeriodType":"MINUTES",
"intervalLoggingType":"AVERAGE",
"purgeType":"YEARS",
"pointLocator":{
"dataType":"NUMERIC",
"contextUpdate":false,
"settable":true,
"varName":"basePoint"
},
"eventDetectors":[
],
"plotType":"SPLINE",
"rollup":"NONE",
"unit":"",
"simplifyType":"NONE",
"chartColour":"",
"chartRenderer":{
"type":"IMAGE",
"timePeriodType":"DAYS",
"numberOfPeriods":1
},
"dataSourceXid":"DS_8ffb2983-dd50-42e1-9b43-706bc0a10eb2",
"defaultCacheSize":1,
"deviceName":"Email Parser",
"discardExtremeValues":false,
"discardHighLimit":1.7976931348623157E308,
"discardLowLimit":-1.7976931348623157E308,
"intervalLoggingPeriod":1,
"intervalLoggingSampleWindowSize":0,
"overrideIntervalLoggingSamples":false,
"preventSetExtremeValues":false,
"purgeOverride":false,
"purgePeriod":1,
"readPermission":"",
"setExtremeHighLimit":1.7976931348623157E308,
"setExtremeLowLimit":-1.7976931348623157E308,
"setPermission":"",
"tags":{
},
"textRenderer":{
"type":"ANALOG",
"useUnitAsSuffix":true,
"unit":"",
"renderedUnit":"",
"format":"0.000"
},
"tolerance":0.0
}
]
}