Spaces:
Runtime error
Runtime error
File size: 12,102 Bytes
6d32e05 49e89d7 6d32e05 b9813bd 6d32e05 b9813bd 6d32e05 49e89d7 27f1dee 49e89d7 6d32e05 e758957 b9813bd 1112449 b9813bd e758957 b9813bd 6d32e05 e758957 b9813bd 49e89d7 b9813bd a7ae8ca 2a97e80 e758957 b9813bd e758957 b9813bd 49e89d7 b9813bd a7ae8ca e758957 b9813bd e758957 b9813bd e758957 b9813bd 49e89d7 b9813bd a7ae8ca e758957 b9813bd e758957 b9813bd 49e89d7 b9813bd 925904d a7ae8ca e758957 b9813bd 925904d b9813bd 925904d e758957 b9813bd 49e89d7 b9813bd 925904d e758957 b9813bd e758957 b9813bd 49e89d7 b9813bd a7ae8ca 1112449 |
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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
import streamlit as st
import psycopg2
import pandas as pd
import asyncio
from io import BytesIO
def create_conn():
conn = psycopg2.connect(dbname="neondb", user="zhanabayevasset", password="txDhFR1yl8Pi", host='ep-cool-poetry-346809.us-east-2.aws.neon.tech')
return conn
def get_data(table, start_date, end_date):
conn = create_conn()
cursor = conn.cursor()
cursor.execute(f"""select * from {table}_params
where created_at >= '{start_date}'
and created_at <= '{end_date}'
order by created_at desc""")
data = cursor.fetchall()
cols =[]
for i in cursor.description:
cols.append(i[0])
cursor.close()
conn.close()
return pd.DataFrame(data, columns = cols)
def to_excel(df):
output = BytesIO()
writer = pd.ExcelWriter(output, engine='xlsxwriter')
df.to_excel(writer, index=False, sheet_name='Sheet1')
workbook = writer.book
worksheet = writer.sheets['Sheet1']
format1 = workbook.add_format({'num_format': '0.00'})
worksheet.set_column('A:A', None, format1)
writer.close()
processed_data = output.getvalue()
return processed_data
st.set_page_config(page_title='Seyco QC page')
st.title('Working line operations monitoring system')
val = st.selectbox('select product', [None,'PVC', 'PPR-C','Fitting Vodopr', 'Fitting Canal', 'Fitting Other', 'PERT', 'Window_door', 'bead','laminated_profile','laminated_other', 'windowsill'])
start_date = st.date_input('start_date')
end_date = st.date_input('end_date')
if val == 'PVC':
df = get_data('pvc', start_date, end_date)
st.write(f"weight: {df['weight'].sum()}")
brands = df['brand'].unique().tolist()
nom_diam = df['nominal_diameter'].unique().tolist()
nom_length = df['nominal_length'].unique().tolist()
brands.append(None)
nom_diam.append(None)
nom_length.append(None)
brand = st.selectbox('select brand', brands)
diam = st.selectbox('select nominal diameter', nom_diam)
length = st.selectbox('select nominal length', nom_length)
if (brand == None) | (length == None) | (diam == None):
df = df.set_index('created_at')
st.dataframe(df)
df_xlsx = to_excel(df)
st.download_button(label='π₯ Download Current Result',
data=df_xlsx ,
file_name= 'pvc.xlsx')
else:
df = df[df['brand'] == brand]
df = df[df['nominal_diameter'] == diam]
df = df[df['nominal_length'] == length]
df = df.set_index('created_at')
st.dataframe(df)
df_xlsx = to_excel(df)
st.download_button(label='π₯ Download Current Result',
data=df_xlsx ,
file_name= 'pvc.xlsx')
st.line_chart(df['view'])
st.line_chart(df['functionality'])
st.line_chart(df['diameter'])
st.line_chart(df[df['weight'].isnull()==False]['weight'])
st.line_chart(df[df['width'].isnull() == False]['width'])
st.line_chart(df[df['mark_control'].isnull() == False]['mark_control'])
st.line_chart(df[df['strength'].isnull() == False]['strength'])
st.line_chart(df[df['length'].isnull() == False]['length'])
if val == 'PPR-C':
df = get_data('pprc', start_date, end_date)
st.write(f"weight: {df['weight'].sum()}")
brands = df['brand'].unique().tolist()
nom_diam = df['nominal_diameter'].unique().tolist()
brand = st.selectbox('select brand', brands)
diam = st.selectbox('select nominal diameter', nom_diam)
brands.append(None)
nom_diam.append(None)
if (brand == None) | (diam == None):
df = df.set_index('created_at')
st.dataframe(df)
df_xlsx = to_excel(df)
st.download_button(label='π₯ Download Current Result',
data=df_xlsx ,
file_name= 'pprc.xlsx')
else:
df = df[df['brand'] == brand]
df = df[df['nominal_diameter'] == diam]
df = df.set_index('created_at')
st.dataframe(df)
df_xlsx = to_excel(df)
st.download_button(label='π₯ Download Current Result',
data=df_xlsx ,
file_name= 'pprc.xlsx')
st.line_chart(df['view'])
st.line_chart(df['diameter'])
st.line_chart(df['width'])
st.line_chart(df[df['weight'].isnull()==False]['weight'])
st.line_chart(df[df['mark_control'].isnull()==False]['mark_control'])
if val == 'Fitting Vodopr':
df = get_data('fitting_vodop', start_date, end_date)
st.write(f"weight: {df['weight'].sum()}")
brands = df['brand'].unique().tolist()
stanoks = df['stanok'].unique().tolist()
fit_names = df['fitting_name'].unique().tolist()
brands.append(None)
stanoks.append(None)
fit_names.append(None)
brand = st.selectbox('select brand', brands)
stanok = st.selectbox('select line', stanoks)
fit_name = st.selectbox('select fitting name', fit_names)
if (brand == None) | (stanok == None) | (fit_name==None):
df = df.set_index('created_at')
st.dataframe(df)
df_xlsx = to_excel(df)
st.download_button(label='π₯ Download Current Result',
data=df_xlsx ,
file_name= 'fitting vodop.xlsx')
else:
df = df[df['brand'] == brand]
df = df[df['stanok'] == stanok]
df = df[df['fitting_name'] == fit_name]
df = df.set_index('created_at')
st.dataframe(df)
df_xlsx = to_excel(df)
st.download_button(label='π₯ Download Current Result',
data=df_xlsx ,
file_name= 'fitting vodop.xlsx')
st.line_chart(df['view'])
st.line_chart(df['functionality'])
st.line_chart(df[df['weight'].isnull()==False]['weight'])
if val == 'Fitting Canal':
df = get_data('fitting_canal', start_date, end_date)
st.write(f"weight: {df['weight'].sum()}")
brands = df['brand'].unique().tolist()
stanoks = df['stanok'].unique().tolist()
fit_names = df['fitting_name'].unique().tolist()
nom_diams = df['nominal_diameter'].unique().tolist()
type_materials = df['type_syr'].unique().tolist()
prod_types = df['product_type'].unique().tolist()
brand = st.selectbox('select brand', brands)
stanok = st.selectbox('select line', stanoks)
fit_name = st.selectbox('select fitting name', fit_names)
nom_diam = st.selectbox('select nom diameter', nom_diams)
type_mat = st.selectbox('select type material', type_materials)
prod_type = st.selectbox('select product_type', prod_types)
if (brand==None) | (stanok == None) | (fit_name == None) | (nom_diam == None) | (type_mat == None) | (prod_type == None):
df = df.set_index('created_at')
st.dataframe(df)
df_xlsx = to_excel(df)
st.download_button(label='π₯ Download Current Result',
data=df_xlsx ,
file_name= 'fitting canal.xlsx')
# if (brand in brands) & (stanok in stanoks) & (fit_name in fit_names) & (nom_diam in nom_diams) & (prod_type in prod_types) & (type_mat in type_materials):
else:
df = df[df['brand'] == brand]
df = df[df['stanok'] == stanok]
df = df[df['fitting_name'] == fit_name]
df = df[df['type_syr'] == type_mat]
df = df[df['product_type'] == prod_type]
df = df.set_index('created_at')
st.dataframe(df)
df_xlsx = to_excel(df)
st.download_button(label='π₯ Download Current Result',
data=df_xlsx ,
file_name= 'fitting canal.xlsx')
st.line_chart(df['view'])
st.line_chart(df[df['functionality'].isnull()==False]['functionality'])
st.line_chart(df[df['weight'].isnull()==False]['weight'])
if val == 'Fitting Other':
df = get_data('fitting_other', start_date, end_date)
brands = df['brand'].unique().tolist()
stanoks = df['stanok'].unique().tolist()
fit_names = df['fitting_name'].unique().tolist()
nom_sizes = df['nominal_size'].unique().tolist()
colors = df['color'].unique().tolist()
brand = st.selectbox('select brand', brands)
stanok = st.selectbox('select line', stanoks)
fit_name = st.selectbox('select fitting name', fit_names)
nom_size = st.selectbox('select nom size', nom_sizes)
color = st.selectbox('select color', colors)
if (brand==None) | (stanok == None) | (fit_name == None) | (nom_size == None) | (color == None):
df = df.set_index('created_at')
st.dataframe(df)
df_xlsx = to_excel(df)
st.download_button(label='π₯ Download Current Result',
data=df_xlsx ,
file_name= 'fitting other.xlsx')
else:
# if (brand in brands) & (stanok in stanoks) & (fit_name in fit_names) & (nom_size in nom_sizes) & (color in colors):
df = df[df['brand'] == brand]
df = df[df['stanok'] == stanok]
df = df[df['fitting_name'] == fit_name]
df = df[df['nominal_size'] == nom_size]
df = df.set_index('created_at')
st.dataframe(df)
df_xlsx = to_excel(df)
st.download_button(label='π₯ Download Current Result',
data=df_xlsx ,
file_name= 'fitting other.xlsx')
st.line_chart(df['view'])
st.line_chart(df['functionality'])
st.line_chart(df['view'])
# st.line_chart(df['color'])
if val == 'PERT':
df = get_data('pert', start_date, end_date)
st.write(f"weight: {df['weight'].sum()}")
brands = df['brand'].unique().tolist()
brand = st.selectbox('select brand', brands)
if brand ==None:
df = df.set_index('created_at')
st.dataframe(df)
df_xlsx = to_excel(df)
st.download_button(label='π₯ Download Current Result',
data=df_xlsx ,
file_name= 'pert.xlsx')
# if (brand in brands):
else:
# if st.button('show data') == True:
df = df[df['brand'] == brand]
df = df.set_index('created_at')
st.dataframe(df)
df_xlsx = to_excel(df)
st.download_button(label='π₯ Download Current Result',
data=df_xlsx ,
file_name= 'pert.xlsx')
st.line_chart(df['view'])
st.line_chart(df['outer_diameter'])
st.line_chart(df['width_st'])
st.line_chart(df['weight_b'])
st.line_chart(df[df['weight'].isnull()==False]['weight'])
st.line_chart(df[df['mark_control'].isnull()==False]['mark_control'])
if val == 'Window_door':
df = get_data('window_door', start_date, end_date)
st.dataframe(df)
if val == 'bead':
df = get_data('bead', start_date, end_date)
st.dataframe(df)
if val == 'laminated_profile':
df = get_data('laminated_profile', start_date, end_date)
st.dataframe(df)
if val == 'laminated_other':
df = get_data('laminated_other', start_date, end_date)
st.dataframe(df)
if val == 'windowsill':
df = get_data('windowsill', start_date, end_date)
st.dataframe(df)
|