Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions monitoring/db_update_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from django.db import DatabaseError
import pandas as pd
from django.utils.timezone import make_aware, is_naive
from datetime import datetime


BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
Expand Down Expand Up @@ -138,15 +139,34 @@ def determine_sync_status(f):
"""
Helper to determine sync status between published and the database record counts.
"""
if is_current_month(f):
return "OK [ Current month ]"

RecordCountPublished = f.get("RecordCountPublished")
RecordCountInDb = f.get("RecordCountInDb")
rel_diff1 = abs(RecordCountPublished - RecordCountInDb)/RecordCountInDb
rel_diff2 = abs(RecordCountPublished - RecordCountInDb)/RecordCountPublished
if rel_diff1 < 0.01 or rel_diff2 < 0.01:
syncstatus = "OK"
else:
syncstatus = "ERROR [ Please use the Gap Publisher to synchronise this dataset]"
return syncstatus

# catches None or zero
if not RecordCountPublished or not RecordCountInDb:
return "WARNING [ Invalid record counts ]"

diff = abs(RecordCountPublished - RecordCountInDb)
rel_diff1 = diff/RecordCountInDb
rel_diff2 = diff/RecordCountPublished
if RecordCountPublished > RecordCountInDb or rel_diff1 < 0.01 or rel_diff2 < 0.01:
return "OK"

return "WARNING [ Please try to republish the missing data or raise a GGUS ticket ]"


def is_current_month(f):
month = f.get("Month")
year = f.get("Year")

if month is None or year is None:
return False

now = datetime.now()
return now.month == month and now.year == year


def refresh_gridsite():
Expand Down
2 changes: 1 addition & 1 deletion monitoring/publishing/templates/gridsync.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ <h3>APEL Synchronisation Test</h3>
<td>{{ record.YearMonth }}</td>
<td>{{ record.RecordStart }}</td>
<td>{{ record.RecordEnd }}</td>
<td>{{ record.RecordCountPublished|intcomma }}</td>
<td>{{ record.RecordCountInDb|intcomma }}</td>
<td>{{ record.RecordCountPublished|intcomma }}</td>
<td>{{ record.SyncStatus }}</td>
</tr>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion monitoring/publishing/templates/gridsync_singlesite.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ <h3>APEL Synchronisation Test</h3>
</td>
<td>{{ record.RecordStart }}</td>
<td>{{ record.RecordEnd }}</td>
<td>{{ record.RecordCountPublished|intcomma }}</td>
<td>{{ record.RecordCountInDb|intcomma }}</td>
<td>{{ record.RecordCountPublished|intcomma }}</td>
<td>{{ record.SyncStatus }}</td>
</tr>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion monitoring/publishing/templates/gridsync_submithost.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ <h3>APEL Synchronisation Test</h3>
<td>{{ host.SubmitHost }}</td>
<td>{{ host.RecordStart }}</td>
<td>{{ host.RecordEnd }}</td>
<td>{{ host.RecordCountPublished|intcomma }}</td>
<td>{{ host.RecordCountInDb|intcomma }}</td>
<td>{{ host.RecordCountPublished|intcomma }}</td>
</tr>
{% endfor %}
</table>
Expand Down