YashMK89 commited on
Commit
a0ac8ef
·
verified ·
1 Parent(s): 5b984f4

update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -18
app.py CHANGED
@@ -694,25 +694,45 @@ def process_aggregation(locations_df, start_date_str, end_date_str, dataset_id,
694
  progress_bar.progress(progress_percentage)
695
  progress_text.markdown(f"Processing: {int(progress_percentage * 100)}%")
696
 
697
- if aggregated_results:
698
- result_df = pd.DataFrame(aggregated_results)
699
- if aggregation_period.lower() == 'daily':
700
- aggregated_output = result_df.groupby('Location Name').agg({
701
- 'Latitude': 'first' if shape_type.lower() == 'point' else None,
702
- 'Longitude': 'first' if shape_type.lower() == 'point' else None,
703
- 'Start Date': 'first',
704
- 'End Date': 'first',
705
- 'Calculated Value': 'mean'
706
- }).reset_index()
707
- # Remove None columns (for polygons)
708
- aggregated_output = aggregated_output[[col for col in aggregated_output.columns if col is not None]]
709
- aggregated_output.rename(columns={'Calculated Value': 'Aggregated Value'}, inplace=True)
710
- return aggregated_output.to_dict(orient='records')
711
- else:
712
- return result_df.to_dict(orient='records')
713
 
714
- return []
715
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
716
  # When the user clicks the process button, start the calculation
717
  if st.button(f"Calculate ({index_choice})"):
718
  if file_upload is not None:
 
694
  progress_bar.progress(progress_percentage)
695
  progress_text.markdown(f"Processing: {int(progress_percentage * 100)}%")
696
 
697
+ # if aggregated_results:
698
+ # result_df = pd.DataFrame(aggregated_results)
699
+ # if aggregation_period.lower() == 'daily':
700
+ # aggregated_output = result_df.groupby('Location Name').agg({
701
+ # 'Latitude': 'first' if shape_type.lower() == 'point' else None,
702
+ # 'Longitude': 'first' if shape_type.lower() == 'point' else None,
703
+ # 'Start Date': 'first',
704
+ # 'End Date': 'first',
705
+ # 'Calculated Value': 'mean'
706
+ # }).reset_index()
707
+ # # Remove None columns (for polygons)
708
+ # aggregated_output = aggregated_output[[col for col in aggregated_output.columns if col is not None]]
709
+ # aggregated_output.rename(columns={'Calculated Value': 'Aggregated Value'}, inplace=True)
710
+ # return aggregated_output.to_dict(orient='records')
711
+ # else:
712
+ # return result_df.to_dict(orient='records')
713
 
714
+ # return []
715
+
716
+ if aggregated_results:
717
+ result_df = pd.DataFrame(aggregated_results)
718
+ if aggregation_period.lower() == 'daily':
719
+ # Define aggregation dictionary based on shape_type
720
+ agg_dict = {
721
+ 'Start Date': 'first',
722
+ 'End Date': 'first',
723
+ 'Calculated Value': 'mean'
724
+ }
725
+ if shape_type.lower() == 'point':
726
+ agg_dict['Latitude'] = 'first'
727
+ agg_dict['Longitude'] = 'first'
728
+
729
+ aggregated_output = result_df.groupby('Location Name').agg(agg_dict).reset_index()
730
+ aggregated_output.rename(columns={'Calculated Value': 'Aggregated Value'}, inplace=True)
731
+ return aggregated_output.to_dict(orient='records')
732
+ else:
733
+ return result_df.to_dict(orient='records')
734
+
735
+ return []
736
  # When the user clicks the process button, start the calculation
737
  if st.button(f"Calculate ({index_choice})"):
738
  if file_upload is not None: