Example #1
0
def get_timestamps(cursor, meters, query):
    """
    For each meter in meters list, execute SQL query using existing cursor
    object.

    Returns a dictionary where keys are meter ION names and values are
    earliest or latest timestamps, depending on query's contents.

    Params:
        cursor: Cursor object
        meters: list of meter rows
        query: string
    """
    output = {}
    for m in meters:
        ion_name = utils.get_ion_name(m)
        qid = utils.get_ion_qid(m)
        try:
            cursor.execute(query, ion_name, qid)
        except pyodbc.Error:
            pass
        if cursor.rowcount == 0:
            output[ion_name] = None
            continue
        row = cursor.fetchone()
        ts = row.TimestampUTC.split(".")[0]
        output[ion_name] = ts

    return output
Example #2
0
def get_timestamps(cursor, meters, query):
    """
    For each meter in meters list, execute SQL query using existing cursor
    object.

    Returns a dictionary where keys are meter ION names and values are
    earliest or latest timestamps, depending on query's contents.

    Params:
        cursor: Cursor object
        meters: list of meter rows
        query: string
    """
    output = {}
    for m in meters:
        ion_name = utils.get_ion_name(m)
        qid = utils.get_ion_qid(m)
        try:
            cursor.execute(query, ion_name, qid)
        except pyodbc.Error:
            pass
        if cursor.rowcount == 0:
            output[ion_name] = None
            continue
        row = cursor.fetchone()
        ts = row.TimestampUTC.split(".")[0]
        output[ion_name] = ts

    return output
Example #3
0
def run(root):
    creds_file = defaults.creds(root)
    cnxn_str = utils.get_cnxn_str(creds_file)
    meter_file = defaults.meter_file(root)

    earliest = {}
    latest = {}
    print("Running check.py...")
    with Cursor.Cursor(cnxn_str) as cursor:
        earliest_query = get_query_str(True)
        latest_query = get_query_str(False)
        meter_generator = utils.read_meter_file(meter_file)
        meters = [m for m in meter_generator]
        earliest = get_timestamps(cursor, meters, earliest_query)
        latest = get_timestamps(cursor, meters, latest_query)

        for i, m in enumerate(meters):
            ion_name = utils.get_ion_name(m)
            earliest_ts = earliest[ion_name]
            latest_ts = latest[ion_name]
            print(" %d)\t%s\tStart: %s\tEnd: %s" % (i, ion_name, earliest_ts, latest_ts))
Example #4
0
def run(root):
    creds_file = defaults.creds(root)
    cnxn_str = utils.get_cnxn_str(creds_file)
    meter_file = defaults.meter_file(root)

    earliest = {}
    latest = {}
    print("Running check.py...")
    with Cursor.Cursor(cnxn_str) as cursor:
        earliest_query = get_query_str(True)
        latest_query = get_query_str(False)
        meter_generator = utils.read_meter_file(meter_file)
        meters = [m for m in meter_generator]
        earliest = get_timestamps(cursor, meters, earliest_query)
        latest = get_timestamps(cursor, meters, latest_query)

        for i, m in enumerate(meters):
            ion_name = utils.get_ion_name(m)
            earliest_ts = earliest[ion_name]
            latest_ts = latest[ion_name]
            print(" %d)\t%s\tStart: %s\tEnd: %s" %
                  (i, ion_name, earliest_ts, latest_ts))