-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.js
154 lines (148 loc) · 4.64 KB
/
process.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
const glob = require('glob');
const fs = require('fs');
const jsonfile = require('jsonfile');
const chalk = require('chalk');
const log = console.log;
const _ = require('lodash');
const ignoreList = [
'package-lock.json',
'node_modules',
'data',
'data/**.json',
'node_modules/**/*.json',
'data/filenames.json',
'resources/facebook_login.json'
];
const runTasks = {
'TASK_1': false,
'TASK_2': false,
'TASK_3': false
};
const fileParent = 'data';
const classfiedFileParent = 'data/classified';
const dashboardFolder = 'data/classified/dashboard';
const taxonomySpecFolder = 'data/classified/taxonomies_based';
function GetDashboarData(dataCategory) {
let file = `${dashboardFolder + '/' + 'all'}.json`;
if (dataCategory) {
file = `${dashboardFolder + '/' + dataCategory}.json`;
}
const contents = fs.readFileSync(file);
const data = JSON.parse(contents);
return data;
}
function GetTaxonomyData(parent, child) {
let data = null;
if (parent) {
parent = parent.toUpperCase();
}
if (child) {
child = child.toUpperCase();
}
if (parent && child) {
const file = `${classfiedFileParent}/taxonomies_based/${parent}.${child}.json`;
const contents = fs.readFileSync(file);
data = JSON.parse(contents);
}
return data;
}
function GetDashboardStatisticsData() {
let data = [];
let file = `${dashboardFolder + '/' + 'all'}.json`;
const contents = fs.readFileSync(file);
const fileData = JSON.parse(contents);
const items = [];
fileData.data.forEach(taxonomy => {
items.push(...taxonomy.taxonomies);
});
/* Network vs Location */
const locationData = items.find(x => x.name === 'LOCATION');
const networkData = items.find(x => x.name === 'NETWORK');
data.push({
id: 'network-location-comparison',
label: 'NETWORK vs LOCATION',
type: 'COMPARISON',
data: [
{ key: 'NETWORK', value: networkData.appsCount },
{ key: 'LOCATION', value: locationData.appsCount }
]
});
/* Network vs Location */
const accountData = items.find(x => x.name === 'ACCOUNT');
const contactData = items.find(x => x.name === 'CONTACTS');
data.push({
id: 'account-contacts-comparison',
label: 'ACCOUNT vs CONTACTS',
type: 'COMPARISON',
data: [
{ key: 'ACCOUNT', value: accountData.appsCount },
{ key: 'CONTACTS', value: contactData.appsCount }
]
});
/* Microphone vs Battery */
const microphoneData = items.find(x => x.name === 'MICROPHONE');
const batteryData = items.find(x => x.name === 'BATTERY');
data.push({
id: 'microphone-contacts-comparison',
label: 'MICROPHONE vs BATTERY',
type: 'COMPARISON',
data: [
{ key: 'MICROPHONE', value: microphoneData.appsCount },
{ key: 'BATTERY', value: batteryData.appsCount }
]
});
/* Device */
const deviceData = items.find(x => x.name === 'DEVICE');
data.push({
id: 'device-number',
label: 'DEVICE',
type: 'NUMBER',
data: [
{ key: 'Apps', value: deviceData.appsCount },
{ key: 'Requests', value: deviceData.requestsCount }
]
});
/* Calendar */
const calendarFile = `${taxonomySpecFolder}/PERSONAL.CALENDAR.json`
const calendarFileContents = fs.readFileSync(calendarFile);
const calendarFileData = JSON.parse(calendarFileContents);
data.push({
id: 'calendar-list',
label: 'Calendar',
type: 'LIST',
data: calendarFileData.uniqueApps.data
});
/* Apps With Most Taxonomies */
const appsFile = `${classfiedFileParent}/uniqued/apps.json`;
const appsFileContents = fs.readFileSync(appsFile);
const appsFileData = JSON.parse(appsFileContents);
let uniqueApps = appsFileData.data;
uniqueApps = uniqueApps.sort((x,y) => y.taxonomies.length - x.taxonomies.length);
const topApp = _.take(uniqueApps, 1)[0];
data.push({
id: 'apps-with-most-permissions',
label: 'App with most permissions',
type: 'App',
data: topApp
});
return data;
}
const result = GetDashboardStatisticsData();
console.log(JSON.stringify(result));
function GetFileName(file) {
const splits = file.split('/');
if (splits.length > 0) {
return splits[splits.length - 1];
}
return '';
}
function RemoveJSON(fileName) {
if (fileName.indexOf('.json') !== -1) {
const splits = fileName.split('.');
if (splits.length > 0) {
splits.pop();
}
return splits.join('.');
}
return fileName;
}