コード例 #1
0
def post_new_elog_entry(experiment_name, content, content_type, run_num,
                        author):
    """
    Post a new elog entry for the experiment. 
    :param experiment_name - for example - diadaq13
    :param content - The content of the elog entry
    :param content_type - TEXT or HTML
    :param run_num - Can be None..
    :param author - The person posting the elog.
    :return: The posted elog entry
    We first lookup the run_num if specified; then create a header and a entry; then fetch the "document" for the entry and return that.
    """
    if run_num:
        with logbook_db.connect() as cursor:
            cursor.execute(QUERY_INSERT_NEW_HEADER_WITH_RUN, {
                "experiment_name": experiment_name,
                "run_num": run_num
            })
            header_id = cursor.lastrowid

    else:
        with logbook_db.connect() as cursor:
            cursor.execute(QUERY_INSERT_NEW_HEADER_WITHOUT_RUN,
                           {"experiment_name": experiment_name})
            header_id = cursor.lastrowid

    try:
        with logbook_db.connect() as cursor:
            cursor.execute(
                QUERY_INSERT_NEW_ELOG_ENTRY, {
                    "header_id": header_id,
                    "content": content,
                    "content_type": content_type,
                    "author": author
                })
            entry_id = cursor.lastrowid
    except:
        print(cursor._last_executed)
        raise

    with logbook_db.connect() as cursor:
        cursor.execute(QUERY_SELECT_ELOG_ENTRY_FOR_EXPERIMENT, {
            "experiment_name": experiment_name,
            'entry_id': entry_id
        })
        return cursor.fetchone()
コード例 #2
0
def get_experiment_id_for_name(experiment_name):
    try:
        conn = logbook_db.connect()
        with conn as cursor:
            cursor.execute(QUERY_SELECT_EXPERIMENT_ID_FOR_NAME,
                           {"experiment_name": experiment_name})
            return int(cursor.fetchone()['id'])
    finally:
        conn.close()
コード例 #3
0
def get_elog_for_experiment(experiment_name):
    """
    Get the elog entries for an experiment. 
    :param experiment_name - for example - diadaq13
    :return: List of elog entries + run start/stop entries for the experiment sorted by descending time.
    """
    with logbook_db.connect() as cursor:
        cursor.execute(QUERY_SELECT_ELOG_ENTRIES_FOR_EXPERIMENT,
                       {"experiment_name": experiment_name})
        return cursor.fetchall()
コード例 #4
0
def get_experiments_for_instrument(instrument_name):
    """
    Return the experiments for a given instrument
    :param instrument_name: The instrument for the experiments, for example, XPP
    :return: List of experiments for this instrument.
    """
    with logbook_db.connect() as cursor:
        cursor.execute(QUERY_SELECT_EXPERIMENTS_FOR_INSTRUMENT,
                       {"instrument_name": instrument_name})
        return cursor.fetchall()
コード例 #5
0
def get_new_experiments_after_id(last_known_experiment_id):
    """
    Get the experiment id and names for experiments after the last known experiment id.
    Used for publishing Kafka experiment registeration messages
    """
    try:
        conn = logbook_db.connect()
        with conn as cursor:
            cursor.execute(
                QUERY_SELECT_NAME_ID_FOR_NEW_EXPERIMENTS,
                {"last_known_experiment_id": last_known_experiment_id})
            return list(cursor.fetchall())
    finally:
        conn.close()
コード例 #6
0
def register_new_job_hash(experiment_name, job_details):
    """
    Add a new hash into the batch_hashes for the specified experiment
    """
    experiment_id = get_experiment_id_for_name(experiment_name)
    jc = {"experiment_id": experiment_id}
    jc.update(job_details)
    try:
        conn = logbook_db.connect()
        with conn as cursor:
            cursor.execute(QUERY_INSERT_JOB_HASH_FOR_EXPERIMENT, jc)
            return cursor.lastrowid
    finally:
        conn.close()
コード例 #7
0
def get_current_job_hashes(experiment_name):
    """
    Get the current job hashes for the given experiment
    :param experiment_name
    :return: List of batch job hashes for this instrument.
    """
    experiment_id = get_experiment_id_for_name(experiment_name)
    try:
        conn = logbook_db.connect()
        with conn as cursor:
            cursor.execute(QUERY_SELECT_JOB_HASHES_FOR_EXPERIMENT,
                           {"experiment_id": experiment_id})
            return cursor.fetchall()
    finally:
        conn.close()