{=========================== CustomJSONProcessor =============================} { Custom JSON data processor for the JSONXMLDriver - Env Canada History Data } { Processes Historical DISCHARGE & Level data with Timestamps } {=============================================================================} ( Data; UniqueID; ) [ CONSTANT IsJSONXMLProcessor = TRUE; DrawLabel = "Env Can JSON Processor"; NewData; TimeValuePair Struct [ Timestamp; Value; ]; DateTime; DateTimeVTS; i; {for loop pointer} r; {records retured in JSON} ] Main [ If 1; [ r = Data.numberReturned; {only process returned records} DateTime = New(r); DateTimeVTS = New(r); i = 0; WhileLoop(i < r , DateTime[i] = Data.features[i].properties.DATETIME; DateTimeVTS[i] = (datenum(substr(DateTime[i],8,2),substr(DateTime[i],5,2),substr(DateTime[i],0,4))*86400) + (substr(DateTime[i],11,2)*3600) + (substr(DateTime[i],14,2)*60) + substr(DateTime[i],17,2); i++); NewData = Dictionary(); NewData["STATION_NUMBER"] = Data.features[0].properties.STATION_NUMBER; NewData["STATION_NAME"] = Data.features[0].properties.STATION_NAME; NewData["NEWEST_TIMESTAMP"] = Data.features[0].properties.DATETIME; NewData["RECORDS_RETURNED"] = r; NewData["DISCHARGE"] = Data.features[0].properties.DISCHARGE; NewData["DISCHARGE:History"] = TimeValuePair(New(r), New(r)); i = 0; WhileLoop(i < r , NewData["DISCHARGE:History"].Value[r-i-1] = Data.features[i].properties.DISCHARGE; NewData["DISCHARGE:History"].Timestamp[r-i-1] = DateTimeVTS[i]; i++); NewData["LEVEL"] = Data.features[0].properties.LEVEL; NewData["LEVEL:History"] = TimeValuePair(New(r), New(r)); i = 0; WhileLoop(i < r , NewData["LEVEL:History"].Value[r-i-1] = Data.features[i].properties.DISCHARGE; NewData["LEVEL:History"].Timestamp[r-i-1] = DateTimeVTS[i]; i++); NewData["UniqueID"] = UniqueID; NewData["Timestamp"] = "Not a timestamp"; Return(NewData); ] ]