Loading cog/actions.py +4 −9 Original line number Diff line number Diff line Loading @@ -1890,14 +1890,9 @@ async def monitor_ocr_sheet(client, *, last_timestamp=None, delay_minutes=30, re # Data refreshed, analyse and update with cogdb.session_scope(cogdb.Session) as session: updates = cogdb.query.ocr_update_fort_status(session) if updates: await get_scanner('hudson_cattle').send_batch(updates) prep_report = cogdb.query.ocr_prep_report(session) # Only send messages if generated and channel set await report_to_leadership(client, [prep_report]) cell_updates, _ = cogdb.query.ocr_update_fort_status(session) if cell_updates: await get_scanner('hudson_cattle').send_batch(cell_updates) # A onetime flag to trigger for testing if repeat: Loading @@ -1908,7 +1903,7 @@ async def monitor_ocr_sheet(client, *, last_timestamp=None, delay_minutes=30, re ) async def report_to_leadership(client, msgs): async def report_to_leadership(client, msgs): # pragma: no cover """ Send messages to the channel configured to receive reports. Loading cogdb/query.py +13 −4 Original line number Diff line number Diff line Loading @@ -1138,21 +1138,27 @@ def ocr_update_fort_status(session): Iterate every fort in the system and update fort_status, um_status and triggers if needed. For any system that is updated generate an update_system_dict to be sent in batch. Returns: A list of FortScanner.update_system_dicts that will update the sheet with OCR changes. Args: session: A session for the database. Returns: (cell_updates, warnings) cell_updates: A list of FortScanner.update_system_dicts that will update the sheet with OCR changes. warnings: A list of warnings about NEWLY undermined systems. """ cell_updates = [] for sys in session.query(FortSystem): if not sys.ocr_tracker: continue changed = False if sys.ocr_tracker.fort > sys.fort_status: if not sys.is_fortified and sys.ocr_tracker.fort > sys.fort_status: sys.fort_status = sys.ocr_tracker.fort changed = True if sys.ocr_tracker.um > sys.um_status: if not sys.is_undermined and sys.ocr_tracker.um > sys.um_status: sys.um_status = sys.ocr_tracker.um changed = True if changed: cell_updates += FortScanner.update_system_dict(sys.sheet_col, sys.fort_status, sys.um_status) Loading @@ -1163,6 +1169,9 @@ def ocr_prep_report(session): """ Generate a small report on the preps currently tracked. Args: session: A session for the database. Returns: Report on current consolidation and prep merits. (String) """ globe = get_current_global(session) Loading cogdb/schema.py +1 −0 Original line number Diff line number Diff line Loading @@ -1252,6 +1252,7 @@ class Global(Base): Update the object with expected kwargs. kwargs: cycle: The current cycle number. consolidation: The consolidation % of the curent vote. updated_at: The new date time to set for this update. (Required) Loading tests/cogdb/test_query.py +8 −5 Original line number Diff line number Diff line Loading @@ -783,13 +783,16 @@ def test_ocr_update_forts(session, db_cleanup): OCRTracker(id=2, system="Nurundere", fort=4444, um=1000, updated_at=date), OCRTracker(id=3, system="Sol", fort=4444, um=1250, updated_at=date), ] session.add_all(fort_systems + ocr_tracks) ocr_triggers = [ OCRTrigger(id=3, system="Sol", fort_trigger=8000, um_trigger=1000, updated_at=date), ] session.add_all(fort_systems + ocr_tracks + ocr_triggers) session.commit() result = cogdb.query.ocr_update_fort_status(session) cell_updates = cogdb.query.ocr_update_fort_status(session) session.commit() system = session.query(FortSystem).filter(FortSystem.name == 'Frey').one() assert system.fort_status == 5555 assert system.fort_status == 4910 assert system.um_status == 2500 system = session.query(FortSystem).filter(FortSystem.name == 'Nurundere').one() assert system.fort_status == 5422 Loading @@ -798,8 +801,8 @@ def test_ocr_update_forts(session, db_cleanup): assert system.fort_status == 4444 assert system.um_status == 2250 expect = [{'range': 'G6:G7', 'values': [[5555], [2500]]}, {'range': 'H6:H7', 'values': [[5422], [1000]]}, {'range': 'J6:J7', 'values': [[4444], [2250]]}] assert result == expect expect = [{'range': 'G6:G7', 'values': [[4910], [2500]]}, {'range': 'H6:H7', 'values': [[5422], [1000]]}, {'range': 'J6:J7', 'values': [[4444], [2250]]}] assert cell_updates == expect def test_ocr_prep_report(session, f_ocr_testbed, f_global_testbed): Loading Loading
cog/actions.py +4 −9 Original line number Diff line number Diff line Loading @@ -1890,14 +1890,9 @@ async def monitor_ocr_sheet(client, *, last_timestamp=None, delay_minutes=30, re # Data refreshed, analyse and update with cogdb.session_scope(cogdb.Session) as session: updates = cogdb.query.ocr_update_fort_status(session) if updates: await get_scanner('hudson_cattle').send_batch(updates) prep_report = cogdb.query.ocr_prep_report(session) # Only send messages if generated and channel set await report_to_leadership(client, [prep_report]) cell_updates, _ = cogdb.query.ocr_update_fort_status(session) if cell_updates: await get_scanner('hudson_cattle').send_batch(cell_updates) # A onetime flag to trigger for testing if repeat: Loading @@ -1908,7 +1903,7 @@ async def monitor_ocr_sheet(client, *, last_timestamp=None, delay_minutes=30, re ) async def report_to_leadership(client, msgs): async def report_to_leadership(client, msgs): # pragma: no cover """ Send messages to the channel configured to receive reports. Loading
cogdb/query.py +13 −4 Original line number Diff line number Diff line Loading @@ -1138,21 +1138,27 @@ def ocr_update_fort_status(session): Iterate every fort in the system and update fort_status, um_status and triggers if needed. For any system that is updated generate an update_system_dict to be sent in batch. Returns: A list of FortScanner.update_system_dicts that will update the sheet with OCR changes. Args: session: A session for the database. Returns: (cell_updates, warnings) cell_updates: A list of FortScanner.update_system_dicts that will update the sheet with OCR changes. warnings: A list of warnings about NEWLY undermined systems. """ cell_updates = [] for sys in session.query(FortSystem): if not sys.ocr_tracker: continue changed = False if sys.ocr_tracker.fort > sys.fort_status: if not sys.is_fortified and sys.ocr_tracker.fort > sys.fort_status: sys.fort_status = sys.ocr_tracker.fort changed = True if sys.ocr_tracker.um > sys.um_status: if not sys.is_undermined and sys.ocr_tracker.um > sys.um_status: sys.um_status = sys.ocr_tracker.um changed = True if changed: cell_updates += FortScanner.update_system_dict(sys.sheet_col, sys.fort_status, sys.um_status) Loading @@ -1163,6 +1169,9 @@ def ocr_prep_report(session): """ Generate a small report on the preps currently tracked. Args: session: A session for the database. Returns: Report on current consolidation and prep merits. (String) """ globe = get_current_global(session) Loading
cogdb/schema.py +1 −0 Original line number Diff line number Diff line Loading @@ -1252,6 +1252,7 @@ class Global(Base): Update the object with expected kwargs. kwargs: cycle: The current cycle number. consolidation: The consolidation % of the curent vote. updated_at: The new date time to set for this update. (Required) Loading
tests/cogdb/test_query.py +8 −5 Original line number Diff line number Diff line Loading @@ -783,13 +783,16 @@ def test_ocr_update_forts(session, db_cleanup): OCRTracker(id=2, system="Nurundere", fort=4444, um=1000, updated_at=date), OCRTracker(id=3, system="Sol", fort=4444, um=1250, updated_at=date), ] session.add_all(fort_systems + ocr_tracks) ocr_triggers = [ OCRTrigger(id=3, system="Sol", fort_trigger=8000, um_trigger=1000, updated_at=date), ] session.add_all(fort_systems + ocr_tracks + ocr_triggers) session.commit() result = cogdb.query.ocr_update_fort_status(session) cell_updates = cogdb.query.ocr_update_fort_status(session) session.commit() system = session.query(FortSystem).filter(FortSystem.name == 'Frey').one() assert system.fort_status == 5555 assert system.fort_status == 4910 assert system.um_status == 2500 system = session.query(FortSystem).filter(FortSystem.name == 'Nurundere').one() assert system.fort_status == 5422 Loading @@ -798,8 +801,8 @@ def test_ocr_update_forts(session, db_cleanup): assert system.fort_status == 4444 assert system.um_status == 2250 expect = [{'range': 'G6:G7', 'values': [[5555], [2500]]}, {'range': 'H6:H7', 'values': [[5422], [1000]]}, {'range': 'J6:J7', 'values': [[4444], [2250]]}] assert result == expect expect = [{'range': 'G6:G7', 'values': [[4910], [2500]]}, {'range': 'H6:H7', 'values': [[5422], [1000]]}, {'range': 'J6:J7', 'values': [[4444], [2250]]}] assert cell_updates == expect def test_ocr_prep_report(session, f_ocr_testbed, f_global_testbed): Loading