-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataProcessor3.js
143 lines (132 loc) · 6.59 KB
/
dataProcessor3.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
const dataStorage = require('./dataStorage.js')
const cron = require('node-cron');
const keys = require('./private/api-keys.json')
const admin = require("firebase-admin");
const fetch = require('node-fetch');
const fs = require('fs')
const moment = require('moment-timezone');
const nlp = require('compromise')
//const roster = require('./private/roster.json')
admin.initializeApp({
credential: admin.credential.cert(keys.firebase),
databaseURL: "https://hyphen-hacks-2019.firebaseio.com"
});
const startTime = moment().tz("America/Los_Angeles").format('MMM Do, HH:mm:ss')
const nodeVersion = process.version
console.log(`Hyphen-Hacks Data Processor v3 API Init ${startTime} Node ${nodeVersion}`)
function processData() {
console.log('Loading Data', moment().tz("America/Los_Angeles").format('MMMM Do YYYY, h:mm:ss a'))
let DS = new dataStorage()
DS.singleStat.init({path: 'totalPeople'})
DS.singleStat.init({path: 'attendees'})
DS.singleStat.init({path: 'mentors'})
DS.singleStat.init({path: 'volunteers'})
DS.singleStat.init({path: 'attendeesWithTeam'})
DS.singleStat.init({path: 'attendeesWithOutTeam'})
DS.singleStat.init({path: 'attendeesWithAcceptedWaivers'})
DS.singleStat.init({path: 'mentorsWithAcceptedWaivers'})
DS.singleStat.init({path: 'volunteersWithAcceptedWaivers'})
DS.singleStat.init({path: 'attendeesWithSubmittedWaivers'})
DS.singleStat.init({path: 'mentorsWithSubmittedWaivers'})
DS.singleStat.init({path: 'volunteersWithSubmittedWaivers'})
DS.singleStat.init({path: 'volunteersWithDeclinedWaivers'})
DS.singleStat.init({path: 'attendeesWithDeclinedWaivers'})
DS.singleStat.init({path: 'mentorsWithDeclinedWaivers'})
DS.textStat.init({path: 'attendeeGenderDistribution'})
DS.textStat.init({path: 'attendeeRaceDistribution'})
DS.textStat.init({path: 'schools'})
DS.textStat.init({path: 'shirtSizeDistribution'})
DS.textStat.init({path: 'foodAllergies'})
DS.textStat.init({path: 'graduationDistribution'})
DS.textStat.init({path: 'dietaryRestrictions'})
DS.textStat.init({path: 'attendeeTeamCodingExperience'})
DS.textStat.init({path: 'attendeeHackathonExperience'})
DS.textStat.init({path: 'attendeeHardwareExperience'})
DS.textStat.init({path: 'attendeeSoftwareExperience'})
DS.textStat.init({path: 'laptops'})
DS.multiTextStat.init({path: 'referrers'})
DS.multiTextStat.init({path: 'connections'})
DS.list.init({path: 'whyAreAttendeesInterested'})
DS.list.init({path: 'attendeeDescriptionOfCodingExperience'})
DS.list.init({path: 'specialNeeds'})
DS.list.init({path: 'attendeeBirthDays'})
DS.dateStat.init({path: 'attendeesSignedUp'})
admin.firestore().collection('people').get().then(snap => {
const timeFetched = moment().tz("America/Los_Angeles")
DS.setMeta({path: 'timeStamp', value: timeFetched})
console.log('downloaded Data', timeFetched.format('MMMM Do YYYY, h:mm:ss a'))
snap.forEach(i => {
const person = i.data()
if (!person.testApplicant && person.answers) {
DS.singleStat.increment({path: 'totalPeople'})
let role = ''
if (person.ticket_class_name === 'High school Student') {
role = 'attendee'
DS.singleStat.increment({path: 'attendees'})
DS.list.add({path: 'attendeeBirthDays', value: person.profile.birth_date})
DS.dateStat.add({path: 'attendeesSignedUp', value: person.created})
DS.textStat.increment({path: 'graduationDistribution', value: person.answers[0].answer})
DS.multiTextStat.increment({path: 'schools', value: person.answers[1].answer})
if (person.answers[23].answer) {
DS.multiTextStat.increment({path: 'referrers', value: person.answers[23].answer})
}
DS.textStat.increment({path: 'shirtSizeDistribution', value: person.answers[2].answer})
DS.textStat.increment({path: 'attendeeRaceDistribution', value: person.answers[3].answer})
DS.textStat.increment({path: 'attendeeGenderDistribution', value: person.answers[4].answer})
DS.textStat.increment({path: 'attendeeSoftwareExperience', value: person.answers[9].answer})
DS.textStat.increment({path: 'attendeeHardwareExperience', value: person.answers[10].answer})
DS.textStat.increment({path: 'attendeeHackathonExperience', value: person.answers[11].answer})
DS.textStat.increment({path: 'attendeeTeamCodingExperience', value: person.answers[12].answer})
DS.list.add({path: 'whyAreAttendeesInterested', value: person.answers[8].answer})
DS.list.add({path: 'attendeeDescriptionOfCodingExperience', value: person.answers[13].answer})
if (person.answers[22].answer.toLowerCase() === "yes") {
DS.singleStat.increment({path: 'attendeesWithTeam'})
} else {
DS.singleStat.increment({path: 'attendeesWithOutTeam'})
}
} else if (person.ticket_class_name === 'Mentor/Judge') {
role = 'mentor'
DS.singleStat.increment({path: 'mentors'})
} else {
DS.singleStat.increment({path: 'volunteers'})
DS.multiTextStat.increment({path: 'connections', value: person.answers[24].answer})
role = 'volunteer'
}
DS.textStat.increment({path: 'foodAllergies', value: person.answers[5].answer})
DS.textStat.increment({path: 'dietaryRestrictions', value: person.answers[6].answer})
if (person.answers[7].answer) {
DS.list.add({path: 'specialNeeds', value: person.answers[7].answer, filter: 'none'})
}
DS.textStat.increment({path: 'laptops', value: person.answers[21].answer})
if (person.waiverStatus === 1) {
DS.singleStat.increment({path: `${role}sWithSubmittedWaivers`})
} else if (person.waiverStatus === 2) {
DS.singleStat.increment({path: `${role}sWithAcceptedWaivers`})
}
if (person.waiverStatus === 3) {
DS.singleStat.increment({path: `${role}sWithDeclinedWaivers`})
}
}
})
const dataToSend = JSON.stringify(DS.getJSON())
admin.firestore().collection('secrets').doc('analytics').set(JSON.parse(dataToSend)).then(e => {
if (e.error) {
console.log(e.error)
} else {
console.log('written for v3')
}
})
fs.writeFile('./private/analyticsDatabase.json', dataToSend, (e) => {
if (e) {
console.log(e)
}
console.log('writen for legacy')
})
})
}
admin.firestore().collection('secrets').doc('changelog').onSnapshot(docSnapshot => {
console.log(`Received doc snapshot: ${moment().tz('America/Los_Angeles').format('dddd, MMMM Do YYYY, h:mm:ss a')}`);
processData()
}, err => {
console.log(`Encountered error: ${err}`);
});