|
12 | 12 | from django.db import DatabaseError |
13 | 13 | import pandas as pd |
14 | 14 | from django.utils.timezone import make_aware, is_naive |
| 15 | +from datetime import datetime |
15 | 16 |
|
16 | 17 |
|
17 | 18 | BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) |
@@ -138,15 +139,34 @@ def determine_sync_status(f): |
138 | 139 | """ |
139 | 140 | Helper to determine sync status between published and the database record counts. |
140 | 141 | """ |
| 142 | + if is_current_month(f): |
| 143 | + return "OK [ Current month ]" |
| 144 | + |
141 | 145 | RecordCountPublished = f.get("RecordCountPublished") |
142 | 146 | RecordCountInDb = f.get("RecordCountInDb") |
143 | | - rel_diff1 = abs(RecordCountPublished - RecordCountInDb)/RecordCountInDb |
144 | | - rel_diff2 = abs(RecordCountPublished - RecordCountInDb)/RecordCountPublished |
145 | | - if rel_diff1 < 0.01 or rel_diff2 < 0.01: |
146 | | - syncstatus = "OK" |
147 | | - else: |
148 | | - syncstatus = "ERROR [ Please use the Gap Publisher to synchronise this dataset]" |
149 | | - return syncstatus |
| 147 | + |
| 148 | + # catches None or zero |
| 149 | + if not RecordCountPublished or not RecordCountInDb: |
| 150 | + return "WARNING [ Invalid record counts ]" |
| 151 | + |
| 152 | + diff = abs(RecordCountPublished - RecordCountInDb) |
| 153 | + rel_diff1 = diff/RecordCountInDb |
| 154 | + rel_diff2 = diff/RecordCountPublished |
| 155 | + if RecordCountPublished > RecordCountInDb or rel_diff1 < 0.01 or rel_diff2 < 0.01: |
| 156 | + return "OK" |
| 157 | + |
| 158 | + return "WARNING [ Please try to republish the missing data or raise a GGUS ticket ]" |
| 159 | + |
| 160 | + |
| 161 | +def is_current_month(f): |
| 162 | + month = f.get("Month") |
| 163 | + year = f.get("Year") |
| 164 | + |
| 165 | + if month is None or year is None: |
| 166 | + return False |
| 167 | + |
| 168 | + now = datetime.now() |
| 169 | + return now.month == month and now.year == year |
150 | 170 |
|
151 | 171 |
|
152 | 172 | def refresh_gridsite(): |
|
0 commit comments