sadickam commited on
Commit
f758ece
·
verified ·
1 Parent(s): 8be0704

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -18
app.py CHANGED
@@ -56,10 +56,10 @@ for key, value in default_values.items():
56
  def calculate_absorption_area(volume, reverberation_time):
57
  return 0.161 * volume / reverberation_time if reverberation_time else float('inf')
58
 
59
- def generate_pdf(volume: float, current_rt: Dict[int, float], existing_materials: List[Dict[str, Any]],
60
- min_rt: Dict[int, float], max_rt: Dict[int, float], desired_rt: Dict[int, float],
61
- new_materials: List[Dict[str, Any]], fig1: go.Figure, fig2: go.Figure,
62
- sound_pressure: pd.DataFrame, updated_sound_pressure: pd.DataFrame, noise_reduction: float) -> bytes:
63
 
64
  pdf = FPDF()
65
  pdf.add_page()
@@ -97,20 +97,24 @@ def generate_pdf(volume: float, current_rt: Dict[int, float], existing_materials
97
  fig.write_image(tmpfile.name, engine='kaleido')
98
  pdf.image(tmpfile.name, x=10, y=None, w=180)
99
 
 
100
  pdf.add_page()
101
  pdf.cell(200, 10, txt="Current Sound Pressure Levels (dB):", ln=True)
102
- for index, row in sound_pressure.iterrows():
103
- pdf.cell(200, 10, txt=f"{index}: {', '.join([f'{val:.2f}' for val in row])}", ln=True)
104
-
105
- pdf.cell(200, 10, txt="Noise Reduction (dB):", ln=True)
106
- pdf.cell(200, 10, txt=f"{noise_reduction:.2f}", ln=True)
107
 
 
108
  pdf.cell(200, 10, txt="Updated Sound Pressure Levels (dB):", ln=True)
109
- for index, row in updated_sound_pressure.iterrows():
110
- pdf.cell(200, 10, txt=f"{index}: {', '.join([f'{val:.2f}' for val in row])}", ln=True)
 
 
111
 
112
  return pdf.output(dest='S').encode('latin1')
113
 
 
114
  def read_uploaded_file(uploaded_file, header=0, index_col=None):
115
  try:
116
  if uploaded_file.name.endswith('.csv'):
@@ -728,16 +732,23 @@ def display_intelligibility_noise_reduction():
728
  **IMPORTANT NOTE ABOUT PDF REPORT:** The purpose of the PDF report is to provide you detailed record of all
729
  your input data and the graphs generated. Graphs in PDF report are of low resolutions. Hence, remember to download
730
  individual graphs and tables to include in your report. Hover your mouse over a graph and several icons would
731
- appear at the top right corner of the graph, click the first icon to download the graph. Repeat the same process
732
  to download tables.
733
  """)
734
  if st.button("Download PDF Report"):
735
- pdf = generate_pdf(st.session_state.volume, st.session_state.current_rt,
736
- st.session_state.existing_materials, st.session_state.min_rt_val,
737
- st.session_state.max_rt_val, st.session_state.desired_rt,
738
- st.session_state.new_materials, st.session_state.fig1, st.session_state.fig2,
739
- st.session_state.df_sound_pressure, st.session_state.updated_sound_pressure,
740
- st.session_state.noise_reduction)
 
 
 
 
 
 
 
741
  st.download_button(label="Download PDF", data=pdf, file_name="Room_Acoustics_Report.pdf",
742
  mime="application/pdf")
743
 
 
56
  def calculate_absorption_area(volume, reverberation_time):
57
  return 0.161 * volume / reverberation_time if reverberation_time else float('inf')
58
 
59
+ def generate_pdf(volume, current_rt, existing_materials, min_rt, max_rt, desired_rt, new_materials, fig1, fig2, df_sound_pressure, updated_df):
60
+ from fpdf import FPDF
61
+ import tempfile
62
+ import kaleido
63
 
64
  pdf = FPDF()
65
  pdf.add_page()
 
97
  fig.write_image(tmpfile.name, engine='kaleido')
98
  pdf.image(tmpfile.name, x=10, y=None, w=180)
99
 
100
+ # Add sound pressure levels data
101
  pdf.add_page()
102
  pdf.cell(200, 10, txt="Current Sound Pressure Levels (dB):", ln=True)
103
+ for index, row in df_sound_pressure.iterrows():
104
+ pdf.cell(200, 10, txt=f"{index}:", ln=True)
105
+ for col in df_sound_pressure.columns:
106
+ pdf.cell(200, 10, txt=f"{col} Hz: {row[col]:.2f}", ln=True)
 
107
 
108
+ # Add updated sound pressure levels data
109
  pdf.cell(200, 10, txt="Updated Sound Pressure Levels (dB):", ln=True)
110
+ for index, row in updated_df.iterrows():
111
+ pdf.cell(200, 10, txt=f"{index}:", ln=True)
112
+ for col in updated_df.columns:
113
+ pdf.cell(200, 10, txt=f"{col} Hz: {row[col]:.2f}", ln=True)
114
 
115
  return pdf.output(dest='S').encode('latin1')
116
 
117
+
118
  def read_uploaded_file(uploaded_file, header=0, index_col=None):
119
  try:
120
  if uploaded_file.name.endswith('.csv'):
 
732
  **IMPORTANT NOTE ABOUT PDF REPORT:** The purpose of the PDF report is to provide you detailed record of all
733
  your input data and the graphs generated. Graphs in PDF report are of low resolutions. Hence, remember to download
734
  individual graphs and tables to include in your report. Hover your mouse over a graph and several icons would
735
+ appear at the top right corner of the graph, click the first icon to download the graph. Repeat the same process
736
  to download tables.
737
  """)
738
  if st.button("Download PDF Report"):
739
+ pdf = generate_pdf(
740
+ st.session_state.volume,
741
+ st.session_state.current_rt,
742
+ st.session_state.existing_materials,
743
+ {freq: st.session_state.min_rt_val for freq in st.session_state.frequencies},
744
+ {freq: st.session_state.max_rt_val for freq in st.session_state.frequencies},
745
+ st.session_state.desired_rt,
746
+ st.session_state.new_materials,
747
+ st.session_state.fig1,
748
+ st.session_state.fig2,
749
+ st.session_state.df_sound_pressure,
750
+ updated_df
751
+ )
752
  st.download_button(label="Download PDF", data=pdf, file_name="Room_Acoustics_Report.pdf",
753
  mime="application/pdf")
754