File size: 5,123 Bytes
bcad657
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89ce392
bcad657
 
655c3fa
bcad657
 
 
 
 
 
 
 
 
655c3fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bcad657
 
 
 
 
 
 
 
 
 
cd478f2
bcad657
f5d228a
de8ce68
bcad657
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de8ce68
bcad657
 
de8ce68
bcad657
 
 
de8ce68
bcad657
de8ce68
bcad657
de8ce68
bcad657
 
 
 
b704a19
bcad657
 
 
 
f5d228a
bcad657
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
748e1a1
d00ac21
bcad657
 
 
 
a8b82d2
0bf779a
bcad657
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import streamlit as st
import sys
import os
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import torch
import numpy as np
import threading
import hmac


from processing.surface_plots import surface_plot
from processing.preprocessing import plot_timeseries
from processing.prediction import NN_prediction
from processing.classification_model import classify
from processing.barsplots_rootcauses import check_classification
from processing.cloud_access import auto_download

sprint_data_folder = "Messungen"
seafile_token = os.environ['SEAFILE_TOKEN']



def get_csv_files(data_folder):
    csv_files = []
    for file in os.listdir(data_folder):
        if file.endswith(".csv"):
            csv_file = os.path.join(data_folder, file)
            csv_files.append(csv_file)
    return csv_files
    

def check_password():
    """Returns `True` if the user had the correct password."""

    def password_entered():
        """Checks whether a password entered by the user is correct."""
        if hmac.compare_digest(st.session_state["password"], st.secrets["password"]):
            st.session_state["password_correct"] = True
            del st.session_state["password"]  # Don't store the password.
        else:
            st.session_state["password_correct"] = False

    # Return True if the password is validated.
    if st.session_state.get("password_correct", False):
        return True

    # Show input for password.
    st.text_input(
        "Password", type="password", on_change=password_entered, key="password"
    )
    if "password_correct" in st.session_state:
        st.error("😕 Password incorrect")
    return False

if not check_password():
    st.stop()  # Do not continue if check_password is not True.


def main():

    sprint_csv_files = get_csv_files(sprint_data_folder)

    st.set_page_config(page_title="Assistenzsystem", page_icon=":eyeglasses:", layout="wide")
    with open("assets/style.css") as f:
        st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
    
    st.write("")
    col1, col2 = st.columns([1, 0.2])
    with col1: st.image("assets/ProKI_Logo.png", width=200)
    with col2: st.image("assets/qr-code.png", width=100)
    #with col2: st.markdown("<h2 style='text-align: right; color: black; font-family:Arial;font-size:2.25rem;'>Assistenzsystem</h2>",  unsafe_allow_html=True)


    tab1, tab2 = st.tabs(["Modellierung der Bauteilqualität", "Klassifizierungsergebnisse"])

    with tab1:
        
        st.markdown("#")        
        col1, col2, col3 = st.columns([0.5, 0.1, 0.4], gap="large")
        
        with col1:
            
            feed = st.slider("Vorschub [mm/min]", 400, 1300, 850)
            plaindepth = st.slider("Schnitttiefe [mm]", 0.1, 0.5, 0.3)
            wear = st.slider("Werkzeugverschleiß %", 0, 100, 50)

            try:
                fig = NN_prediction((feed-400)/900, (plaindepth-0.1)/0.4, wear/100)
                st.pyplot(fig)
            except:
                st.write("Models not loaded yet")

        with col2:
            st.write("")

        with col3:
            st.write("")

            st.image("assets/slice.png")

            auswahl = st.radio("Merkmal", ["Vorschub", "Schnitttiefe", "Werkzeugverschleiß"], horizontal=True, index=0)
            #width = 500
        

            if auswahl == "Vorschub":
                st.image("assets/max_Vorschub.PNG")
            elif auswahl == "Schnitttiefe":
                st.image("assets/max_Schnitttiefe.PNG")
            else:
                st.image("assets/max_Verschleiß.PNG")

    with tab2:

        selected_file = st.selectbox("Oberflächenscan auswählen", sprint_csv_files, 0)
        col1, col_blanc, col2= st.columns([0.6, 0.05, 0.35], gap="large")

        with col1:
            try:
                fig = surface_plot(selected_file)
                fig.update_layout(height=600, width=800)
                st.plotly_chart(fig, theme="streamlit", use_container_width=False)
            except:
                pass
        
        with col_blanc:
            st.write("")
        
        with col2:
            st.markdown("<h2 style='text-align: center; color: black; font-family:Arial;font-size:2rem;'>Klassifizierung</h2>", unsafe_allow_html=True)
            st.markdown("#")
            
            dummy, tolerance, z_data, fivetothirty = plot_timeseries(selected_file, 9)
            data = fivetothirty["z"].values
            mean = np.mean(data)
            data = data - mean
            
            try:
                data = torch.tensor(data, dtype=torch.float).to("cpu")
                data = data.view(1,1,500)
                prediction = classify(data)

                fig_feed, fig_depth, fig_condition = check_classification(prediction[0])
                st.pyplot(fig_feed)
                st.pyplot(fig_depth)
                st.pyplot(fig_condition) 
            except Exception as e:
                st.write(e)


if __name__ == "__main__":
    main()

    t1 = threading.Thread(target=auto_download, args=(seafile_token,))
    t1.start()