Logic Machine Forum
trends from an xml file - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: trends from an xml file (/showthread.php?tid=2970)



trends from an xml file - SigmaTec - 11.11.2020

Hi all,

I saw that a lot of scripts allowed to process trends, but I couldn't find anything on the following subject:
is it possible to create a curve in LM from an xml file, created independently of the controller objects?

My need: draw a trend whose data is in an xml file created outside the LM (therefore not in its SQL database).

If it's possible : what is the xml data format interpreted by the LM ?

Thank's in advance for your answer.
Take care of you.


RE: trends from an xml file - Erwin van der Zwart - 12.11.2020

You could read the xml from script, add the values from the .xml to objects and attach trends to those objects ..


RE: trends from an xml file - admin - 12.11.2020

Can you post an example of this XML file?


RE: trends from an xml file - SigmaTec - 15.11.2020

Hi Admin

the data can be in csv or xml format.
These are measurements taken every 12 seconds : how many values can we store at most for an object ?

Have a good week.

Code:
   <Row>
    <Cell><Data ss:Type="String"> 11-05-20 16:01:06</Data></Cell>
    <Cell><Data ss:Type="Number">0.51</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String"> 11-05-20 16:01:17</Data></Cell>
    <Cell><Data ss:Type="Number">0.44</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String"> 11-05-20 16:01:29</Data></Cell>
    <Cell><Data ss:Type="Number">0.48</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String"> 11-05-20 16:01:40</Data></Cell>
    <Cell><Data ss:Type="Number">0.48</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String"> 11-05-20 16:01:52</Data></Cell>
    <Cell><Data ss:Type="Number">0.53</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String"> 11-05-20 16:02:03</Data></Cell>
    <Cell><Data ss:Type="Number">0.48</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String"> 11-05-20 16:02:15</Data></Cell>
    <Cell><Data ss:Type="Number">0.45</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String"> 11-05-20 16:02:26</Data></Cell>
    <Cell><Data ss:Type="Number">0.49</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String"> 11-05-20 16:02:38</Data></Cell>
    <Cell><Data ss:Type="Number">0.47</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="String"> 11-05-20 16:02:49</Data></Cell>
    <Cell><Data ss:Type="Number">0.47</Data></Cell>
   </Row>

Code:
11-05-20 16:01:06;0,51
11-05-20 16:01:17;0,44
11-05-20 16:01:29;0,48
11-05-20 16:01:40;0,48
11-05-20 16:01:52;0,53
11-05-20 16:02:03;0,48
11-05-20 16:02:15;0,45
11-05-20 16:02:26;0,49
11-05-20 16:02:38;0,47
11-05-20 16:02:49;0,47



RE: trends from an xml file - admin - 16.11.2020

It's possible to get this data into trends but you won't get better resolution than 5 minutes. Another possibility is to use built-in Dygraphs library and some Custom JavaScript to display this data. Where does this data come from, can it be retrieved by the client's browser or LM?

Example graph:
   


RE: trends from an xml file - SigmaTec - 16.11.2020

Hi Admin,

very interesting !

Datas are generated by the LM and can therefore be put in one of two formats (csv or xml). It must be possible to visualize the curves on the LM or in a browser.

Dear Admin,

I will test the Dygraph library and I will ask you if necessary. Thanks for that advice.

Have a good week.


RE: trends from an xml file - admin - 16.11.2020

Here's an example that can be used as a starting point.
It should be modified to fetch the data remotely. It already converts CSV into correct data format for the graph library.
Code:
$(function() {
  var csv = `11-05-20 16:01:06;0,51
11-05-20 16:01:17;0,44
11-05-20 16:01:29;0,48
11-05-20 16:01:40;0,48
11-05-20 16:01:52;0,53
11-05-20 16:02:03;0,48
11-05-20 16:02:15;0,45
11-05-20 16:02:26;0,49
11-05-20 16:02:38;0,47
11-05-20 16:02:49;0,47`;

  var data = [];
  // convert CSV to correct data format
  $.each(csv.split('\n'), function(_, line) {
    var items = line.split(';')
      , d = items[0].replace(/(\d+)\-(\d+)\-(\d+) (.*)/, '20$3-$2-$1 $4')
      , n = items[1].replace(',', '.');
    
    data.push([
      new Date(d),
      Number(n)
    ]);
  });
  
  // create element for graph display, add to plan #1
  var el = $('<div></div>').css({
    position: 'absolute',
    width: 500,
    height: 300,
    left: 250,
    top: 380    
  }).appendTo('#plan-1').get(0);
  
  // create graph instance
  var graph = new Dygraph(el, data, {
    labels: [ '', 'My data' ],
    xAxisLabelWidth: 60
  });
});

graph should only be created once, to update it with new data use this:
Code:
graph.updateOptions({ file: data });



RE: trends from an xml file - SigmaTec - 16.11.2020

Dear Admin,

thanks for your script.

I have just done some pretty thorough tests with Dygraph: impressive!
I understand why you used it for Trends in LM.


RE: trends from an xml file - khalil - 04.02.2021

(16.11.2020, 08:31)admin Wrote: Here's an example that can be used as a starting point.
It should be modified to fetch the data remotely. It already converts CSV into correct data format for the graph library.
Code:
$(function() {
  var csv = `11-05-20 16:01:06;0,51
11-05-20 16:01:17;0,44
11-05-20 16:01:29;0,48
11-05-20 16:01:40;0,48
11-05-20 16:01:52;0,53
11-05-20 16:02:03;0,48
11-05-20 16:02:15;0,45
11-05-20 16:02:26;0,49
11-05-20 16:02:38;0,47
11-05-20 16:02:49;0,47`;

  var data = [];
  // convert CSV to correct data format
  $.each(csv.split('\n'), function(_, line) {
    var items = line.split(';')
      , d = items[0].replace(/(\d+)\-(\d+)\-(\d+) (.*)/, '20$3-$2-$1 $4')
      , n = items[1].replace(',', '.');
   
    data.push([
      new Date(d),
      Number(n)
    ]);
  });
 
  // create element for graph display, add to plan #1
  var el = $('<div></div>').css({
    position: 'absolute',
    width: 500,
    height: 300,
    left: 250,
    top: 380   
  }).appendTo('#plan-1').get(0);
 
  // create graph instance
  var graph = new Dygraph(el, data, {
    labels: [ '', 'My data' ],
    xAxisLabelWidth: 60
  });
});

graph should only be created once, to update it with new data use this:
Code:
graph.updateOptions({ file: data });

Hello Admin
Is it possible to use this way to show values from object logs as trend/curve?


RE: trends from an xml file - admin - 04.02.2021

You can use graph element to display object logs in the visualization


RE: trends from an xml file - khalil - 04.02.2021

(04.02.2021, 16:21)admin Wrote: You can use graph element to display object logs in the visualization

Thank you admin
I notice the graph element but i didnt use it before, great feature.