gauravlochab commited on
Commit
0f42fbc
·
1 Parent(s): e4e0ab5

refactor: Update date range generation with gaps for better visibility

Browse files
Files changed (1) hide show
  1. app_trans_new.py +18 -12
app_trans_new.py CHANGED
@@ -239,6 +239,21 @@ def fetch_transactions():
239
  df_transactions_new.to_csv(csv_filename, index=False)
240
  return df_transactions_new
241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
 
243
  def create_transcation_visualizations():
244
  df_transactions_new = fetch_transactions()
@@ -248,21 +263,12 @@ def create_transcation_visualizations():
248
  daily_counts = df_transactions_new.groupby([df_transactions_new['timestamp'].dt.date, 'chain']).size().unstack(fill_value=0)
249
 
250
  daily_counts = daily_counts[['optimism', 'base', 'ethereum']]
251
-
252
  # Create a complete date range with gaps between weeks
253
- full_date_range = pd.date_range(start=daily_counts.index.min(), end=daily_counts.index.max(), freq='D').to_list()
254
- for d in list(full_date_range):
255
- if d.weekday() == 6: # If it's Sunday, add gaps for better visibility
256
- full_date_range.extend([d + timedelta(days=1), d + timedelta(days=2)])
257
- full_date_range = sorted(set(full_date_range))
258
-
259
- full_date_range = pd.date_range(start=daily_counts.index.min(), end=daily_counts.index.max(), freq='D').to_list()
260
- for d in full_date_range:
261
- if d.weekday() == 6:
262
- full_date_range.extend([d + timedelta(days=1), d + timedelta(days=2)])
263
- full_date_range = sorted(set(full_date_range))
264
 
265
  # Reindex the DataFrame to include the new date range
 
266
  daily_counts = daily_counts.reindex(full_date_range, fill_value=0)
267
  # Set up the plot
268
  fig_tx_chain = px.bar(
 
239
  df_transactions_new.to_csv(csv_filename, index=False)
240
  return df_transactions_new
241
 
242
+ def date_range_with_gaps(start_date, end_date):
243
+ """Generates a range of dates from start_date to end_date inclusive, with extra days between weeks."""
244
+ start_dt = datetime.strptime(start_date, "%Y-%m-%d")
245
+ end_dt = datetime.strptime(end_date, "%Y-%m-%d")
246
+ delta = timedelta(days=1)
247
+ current_dt = start_dt
248
+ date_list = []
249
+ while current_dt <= end_dt:
250
+ date_list.append(current_dt.date())
251
+ if current_dt.weekday() == 6: # If it's Sunday, add gaps for better visibility
252
+ for _ in range(2):
253
+ current_dt += delta
254
+ date_list.append(current_dt.date())
255
+ current_dt += delta
256
+ return date_list
257
 
258
  def create_transcation_visualizations():
259
  df_transactions_new = fetch_transactions()
 
263
  daily_counts = df_transactions_new.groupby([df_transactions_new['timestamp'].dt.date, 'chain']).size().unstack(fill_value=0)
264
 
265
  daily_counts = daily_counts[['optimism', 'base', 'ethereum']]
266
+
267
  # Create a complete date range with gaps between weeks
268
+ full_date_range = date_range_with_gaps(daily_counts.index.min().strftime("%Y-%m-%d"), daily_counts.index.max().strftime("%Y-%m-%d"))
 
 
 
 
 
 
 
 
 
 
269
 
270
  # Reindex the DataFrame to include the new date range
271
+ full_date_range = pd.to_datetime(full_date_range)
272
  daily_counts = daily_counts.reindex(full_date_range, fill_value=0)
273
  # Set up the plot
274
  fig_tx_chain = px.bar(