annikwag commited on
Commit
16d74db
·
verified ·
1 Parent(s): 609f977

Update appStore/prep_data.py

Browse files

add get_max_end_year function

Files changed (1) hide show
  1. appStore/prep_data.py +26 -0
appStore/prep_data.py CHANGED
@@ -64,3 +64,29 @@ def remove_duplicates(results_list):
64
  unique_results.append(r)
65
 
66
  return unique_results
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  unique_results.append(r)
65
 
66
  return unique_results
67
+
68
+
69
+ def get_max_end_year(_client, collection_name):
70
+ """
71
+ Return the maximum 'end_year' in the entire collection
72
+ so we can set the slider's max_value dynamically.
73
+ """
74
+ # For safety, get a large pool of items
75
+ all_res = hybrid_search(_client, "", collection_name, limit=2000)
76
+ big_list = all_res[0] + all_res[1]
77
+
78
+ years = []
79
+ for r in big_list:
80
+ metadata = r.payload.get('metadata', {})
81
+ year_str = metadata.get('end_year', None)
82
+ if year_str:
83
+ try:
84
+ years.append(float(year_str))
85
+ except ValueError:
86
+ pass
87
+
88
+ if not years:
89
+ # fallback if no valid end years found
90
+ return 2030
91
+ return int(max(years))
92
+