Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,143 +1,151 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import
|
3 |
-
import
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
)
|
14 |
-
recipes_dict = {
|
15 |
-
("cotton", "dark"): recipes_1_cotton_dark,
|
16 |
-
("cotton", "medium"): recipes_2_cotton_medium,
|
17 |
-
("cotton", "light"): recipes_3_cotton_light,
|
18 |
-
("polyester", "dark"): recipes_4_polyester_dark,
|
19 |
-
("polycotton", "dark"): recipes_5_pc_dark,
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
moment_time
|
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 |
-
st.
|
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 |
-
st.
|
130 |
-
|
131 |
-
|
132 |
-
st.
|
133 |
-
|
134 |
-
st.
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
from plot_app import Plot
|
5 |
+
plotter = Plot()
|
6 |
+
from recipes import (
|
7 |
+
recipes_1_cotton_dark,
|
8 |
+
recipes_2_cotton_medium,
|
9 |
+
recipes_3_cotton_light,
|
10 |
+
recipes_4_polyester_dark,
|
11 |
+
recipes_5_pc_dark,
|
12 |
+
cotton_cotton_lycra
|
13 |
+
)
|
14 |
+
recipes_dict = {
|
15 |
+
("cotton", "dark"): recipes_1_cotton_dark,
|
16 |
+
("cotton", "medium"): recipes_2_cotton_medium,
|
17 |
+
("cotton", "light"): recipes_3_cotton_light,
|
18 |
+
("polyester", "dark"): recipes_4_polyester_dark,
|
19 |
+
("polycotton", "dark"): recipes_5_pc_dark,
|
20 |
+
("lycra","dark"): cotton_cotton_lycra
|
21 |
+
}
|
22 |
+
latent_heat = 494
|
23 |
+
|
24 |
+
def calculate_outputs(mlr, recipes, capacity):
|
25 |
+
"""Perform calculations for each machine."""
|
26 |
+
steam_consumption = []
|
27 |
+
moment_time = 0
|
28 |
+
time = []
|
29 |
+
initial_temp = []
|
30 |
+
final_temp = []
|
31 |
+
temp_grad = []
|
32 |
+
for i in recipes:
|
33 |
+
time.append(moment_time)
|
34 |
+
delta_t = recipes[i]["Duration"]
|
35 |
+
moment_time += delta_t
|
36 |
+
|
37 |
+
temp_diff = recipes[i]["final_temp"] - recipes[i]["init_temp"]
|
38 |
+
final_temp.append(recipes[i]["final_temp"])
|
39 |
+
initial_temp.append(recipes[i]["init_temp"])
|
40 |
+
temp_grad.append(recipes[i]["temp.grad"])
|
41 |
+
temp = recipes[i]["temp.grad"]
|
42 |
+
temp_diff = abs(temp_diff)
|
43 |
+
steam_use = (capacity * mlr * temp_diff*1) + (capacity * temp_diff*1) # cp = 1
|
44 |
+
if temp != 0 :
|
45 |
+
steam_ = steam_use*60/temp
|
46 |
+
else:
|
47 |
+
steam_ = steam_use*60
|
48 |
+
steam_kg_hr = steam_/latent_heat
|
49 |
+
steam_consumption.append(round(steam_kg_hr,2))
|
50 |
+
|
51 |
+
return {
|
52 |
+
"Steam Consumption": steam_consumption,
|
53 |
+
"Time": time,
|
54 |
+
"init_Temp": initial_temp,
|
55 |
+
"final_Temp": final_temp,
|
56 |
+
"temp_grad": temp_grad
|
57 |
+
}
|
58 |
+
|
59 |
+
def calculate_peak_avg_load(machine_results):
|
60 |
+
"""Calculate peak and average steam load for all machines."""
|
61 |
+
combined_steam_load = {}
|
62 |
+
start_time_offset = 0
|
63 |
+
|
64 |
+
for machine, results in machine_results.items():
|
65 |
+
for t, load in zip(results["Time"], results["Steam Consumption"]):
|
66 |
+
adjusted_time = t + start_time_offset
|
67 |
+
if adjusted_time in combined_steam_load:
|
68 |
+
combined_steam_load[adjusted_time] += load
|
69 |
+
else:
|
70 |
+
combined_steam_load[adjusted_time] = load
|
71 |
+
start_time_offset += 10 # Each machine starts 10 units after the previous one
|
72 |
+
|
73 |
+
peak_load = max(combined_steam_load.values())
|
74 |
+
avg_load = sum(combined_steam_load.values()) / len(combined_steam_load)
|
75 |
+
|
76 |
+
return peak_load, avg_load
|
77 |
+
|
78 |
+
def convert_df_to_csv(df):
|
79 |
+
return df.to_csv(index=False).encode('utf-8')
|
80 |
+
|
81 |
+
st.title("Dyeing Machine Load & Steam Calculator")
|
82 |
+
|
83 |
+
machine_type = st.selectbox("Select Type of Machine", ['SoftFlow'])
|
84 |
+
num_machines = st.number_input("Number of Dyeing Machines", min_value=1, value=5)
|
85 |
+
mlr = st.number_input("Enter the MLR for the process", min_value=2, value=6)
|
86 |
+
machine_capacities = {}
|
87 |
+
|
88 |
+
st.write("### Enter Machine Capacities")
|
89 |
+
for i in range(1, num_machines + 1):
|
90 |
+
capacity = st.number_input(f"Capacity of Machine {i} (kg)", min_value=1, value=100)
|
91 |
+
machine_capacities[f"{machine_type} {i}"] = capacity
|
92 |
+
|
93 |
+
toggle_fetch = st.checkbox("Take pre-built Recipe")
|
94 |
+
if toggle_fetch:
|
95 |
+
fabric = st.radio("Choose Fabric Type", ["Cotton", "Polyester", "PolyCotton","Lycra"], index=0)
|
96 |
+
shade = st.radio("Choose your Shade", ["Dark", "Medium", "Light", "White"])
|
97 |
+
fabric_type = fabric.strip().lower()
|
98 |
+
shade = shade.strip().lower()
|
99 |
+
recipes = recipes_dict.get((fabric_type, shade), {})
|
100 |
+
else:
|
101 |
+
recipes = {}
|
102 |
+
|
103 |
+
st.write("### Results")
|
104 |
+
if "current_machine_index" not in st.session_state:
|
105 |
+
st.session_state["current_machine_index"] = 0
|
106 |
+
|
107 |
+
machine_names = list(machine_capacities.keys())
|
108 |
+
machine_results = {}
|
109 |
+
for machine in machine_names:
|
110 |
+
machine_results[machine] = calculate_outputs(mlr, recipes, machine_capacities[machine])
|
111 |
+
|
112 |
+
peak_load, avg_load = calculate_peak_avg_load(machine_results)
|
113 |
+
|
114 |
+
if st.button("Calculate Summary"):
|
115 |
+
st.markdown(
|
116 |
+
f"""
|
117 |
+
<div style='padding:10px; border-radius:10px; background-color:#05f5f5;'>
|
118 |
+
<h3 style='color:black;'>Summary</h3>
|
119 |
+
<p style='color:black;'><strong>Peak Steam Load:</strong> {peak_load} kg/hr</p>
|
120 |
+
<p style='color:black;'><strong>Average Steam Load:</strong> {avg_load} kg/hr</p>
|
121 |
+
</div>
|
122 |
+
""",
|
123 |
+
unsafe_allow_html=True,
|
124 |
+
)
|
125 |
+
|
126 |
+
col1, col2 = st.columns(2)
|
127 |
+
with col1:
|
128 |
+
if st.button("Previous Machine"):
|
129 |
+
st.session_state["current_machine_index"] = (st.session_state["current_machine_index"] - 1) % len(machine_names)
|
130 |
+
with col2:
|
131 |
+
if st.button("Next Machine"):
|
132 |
+
st.session_state["current_machine_index"] = (st.session_state["current_machine_index"] + 1) % len(machine_names)
|
133 |
+
|
134 |
+
current_machine = machine_names[st.session_state["current_machine_index"]]
|
135 |
+
st.write(f"### Calculations for {current_machine}")
|
136 |
+
df_results = pd.DataFrame(machine_results[current_machine])
|
137 |
+
st.table(df_results)
|
138 |
+
|
139 |
+
csv = convert_df_to_csv(df_results)
|
140 |
+
st.download_button("Download Table as CSV", data=csv, file_name=f"{current_machine}_results.csv", mime='text/csv')
|
141 |
+
|
142 |
+
st.header("Steam Load Variation Over Time")
|
143 |
+
if st.button("Plot Steam Load Variation"):
|
144 |
+
fig1 = plotter.plot_steam_load(machine_results[current_machine]['Time'], machine_results[current_machine]['Steam Consumption'])
|
145 |
+
st.pyplot(fig1)
|
146 |
+
|
147 |
+
st.header("Temperature Variation Over Time")
|
148 |
+
if st.button("Plot Temperature Variation"):
|
149 |
+
fig2 = plotter.plot_temperature_curve(machine_results[current_machine]['Time'], machine_results[current_machine]['init_Temp'], machine_results[current_machine]['final_Temp'], machine_results[current_machine]['temp_grad'])
|
150 |
+
st.pyplot(fig2)
|
151 |
+
|