Skip to content
Snippets Groups Projects
Commit b677b618 authored by Georgi's avatar Georgi
Browse files

General update to the helper functions used by different views

parent e5847e74
No related branches found
No related tags found
No related merge requests found
//method to parse the data used for the timeline and package it to be displayed //method to parse the data used for the timeline and package it to be displayed
function create_timeline_evidences(data) { function create_timeline_evidences(data, unique) {
var period = data.period; var period = data.period;
var interval = data.interval; var interval = data.interval;
var evidences = data.evidences; var evidences = data.evidences;
...@@ -15,6 +15,10 @@ function create_timeline_evidences(data) { ...@@ -15,6 +15,10 @@ function create_timeline_evidences(data) {
for (var a = 0; a < agents.length; a++) { for (var a = 0; a < agents.length; a++) {
var filtered_ev = []; var filtered_ev = [];
(bin === null) ? filtered_ev = [] : filtered_ev = bin.filter(ev => ev.label === agents[a].label); (bin === null) ? filtered_ev = [] : filtered_ev = bin.filter(ev => ev.label === agents[a].label);
if (unique == true) {
filtered_ev = filter_unique_ev(filtered_ev);
}
//console.log(filtered_ev);
const timeline_evidence = {"label" : agents[a].label, const timeline_evidence = {"label" : agents[a].label,
"amount" : filtered_ev.length, "amount" : filtered_ev.length,
"evidences" : filtered_ev, "evidences" : filtered_ev,
...@@ -25,6 +29,29 @@ function create_timeline_evidences(data) { ...@@ -25,6 +29,29 @@ function create_timeline_evidences(data) {
return timeline_evidences; return timeline_evidences;
} }
//method for filtering unique evidences from an array of create_donut_evidences
function filter_unique_ev(ev_array) {
//console.log(ev_array);
var unique_evs = [];
//check the format of the filtered_ev array and leave only last unique ones
for (var i = 0; i < ev_array.length; i++) {
if (unique_evs.length == 0) {
unique_evs.push(ev_array[i]);
} else {
const index = unique_evs.findIndex(e => _.isEqual(e.subject, ev_array[i].subject));
if (index > -1) {
if (ev_array[i].score > unique_evs[index]) {
unique_evs[index] = ev_array[i];
}
} else {
unique_evs.push(ev_array[i]);
}
}
}
//console.log(unique_evs);
return unique_evs;
}
//method for counting number of evidences per agent in the database to be used by the donut chart //method for counting number of evidences per agent in the database to be used by the donut chart
function create_donut_evidences(data) { function create_donut_evidences(data) {
const donut_evidences = []; const donut_evidences = [];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment