update app.py
Browse files
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 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.")
|