Beispiel #1
0
def load_wobble_frequencies(motor:str, date:int=-1, database:str='../data/.database.db'):
    query = f'SELECT * FROM WOBBLE WHERE DATE>{date} AND (MOTOR LIKE "{motor}" OR MOTOR="ANY") AND TYPE="frequencies" ORDER BY DATE DESC LIMIT 1;'
    res = execute_sql(query, database)
    if not res:
        raise WobbleError(f'No data for date {date} and motor {motor} in database.')
    data_blob = res[0]['DATA']
    data = pickle.loads(data_blob)
    return data
Beispiel #2
0
def get_percentage_uncertainty(parameter: str,
                               database: str = '../data/.database.db'):
    '''returns percentage uncertainty in measurement named $parameter'''

    parameter = parameter.upper()
    res = execute_sql(
        f'SELECT PERCENTAGE_UNCERTAINTY FROM UNCERTAINTIES WHERE PROPERTY="{parameter}";',
        database)[0]
    res = float(res['PERCENTAGE_UNCERTAINTY'])
    return res
Beispiel #3
0
def get_calibration(date):

    if isinstance(date, dt):
        date = date.strftime('%Y%m%d')

    calibration_row = execute_sql(
        f'SELECT * FROM [STRESS CALIBRATIONS] WHERE [VALID FROM] <= {date} ORDER BY [VALID FROM] DESC LIMIT 1;',
        database='../data/.database.db')

    if calibration_row:
        cal_str = calibration_row[0]['DATA']
        return json.loads(cal_str)
    else:
        raise Exception(f'No suitable calibration for log date {date} found!')
Beispiel #4
0
def get_from_local(query, *, database='../data/.database.db', process_results=True, max_results=500, max_processes=20,
                   ignore_exceptions=False, plain_collection=True, **kwargs):
    database = os.path.expanduser(database)
    results = execute_sql(query, database)
    kwargs['ignore_exceptions'] = ignore_exceptions

    if not results:
        raise QueryError(f"No results returned by query \"{query}\"")

    if not process_results:
        return [dict(result) for result in results]

    if (lr := len(results)) > max_results and get_hostname() != 'Poseidona':
        raise TooManyResultsError(f"Jeez, that's a lot of data! ({lr} > {max_results}, set 'max_results' to override.)")
Beispiel #5
0
def get_material_list(database='../data/.database.db'):
    results = execute_sql('SELECT DISTINCT MATERIAL FROM LOGS;', database)
    materials = [row['MATERIAL'] for row in results]
    return materials