YashMK89 commited on
Commit
930eab6
·
verified ·
1 Parent(s): 4891f4b

update app.py

Browse files
Files changed (1) hide show
  1. app.py +91 -0
app.py CHANGED
@@ -11,6 +11,8 @@ from shapely.geometry import base
11
  from xml.etree import ElementTree as XET
12
  from concurrent.futures import ThreadPoolExecutor, as_completed
13
  import time
 
 
14
 
15
  # Set up the page layout
16
  st.set_page_config(layout="wide")
@@ -641,6 +643,45 @@ if file_upload is not None:
641
  st.write("Map of Uploaded Polygons:")
642
  m.to_streamlit()
643
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
644
  if st.button(f"Calculate {custom_formula}"):
645
  if not locations_df.empty:
646
  with st.spinner("Processing Data..."):
@@ -662,8 +703,12 @@ if st.button(f"Calculate {custom_formula}"):
662
  )
663
  if results:
664
  result_df = pd.DataFrame(results)
 
 
665
  st.write(f"Processed Results Table ({aggregation_period}) for Formula: {custom_formula}")
666
  st.dataframe(result_df)
 
 
667
  filename = f"{main_selection}_{dataset_id}_{start_date.strftime('%Y%m%d')}_{end_date.strftime('%Y%m%d')}_{aggregation_period.lower()}.csv"
668
  st.download_button(
669
  label="Download results as CSV",
@@ -671,10 +716,56 @@ if st.button(f"Calculate {custom_formula}"):
671
  file_name=filename,
672
  mime='text/csv'
673
  )
 
 
674
  st.success(f"Processing complete! Total processing time: {processing_time:.2f} seconds.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
675
  else:
676
  st.warning("No results were generated. Check your inputs or formula.")
677
  st.info(f"Total processing time: {processing_time:.2f} seconds.")
 
678
  except Exception as e:
679
  st.error(f"An error occurred during processing: {str(e)}")
680
  else:
 
11
  from xml.etree import ElementTree as XET
12
  from concurrent.futures import ThreadPoolExecutor, as_completed
13
  import time
14
+ import matplotlib.pyplot as plt
15
+ import plotly.express as px
16
 
17
  # Set up the page layout
18
  st.set_page_config(layout="wide")
 
643
  st.write("Map of Uploaded Polygons:")
644
  m.to_streamlit()
645
 
646
+ # if st.button(f"Calculate {custom_formula}"):
647
+ # if not locations_df.empty:
648
+ # with st.spinner("Processing Data..."):
649
+ # try:
650
+ # results, processing_time = process_aggregation(
651
+ # locations_df,
652
+ # start_date_str,
653
+ # end_date_str,
654
+ # dataset_id,
655
+ # selected_bands,
656
+ # reducer_choice,
657
+ # shape_type,
658
+ # aggregation_period,
659
+ # original_lat_col,
660
+ # original_lon_col,
661
+ # custom_formula,
662
+ # kernel_size,
663
+ # include_boundary
664
+ # )
665
+ # if results:
666
+ # result_df = pd.DataFrame(results)
667
+ # st.write(f"Processed Results Table ({aggregation_period}) for Formula: {custom_formula}")
668
+ # st.dataframe(result_df)
669
+ # filename = f"{main_selection}_{dataset_id}_{start_date.strftime('%Y%m%d')}_{end_date.strftime('%Y%m%d')}_{aggregation_period.lower()}.csv"
670
+ # st.download_button(
671
+ # label="Download results as CSV",
672
+ # data=result_df.to_csv(index=False).encode('utf-8'),
673
+ # file_name=filename,
674
+ # mime='text/csv'
675
+ # )
676
+ # st.success(f"Processing complete! Total processing time: {processing_time:.2f} seconds.")
677
+ # else:
678
+ # st.warning("No results were generated. Check your inputs or formula.")
679
+ # st.info(f"Total processing time: {processing_time:.2f} seconds.")
680
+ # except Exception as e:
681
+ # st.error(f"An error occurred during processing: {str(e)}")
682
+ # else:
683
+ # st.warning("Please upload a valid file to proceed.")
684
+
685
  if st.button(f"Calculate {custom_formula}"):
686
  if not locations_df.empty:
687
  with st.spinner("Processing Data..."):
 
703
  )
704
  if results:
705
  result_df = pd.DataFrame(results)
706
+
707
+ # Display processed results table
708
  st.write(f"Processed Results Table ({aggregation_period}) for Formula: {custom_formula}")
709
  st.dataframe(result_df)
710
+
711
+ # Download button for results
712
  filename = f"{main_selection}_{dataset_id}_{start_date.strftime('%Y%m%d')}_{end_date.strftime('%Y%m%d')}_{aggregation_period.lower()}.csv"
713
  st.download_button(
714
  label="Download results as CSV",
 
716
  file_name=filename,
717
  mime='text/csv'
718
  )
719
+
720
+ # Success message
721
  st.success(f"Processing complete! Total processing time: {processing_time:.2f} seconds.")
722
+
723
+ # Graph Visualization Section
724
+ st.markdown("<h5>Graph Visualization</h5>", unsafe_allow_html=True)
725
+
726
+ # Allow user to select graph type
727
+ graph_type = st.selectbox(
728
+ "Select Graph Type",
729
+ ["Line Chart", "Bar Chart"],
730
+ index=0
731
+ )
732
+
733
+ # Filter data for plotting
734
+ if 'Date' in result_df.columns:
735
+ x_column = 'Date'
736
+ elif 'Week' in result_df.columns:
737
+ x_column = 'Week'
738
+ elif 'Month' in result_df.columns:
739
+ x_column = 'Month'
740
+ elif 'Year' in result_df.columns:
741
+ x_column = 'Year'
742
+ else:
743
+ st.warning("No valid time column found for plotting.")
744
+ st.stop()
745
+
746
+ y_column = 'Calculated Value'
747
+
748
+ # Plot using Streamlit's built-in charts
749
+ if graph_type == "Line Chart":
750
+ st.line_chart(result_df.set_index(x_column)[y_column])
751
+ elif graph_type == "Bar Chart":
752
+ st.bar_chart(result_df.set_index(x_column)[y_column])
753
+
754
+ # Optional: Use Matplotlib or Plotly for more advanced plots
755
+ if st.checkbox("Show Advanced Plot (Plotly)"):
756
+ fig = px.line(
757
+ result_df,
758
+ x=x_column,
759
+ y=y_column,
760
+ color='Location Name',
761
+ title=f"{custom_formula} Over Time"
762
+ )
763
+ st.plotly_chart(fig)
764
+
765
  else:
766
  st.warning("No results were generated. Check your inputs or formula.")
767
  st.info(f"Total processing time: {processing_time:.2f} seconds.")
768
+
769
  except Exception as e:
770
  st.error(f"An error occurred during processing: {str(e)}")
771
  else: