-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.js
More file actions
44 lines (34 loc) · 1.04 KB
/
Logger.js
File metadata and controls
44 lines (34 loc) · 1.04 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
class Logger {
constructor(){
this.fields = [];
this.actions = [];
}
logField = (field) => {
let index = this.fields.findIndex(e => e.position === field.position);
if(index !== -1){
this.fields[index].visitCount += 1;
}
else{
this.fields.push({...field, visitCount: 1})
}
}
logAction = (action) => {
/*let keepStored = 1000;
if(this.actions.length === keepStored) this.actions.shift();
this.actions.push(action);*/
}
toCSV = (data) => {
let table = null;
const seperator = ";";
for(const row of data){
if(table === null){
table = Object.keys(row).join(seperator) + '\n';
}
table += Object.values(row).join(seperator) + '\n';
}
return table;
}
getFields = () => this.fields.sort((a,b) => (a.visitCount > b.visitCount) ? 1 : ((b.visitCount > a.visitCount) ? -1 : 0));
getActions = () => this.actions;
}
export default Logger