-
Notifications
You must be signed in to change notification settings - Fork 1
/
process.mjs
69 lines (53 loc) · 1.37 KB
/
process.mjs
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
import { readFileSync, writeFileSync, rmdirSync, mkdirSync } from 'fs'
const files = [
'appletvs.json',
'ipads.json',
'iphones.json',
'macs.json',
'other.json',
'wearables.json',
]
const keys = [
'readableName',
'deviceType',
'processorType',
'processorFamily',
'systemFirstRelease',
'systemLastRelease',
]
function prepare() {
try {
rmdirSync('./output', { recursive: true })
} catch (err) {}
mkdirSync('./output')
}
function getDataFromFiles(files, key) {
var allFilesData = {}
for (const file of files) {
const data = readFileSync('./dataset/' + file, { encoding: 'utf8' })
const json = JSON.parse(data)
allFilesData = { ...allFilesData, ...json }
}
return allFilesData
}
function extractKey(data, key) {
const extractedData = {}
for (let device in data) {
extractedData[device] = data[device][key]
}
return extractedData
}
function writeDataToFile(jsonData, fileName) {
const data = JSON.stringify(jsonData)
writeFileSync('./output/' + fileName, data)
}
function process(files, key) {
const data = getDataFromFiles(files, key)
const extractedData = extractKey(data, key)
writeDataToFile(extractedData, key + '.json')
}
prepare()
for (const key of keys) {
console.log('Processing ' + key + '...')
process(files, key)
}