Skip to content

Commit b36b3f5

Browse files
committed
@mbridak Fixed some rate queries.
1 parent 768ec40 commit b36b3f5

File tree

1 file changed

+97
-41
lines changed

1 file changed

+97
-41
lines changed

not1mm/ratewindow.py

Lines changed: 97 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __init__(self):
4848
self.database.current_contest = self.pref.get("contest", 0)
4949

5050
uic.loadUi(fsutils.APP_DATA_PATH / "ratewindow.ui", self)
51+
self.hide_unused()
5152
self.timer = QTimer()
5253
self.timer.timeout.connect(self.get_run_and_total_qs)
5354
self.timer.start(1000)
@@ -141,7 +142,7 @@ def get_run_and_total_qs(self):
141142
# last_hour
142143
# 10_last_qso
143144
# hundred_last_qso
144-
# since_starttime
145+
# since_lasthour_label since_lasthour
145146
# --------------------
146147
# time_on
147148
# time_off
@@ -161,47 +162,102 @@ def get_run_and_total_qs(self):
161162
# {'runs': 3, 'totalqs': 3}
162163

163164
# WHERE datetime(timestamp) > datetime(current_timestamp, '-60 minutes')
164-
if self.active:
165-
query = f"select sum(IsRunQSO) as runs, count(*) as totalqs from dxlog where ContestNR = {self.database.current_contest};"
166-
result = self.database.exec_sql(query)
165+
166+
if not self.active:
167+
return
168+
169+
# Get Q's in the 60 Minutes
170+
query = f"select (julianday(MAX(ts)) - julianday(MIN(ts))) * 24 * 60 as timespan, count(*) as items from (select * from dxlog where ContestNR = {self.database.current_contest} and datetime(TS) > datetime(current_timestamp, '-60 minutes'));"
171+
result = self.database.exec_sql(query)
172+
173+
if result.get("items", 0) < 1:
174+
self.last_hour.setText("--- Q/h")
175+
else:
167176
try:
168-
sandp = result.get("totalqs", 0) - result.get("runs", 0)
169-
self.run_qso.setText(f"{result.get("runs", 0)}")
170-
self.sandp_qso.setText(f"{sandp}")
171-
self.qso_counts.setText(f"{result.get("totalqs", 0)} pts")
172-
except TypeError:
177+
perhour = (60.0 / result.get("timespan", 60)) * result.get("items", 0)
178+
self.last_hour.setText(str(f"{perhour:.2f} Q/h"))
179+
except (ZeroDivisionError, TypeError):
173180
...
174181

175-
query = f"select count(*) as totalqs from dxlog where ContestNR = {self.database.current_contest} and datetime(TS) > datetime(current_timestamp, '-60 minutes');"
176-
result = self.database.exec_sql(query)
177-
self.last_hour.setText(f"{result.get("totalqs", 0)} Q/h")
182+
# Get Q's per hour rate of the last 10 QSO's
183+
query = f"SELECT (julianday(MAX(ts)) - julianday(MIN(ts))) * 24 * 60 as timespan, count(*) as items FROM ( select * from DXLOG where ContestNR = {self.database.current_contest} ORDER by ts DESC limit 10);"
184+
result = self.database.exec_sql(query)
185+
if result.get("items", 0) < 10:
186+
self.ten_last_qso.setText("--- Q/h")
187+
else:
188+
try:
189+
perhour = (60.0 / result.get("timespan", 60)) * result.get("items", 0)
190+
self.ten_last_qso.setText(str(f"{perhour:.2f} Q/h"))
191+
except (ZeroDivisionError, TypeError):
192+
...
178193

179-
query = f"SELECT (julianday(MAX(ts)) - julianday(MIN(ts))) * 24 * 60 as timespan, count(*) as items FROM DXLOG where ContestNR = {self.database.current_contest} ORDER by ts DESC limit 10;"
180-
result = self.database.exec_sql(query)
181-
print(f"{result=}\n{query=}")
182-
# timespan items
183-
if result.get("items", 0) < 2:
184-
self.ten_last_qso.setText(str(f"{result.get("items", 0)} Q/h"))
185-
else:
186-
try:
187-
perhour = (60.0 / result.get("timespan", 60)) * result.get(
188-
"items", 0
189-
)
190-
self.ten_last_qso.setText(str(f"{perhour:.2f} Q/h"))
191-
except (ZeroDivisionError, TypeError):
192-
...
193-
194-
query = f"SELECT (julianday(MAX(ts)) - julianday(MIN(ts))) * 24 * 60 as timespan, count(*) as items FROM DXLOG where ContestNR = {self.database.current_contest} ORDER by ts DESC limit 100;"
195-
result = self.database.exec_sql(query)
196-
print(f"{result=}\n{query=}")
197-
# timespan items
198-
if result.get("items", 0) < 2:
199-
self.hundred_last_qso.setText(str(f"{result.get("items", 0)} Q/h"))
200-
else:
201-
try:
202-
perhour = (60.0 / result.get("timespan", 60)) * result.get(
203-
"items", 0
204-
)
205-
self.hundred_last_qso.setText(str(f"{perhour:.2f} Q/h"))
206-
except (ZeroDivisionError, TypeError):
207-
...
194+
# Get Q's per hour rate of the last 100 QSO's
195+
query = f"SELECT (julianday(MAX(ts)) - julianday(MIN(ts))) * 24 * 60 as timespan, count(*) as items FROM (select * from DXLOG where ContestNR = {self.database.current_contest} ORDER by ts DESC limit 100);"
196+
result = self.database.exec_sql(query)
197+
if result.get("items", 0) < 100:
198+
self.hundred_last_qso.setText("--- Q/h")
199+
else:
200+
try:
201+
perhour = (60.0 / result.get("timespan", 60)) * result.get("items", 0)
202+
self.hundred_last_qso.setText(str(f"{perhour:.2f} Q/h"))
203+
except (ZeroDivisionError, TypeError):
204+
...
205+
206+
# Get rate for the current hour
207+
query = f"SELECT strftime('%Y-%m-%d %H:00:00','now') as limit_stamp, strftime('%H:00:00','now') as current_hour, count(*) as items FROM DXLOG where ContestNR = {self.database.current_contest} and datetime(TS) > limit_stamp;"
208+
result = self.database.exec_sql(query)
209+
210+
self.since_lasthour_label.setText(
211+
f"Since {result.get('current_hour', '00:00:00')}z:"
212+
)
213+
self.since_lasthour.setText(f"{result.get('items', '0')} QSO")
214+
215+
# Get Run QSO's and S&P QSO's
216+
query = f"select sum(IsRunQSO) as runs, count(*) as totalqs from dxlog where ContestNR = {self.database.current_contest};"
217+
result = self.database.exec_sql(query)
218+
try:
219+
sandp = result.get("totalqs", 0) - result.get("runs", 0)
220+
self.run_qso.setText(f"{result.get("runs", 0)}")
221+
self.sandp_qso.setText(f"{sandp}")
222+
self.qso_counts.setText(f"{result.get("totalqs", 0)} pts")
223+
except TypeError:
224+
...
225+
226+
# Get runs for the current hour
227+
query = f"SELECT strftime('%Y-%m-%d %H:00:00','now') as limit_stamp, sum(IsRunQSO) as runs, count(*) as totalqs FROM DXLOG where ContestNR = {self.database.current_contest} and datetime(TS) > limit_stamp;"
228+
result = self.database.exec_sql(query)
229+
try:
230+
sandp = result.get("totalqs", 0) - result.get("runs", 0)
231+
self.hour_run_qso.setText(f"{result.get("runs", 0)}")
232+
self.hour_sandp_qso.setText(f"{sandp}")
233+
except TypeError:
234+
...
235+
236+
def hide_unused(self):
237+
self.line.hide()
238+
self.label_10.hide()
239+
self.time_on.hide()
240+
self.label_12.hide()
241+
self.time_off.hide()
242+
243+
self.band_mode.hide()
244+
self.label_23.hide()
245+
self.avg_km.hide()
246+
self.label_25.hide()
247+
self.avg_pts.hide()
248+
self.best_dx.hide()
249+
self.label_26.hide()
250+
251+
self.line_5.hide()
252+
self.label_29.hide()
253+
self.label_30.hide()
254+
self.time_by_mult.hide()
255+
self.label_32.hide()
256+
self.qso_counts.hide()
257+
self.label_34.hide()
258+
self.mult_counts.hide()
259+
self.label_35.hide()
260+
self.mult_worth.hide()
261+
262+
self.line_6.hide()
263+
self.label_38.hide()

0 commit comments

Comments
 (0)