YashMK89 commited on
Commit
04d275e
·
verified ·
1 Parent(s): 1d3ba23

update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -29
app.py CHANGED
@@ -709,36 +709,83 @@ if file_upload is not None:
709
  m.to_streamlit()
710
  st.session_state.map_data = m
711
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
712
  if st.button(f"Calculate {custom_formula}"):
713
  if not locations_df.empty:
714
- results, processing_time = process_aggregation( # Capture results and processing time
715
- locations_df,
716
- start_date_str,
717
- end_date_str,
718
- dataset_id,
719
- selected_bands,
720
- reducer_choice,
721
- shape_type,
722
- aggregation_period,
723
- custom_formula,
724
- kernel_size,
725
- include_boundary
726
- )
727
- if results:
728
- result_df = pd.DataFrame(results)
729
- st.write(f"Processed Results Table ({aggregation_period}) for Formula: {custom_formula}")
730
- st.dataframe(result_df)
731
- filename = f"{main_selection}_{dataset_id}_{start_date.strftime('%Y%m%d')}_{end_date.strftime('%Y%m%d')}_{aggregation_period.lower()}.csv"
732
- st.download_button(
733
- label="Download results as CSV",
734
- data=result_df.to_csv(index=False).encode('utf-8'),
735
- file_name=filename,
736
- mime='text/csv'
737
- )
738
- # Display processing time
739
- st.success(f"Processing complete! Total processing time: {processing_time:.2f} seconds.")
740
- else:
741
- st.warning("No results were generated. Check your inputs or formula.")
742
- st.info(f"Total processing time: {processing_time:.2f} seconds.") # Show processing time even if no results
 
 
 
 
 
 
 
 
 
 
 
 
743
  else:
744
  st.warning("Please upload a file to proceed.")
 
709
  m.to_streamlit()
710
  st.session_state.map_data = m
711
 
712
+ # if st.button(f"Calculate {custom_formula}"):
713
+ # if not locations_df.empty:
714
+ # with st.spinner("Processing Data..."):
715
+ # results, processing_time = process_aggregation( # Capture results and processing time
716
+ # locations_df,
717
+ # start_date_str,
718
+ # end_date_str,
719
+ # dataset_id,
720
+ # selected_bands,
721
+ # reducer_choice,
722
+ # shape_type,
723
+ # aggregation_period,
724
+ # custom_formula,
725
+ # kernel_size,
726
+ # include_boundary
727
+ # )
728
+ # if results:
729
+ # result_df = pd.DataFrame(results)
730
+ # st.write(f"Processed Results Table ({aggregation_period}) for Formula: {custom_formula}")
731
+ # st.dataframe(result_df)
732
+ # filename = f"{main_selection}_{dataset_id}_{start_date.strftime('%Y%m%d')}_{end_date.strftime('%Y%m%d')}_{aggregation_period.lower()}.csv"
733
+ # st.download_button(
734
+ # label="Download results as CSV",
735
+ # data=result_df.to_csv(index=False).encode('utf-8'),
736
+ # file_name=filename,
737
+ # mime='text/csv'
738
+ # )
739
+ # # Display processing time
740
+ # st.success(f"Processing complete! Total processing time: {processing_time:.2f} seconds.")
741
+ # else:
742
+ # st.warning("No results were generated. Check your inputs or formula.")
743
+ # st.info(f"Total processing time: {processing_time:.2f} seconds.") # Show processing time even if no results
744
+ # else:
745
+ # st.warning("Please upload a file to proceed.")
746
+
747
  if st.button(f"Calculate {custom_formula}"):
748
  if not locations_df.empty:
749
+ # Use a spinner to indicate data processing
750
+ with st.spinner("Processing Data..."):
751
+ try:
752
+ # Call the aggregation function and capture results and processing time
753
+ results, processing_time = process_aggregation(
754
+ locations_df,
755
+ start_date_str,
756
+ end_date_str,
757
+ dataset_id,
758
+ selected_bands,
759
+ reducer_choice,
760
+ shape_type,
761
+ aggregation_period,
762
+ custom_formula,
763
+ kernel_size,
764
+ include_boundary
765
+ )
766
+
767
+ # Check if results were generated
768
+ if results:
769
+ result_df = pd.DataFrame(results)
770
+ st.write(f"Processed Results Table ({aggregation_period}) for Formula: {custom_formula}")
771
+ st.dataframe(result_df)
772
+
773
+ # Generate a downloadable CSV file
774
+ filename = f"{main_selection}_{dataset_id}_{start_date.strftime('%Y%m%d')}_{end_date.strftime('%Y%m%d')}_{aggregation_period.lower()}.csv"
775
+ st.download_button(
776
+ label="Download results as CSV",
777
+ data=result_df.to_csv(index=False).encode('utf-8'),
778
+ file_name=filename,
779
+ mime='text/csv'
780
+ )
781
+
782
+ # Display processing time
783
+ st.success(f"Processing complete! Total processing time: {processing_time:.2f} seconds.")
784
+ else:
785
+ st.warning("No results were generated. Check your inputs or formula.")
786
+ st.info(f"Total processing time: {processing_time:.2f} seconds.") # Show processing time even if no results
787
+
788
+ except Exception as e:
789
+ st.error(f"An error occurred during processing: {str(e)}")
790
  else:
791
  st.warning("Please upload a file to proceed.")