예제 #1
0
def generate_records_table(username):
    rol = get_user_rol(username)
    if rol == "Doctor":
        cols = ('PATIENT ID', 'DATE', 'DATA', 'MODEL DISEASE', 'MODEL TYPE', 'OUTPUT')
        body = '<table class="table" id="table">\
                                              <thead>'
        body += new_head(cols)
        body += '</thead>  \
                                    <tbody>'
        conn = Connection()
        prediction = conn.do_query_mult_col(
            'SELECT PRE.patient_id, PRE.datetime, PRE.expression_file_path, M.disease, M.model_type, PRE.result FROM prediction PRE, user U, model M WHERE U.email=\"' + username + '\" and U.id=PRE.user_id and PRE.model_id=M.id;')
        if prediction is not None:  # There are data to show
            for row in prediction:
                body += new_row(row)
        body += '  </tbody>\
                    </table>'
        return body
    elif rol == "Admin":
        cols = ('PREDICTION ID', 'USER ID', 'DATE', 'MODEL')
        body = '<table class="table" id="table">\
                                      <thead>'
        body += new_head(cols)
        body += '</thead>  \
                            <tbody>'
        conn = Connection()
        prediction = conn.do_query_mult_col(
            'SELECT PRE.id, PRE.user_id, PRE.datetime, PRE.model_id FROM prediction PRE;')
        if prediction is not None:  # There are data to show
            for row in prediction:
                body += new_row(row)
            body += '  </tbody>\
                    </table>'
    return body
예제 #2
0
def get_model_path(disease, model_type):
    """
    Returns first DB occurrence of model filepath given a disease and a model type.
    :param disease:
    :param model_type:
    :return: model filepath (string)
    """
    conn = Connection()
    cancers_models = conn.do_query_mult_col(
        'SELECT model_path FROM model WHERE disease="' + disease + '" AND model_type="' + model_type + '";')
    return cancers_models[0]
예제 #3
0
def get_cancers_models():
    """
    Returns disease and model type for each of the models in DB.
    :return: disease,model_type (dict).
    """
    conn = Connection()
    cancers_models = conn.do_query_mult_col('SELECT disease, model_type FROM model;')
    if cancers_models is None:
        return dict()
    else:
        models_dict = dict()
        for row in cancers_models:
            models_dict.setdefault(row[0], []).append(row[1])
        return models_dict
예제 #4
0
def hist_from_db():
    conn = Connection()
    y = conn.do_query_mult_col('SELECT datetime FROM prediction;')
    if y:
        x = list()
        for i in range(0, len(y)):
            x.append(y[i][0].day)
        print(x)
        data = [go.Histogram(x=x)]
        first_plot_url = py.plot(data, filename='./template/plot.html', auto_open=False)
        with open(first_plot_url.replace("file://", "")) as plot_html_file:
            return plot_html_file.read()
    else:
        return "<h1 style=\"position: fixed; top: 50%;left: 40%;\">Nothing to show</h1>"
예제 #5
0
def generate_table_from_db(table_name):
    conn = Connection()
    cols = conn.do_query(
        'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME=\"' + table_name + '\" AND TABLE_SCHEMA = \'' + conn.get_database() + '\' ORDER BY ORDINAL_POSITION;')
    index_id = cols.index('id')
    num_cols = len(cols)
    table = conn.do_query_mult_col(
        'SELECT * FROM ' + table_name + ';')
    if cols is not None:
        body = '<form class="needs-validation" id="form_funciona" name="user_form" method="post" action="/administration/' + table_name + '/insert" enctype=multipart/form-data>'
        body += '<table class="table" id="table">\
                              <thead>'
        cols.append(' ')  # For delete column
        cols.append(' ')  # For update column
        body += new_head(tuple(cols))
        body += '</thead>  \
                    <tbody>'
        if table is not None:
            row_num = 1
            for row in table:
                row_id = row[index_id]
                body += new_row(row).replace('</tr>',
                                             '<td><a href="/administration/' + table_name + '/delete/' + str(
                                                 row_id) + '"><span class="glyphicon glyphicon-remove"></span></a></td>')  # Adds delete button to each row
                body += '<td><a href="#"><span class="glyphicon glyphicon-pencil" onclick="update_db(' + str(
                    row_num) + ')"></span></a></td></tr>'  # Adds delete button to each row
                row_num += 1
        insert_row = list()
        if table_name == 'model':
            insert_row = insert_row_model(num_cols, index_id, insert_row, cols)
        else:
            for i in range(1, num_cols + 1):
                if i == index_id + 1:
                    insert_row.append(' ')
                else:
                    insert_row.append('<input class="form-control" name=\"' + cols[
                        i - 1] + '\" style="border-width: thin; border-radius: 10px ; box-sizing: border-box; '
                                 'width: 100%" '
                                 'type="text" required></input>')
        insert_row.append(
            '<button class="btn btn-default" type="submit"><a href="#"><span class="glyphicon glyphicon-plus"></span></a></button>')
        insert_row.append(' ')
        body += new_insert_row_form(insert_row)
        print(body)
        body += '  </tbody>'
        body += '</table>'
        body += '</form>'
    return body
예제 #6
0
def get_json_values(disease, model_type):
    """
    Returns json model data in html table format for given disease and model type.
    :param disease:
    :param model_type:
    :return: html table (string)
    """
    conn = Connection()
    json_file = conn.do_query_mult_col(
        'SELECT dataset_description FROM model WHERE disease="' + disease + '" AND model_type="' + model_type + '";')[0]
    acc = get_model_acc(disease, model_type)
    with open('predictor/models/'+json_file[0]) as f:
        data = json.load(f)
        html= """<table class="table">
  <tbody>
    <tr>
      <th scope="row">Description</th>
      <td>"""+data['description']+"""</td>
    </tr>
    <tr>
      <th scope="row">Number of variables</th>
      <td>"""+str(data['num_of_variables'])+"""</td>
    </tr>
    <tr>
      <th scope="row">Class name</th>
      <td>"""+data['class_info']['name']+"""</td>
    </tr>
        <tr>
      <th scope="row">Class values</th>
      <td>"""+str(data['class_info']['values'])+"""</td>
    </tr>
    <tr>
      <th scope="row">Accuracy</th>
      <td>"""+str(acc[0])+"""</td>
    </tr>
  </tbody>
</table>"""
    return html