<commit_before>"""
Check the status of our ISUSM sites being offline or online
run from RUN_40_AFTER.sh
"""

import datetime
import psycopg2
import pytz
from pyiem.tracker import TrackerEngine
from pyiem.network import Table as NetworkTable

NT = NetworkTable("ISUSM")
IEM = psycopg2.connect(database='iem', host='iemdb')
PORTFOLIO = psycopg2.connect(database='portfolio', host='iemdb')


threshold = datetime.datetime.utcnow() - datetime.timedelta(hours=2)
threshold = threshold.replace(tzinfo=pytz.timezone("UTC"))

icursor = IEM.cursor()
icursor.execute("""SELECT id, valid from current c JOIN stations t
     ON (t.iemid = c.iemid) WHERE t.network = 'ISUSM'
     """)
obs = {}
for row in icursor:
    obs[row[0]] = dict(id=row[0], valid=row[1])

tracker = TrackerEngine(IEM.cursor(), PORTFOLIO.cursor(), 7)
tracker.process_network(obs, 'isusm', NT, threshold)
tracker.send_emails()
tac = tracker.action_count
if tac > 6:
    print 'check_isusm_online.py had %s actions, did not email' % (tac,)
IEM.commit()
PORTFOLIO.commit()
<commit_msg>increase ISUSM outage duration to 12h before alerting<commit_after>"""
Check the status of our ISUSM sites being offline or online
run from RUN_40_AFTER.sh
"""

import datetime
import psycopg2
import pytz
from pyiem.tracker import TrackerEngine
from pyiem.network import Table as NetworkTable

NT = NetworkTable("ISUSM")
IEM = psycopg2.connect(database='iem', host='iemdb')
PORTFOLIO = psycopg2.connect(database='portfolio', host='iemdb')


threshold = datetime.datetime.utcnow() - datetime.timedelta(hours=12)
threshold = threshold.replace(tzinfo=pytz.timezone("UTC"))

icursor = IEM.cursor()
icursor.execute("""SELECT id, valid from current c JOIN stations t
     ON (t.iemid = c.iemid) WHERE t.network = 'ISUSM'
     """)
obs = {}
for row in icursor:
    obs[row[0]] = dict(id=row[0], valid=row[1])

tracker = TrackerEngine(IEM.cursor(), PORTFOLIO.cursor(), 7)
tracker.process_network(obs, 'isusm', NT, threshold)
tracker.send_emails()
tac = tracker.action_count
if tac > 6:
    print 'check_isusm_online.py had %s actions, did not email' % (tac,)
IEM.commit()
PORTFOLIO.commit()

{'fraction_non_alphanumeric': 0.13270588235294117, 'fraction_numerical': 0.011764705882352941, 'mean_word_length': 5.4817073170731705, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1342745', 'n_tokens_mistral': 770, 'n_tokens_neox': 745, 'n_words': 195}