Spaces:
Sleeping
Sleeping
File size: 5,713 Bytes
3be3f9c |
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 |
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
from plot_app import Plot
plotter = Plot()
from recipes import (
recipes_1_cotton_dark,
recipes_2_cotton_medium,
recipes_3_cotton_light,
recipes_4_polyester_dark,
recipes_5_pc_dark,
cotton_cotton_lycra
)
recipes_dict = {
("cotton", "dark"): recipes_1_cotton_dark,
("cotton", "medium"): recipes_2_cotton_medium,
("cotton", "light"): recipes_3_cotton_light,
("polyester", "dark"): recipes_4_polyester_dark,
("polycotton", "dark"): recipes_5_pc_dark,
("lycra","dark"): cotton_cotton_lycra
}
latent_heat = 494
def calculate_outputs(mlr, recipes, capacity):
"""Perform calculations for each machine."""
steam_consumption = []
moment_time = 0
time = []
initial_temp = []
final_temp = []
temp_grad = []
for i in recipes:
time.append(moment_time)
delta_t = recipes[i]["Duration"]
moment_time += delta_t
temp_diff = recipes[i]["final_temp"] - recipes[i]["init_temp"]
final_temp.append(recipes[i]["final_temp"])
initial_temp.append(recipes[i]["init_temp"])
temp_grad.append(recipes[i]["temp.grad"])
temp = recipes[i]["temp.grad"]
temp_diff = abs(temp_diff)
steam_use = (capacity * mlr * temp_diff*1) + (capacity * temp_diff*1) # cp = 1
if temp != 0 :
steam_ = steam_use*60/temp
else:
steam_ = steam_use*60
steam_kg_hr = steam_/latent_heat
steam_consumption.append(round(steam_kg_hr,2))
return {
"Steam Consumption": steam_consumption,
"Time": time,
"init_Temp": initial_temp,
"final_Temp": final_temp,
"temp_grad": temp_grad
}
def calculate_peak_avg_load(machine_results):
"""Calculate peak and average steam load for all machines."""
combined_steam_load = {}
start_time_offset = 0
for machine, results in machine_results.items():
for t, load in zip(results["Time"], results["Steam Consumption"]):
adjusted_time = t + start_time_offset
if adjusted_time in combined_steam_load:
combined_steam_load[adjusted_time] += load
else:
combined_steam_load[adjusted_time] = load
start_time_offset += 10 # Each machine starts 10 units after the previous one
peak_load = max(combined_steam_load.values())
avg_load = sum(combined_steam_load.values()) / len(combined_steam_load)
return peak_load, avg_load
def convert_df_to_csv(df):
return df.to_csv(index=False).encode('utf-8')
st.title("Dyeing Machine Load & Steam Calculator")
machine_type = st.selectbox("Select Type of Machine", ['SoftFlow'])
num_machines = st.number_input("Number of Dyeing Machines", min_value=1, value=5)
mlr = st.number_input("Enter the MLR for the process", min_value=2, value=6)
machine_capacities = {}
st.write("### Enter Machine Capacities")
for i in range(1, num_machines + 1):
capacity = st.number_input(f"Capacity of Machine {i} (kg)", min_value=1, value=100)
machine_capacities[f"{machine_type} {i}"] = capacity
toggle_fetch = st.checkbox("Take pre-built Recipe")
if toggle_fetch:
fabric = st.radio("Choose Fabric Type", ["Cotton", "Polyester", "PolyCotton","Lycra"], index=0)
shade = st.radio("Choose your Shade", ["Dark", "Medium", "Light", "White"])
fabric_type = fabric.strip().lower()
shade = shade.strip().lower()
recipes = recipes_dict.get((fabric_type, shade), {})
else:
recipes = {}
st.write("### Results")
if "current_machine_index" not in st.session_state:
st.session_state["current_machine_index"] = 0
machine_names = list(machine_capacities.keys())
machine_results = {}
for machine in machine_names:
machine_results[machine] = calculate_outputs(mlr, recipes, machine_capacities[machine])
peak_load, avg_load = calculate_peak_avg_load(machine_results)
if st.button("Calculate Summary"):
st.markdown(
f"""
<div style='padding:10px; border-radius:10px; background-color:#05f5f5;'>
<h3 style='color:black;'>Summary</h3>
<p style='color:black;'><strong>Peak Steam Load:</strong> {peak_load} kg/hr</p>
<p style='color:black;'><strong>Average Steam Load:</strong> {avg_load} kg/hr</p>
</div>
""",
unsafe_allow_html=True,
)
col1, col2 = st.columns(2)
with col1:
if st.button("Previous Machine"):
st.session_state["current_machine_index"] = (st.session_state["current_machine_index"] - 1) % len(machine_names)
with col2:
if st.button("Next Machine"):
st.session_state["current_machine_index"] = (st.session_state["current_machine_index"] + 1) % len(machine_names)
current_machine = machine_names[st.session_state["current_machine_index"]]
st.write(f"### Calculations for {current_machine}")
df_results = pd.DataFrame(machine_results[current_machine])
st.table(df_results)
csv = convert_df_to_csv(df_results)
st.download_button("Download Table as CSV", data=csv, file_name=f"{current_machine}_results.csv", mime='text/csv')
st.header("Steam Load Variation Over Time")
if st.button("Plot Steam Load Variation"):
fig1 = plotter.plot_steam_load(machine_results[current_machine]['Time'], machine_results[current_machine]['Steam Consumption'])
st.pyplot(fig1)
st.header("Temperature Variation Over Time")
if st.button("Plot Temperature Variation"):
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'])
st.pyplot(fig2)
|