-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
173 lines (147 loc) · 5.37 KB
/
utils.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
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
import os
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import pdb
def get_last_file(folder):
files_list = os.listdir(folder)
sorted = np.sort(files_list)
full_path = os.path.join(folder, sorted[-1])
print("read", full_path)
return full_path
def get_files_list(folder):
return np.sort(os.listdir(folder))
def get_files_number(folder):
return len(os.listdir(folder))
def create_info_dict(row_values):
info_dict = {
'kids': int(np.sum(row_values[2:4])),
'teenagers': int(np.sum(row_values[4:6])),
'young': int(np.sum(row_values[6:9])),
'adults': int(np.sum(row_values[9:12])),
'experienced': int(np.sum(row_values[12:15])),
'pensionates':int(np.sum(row_values[15:18])),
'over80': int(np.sum(row_values[18:])),
'total': int(np.sum(row_values[2:]))
}
return info_dict
def get_labels():
expl_dict = {
'kids': "bambini (0-9)",
'teenagers': "ragazzi (10-19)",
'young': "giovani (20-34)",
'adults': "adulti (35-49)",
'experienced': "esperti (50-64)",
'pensionates': "pensionati (65-80)",
'over80': "over 80 (80+)",
'total': "totale"
}
return expl_dict
def append_values(fulL_data, single_day, labels):
for label in labels:
fulL_data[label].append(single_day[label])
def plot_pie_chart(info_dict):
labels = []
values = []
for k in info_dict.keys():
if not k == "total":
labels.append(k)
values.append(info_dict[k])
plt.pie(values, labels=labels)
plt.show()
class df_comune(object):
"""a class with base methods"""
def __init__(self, file_path):
try:
self.df = pd.read_html(file_path)[0]
self.isEmpty = False
except:
self.df = None
self.isEmpty = True
def isValid(self):
if self.isEmpty is True:
return False
return True
def get_venezia_insulare(self):
"""venezia, murano, burano"""
row_c1 = self.df["Municipalita'"] == "VENEZIA - MURANO - BURANO (VENEZIA INSULARE)"
row_c2 = self.df["Sesso"] == "M+F"
row_values = row_c1.values*row_c2.values
index = np.argmax(row_values.astype(int))
row_values = self.df.iloc[index]
info_dict = create_info_dict(row_values)
return info_dict
def get_venezia_litorale(self):
row_c1 = self.df["Municipalita'"] == "LIDO - PELLESTRINA (VENEZIA LITORALE)"
row_c2 = self.df["Sesso"] == "M+F"
row_values = row_c1.values*row_c2.values
index = np.argmax(row_values.astype(int))
row_values = self.df.iloc[index]
info_dict = create_info_dict(row_values)
return info_dict
def get_totale_comune(self):
row_c1 = self.df["Municipalita'"] == "TOTALI"
row_c2 = self.df["Sesso"] == "M+F"
row_values = row_c1.values*row_c2.values
index = np.argmax(row_values.astype(int))
row_values = self.df.iloc[index]
info_dict = create_info_dict(row_values)
return info_dict
class df_isole(object):
"""a class with base methods"""
def __init__(self, file_path):
try:
self.df = pd.read_html(file_path)[0]
self.isEmpty = False
except:
self.df = None
self.isEmpty = True
def isValid(self):
if self.isEmpty is True:
return False
return True
def get_est(self):
"""san marco, castello, cannaregio, sant'elena"""
row_c1 = self.df["Quartiere"] == "S. MARCO, CASTELLO, S. ELENA, CANNAREGIO"
row_c2 = self.df["Sesso"] == "M+F"
row_values = row_c1.values*row_c2.values
index = np.argmax(row_values.astype(int))
row_values = self.df.iloc[index]
info_dict = create_info_dict(row_values)
return info_dict
def get_ovest(self):
"""dorsoduro, san polo, santa croce, giudecca"""
row_c1 = self.df["Quartiere"] == "DORSODURO, S. POLO, S. CROCE, GIUDECCA, SACCA FISO"
row_c2 = self.df["Sesso"] == "M+F"
row_values = row_c1.values*row_c2.values
index = np.argmax(row_values.astype(int))
row_values = self.df.iloc[index]
info_dict = create_info_dict(row_values)
return info_dict
def get_murano(self):
"""murano, s.erasmo"""
row_c1 = self.df["Quartiere"] == "MURANO, S. ERASMO"
row_c2 = self.df["Sesso"] == "M+F"
row_values = row_c1.values*row_c2.values
index = np.argmax(row_values.astype(int))
row_values = self.df.iloc[index]
info_dict = create_info_dict(row_values)
return info_dict
def get_burano(self):
"""burano, mazzorbo, torcello"""
row_c1 = self.df["Quartiere"] == "BURANO, MAZZORBO, TORCELLO"
row_c2 = self.df["Sesso"] == "M+F"
row_values = row_c1.values*row_c2.values
index = np.argmax(row_values.astype(int))
row_values = self.df.iloc[index]
info_dict = create_info_dict(row_values)
return info_dict
def get_total(self):
"""tutti"""
row_c1 = self.df["Quartiere"] == "TOTALI"
row_c2 = self.df["Sesso"] == "M+F"
row_values = row_c1.values*row_c2.values
index = np.argmax(row_values.astype(int))
row_values = self.df.iloc[index]
info_dict = create_info_dict(row_values)
return info_dict