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
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
function eventAnalytics() {

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

  // region request for training model.
  const xhr = new XMLHttpRequest();
  xhr.open('POST', `/api/eventremoval/v3/removeDuplicateEvents`, 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",
    "splitInterval": 5000
  },
  "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:01.081Z",
      "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:04.091Z",
      "text": "Error code: 340",
      "text_qc": 0
    },
    {
      "_time": "2017-10-01T12:00:03.001Z",
      "text": "Error code: 340",
      "text_qc": 0
    },
    {
      "_time": "2017-10-01T12:00:04.001Z",
      "text": "Error code: 340",
      "text_qc": 0
    },
    {
      "_time": "2017-10-01T12:00:04.061Z",
      "text": "Error code: 340",
      "text_qc": 0
    },
    {
      "_time": "2017-10-01T12:00:05.001Z",
      "text": "Error code: 340",
      "text_qc": 0
    },
    {
      "_time": "2017-10-01T12:00:06.001Z",
      "text": "INTRODUCING FUEL",
      "text_qc": 0
    },
    {
      "_time": "2017-10-01T12:00:06.231Z",
      "text": "INTRODUCING FUEL",
      "text_qc": 0
    },
    {
      "_time": "2017-10-01T12:00:08.001Z",
      "text": "Status@Flame On",
      "text_qc": 0
    },
    {
      "_time": "2017-10-01T12:00:09.001Z",
      "text": "Status@Flame On",
      "text_qc": 0
    },
    {
      "_time": "2017-10-01T12:00:09.231Z",
      "text": "INTRODUCING FUEL",
      "text_qc": 0
    }
  ]
}, undefined, 4);
});

Any questions left?

Ask the community


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