RathodHarish commited on
Commit
007a560
·
verified ·
1 Parent(s): 4d3cbee

Create upload_csv

Browse files
Files changed (1) hide show
  1. upload_csv +29 -0
upload_csv ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def upload_csv(file):
2
+ global df
3
+ try:
4
+ if file is None:
5
+ return ["All"], ["All"], "No file uploaded. Please upload a CSV file.", "All", "All"
6
+
7
+ df = pd.read_csv(file)
8
+ if df.empty:
9
+ return ["All"], ["All"], "The uploaded CSV file is empty.", "All", "All"
10
+
11
+ # Debug: Print the DataFrame to check its content
12
+ print("DataFrame content:\n", df.to_string())
13
+
14
+ required_columns = {'DeviceID', 'Lab', 'Type', 'Timestamp', 'Status', 'UsageCount'}
15
+ if not required_columns.issubset(df.columns):
16
+ missing_cols = required_columns - set(df.columns)
17
+ return ["All"], ["All"], f"CSV is missing required columns: {', '.join(missing_cols)}", "All", "All"
18
+
19
+ labs = ['All'] + sorted([str(lab) for lab in df['Lab'].dropna().unique() if str(lab).strip()])
20
+ types = ['All'] + sorted([str(type_) for type_ in df['Type'].dropna().unique() if str(type_).strip()])
21
+
22
+ if len(labs) == 1:
23
+ labs = ["All"]
24
+ if len(types) == 1:
25
+ types = ["All"]
26
+
27
+ return labs, types, "", "All", "All"
28
+ except Exception as e:
29
+ return ["All"], ["All"], f"Failed to load CSV: {str(e)}", "All", "All"