-
Notifications
You must be signed in to change notification settings - Fork 0
/
Weather Data
172 lines (136 loc) · 5.18 KB
/
Weather Data
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
import os
from glob import glob
import pandas as pd
import csv
PATH = "C:\\Users\\Hamza\\Desktop\\weatherfiles"
EXT = "*.csv"
#path assign of per file
all_csv_files = [] # all path in it
for path, subdir, files in os.walk(PATH):
for file in glob(os.path.join(path, EXT)):
all_csv_files.append(file)
#print(all_csv_files)
class weather:
date=[]
maxtemp=[]
mintemp=[]
humidity=[]
date2=[]
Month=[]
maxvaluewithinput=[] # Max TemperatureC Column data in it
minvaluewithinput=[] # Min TemperatureC Column in it
maxhumvaluewithinput=[] #Max Humidity column in it
for x in all_csv_files:
with open(x, newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
#print(row)
date.append(row.get('PKT') or row.get('PKST'))
maxtemp.append(row.get('Max TemperatureC'))
mintemp.append(row.get('Min TemperatureC'))
humidity.append(row.get('Max Humidity'))
def datedata(self,f):
y=0
for x in self.date:
da=x.split("-") or x.split("/")
year=da[0]
#month=da[1]
#print(year)
#print(da[1]+"/"+da[2]+"/"+year)
if year==f:
#print("y="+str(y))
if self.maxtemp[y] != "":
#print(da[2])
self.date2.append(da[2])
self.Month.append(da[1])
self.maxvaluewithinput.append(int(self.maxtemp[y]))
if self.mintemp[y] != "":
self.minvaluewithinput.append(int(self.mintemp[y]))
if self.humidity[y] != "":
self.maxhumvaluewithinput.append(int(self.humidity[y]))
y=y+1
else:
y=y+1
else:
y=y+1
#print("MaxTemperature: "+str(self.maxvaluewithinput))
#print("Mintemperature: "+str(self.minvaluewithinput))
#print("Humidity: "+str(self.maxhumvaluewithinput))
#else:
# y=y+1
#print(minvaluewithinput)
#print(self.date2)
maxnumber=max(self.maxvaluewithinput)
minnumber=min(self.minvaluewithinput)
maxhumi=max(self.maxhumvaluewithinput)
return (maxnumber, minnumber,maxhumi)
#Calculation of Highest Lowest Temperature and Humidty
#function for finding maximum temperature
def maxvalues(self,z,maxnumber):
for x in self.maxvaluewithinput:
if x==maxnumber:
print('Maximum temperature is: '+str(maxnumber)+" C "+' on the date of: '+self.date2[z]+' on the Month: '+self.Month[z])
break
z=z+1
#function for finding lowest temperature
def minvalues(self,z,minnumber):
for x in self.minvaluewithinput:
if x==minnumber:
print('Lowest temperature is: '+str(minnumber)+" C "+' on the date of: '+self.date2[z]+' on the Month: '+self.Month[z])
break
z=z+1
#function for finding humidity
def humidty(self,z,maxhumi):
for x in self.maxhumvaluewithinput:
if x==maxhumi:
print('Humidty is: '+str(maxhumi)+" % "+' on the date of: '+self.date2[z]+' on the Month: '+self.Month[z])
break
z=z+1
#Average CalCulations
#average maximum temperature
def averagetemp(self,y,num,maxnumber):
for x in self.maxvaluewithinput:
if x==maxnumber:
y=y+1
num=num+maxnumber
#print("Maxnum"+str(num))
#print("Maxnum"+str(y))
averagetemp=num/y
print("Average Max temperature: "+str(averagetemp)+"C")
#average minimum temperature
def averagemintemp(self,y,num,minnumber):
for x in self.minvaluewithinput:
if x==minnumber:
#print(x)
y=y+1
num=num+minnumber
averagetemp=num/y
print("Average Min temperature: "+str(averagetemp)+"C")
#average humidity
def averagehum(self,y,num,maxhumi):
for x in self.maxhumvaluewithinput:
if x==maxhumi:
y=y+1
num=num+maxhumi
averagehum=num/y
print("Average Min Humidity: "+str(averagehum)+"%")
#main for calling all the functions
def main():
a,b=0,0
name = input("Enter a name: ")
years=['2004','2005','2006','2007','2008','2009','2010','2011','2012','2013','2014','2015','2016']
for x in years:
if x==name:
emp1=weather()
maxnumber, minnumber,maxhumi= emp1.datedata(name)
emp1.maxvalues(a,maxnumber)
emp1.minvalues(a,minnumber)
emp1.humidty(a,maxhumi)
emp1.averagetemp(a,b,maxnumber)
emp1.averagemintemp(a,b,minnumber)
emp1.averagehum(a,b,maxhumi)
elif name<"2004" or name>"2016":
print("You enter wrong Input")
break
if __name__ == "__main__":
main()