atsuga commited on
Commit
ed714a9
·
verified ·
1 Parent(s): d3b7829

Update app/routes.py

Browse files
Files changed (1) hide show
  1. app/routes.py +20 -33
app/routes.py CHANGED
@@ -150,6 +150,26 @@ def get_statistics():
150
  for city in city_names
151
  ]
152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  # Pastikan kolom tanggal ada
154
  if 'tanggal' in data_lower.columns:
155
  try:
@@ -194,39 +214,6 @@ def get_statistics():
194
 
195
  forecast_result = forecast(forecast_data)
196
 
197
- if (filtered):
198
- data_lower = filtered_data
199
-
200
- #mengambil untuk option dropdown
201
- # Crime types + count (sudah OK)
202
- all_crimes = data_lower['kata_kunci'].value_counts()
203
- crime_types = [
204
- {'value': crime, 'label': crime.title(), 'count': int(count)}
205
- for crime, count in all_crimes.items()
206
- ]
207
-
208
- # Years + count
209
- all_years = data_lower['tahun_putusan'].dropna().astype(int).value_counts().sort_index(ascending=False)
210
- year_options = [
211
- {'value': str(year), 'label': str(year), 'count': int(count)}
212
- for year, count in all_years.items()
213
- ]
214
-
215
- # ============================================
216
- # MONTHLY SEASONALITY DATA (1–12)
217
- # ============================================
218
- # Pastikan kolom tanggal ada
219
- if 'tanggal' in data_lower.columns:
220
- try:
221
- data_lower['tanggal'] = pd.to_datetime(
222
- data_lower['tanggal'], errors='coerce'
223
- )
224
- except:
225
- pass
226
-
227
- # Extract month
228
- data_lower['bulan_putusan'] = data_lower['tanggal'].dt.month
229
-
230
  # Monthly count (filtered data)
231
  monthly_counts_raw = (
232
  data_lower['bulan_putusan']
 
150
  for city in city_names
151
  ]
152
 
153
+
154
+ if (filtered):
155
+ data_lower = filtered_data
156
+
157
+ #mengambil untuk option dropdown
158
+ # Crime types + count (sudah OK)
159
+ all_crimes = data_lower['kata_kunci'].value_counts()
160
+ crime_types = [
161
+ {'value': crime, 'label': crime.title(), 'count': int(count)}
162
+ for crime, count in all_crimes.items()
163
+ ]
164
+
165
+ # Years + count
166
+ all_years = data_lower['tahun_putusan'].dropna().astype(int).value_counts().sort_index(ascending=False)
167
+ year_options = [
168
+ {'value': str(year), 'label': str(year), 'count': int(count)}
169
+ for year, count in all_years.items()
170
+ ]
171
+
172
+
173
  # Pastikan kolom tanggal ada
174
  if 'tanggal' in data_lower.columns:
175
  try:
 
214
 
215
  forecast_result = forecast(forecast_data)
216
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
  # Monthly count (filtered data)
218
  monthly_counts_raw = (
219
  data_lower['bulan_putusan']