deepak6593 commited on
Commit
32d5829
·
1 Parent(s): 7bb0628
Files changed (1) hide show
  1. main.py +27 -6
main.py CHANGED
@@ -40,22 +40,43 @@ gcs_bucket = gcs_client.bucket(gcs_bucket_name)
40
  # File path in GCS bucket
41
  gcs_file_path = "deepak_6593/db.csv"
42
 
43
- # Function to create an empty file in GCS bucket
44
- def create_empty_file():
45
  # Initialize GCS client
46
  gcs_client = storage.Client()
47
  gcs_bucket = gcs_client.bucket(gcs_bucket_name)
48
  blob = gcs_bucket.blob(gcs_file_path)
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  # Delete file if it exists
51
  if blob.exists():
52
  blob.delete()
53
 
54
- # Create an empty file
55
- blob.upload_from_string("", content_type="text/csv")
56
 
57
- # Check and create file before endpoint is accessed
58
- create_empty_file()
59
 
60
  def read_csv(location="tambaram"):
61
  global stop_reading
 
40
  # File path in GCS bucket
41
  gcs_file_path = "deepak_6593/db.csv"
42
 
43
+ def create_empty_csv():
 
44
  # Initialize GCS client
45
  gcs_client = storage.Client()
46
  gcs_bucket = gcs_client.bucket(gcs_bucket_name)
47
  blob = gcs_bucket.blob(gcs_file_path)
48
 
49
+ # Define columns for the empty DataFrame
50
+ columns = [
51
+ "timestamp",
52
+ "time",
53
+ "Vibration (mm/s)",
54
+ "Temperature (°C)",
55
+ "Pressure (psi)",
56
+ "Flow Rate (L/min)",
57
+ "Level (%)",
58
+ "Current (A)",
59
+ "Humidity (%)",
60
+ "Oil Quality (%)",
61
+ "pump_status",
62
+ "location"
63
+ ]
64
+
65
+ # Create an empty DataFrame with the specified columns
66
+ empty_df = pd.DataFrame(columns=columns)
67
+
68
+ # Convert the empty DataFrame to CSV format
69
+ csv_data = empty_df.to_csv(index=False)
70
+
71
  # Delete file if it exists
72
  if blob.exists():
73
  blob.delete()
74
 
75
+ # Upload the CSV data to the GCS bucket
76
+ blob.upload_from_string(csv_data, content_type="text/csv")
77
 
78
+ # Create an empty CSV file before endpoint is accessed
79
+ create_empty_csv()
80
 
81
  def read_csv(location="tambaram"):
82
  global stop_reading