-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata-service.js
58 lines (52 loc) · 1.68 KB
/
data-service.js
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
function DataService(results) {
let isInit = false;
function initData(results) {
let parsedata = results.data;
console.log(parsedata);
// const spelling = trainSpelling(parsedata);
isInit = true;
return parsedata;
}
let data = initData(results);
let selection = extractKeyValues(data);
let wordleData;
showSelections(selection);
function extractKeyValues(data) {
// data = doneParse();
// Get all possible keys; delete empty keys and ignore column 1
let keys = Object.keys(data[0]).filter((val) => {
console.log(`val: ${val}`);
return val !== "";
});
if (keys.length > 1) {
keys = keys.slice(1, keys.length);
} else {
return keys;
}
// Create global object to hold the selection
let selection = {};
// Get all possible values for each key, then put the unique array into selection object
// Result: selection = {key1: [value1, value2, value3], key2: [value1, value2, value3]}
keys.map((val) => {
let tempdata = data.map((sub) => sub[val]);
let tempset = new Set(tempdata);
selection[val] = [...tempset];
});
return selection;
}
return {
getData() {
if (!isInit) throw new Error(`You did not init the DataService yet dummy!!`);
return data;
},
setWordleData(parseData) {
wordleData = checkFilters()
},
getSelection() {
return selection;
},
updateSelectionGroup(data) {
selection = extractKeyValues(data);
}
}
}