This repository has been archived by the owner on Oct 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql_statements.py
153 lines (122 loc) · 7.05 KB
/
sql_statements.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Holds all SQL statements for the program
class SQLStatements:
# Select by ID and index
def select_by_ids_picture(self, hike_id: int, index_in_hike: int) -> str:
statement = 'SELECT * FROM pictures WHERE hike={id} AND \
index_in_hike={index}'.format(id=hike_id, index=index_in_hike)
return statement
# ******************** Time ********************
# Time - first & last across hikes
def select_by_time_first_picture(self) -> str:
statement = 'SELECT * FROM pictures ORDER BY time ASC LIMIT 1'
return statement
def select_by_time_last_picture(self) -> str:
statement = 'SELECT * FROM pictures ORDER BY time DESC LIMIT 1'
return statement
# Time - next & previous across hikes
def select_by_time_next_picture(self, time: float) -> str:
statement = 'SELECT * FROM pictures WHERE time>{t} \
ORDER BY time ASC LIMIT 1'.format(t=time)
return statement
def select_by_time_previous_picture(self, time: float) -> str:
statement = 'SELECT * FROM pictures WHERE time<{t} \
ORDER BY time DESC LIMIT 1'.format(t=time)
return statement
# Time - first & last in a hike
def select_by_time_first_picture_in_hike(self, hike_id: float) -> str:
statement = 'SELECT * FROM pictures WHERE hike={id} \
ORDER BY time ASC LIMIT 1'.format(id=hike_id)
return statement
def select_by_time_last_picture_in_hike(self, hike_id: float) -> str:
statement = 'SELECT * FROM pictures WHERE hike={id} \
ORDER BY time DESC LIMIT 1'.format(id=hike_id)
return statement
# Time - next & previous in a hike
def select_by_time_next_picture_in_hike(self, hike_id: float, time: float) -> str:
statement = 'SELECT * FROM pictures WHERE hike={id} AND time>{t} \
ORDER BY time ASC LIMIT 1'.format(id=hike_id, t=time)
return statement
def select_by_time_previous_picture_in_hike(self, hike_id: float, time: float) -> str:
statement = 'SELECT * FROM pictures WHERE hike={id} AND time<{t} \
ORDER BY time DESC LIMIT 1'.format(id=hike_id, t=time)
return statement
# ******************** Altitude ********************
# Altitude - greatest & least across hikes
def select_by_altitude_greatest_picture(self) -> str:
statement = 'SELECT * FROM pictures ORDER BY altitude DESC LIMIT 1'
return statement
def select_by_altitude_least_picture(self) -> str:
statement = 'SELECT * FROM pictures ORDER BY altitude ASC LIMIT 1'
return statement
# Altitude - count of same altitude across hikes
def find_size_by_altitude_greater_time(self, altitude: float, time: float) -> str:
statement = 'SELECT count(*) FROM pictures WHERE altitude={alt} \
AND time>{t}'.format(alt=altitude, t=time)
return statement
def find_size_by_altitude_less_time(self, altitude: float, time: float) -> str:
statement = 'SELECT count(*) FROM pictures WHERE altitude={alt} \
AND time<{t}'.format(alt=altitude, t=time)
return statement
# Altitude - next across hikes
def select_by_greater_altitude_next_picture(self, altitude: float) -> str:
statement = 'SELECT * FROM pictures WHERE altitude>{alt} \
ORDER BY altitude ASC, time ASC LIMIT 1'.format(alt=altitude)
return statement
def select_by_equal_altitude_next_picture(self, altitude: float, time: float) -> str:
statement = 'SELECT * FROM pictures WHERE altitude={alt} AND \
time>{t} ORDER BY altitude ASC, time ASC LIMIT 1'.format(alt=altitude, t=time)
return statement
# Altitude - previous across hikes
def select_by_less_altitude_previous_picture(self, altitude: float) -> str:
statement = 'SELECT * FROM pictures WHERE altitude<{alt} \
ORDER BY altitude DESC, time DESC LIMIT 1'.format(alt=altitude)
return statement
def select_by_equal_altitude_previous_picture(self, altitude: float, time: float) -> str:
statement = 'SELECT * FROM pictures WHERE altitude={alt} AND \
time<{t} ORDER BY altitude DESC, time DESC LIMIT 1'.format(alt=altitude, t=time)
return statement
# Altitude - greatest and least in a hike
def select_by_altitude_greatest_picture_in_hike(self, hike_id: float) -> str:
statement = 'SELECT * FROM pictures WHERE hike={id} \
ORDER BY altitude DESC LIMIT 1'.format(id=hike_id)
return statement
def select_by_altitude_least_picture_in_hike(self, hike_id: float) -> str:
statement = 'SELECT * FROM pictures WHERE hike={id} \
ORDER BY altitude ASC LIMIT 1'.format(id=hike_id)
return statement
# Altitude - count of same altitude in a hike
def find_size_by_altitude_greater_time_in_hike(self, hike_id: float,
altitude: float, time: float) -> str:
statement = 'SELECT count(*) FROM pictures WHERE hike={id} AND altitude={alt} \
AND time>{t}'.format(id=hike_id, alt=altitude, t=time)
return statement
def find_size_by_altitude_less_time_in_hike(self, hike_id: float,
altitude: float, time: float) -> str:
statement = 'SELECT count(*) FROM pictures WHERE hike={id} AND altitude={alt} \
AND time<{t}'.format(id=hike_id, alt=altitude, t=time)
return statement
# Altitdue - next in a hike
def select_by_greater_altitude_next_picture_in_hike(self, hike_id: float,
altitude: float) -> str:
statement = 'SELECT * FROM pictures WHERE hike={id} AND altitude>{alt} \
ORDER BY altitude ASC, time ASC LIMIT 1'.format(id=hike_id, alt=altitude)
return statement
def select_by_equal_altitude_next_picture_in_hike(self, hike_id: float,
altitude: float, time: float) -> str:
statement = 'SELECT * FROM pictures WHERE hike={id} AND altitude={alt} AND \
time>{t} ORDER BY altitude ASC, time ASC LIMIT 1'.format(id=hike_id, alt=altitude, t=time)
return statement
# Altitdue - previous in a hike
def select_by_less_altitude_previous_picture_in_hike(self, hike_id: float,
altitude: float) -> str:
statement = 'SELECT * FROM pictures WHERE hike={id} AND altitude<{alt} \
ORDER BY altitude DESC, time DESC LIMIT 1'.format(id=hike_id, alt=altitude)
return statement
def select_by_equal_altitude_previous_picture_in_hike(self, hike_id: float,
altitude: float, time: float) -> str:
statement = 'SELECT * FROM pictures WHERE hike={id} AND altitude={alt} AND \
time<{t} ORDER BY altitude DESC, time DESC LIMIT 1'.format(id=hike_id, alt=altitude, t=time)
return statement
# Color
# def select_by_color_next_picture() -> str:
# def select_by_color_previous_picture() -> str: