Implement adding reports from wrintermapsreport to wrintermapsreportshistory.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Tue, 17 Dec 2019 20:19:16 +0000 (20:19 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Tue, 17 Dec 2019 20:19:16 +0000 (20:19 +0000)
git-svn-id: http://www.winterrodeln.org/svn/wrpylib/trunk@2864 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrpylib/wrintermaps.py

index 57dfcfd1ed8bb80aeb9ed4fd8a8f075c69a7d9fa..9ae6cab93fa8a5445ee7d8ef4f7ab29b200695d5 100644 (file)
@@ -69,7 +69,25 @@ def update_wrintermapssledrun(session, json_content: dict):
 
 def update_wrintermapsreport(session, json_content: dict, last_check: datetime.datetime):
     # add current content of intermaps_report to intermaps_history
-    pass
+    # the following lines are equivilent to
+    # insert into wrintermapsreporthistory (intermaps_sledrun_id, status, last_update, first_check, utc_offset)
+    #   select intermaps_sledrun_id, status, last_update, last_check, utc_offset from wrintermapsreport r
+    #   where not exists (select 1 from wrintermapsreporthistory h
+    #     where h.intermaps_sledrun_id=r.intermaps_sledrun_id and h.status=r.status and
+    #     h.last_update=r.last_update and h.utc_offset=r.utc_offset);
+    q = session.query(WrIntermapsReportHistory) \
+        .filter(WrIntermapsReportHistory.intermaps_sledrun_id == WrIntermapsReport.intermaps_sledrun_id) \
+        .filter(WrIntermapsReportHistory.status == WrIntermapsReport.status) \
+        .filter(WrIntermapsReportHistory.last_update == WrIntermapsReport.last_update) \
+        .filter(WrIntermapsReportHistory.utc_offset == WrIntermapsReport.utc_offset)
+    for report in session.query(WrIntermapsReport).filter(~q.exists()):
+        report_history = WrIntermapsReportHistory()
+        report_history.intermaps_sledrun_id = report.intermaps_sledrun_id
+        report_history.status = report.status
+        report_history.last_update = report.last_update
+        report_history.first_check = report.last_check
+        report_history.utc_offset = report.utc_offset
+        session.add(report_history)
 
     # delete content of intermaps_report
     session.query(WrIntermapsReport).delete()