-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenData.py
More file actions
215 lines (163 loc) · 6.52 KB
/
genData.py
File metadata and controls
215 lines (163 loc) · 6.52 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
''''
Author: Alison
Generate random data for testing purposes
NOTE: Run this file once to generate new info (note that it WILL NOT be cleaned up, so
duplicate entries from the same person will still be there. Once a Datta object is created, process will be done :)
'''
import gspread
import random
class GenData():
def __init__(self):
"""Creates a new class to generate random data
"""
self.sa = gspread.service_account()
self.sh = self.sa.open("CSUS Parking Data")
self.wWks = self.sh.worksheet("WeeklyInfo") # weekly
self.wAllInfo = self.wWks.get_all_values() # NOTE: QUOTA
self.wNumRows = len(self.wAllInfo)
self.wKey = self.wAllInfo[0] # first row (zero indexed) is the key
self.wAllInfo.pop(0)
self.bWks = self.sh.worksheet("BaseInfo") # weekly
self.bAllInfo = self.bWks.get_all_values() # NOTE: QUOTA
self.bNumRows = len(self.bAllInfo)
self.bKey = self.bAllInfo[0] # first row (zero indexed) is the key
self.bAllInfo.pop(0)
self.sWks = self.sh.worksheet("Students") # weekly
self.sAllInfo = self.sWks.get_all_values() # NOTE: QUOTA
self.sNumRows = len(self.sAllInfo)
self.sKey = self.sAllInfo[0] # first row (zero indexed) is the key
self.sAllInfo.pop(0)
def clearWeeklySheet(self, resetInfo:'bool'=False):
"""Clears the sheet (excludes the key! Never clear the key, or the first row)
"""
self.wWks.delete_rows(2,self.wNumRows)
if resetInfo:
self.wAllInfo = []
def clearBaseSheet(self, resetInfo:'bool'=False):
"""Clears the sheet (excludes the key! Never clear the key, or the first row)
"""
self.bWks.delete_rows(2,self.bNumRows)
if resetInfo:
self.bAllInfo = []
def genWeeklyData(self, cap):
"""Generates new weekly data
Args:
cap (int): number of rows
"""
self.clearWeeklySheet(True)
sz = len(self.sAllInfo)-1
newInfo = []
for i in range(cap):
newRow = []
timestamp = "generated" + str(random.randint(0,5))
newRow.append(timestamp)
person = random.randint(0,sz)
email = self.sAllInfo[person][0]
newRow.append(email)
qualify = 'Yes'
newRow.append(qualify)
# seniors
for i in range(5):
val = random.random()
if val < 0.40: # carpool
carpool = '0'
elif val < 0.70:
carpool = '1'
elif val< 0.90:
carpool = '2'
else: carpool = '3+'
newRow.append(carpool)
# random
for i in range(5):
val = random.random()
if val < 0.40: # carpool
carpool = '0'
elif val < 0.70:
carpool = '1'
elif val< 0.90:
carpool = '2'
else: carpool = '3+'
newRow.append(carpool)
critAccess = []
if random.random() < 0.5: # critical access monday
critAccess.append("Monday")
if random.random() < 0.5: # critical access tuesday
critAccess.append("Tuesday")
if random.random() < 0.5: # critical access wednesday
critAccess.append("Wednesday")
if random.random() < 0.5: # critical access thursday
critAccess.append("Thursday")
if random.random() < 0.5: # critical access friday
critAccess.append("Friday")
newRow.append(", ".join(critAccess))
newRow.append("critical access explanation")
sports = []
if random.random() < 0.5: # sports access monday
sports.append("Monday")
if random.random() < 0.5: # sports access tuesday
sports.append("Tuesday")
if random.random() < 0.5: # sports access wednesday
sports.append("Wednesday")
if random.random() < 0.5: # sports access thursday
sports.append("Thursday")
if random.random() < 0.5: # sports access friday
sports.append("Friday")
newRow.append(", ".join(sports))
newRow.append("sports/ecs access explanation")
newInfo.append(newRow)
self.wWks.insert_rows(newInfo,2)
# print(newInfo)
print("generated new WEEKLY data :)")
def genBaseData(self):
"""Generate base data for all
"""
self.clearBaseSheet(True)
newInfo = []
for row in self.sAllInfo:
newRow = []
timestamp = "generated"
newRow.append(timestamp)
email = row[0]
newRow.append(email)
if random.random() < 0.7: # more probability to be able to drive
qualify = 'Yes'
else: qualify = 'No'
newRow.append(qualify)
if random.random() < 0.2: # 2/10 people have first period free, idk
firstFree = 'Yes'
else: firstFree = 'No'
newRow.append(firstFree)
if random.random() < 0.2: # 2/10 people have last period free, idk
lastFree = 'Yes'
else: lastFree = 'No'
newRow.append(lastFree)
if random.random() < 0.3: # only one third of people can parallel park
para = 'Yes'
else: para = 'No'
newRow.append(para)
if random.random() < 0.3: # only one third of people have large cars
size = 'Large'
else: size = 'Small'
newRow.append(size)
# get zipcode
n = random.random()
if n < 0.2: # just choose from these zipcodes
zip = '94010' # Burlingame
elif n < 0.4:
zip = '94002' # Belmont
elif n < 0.6:
zip = '94025' # Menlo Park
elif n < 0.8:
zip = '94105' # San Francisco
else: zip = '95014' # Los Altos
newRow.append(zip)
newInfo.append(newRow)
self.bWks.insert_rows(newInfo,2)
# print(newInfo)
print("generated new BASE data :)")
def main():
data = GenData()
# COMMENT OUT THE BELOW ACCORDING TO WHAT YOU WANT TO SIMULATE!
data.genWeeklyData(150)
data.genBaseData()
if __name__ == '__main__': main()