6 Replies Latest reply on Sep 23, 2016 10:01 AM by keriw RSS
    mvolanti Apprentice

    LOAD JSON/CSV FILE IN THINGWORX

    Hello everyone!!

    I'm trying to create a demo having data in csv(or json) format.

    I would like to import data's file in the composer, parse it and see data in a mashup with a grid.

    Also i would like to create a stream that show me (in the meshup) the parameter's trend.

     

    I created a thing with a repository template (because the file is in C:/ThingworxStorage/repository) but when i try the service loadJSON anything appeare to me.

     

    Can anyone help me??

    Thank's!!

      • Re: LOAD JSON/CSV FILE IN THINGWORX
        keriw Apprentice

        Maurizio,

         

        Here is an example of pulling data from a csv file stored in a repository and then outputting it as an infotable in a service.

         

        var params = {

          path: "RPTM.csv" /* STRING */,

          columnMappings: "Location;StartTime;EndTime;ProductCode;CasesProduced;PerHourCWS;CWS;Efficiency"/* STRING */,

          hasHeader: true /* BOOLEAN */,

          longitudeField: undefined /* NUMBER */,

          dateFormat: undefined /* STRING */,

          fileRepository: "RPTMFileRepository"/* THINGNAME */,

          latitudeField: undefined /* NUMBER */,

          fieldDelimiter: "," /* STRING */,

          stringDelimiter: "\"" /* STRING */,

          dataShape: "RPTMImport" /* DATASHAPENAME */

        };

         

         

        // result: INFOTABLE

        var rptmData = Resources["CSVParserFunctions"].ReadCSVFile(params);

         

         

        var params = {

          infoTableName : "InfoTable",

          dataShapeName : "RPTM"

        };

         

         

        // CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(RPTM)

        var modifiedData = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

         

        //translating the date fields in csv to date fields in ThingWorx

         

        for each (var row in rptmData.rows) {

           var startTime = new Date(row.StartTime);

           var endTime = new Date(row.EndTime);

           row.StartTime = startTime;

           row.EndTime = endTime;

         

         

           

            modifiedData.AddRow({

                Location: row.Location,

                StartTime: startTime,

                EndTime: endTime,

                ProductCode: row.ProductCode,

                CasesProduced: row.CasesProduced,

                PerHourCWS: row.PerHourCWS,

                CWS: row.CWS,

                Efficiency: row.Efficiency,

                Baseline: 100.00

             

            });

         

         

        }

         

         

        result = modifiedData;

         

        Thanks,

         

        Keri