3morrrrr commited on
Commit
22d5ae9
·
verified ·
1 Parent(s): a341f2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -42,23 +42,30 @@ def adjust_excel_formatting(file_path):
42
  def process_file(input_file):
43
  """Process uploaded Excel file and return output"""
44
  try:
 
45
  input_df = pd.read_excel(input_file, header=1)
 
 
46
  date_columns = input_df.columns[1:].tolist()
47
 
 
48
  df_long = input_df.melt(
49
  id_vars=[input_df.columns[0]],
50
  var_name='DATE',
51
  value_name='CHATTER'
52
  )
53
 
 
54
  df_long['DATE'] = pd.Categorical(
55
  df_long['DATE'],
56
  categories=date_columns,
57
  ordered=True
58
  )
59
 
 
60
  df_long['CHATTER'] = auto_correct_names(df_long['CHATTER'])
61
 
 
62
  grouped = df_long.groupby(['CHATTER', 'DATE'], observed=True)[input_df.columns[0]] \
63
  .apply(lambda x: ', '.join(sorted(x))).reset_index()
64
 
@@ -66,11 +73,18 @@ def process_file(input_file):
66
  chatter_order = grouped['CHATTER'].value_counts().index.tolist()
67
  final_df = pivoted.reindex(chatter_order)[date_columns].fillna("OFF")
68
 
 
69
  final_df = final_df.reset_index()
70
 
71
- temp_file_path = os.path.join(tempfile.gettempdir(), "processed_schedule.xlsx")
 
 
 
 
 
72
  final_df.to_excel(temp_file_path, index=False, sheet_name='Schedule')
73
 
 
74
  adjust_excel_formatting(temp_file_path)
75
 
76
  return final_df, temp_file_path
 
42
  def process_file(input_file):
43
  """Process uploaded Excel file and return output"""
44
  try:
45
+ # Read input file
46
  input_df = pd.read_excel(input_file, header=1)
47
+
48
+ # Store original date order
49
  date_columns = input_df.columns[1:].tolist()
50
 
51
+ # Melt to long format
52
  df_long = input_df.melt(
53
  id_vars=[input_df.columns[0]],
54
  var_name='DATE',
55
  value_name='CHATTER'
56
  )
57
 
58
+ # Force date order
59
  df_long['DATE'] = pd.Categorical(
60
  df_long['DATE'],
61
  categories=date_columns,
62
  ordered=True
63
  )
64
 
65
+ # Clean names
66
  df_long['CHATTER'] = auto_correct_names(df_long['CHATTER'])
67
 
68
+ # Group and pivot
69
  grouped = df_long.groupby(['CHATTER', 'DATE'], observed=True)[input_df.columns[0]] \
70
  .apply(lambda x: ', '.join(sorted(x))).reset_index()
71
 
 
73
  chatter_order = grouped['CHATTER'].value_counts().index.tolist()
74
  final_df = pivoted.reindex(chatter_order)[date_columns].fillna("OFF")
75
 
76
+ # Reset index to show chatter names in preview
77
  final_df = final_df.reset_index()
78
 
79
+ # Create temp file with original filename + "_processed"
80
+ original_filename = os.path.basename(input_file)
81
+ name_part, ext_part = os.path.splitext(original_filename)
82
+ processed_filename = f"{name_part}_processed{ext_part}"
83
+ temp_file_path = os.path.join(tempfile.gettempdir(), processed_filename)
84
+
85
  final_df.to_excel(temp_file_path, index=False, sheet_name='Schedule')
86
 
87
+ # Adjust formatting to ensure everything fits within cells
88
  adjust_excel_formatting(temp_file_path)
89
 
90
  return final_df, temp_file_path