-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
138 lines (113 loc) · 5.68 KB
/
main.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
"""This is the main module. The user should run this module to generate a HTML file
displaying quantitative and qualitative findings of computations performed on dataset.
For a more detailed analysis, please refer to the final report.
By Freeman Cheng and Idris Tarwala
"""
from filter import filtered_data
from sheet import Sheet
from constants import MONTHS
import regressions
import regressions_error
import indicators
def execute() -> None:
"""Create an output HTML file describing the findings of various computations
performed on dataset.
"""
output = Sheet(filtered_data)
output.add_annotation('<h1>', 'CSC110 Final Project Output Sheet')
output.add_annotation('<p>', 'By Idris Tarwala and Freeman Cheng')
output.add_annotation('<h1>', 'General Overview')
output.add_annotation('<p>', '''
The dataset we used is taken from Pangaea, a data publisher for Earth and environmental studies.
The data showcases the average monthly temperature in the Adda basin river area in the Central Alps. Taking the
data from this area was a good choice as the temperature in the Central Alps varies throughout the year. This
will allow us to make better quantitative and qualitative estimations about climate trends. In order to get a clear
understanding of trends in the dataset, we have decided to use data dating back to the 1800’s. With our large scope
of data, it will allow us to be more accurate with our findings and hence our results. <br />
''')
output.add_annotation('<p>', '''
We determined which month was the hottest, median, and coldest on average.
Our results involve these three months.
''')
# Quantitative Findings
output.add_annotation('<h2>', 'Quantitative Findings')
types = ['Linear', 'Exponential', 'Polynomial']
graphs = [output.get_data()['hottest'], output.get_data()['median'], output.get_data()['coldest']]
titles = ['hottest', 'median', 'coldest']
for t in types:
for i in range(0, len(graphs)):
head, tail = regressions_error.get_head_tail(graphs[i])
figure = None
error = None
prediction = None
if t == 'Linear':
figure = regressions.plot_data_linear_regression(graphs[i])
prediction = regressions.predict_linear(graphs[i], 2100)
error = regressions_error.linear_regression_error(head, tail)
elif t == 'Exponential':
figure = regressions.plot_data_exponential_regression(
graphs[i])
prediction = regressions.predict_exponential(graphs[i], 2100)
error = regressions_error.exponential_regression_error(
head, tail)
elif t == 'Polynomial':
figure = regressions.plot_polynomial_regression(graphs[i])
output.add_annotation(
'<h3>', t + ' regression performed on ' + titles[i] + ' month.')
output.add_annotation(
'<p>', 'The ' + titles[i] + ' month was ' + MONTHS[graphs[i].month] + '.')
output.add_figure(figure)
if t in ('Linear', 'Exponential'):
output.add_annotation('<h4>', 'Error and Predictions')
output.add_annotation('<p>', 'Using the first half of our ' + MONTHS[graphs[i].month]
+ ' data, we can predict the second half with an average percentage error of '
+ str(round(error, 2)) + '%.')
output.add_annotation('<p>', 'The regression predicts the average ' + MONTHS[graphs[i].month]
+ ' temperature to be '
+ str(round(prediction, 2)) + ' °C in the year 2100.')
# Qualitative Findings
output.add_annotation('<h2>', 'Qualitative Findings')
types = ['Simple', 'Exponential']
for t in types:
for i in range(0, len(graphs)):
if t == 'Simple':
figure_1 = indicators.plot_simple_moving_average(graphs[i], True, False)
figure_2 = indicators.plot_simple_moving_average(graphs[i], False, True)
else:
figure_1 = indicators.plot_ema(graphs[i], True, False)
figure_2 = indicators.plot_ema(graphs[i], False, True)
output.add_annotation(
'<h3>', t + ' moving average performed on ' + titles[i] + ' month.')
output.add_annotation(
'<p>', 'The ' + titles[i] + ' month was ' + MONTHS[graphs[i].month] + '.')
output.add_figure(figure_1)
output.add_figure(figure_2)
output.add_annotation('<p>', 'The support and resistance lines indicate'
'the general trend which the temperatures '
'are heading towards.')
output.generate_sheet('sheet.html')
if __name__ == '__main__':
import pytest
import python_ta
import python_ta.contracts
pytest.main(['tests.py', '-vv'])
# uncomment this if want to see python_ta report
# python_ta.contracts.DEBUG_CONTRACTS = False
# python_ta.contracts.check_all_contracts()
# python_ta.check_all(config={
# 'extra-imports': [
# 'filter',
# 'sheet',
# 'constants',
# 'regressions',
# 'regressions_error',
# 'indicators',
# 'python_ta.contracts'
# ], # the names (strs) of imported modules
# 'allowed-io': [
# 'execute'
# ], # the names (strs) of functions that call print/open/input
# 'max-line-length': 150,
# 'disable': ['R1705', 'C0200']
# })
execute()