forked from singanjali/Analysis-Graph_plotting_tool
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathyears.py
More file actions
172 lines (144 loc) · 3.72 KB
/
years.py
File metadata and controls
172 lines (144 loc) · 3.72 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
#years plot
import pandas as pd
import matplotlib.pyplot as plt
import joblib
import numpy as np
import os
def isnumberr(numb):
#print(num)
num = str(numb)
#print("*")
isdec=0
#isneg=0
r=0
if(num[0]=='-'):
r=1
for i in range(r,len(num)):
if(num[i]>'9' or num[i]<'0'):
if(num[i]=='.' and isdec==0):
isdec=1
else:
return False
return True
pathgiven=input("Enter the path of file:")
firstY = int(input("Enter the first year: "))
LastY = int(input("Enter the last year: "))
print("Following are measures for yaxis to plot graph(xaxis:Months):")
print("1-Wind Direction")
print("2-Wind speed")
print("3-Temperature")
print("4-Pressure")
print("5-Humidity")
print("6-Dew point")
option = int(input("Choose One of the above:"))
#fol = "csv/"
fol = pathgiven+"/"
days=[]
year=[]
temp=[]
answer=[]
months=[]
YearMean=[]
YearNo=[]
#query
query={"1":"Wind Direction"
,"2":"Wind speed",
"3":"Temperature",
"4":"Pressure",
"5":"Humidity",
"6":"Dew point"
}
#csvNotations
csvNot={"1":"2","2":"3","3":"4","4":"6","6":"5"}
#xlsxNotations
xlsxNot={"1":"3","2":"4","3":"5","4":"6","5":"7","6":"8"}
#csv/i
for i in range (firstY,LastY+1):
NoOfMonths=0
MonthMean=0
#csv/i/j
for j in range (1,13):
if(os.path.isdir(fol+str(i)+"/"+str(j))==True):
months.append(j)
NoOfMonths+=1
Mans=0
Mnum=0
directory = os.fsencode(fol+str(i)+"/"+str(j))
for file in os.listdir(directory):
fname = os.fsdecode(file)
##if file is csv
if(fname[-3:]=="csv"):
print(fol + str(i) + "/" + str(j) + "/" + fname)
# .csv
dataframe = pd.read_csv(fol + str(i) + "/" + str(j) + "/" + fname)
newname = []
total_cols = len(dataframe.axes[1])
for coll in range(0, total_cols):
newname.append(str(coll))
dataframe.columns = newname
myfilename = "" + fol + str(i) + "/" + str(j) + "/" + fname + ""
newOpt = csvNot[str(option)]
col = dataframe[str(newOpt)]
mean = 0
num = 0
flag = 0
for k in range(0, len(col)):
# print(col[k])
# mean+=col[j]
# num+=1
# if(col[k]!="--.-" and col[k]!="---."):
if (isnumberr(col[k]) == True):
# print
flag = 1
mean += (float(col[k]))
num += 1
# (int(col[j]))
# temp.append(mean)
# print(num+" "+mean)
if (flag == 1):
ans = mean / num ##1 day
Mnum += 1 ##no of days
Mans += ans
if (fname[-4:] == "xlsx"):
if(isnumberr(fname[:2])==True):
myfilename = ""+fol+str(i)+"/"+str(j)+"/"+fname+""
print(fol+str(i)+"/"+str(j)+"/"+fname)
#.xlsx
dataframe = pd.read_excel(myfilename,"Sheet1")
#col = dataframe['TEMP_DEG']
#df.index
mean=0
num=0
flag=0
total_rows=len(dataframe.axes[0])
total_cols=len(dataframe.axes[1])
newOpt = xlsxNot[str(option)]
newOpt = int(newOpt)
for k in range(4,total_rows):
#print(dataframe.iloc[k][4]);
if(isnumberr(dataframe.iloc[k][newOpt])==True):
#print
flag=1
mean+=(float(dataframe.iloc[k][newOpt]))
num+=1
#temp.append(mean)
#print(num+" "+mean)
if(flag==1):
ans=mean/num
Mnum+=1
Mans+=ans
#temp.append(ans)
#print(temp)
finalAns=Mans/Mnum
MonthMean+=finalAns
year.append(finalAns)
if(NoOfMonths!=0):
YearMean.append(MonthMean/NoOfMonths)
YearNo.append(i)
print(finalAns)
print(year)
plt.plot(YearNo,YearMean,marker='o', markerfacecolor='red', markersize=9)
plt.xlabel('Year')
# naming the y axis
plt.ylabel(query[str(option)])
plt.show()