コード例 #1
0
def get_dbmapping(syn: Synapse, projectid: str) -> dict:
    """Gets database mapping information

    Args:
        syn: Synapse connection
        projectid: Project id where new data lives

    Returns:
        {'synid': database mapping syn id,
         'df': database mapping pd.DataFrame}

    """
    project_ent = syn.get(projectid)
    dbmapping_synid = project_ent.annotations.get("dbMapping", "")[0]
    database_mapping = syn.tableQuery(f"select * from {dbmapping_synid}")
    database_mappingdf = database_mapping.asDataFrame()
    return {"synid": dbmapping_synid, "df": database_mappingdf}
コード例 #2
0
def get_center_invalid_errors(syn: Synapse, error_tracker_synid: str) -> dict:
    """Get all invalid errors per center

    Args:
        syn: Synapse connection
        error_tracker_synid: Synapse id of invalid error database table

    Returns:
        dict: center - file error string

    """
    error_tracker = syn.tableQuery(f"SELECT * FROM {error_tracker_synid}")
    error_trackerdf = error_tracker.asDataFrame()
    center_errorsdf = error_trackerdf.groupby("center")
    center_error_map = {}
    for center, df in center_errorsdf:
        center_error_map[center] = _combine_center_file_errors(syn, df)
    return center_error_map
コード例 #3
0
def stop_submission_over_quota(syn: Synapse,
                               submission_view: Union[str,
                                                      SubmissionViewSchema],
                               quota: int = sys.maxsize):
    """Stops any submission that has exceeded the run time quota by using
    submission views.  A submission view must first exist.
    Rerunning submissions will require setting TimeRemaining annotation
    to a positive integer.

    Args:
        syn: Synapse connection
        submission_view: Submission View or its Synapse Id.
        quota: Quota in milliseconds. Default is sys.maxsize.
               One hour is 3600000.

    """
    if not isinstance(quota, int):
        raise ValueError("quota must be an integer")
    if quota <= 0:
        raise ValueError("quota must be larger than 0")

    try:
        view_query = syn.tableQuery(
            f"select {WORKFLOW_LAST_UPDATED_KEY}, {WORKFLOW_START_KEY}, id, "
            f"status from {id_of(submission_view)} where "
            "status = 'EVALUATION_IN_PROGRESS'")
    except SynapseHTTPError as http_error:
        raise ValueError(
            "Submission view must have columns: "
            f"{WORKFLOW_LAST_UPDATED_KEY}, {WORKFLOW_START_KEY}, id"
        ) from http_error

    view_querydf = view_query.asDataFrame()
    runtime = (view_querydf[WORKFLOW_LAST_UPDATED_KEY] -
               view_querydf[WORKFLOW_START_KEY])
    submissions_over_quota_idx = runtime > quota
    over_quotadf = view_querydf[submissions_over_quota_idx]
    for index, row in over_quotadf.iterrows():
        add_annotations = {TIME_REMAINING_KEY: 0}
        annotations.annotate_submission(syn,
                                        row['id'],
                                        add_annotations,
                                        is_private=False,
                                        force=True)