-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTotal.html
More file actions
85 lines (68 loc) · 2.38 KB
/
Total.html
File metadata and controls
85 lines (68 loc) · 2.38 KB
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
<div
id="widget_total"
class="rs-theme-dark"
role="widget"
style="width: 100%;"
></div>
<script defer>
function widget_total() {
var groups_to_check = [0,1,2,3,4,5,6,7,8,9,10]
var wgt = document.getElementById('widget_total');
var phrase = "Total inside: "
var now = new Date();
var startOfDay = new Date(now - (now % 86400000));
var now_time = Math.round(now.getTime() / 1000);
var startOfDay_time = Math.round(startOfDay.getTime() / 1000);
function processItem(item) {
return RTMIP.POST('/reports/events', {"profiles": [item[0]], "analytics": [9], "time_at": item[1], "time_to":now_time, "limit": 1000})
.catch((err)=>{
console.error(err)
})
}
async function processItems(ids_to_check) {
var result = 0
for (const id_time of ids_to_check) {
const prof_events = await processItem(id_time);
if (!prof_events["events"]) {
result++;
}
}
return result
}
var inside_now = 0;
wgt.innerHTML = phrase + inside_now;
var ids_to_check = []
var filter = { "analytics": [4], "time_at": startOfDay_time, "time_to": now_time,
"groups": groups_to_check, "limit": 1000
}
RTMIP.POST('reports/events', filter)
.then((events_map)=>{
if (!events_map["events"]) {
return
}
var events = events_map.events
for (var i in events) {
var event = events[i];
for (var j in event.items) {
var item = event.items[j];
if (item.profile) {
ids_to_check.push([item.profile.id, event.time_at])
}
}
}
})
.then(() =>{
processItems(ids_to_check).then((result) => {
inside_now = result;
var path = window.location.pathname;
var page = path.split("/").pop();
console.log(wgt.id + " " + page)
wgt.innerHTML = phrase + inside_now;
});
})
.catch((err)=>{
console.error(err)
})
}
widget_total();
</script>