Skip to content

main.js

Create an main.js file with the following content:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function eventAnalytics() {

  const eventAnalyticsInput = document.getElementById('eventAnalyticsInput').value;

  // region request for training model.
  const xhr = new XMLHttpRequest();
  xhr.open('POST', `/api/eventfilter/v3/filterEvents`, true);
  xhr.setRequestHeader('Content-Type', 'application/json');
  xhr.setRequestHeader('X-XSRF-TOKEN', getCookie("XSRF-TOKEN"));
  xhr.onreadystatechange = function() {
    if (xhr.readyState != 4) return;
    if (xhr.status != 200 && xhr.status != 201) {
      console.log(xhr.status + ': ' + xhr.statusText);
    }
    else {
      console.log(xhr.responseText);
      const response = JSON.parse(xhr.responseText);
      document.getElementById('eventAnalytics-result').textContent = JSON.stringify(response, undefined, 4);
    }
  }
  xhr.send(eventAnalyticsInput);
  // endregion.
}

function getCookie(cname) {
    var name = cname + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for(var i = 0; i <ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
        }
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}

document.addEventListener('DOMContentLoaded', () => {
  document.getElementById('eventAnalyticsInput').value = JSON.stringify({
  "eventsMetadata": {
    "eventTextPropertyName": "text"
  },
  "events": [
    {
      "_time": "2017-10-01T12:00:00.001Z",
      "text": "INTRODUCING FUEL",
      "text_qc": 0
    },
    {
      "_time": "2017-10-01T12:00:01.001Z",
      "text": "Status@Flame On",
      "text_qc": 0
    },
    {
      "_time": "2017-10-01T12:00:02.001Z",
      "text": "Status@Flame Off",
      "text_qc": 0
    },
    {
      "_time": "2017-10-01T12:00:03.001Z",
      "text": "Error code: 340",
      "text_qc": 0
    }
  ],
  "filterList": [
    "INTRODUCING FUEL",
    "MEANINGLESS ALARM",
    "Status@Flame On"
  ]
}, undefined, 4);
});

Any questions left?

Ask the community


Except where otherwise noted, content on this site is licensed under the MindSphere Development License Agreement.