-
Notifications
You must be signed in to change notification settings - Fork 1
/
weatherHelper.py
69 lines (61 loc) · 2.61 KB
/
weatherHelper.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
# -*- coding: utf-8 -*-
import os
import datetime
import weatherPredict
def getYearsOfData(dataYears, todaysDate):
todaysYear = todaysDate.year
tempYearsList = [i for i in dataYears if i < todaysYear]
tempYearsList.sort()
return tempYearsList
def getDaysOfData(yearsFrameList, todaysDate):
todaysMonth = todaysDate.month
todaysDay = todaysDate.day
daysFrameList = []
for year in yearsFrameList:
daysFrameList.append(datetime.date(int(year), int(todaysMonth), int(todaysDay)))
return daysFrameList
def createFrameLists(dataYears, todaysDate):
yearsFrameList = getYearsOfData(dataYears, todaysDate)
daysFrameList = getDaysOfData(yearsFrameList, todaysDate)
return yearsFrameList, daysFrameList
def flattenWindows(windows):
returnWindow = {}
counter = 0
for i in windows:
for j in i:
returnWindow[counter] = i[j]
counter = counter + 1
return returnWindow
def reCalcPredicted(predicted, delta):
maxTemp = float(predicted["maxTemp"]) + delta["maxTempDelta"]
minTemp = float(predicted["minTemp"]) + delta["minTempDelta"]
rainfall = float(predicted["rainfall"]) + delta["rainfallDelta"]
morningHumidity = float(predicted["morningHumidity"]) + delta["morningHumidityDelta"]
eveningHumidity = float(predicted["eveningHumidity"]) + delta["eveningHumidityDelta"]
return {"maxTemp":maxTemp, "minTemp":minTemp, "rainfall":rainfall, "morningHumidity":morningHumidity, "eveningHumidity":eveningHumidity}
def predictWeather(todaysDate, frameSize):
dataYears = [2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013]
(yearsFrameList, daysFrameList) = createFrameLists(dataYears, todaysDate)
fitDF = weatherPredict.getDataFromCSV()
testFrame = weatherPredict.getTestFrame(fitDF, todaysDate, frameSize) #changed to fitFrame
fitFrames = []
for i in daysFrameList : fitFrames.append(weatherPredict.getFitFrame(fitDF, i, frameSize)) #changed to fitFrame
windows = []
for i in fitFrames : windows.append(weatherPredict.getWindows(i, frameSize)) #changed to fitFrame
windows = flattenWindows(windows)
euclideans = weatherPredict.getEuclideans(windows, testFrame)
cdWindows = weatherPredict.findCD(windows, euclideans)
deltas = [weatherPredict.calcPredictedVariations(i, testFrame) for i in cdWindows]
predicted = weatherPredict.getPredictedWeather(testFrame, deltas[0])
print "\n\nTest Frame"
print testFrame
for delta in deltas[1:]:
predicted = reCalcPredicted(predicted, delta)
return predicted, fitDF
if __name__ == "__main__":
todaysDate = datetime.date(2013,6,2)
frameSize = 7
(predicted, fitDF) = predictWeather(todaysDate, frameSize)
print "\n\nPredictions"
print predicted
print fitDF[fitDF["date"] == todaysDate]