RathodHarish commited on
Commit
c20a456
·
verified ·
1 Parent(s): 20498e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -93,7 +93,8 @@ picklist_mapping = {
93
  'ops': 'UV Verification',
94
  'maintenance': 'Smart Log',
95
  'cell': 'Cell Analysis',
96
- 'uv': 'UV Verification'
 
97
  }
98
  }
99
 
@@ -200,11 +201,18 @@ def save_to_salesforce(df, summary, anomalies, amc_reminders, insights):
200
  amc_date_str = None
201
  if pd.notna(row['amc_date']):
202
  try:
203
- amc_date = pd.to_datetime(row['amc_date']).strftime('%Y-%m-%d')
204
- amc_date_str = amc_date
205
- amc_date_dt = datetime.strptime(amc_date, '%Y-%m-%d')
206
- if status == "Active" and current_date.date() <= amc_date_dt.date() <= next_30_days.date():
207
- logging.info(f"Record qualifies for AMC Reminders: Device ID {row['device_id']}, AMC Date {amc_date_str}")
 
 
 
 
 
 
 
208
  except Exception as e:
209
  logging.error(f"Failed to parse AMC Date for Device ID {row['device_id']}: {str(e)}")
210
  amc_date_str = None
 
93
  'ops': 'UV Verification',
94
  'maintenance': 'Smart Log',
95
  'cell': 'Cell Analysis',
96
+ 'uv': 'UV Verification',
97
+ 'weight log': 'Smart Log' # Added mapping for 'weight log'
98
  }
99
  }
100
 
 
201
  amc_date_str = None
202
  if pd.notna(row['amc_date']):
203
  try:
204
+ # Try parsing as DD-MM-YYYY
205
+ amc_date = pd.to_datetime(row['amc_date'], format='%d-%m-%Y', errors='coerce')
206
+ if pd.isna(amc_date):
207
+ # If that fails, try YYYY-MM-DD
208
+ amc_date = pd.to_datetime(row['amc_date'], format='%Y-%m-%d', errors='coerce')
209
+ if pd.isna(amc_date):
210
+ logging.error(f"Failed to parse AMC Date for Device ID {row['device_id']}: {row['amc_date']}")
211
+ else:
212
+ amc_date_str = amc_date.strftime('%Y-%m-%d')
213
+ amc_date_dt = datetime.strptime(amc_date_str, '%Y-%m-%d')
214
+ if status == "Active" and current_date.date() <= amc_date_dt.date() <= next_30_days.date():
215
+ logging.info(f"Record qualifies for AMC Reminders: Device ID {row['device_id']}, AMC Date {amc_date_str}")
216
  except Exception as e:
217
  logging.error(f"Failed to parse AMC Date for Device ID {row['device_id']}: {str(e)}")
218
  amc_date_str = None