Пример #1
0
def delete_patient_session(name, session):
    session_list = strip_hidden(os.listdir(os.path.join(patients_path, name)))
    form = forms.DeleteForm()
    if request.method == "POST":
        try:
            shutil.rmtree(os.path.join(patients_path, name, session))
            flash(
                f"Patient \"{convert_name(name)}\" - Session {session} has been removed."
            )
            return redirect(
                url_for("patients.patient_details", name=name, _external=True))
        except FileNotFoundError:
            flash(f"Patient \"{convert_name(name)}\" does not exist.",
                  category="alert")
            return redirect(
                url_for("patients.patient_details", name=name, _external=True))
    if session not in session_list:
        flash(f"Patient \"{convert_name(name)}\" does not exist.",
              category="alert")
        return redirect(
            url_for("patients.patient_details", name=name, _external=True))
    return render_template("patients/delete.html",
                           form=form,
                           titlename=convert_name(name),
                           name=name,
                           session_number=session,
                           session=True)
Пример #2
0
def show_patients():
    try:
        patients_list = sorted(strip_hidden(os.listdir(patients_path)))
        if len(patients_list) == 0:
            raise FileNotFoundError
        patients_names = [convert_name(name) for name in patients_list]
    except FileNotFoundError:
        patients_names = None
        patients_list = []
    return render_template("patients/table.html",
                           length=len(patients_list),
                           patients=patients_names,
                           patient_folder=patients_list)
Пример #3
0
def patient_details(name):
    patients_list = strip_hidden(os.listdir(patients_path))
    if name not in patients_list:
        flash(f"Patient \"{convert_name(name)}\" does not exist.",
              category="alert")
        return redirect(url_for("patients.show_patients", _external=True))
    else:
        session_list = strip_hidden(
            os.listdir(os.path.join(patients_path, name)))
        session_list.sort()

        # gets status for each of the sessions
        status_list = [read_status(name, session) for session in session_list]
    return render_template("patients/details.html",
                           titlename=convert_name(name),
                           name=name,
                           sessions=len(session_list),
                           session_list=session_list,
                           statuses=status_list,
                           loadable=True)
Пример #4
0
def delete_patient(name):
    patients_list = strip_hidden(os.listdir(patients_path))
    form = forms.DeleteForm()
    if request.method == "POST":
        try:
            shutil.rmtree(os.path.join(patients_path, name))
            flash(f"Patient \"{convert_name(name)}\" has been removed.")
            return redirect(url_for("patients.show_patients", _external=True))
        except FileNotFoundError:
            flash(f"Patient \"{convert_name(name)}\" does not exist.",
                  category="alert")
            return redirect(url_for("patients.show_patients", _external=True))
    if name not in patients_list:
        flash(f"Patient \"{convert_name(name)}\" does not exist.",
              category="alert")
        return redirect(url_for("patients.show_patients", _external=True))
    return render_template("patients/delete.html",
                           form=form,
                           titlename=convert_name(name),
                           name=name,
                           patient=True)
Пример #5
0
def display_chart(name, session):
    source_path = os.path.join(patients_path, name, session)
    csv_source_name = "_".join([name, session]) + ".csv"
    if os.path.exists(os.path.join(source_path, csv_source_name)):
        flag_csv = True
        final_df = pd.read_csv(os.path.join(source_path, csv_source_name))
        # emotion = {'predictions':['surprise','happy_positive','neutral','angry_negative','disgust_negative','sad_negative','fear_negative','not_applicable']}
        emotion = {
            'predictions': [
                'not_applicable', 'fear_negative', 'sad_negative',
                'disgust_negative', 'angry_negative', 'neutral',
                'happy_positive', 'surprise'
            ]
        }
        a = px.histogram(final_df,
                         x=final_df.predictions,
                         title="Histogram",
                         category_orders=emotion)
        b = px.line(final_df,
                    y=final_df.intervals,
                    x=final_df.predictions,
                    category_orders=emotion,
                    title="Line Graph",
                    width=800,
                    height=1000)
        histogram = plot(a, output_type="div")
        scatter_line = plot(b, output_type="div")
    else:
        flash(f"Session {session} does not exist for {convert_name(name)}.",
              category="alert")
        return redirect(url_for("patients.patient_details", name=name))
    return render_template("patients/charts.html",
                           name=name,
                           session=session,
                           titlename=convert_name(name),
                           chart_histogram=Markup(histogram),
                           chart_scatter=Markup(scatter_line),
                           flag=flag_csv)
Пример #6
0
def display_session(name, session):
    # checks if patient exists
    patients_list = strip_hidden(os.listdir(patients_path))
    if name not in patients_list:
        flash(f"Patient \"{convert_name(name)}\" does not exist.",
              category="alert")
        return redirect(url_for("patients.show_patients", _external=True))

    # checks if patient session exists
    session_list = os.listdir(os.path.join(patients_path, name))
    if session not in session_list:
        flash(
            f"Patient \"{convert_name(name)}\" session {session} does not exist.",
            category="alert")
        return redirect(
            url_for("patients.patient_details", name=name, _external=True))

    status = read_status(name, session)
    if status == "0" or status == "1":
        flash(f"Session {session} is not ready.", category="alert")
        return redirect(url_for('patients.patient_details', name=name))
    else:
        # check if source file exsists
        audio_source_name = "_".join([name, "source", session]) + ".mp3"
        csv_source_name = "_".join([name, session]) + ".csv"

        source_path = os.path.join(patients_path, name, session)
        if os.path.exists(os.path.join(source_path, "chunks")):
            pass

        if os.path.exists(os.path.join(
                source_path, csv_source_name)) and os.path.exists(
                    os.path.join(source_path, audio_source_name)):
            flag_csv = True
            final_df = pd.read_csv(os.path.join(source_path, csv_source_name))
            final_df = final_df.rename(
                columns={
                    "filename": "Filename",
                    "intervals": "Intervals",
                    "predictions": "Predicted Emotion",
                    "confidence": "Model Confidence"
                })
        else:
            flash(
                "CSV is not available or has been corrupted. Please delete the session and re-upload the session.",
                category="alert")
            flag_csv = False

            # create empty dataframe
            final_df = pd.DataFrame()

        return render_template(
            "patients/session.html",
            titlename=convert_name(name),
            name=name,
            session=session,
            flag=flag_csv,
            tables=[
                final_df.to_html(classes=("responsive-table", "highlight"),
                                 na_rep="N/A",
                                 header=True,
                                 index=False)
            ],
            loadable=True)