-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraph_data.py
125 lines (111 loc) · 3.85 KB
/
graph_data.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
#-*- coding: utf-8 -*-
import math
def get_data_from_file(filename):
tempfile = open(filename, 'r')
data = tempfile.read()
tempfile.close()
return data
def write_data_to_file(filename, data):
f = open(filename, 'a')
f.seek(0)
f.truncate()
f.write(str(data))
f.flush()
f.close()
def increase_slope():
graph_type = int(get_data_from_file('graph_type.txt'))
if graph_type == 0:
slope = int(get_data_from_file('linear_slope.txt'))
if slope >= 17:
slope = 17
else:
slope += 1
write_data_to_file('linear_slope.txt', slope)
elif graph_type == 1:
slope = int(get_data_from_file('exponential_slope.txt'))
slope += 15
write_data_to_file('exponential_slope.txt', slope)
elif graph_type == 2:
slope = round(float(get_data_from_file('sCurve_slope.txt')), 6)
slope += 0.0005
write_data_to_file('sCurve_slope.txt', round(slope, 6))
def decrease_slope():
graph_type = int(get_data_from_file('graph_type.txt'))
if graph_type == 0:
slope = int(get_data_from_file('linear_slope.txt'))
slope -= 1
write_data_to_file('linear_slope.txt', slope)
elif graph_type == 1:
slope = int(get_data_from_file('exponential_slope.txt'))
if slope <= 15:
slope = 15
else:
slope -= 15
write_data_to_file('exponential_slope.txt', slope)
elif graph_type == 2:
slope = round(float(get_data_from_file('sCurve_slope.txt')), 6)
if slope <= 0.0005:
slope = 0.0005
else:
slope -= 0.0005
write_data_to_file('sCurve_slope.txt', round(slope, 6))
def generate_graph_data_linear():
min_temp = 0.0
max_temp = 1200.0
min_rpm = 0.0
max_rpm = 1630
data_points = 96
slope = float(get_data_from_file('linear_slope.txt'))
temp_data = min_temp
rpm_data = max_rpm
temp_data_array = []
rpm_data_array = []
rpm_step = (max_rpm - min_rpm)/data_points
temp_step = (max_temp - min_temp)/data_points
for i in range(data_points + 1):
temp_data_array.append(round(temp_data,2))
rpm_data_array.append(round(rpm_data,2))
temp_data += temp_step
rpm_data = rpm_data - rpm_step + slope
if rpm_data <= 0:
rpm_data = 0
return temp_data_array, rpm_data_array
def generate_graph_data_exponential():
min_temp = 0.0
max_temp = 1200.0
min_rpm = 0.0
max_rpm = 1630
data_points = 96
slope = float(get_data_from_file('exponential_slope.txt'))
temp_data = min_temp
rpm_data = max_rpm
temp_data_array = []
rpm_data_array = []
rpm_step = (max_rpm - min_rpm)/data_points
temp_step = (max_temp - min_temp)/data_points
for i in range(data_points + 1):
temp_data_array.append(round(temp_data,2))
rpm_data_array.append(round(rpm_data,2))
temp_data += temp_step
rpm_data = max_rpm*(0.5**(temp_data/slope))
return temp_data_array, rpm_data_array
def generate_graph_data_sCurve():
min_temp = 0.0
max_temp = 1200.0
min_rpm = 0.0
max_rpm = 1630
data_points = 96
slope = float(get_data_from_file('sCurve_slope.txt'))
temp_data = min_temp
rpm_data = max_rpm
temp_data_array = []
rpm_data_array = []
rpm_step = (max_rpm - min_rpm)/data_points
temp_step = (max_temp - min_temp)/data_points
for i in range(data_points + 1):
temp_data_array.append(round(temp_data,2))
rpm_data = (max_rpm)/(1 + 2.718**(slope*(temp_data-(max_temp/2))))
rpm_data_array.append(round(rpm_data,2))
temp_data += temp_step
#rpm_data = (max_rpm/2)*math.cos(temp_data*0.5) + (max_rpm/2)
return temp_data_array, rpm_data_array