-
Notifications
You must be signed in to change notification settings - Fork 9
/
get-stats.js
100 lines (90 loc) · 2.7 KB
/
get-stats.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
var fs = require('fs')
var data = fs.readFileSync('assets/data.json').toString()
var stats = {}
writeStats(data)
function writeStats(data) {
visits = formatData(data)
// Remove the item that is hometown visit
// and not painting visit
i = visits.findIndex(getHometownVisit)
visits.splice(i, 1)
// Get stats
getCountries(visits)
getMusuems(visits)
getVisible(visits)
getSeen(visits)
// Write it down
fs.writeFileSync('assets/stats.json', 'var stats = ' + JSON.stringify(stats, null, ' '))
console.log('✨\n')
}
function getHometownVisit (visit) {
return visit.visitID === 'delft'
}
function getCountries (data) {
var visited = []
var remaining = []
data.forEach(function (visit) {
// can't visit ones that aren't public
if (!visit.public) return
var country = visit.exhibitionCountry || visit.permanentCountry
if (!visit.seen) pushUnique(remaining, country)
else pushUnique(visited, country)
})
stats.visitedCountries = visited
stats.visitedCountriesLength = visited.length
stats.remainingCountries = remaining
stats.remainingCountriesLength = remaining.length
}
function getMusuems (data) {
var visited = []
var remaining = []
data.forEach(function (visit) {
// can't visit ones that aren't public
if (!visit.public) return
var location = visit.exhibitionLocation || visit.permanentLocation
if (!visit.seen) {
pushUnique(remaining, location)
}
else pushUnique(visited, location)
})
stats.visitedMuseums = visited
stats.visitedMuseumsLength = visited.length
stats.remainingMuseums = remaining
stats.remainingMuseumsLength = remaining.length
}
function getVisible (data) {
var public = []
var notPublic = []
data.forEach(function (piece) {
if (!piece.public) notPublic.push(piece.name)
else public.push(piece.name)
})
stats.public = public
stats.publicNo = public.length
stats.all = public.concat(notPublic)
stats.allLength = stats.all.length
stats.notPublic = notPublic
stats.notPublicLength = notPublic.length
}
function getSeen (data) {
var seen = []
var remaining = []
var remainingPublic = []
data.forEach(function (piece) {
if (!piece.seen && piece.public) remainingPublic.push(piece.name)
if (piece.seen) seen.push(piece.name)
else remaining.push(piece.name)
})
stats.seen = seen
stats.seenLength = seen.length
stats.remaining = remaining
stats.remainingPublic = remainingPublic
stats.remainingLength = remaining.length
stats.remainingPublicLength = remaining.length - 1 // minus not public pieces
}
function formatData (data) {
return JSON.parse(data.replace('var vermeers = ', ''))
}
function pushUnique (array, item) {
if (array.indexOf(item) < 0) array.push(item)
}