-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_shaper.py
executable file
·103 lines (76 loc) · 2.76 KB
/
data_shaper.py
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
#! /usr/bin/env python3
import pickle
import sys
import itertools
from datetime import datetime,date
def dePickle():
pickle_in = open('./vault/20190226data.pickle','rb')
pickledFile = pickle.load(pickle_in)
#pickle_in.close()
return pickledFile
def combine(field):
combinedList = []
for item in field:
for element in item:
combinedList.append(element)
return combinedList
def clean():
data = dePickle()
error = data.pop('error',None)
print(error)
_resort = []
_date = []
_snow = []
_temp = []
# get the list of resorts
for field in data:
Date = data[field]['date']
snow = data[field]['snow']
lTemp = data[field]['l_temp']
hTemp = data[field]['h_temp']
past24 = data[field]['past24']
# first element is night for the current day
snowDay = snow[0::2]
snowNight = snow[1::2]
# combine all the elements in the list
# [[1,2],[3,4]] => [1,2,3,4]
snowDay = combine(snowDay)
snowNight = combine(snowNight)
Date = combine(Date)
lTemp = combine(lTemp)
hTemp = combine(hTemp)
# process datetime strings
now = date.today()
year = now.strftime('%Y')
# add current year to datetime
Date = [i + '/' + year for i in Date]
n = 0
for i in Date:
Date[n] = datetime.strptime(i,'%m/%d/%Y')
n +=1
# process strings and remove unwanded characters
snowDay = list(map(lambda x:x.strip('\"').split('-'), snowDay))
snowNight = list(map(lambda x:x.strip('\"').split('-'),snowNight))
# remove '-' character, keep grouping and convert to int
snowDay = list(map(lambda x: [int(i) for i in x], snowDay))
snowNight = list(map(lambda x: [int(i) for i in x], snowNight))
# replace degree F swymbol from temps using list comprehension
lTemp = [s.replace(u'\N{DEGREE SIGN}F', '') for s in lTemp]
hTemp = [s.replace(u'\N{DEGREE SIGN}F', '') for s in hTemp]
# convert strings to int
lTemp = list(map(lambda x:int(x),lTemp))
hTemp = list(map(lambda x: int(x),hTemp))
print('Resort: {}\n'.format(field))
print('Dates:\n{}'.format(Date))
print(type(Date[1]))
print('Low Temp:\n{}'.format(lTemp))
print('High Temp:\n{}'.format(hTemp))
print('Day:\n{}'.format(snowDay))
print('Night:\n{}'.format(snowNight))
print('data:\n{}'.format(past24))
print('--------------------------------------------')
return
def main():
return clean()
if __name__ == '__main__':
sys.exit(main())