ecopipeline 0.5.0__py3-none-any.whl → 0.5.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- from .load import check_table_exists, create_new_table, load_overwrite_database, load_event_table
2
- __all__ = ["check_table_exists", "create_new_table", "load_overwrite_database", "load_event_table"]
1
+ from .load import check_table_exists, create_new_table, load_overwrite_database, load_event_table, report_data_loss
2
+ __all__ = ["check_table_exists", "create_new_table", "load_overwrite_database", "load_event_table", "report_data_loss"]
ecopipeline/load/load.py CHANGED
@@ -368,6 +368,69 @@ def load_event_table(config : ConfigManager, event_df: pd.DataFrame, site_name :
368
368
  cursor.close()
369
369
  return True
370
370
 
371
+ def report_data_loss(config : ConfigManager, site_name : str = None):
372
+ """
373
+ Logs data loss event in event database (assumes one exists)
374
+
375
+ Parameters
376
+ ----------
377
+ config : ecopipeline.ConfigManager
378
+ The ConfigManager object that holds configuration data for the pipeline.
379
+ site_name : str
380
+ the name of the site to correspond the events with. If left blank will default to minute table name
381
+
382
+ Returns
383
+ -------
384
+ bool:
385
+ A boolean value indicating if the data was successfully written to the database.
386
+ """
387
+ # Drop empty columns
388
+
389
+ dbname = config.get_db_name()
390
+ table_name = "site_events"
391
+ if site_name is None:
392
+ site_name = config.get_site_name()
393
+ error_string = "Error proccessing data. Please check logs to resolve."
394
+
395
+ print(f"logging DATA_LOSS into {table_name}")
396
+
397
+ # create SQL statement
398
+ insert_str = "INSERT INTO " + table_name + " (start_time_pt, site_name, event_detail, event_type, last_modified_date, last_modified_by) VALUES "
399
+ insert_str += f"('{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}','{site_name}','{error_string}','DATA_LOSS','{datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')}','automatic_upload')"
400
+
401
+ existing_rows = pd.DataFrame({
402
+ 'id' : []
403
+ })
404
+
405
+ connection, cursor = config.connect_db()
406
+
407
+ # create db table if it does not exist, otherwise add missing columns to existing table
408
+ if not check_table_exists(cursor, table_name, dbname):
409
+ print(f"Cannot log data loss. {table_name} does not exist in database {dbname}")
410
+ return False
411
+ else:
412
+ try:
413
+ # find existing times in database for upsert statement
414
+ cursor.execute(
415
+ f"SELECT id FROM {table_name} WHERE end_time_pt IS NULL AND site_name = '{site_name}' AND event_type = 'DATA_LOSS' and event_detail = '{error_string}'")
416
+ # Fetch the results into a DataFrame
417
+ existing_rows = pd.DataFrame(cursor.fetchall(), columns=['id'])
418
+
419
+ except mysqlerrors.Error as e:
420
+ print(f"Retrieving data from {table_name} caused exception: {e}")
421
+ try:
422
+
423
+ if existing_rows.empty:
424
+ cursor.execute(insert_str)
425
+ connection.commit()
426
+ print("Successfully logged data loss.")
427
+ except Exception as e:
428
+ # Print the exception message
429
+ print(f"Caught an exception when uploading to site_events table: {e}")
430
+ connection.close()
431
+ cursor.close()
432
+ return True
433
+
371
434
  def _generate_mysql_update_event_table(row, id):
372
435
  statement = f"UPDATE site_events SET "
373
436
  statment_elems = []
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: ecopipeline
3
- Version: 0.5.0
3
+ Version: 0.5.1
4
4
  Summary: Contains functions for use in Ecotope Datapipelines
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: License :: OSI Approved :: GNU General Public License (GPL)
@@ -1,8 +1,8 @@
1
1
  ecopipeline/__init__.py,sha256=vCRzwd781ciCSXMP1ycM_BXAqxj3KVaNKIjsLOPcbwc,171
2
2
  ecopipeline/extract/__init__.py,sha256=3u_CUMdCguVewU3kN8x6xhVNyo1-p-gwTrhjOh7Psqg,645
3
3
  ecopipeline/extract/extract.py,sha256=ryorqnu1RgyNK7joZRcbMmTajlTlB5hwaYzzpo8Z8Ho,43369
4
- ecopipeline/load/__init__.py,sha256=7ipv7GJfZ5382lcrdNm4MyM-WiCEVuRWTqxyzDSZhqg,197
5
- ecopipeline/load/load.py,sha256=RbGZSsigkChZpX1SZzYvZuS6-DS0k-d2IYUsJvZDvmk,17485
4
+ ecopipeline/load/__init__.py,sha256=oDAVF8AhK_qugqegjW7jK16p-nb9QzKhiNQOkEBniKM,235
5
+ ecopipeline/load/load.py,sha256=H9OKjE-EoqhZJ-5Xixqn5vvhvgUNFDdsVsX4fqht0hE,19975
6
6
  ecopipeline/transform/__init__.py,sha256=DcIJfkRs4OmZzDeEfW_OiOIXNqN6CUl1_lW0SS7-eN8,2280
7
7
  ecopipeline/transform/bayview.py,sha256=TP24dnTsUD95X-f6732egPZKjepFLJgDm9ImGr-fppY,17899
8
8
  ecopipeline/transform/lbnl.py,sha256=EQ54G4rJXaZ7pwVusKcdK2KBehSdCsNo2ybphtMGs7o,33400
@@ -10,8 +10,8 @@ ecopipeline/transform/transform.py,sha256=uyBIXKCXUCT6zVnZyQohripGAzmY1yV9T1GxsX
10
10
  ecopipeline/utils/ConfigManager.py,sha256=t4sfTjGO0g5P50XBQqGVFWaXfAlW1GMDh1DLoBuFGks,9826
11
11
  ecopipeline/utils/__init__.py,sha256=ccWUR0m7gD9DfcgsxBCLOfi4lho6RdYuB2Ugy_g6ZdQ,28
12
12
  ecopipeline/utils/unit_convert.py,sha256=VFh1we2Y8KV3u21BeWb-U3TlZJXo83q5vdxxkpgcuME,3064
13
- ecopipeline-0.5.0.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
- ecopipeline-0.5.0.dist-info/METADATA,sha256=gb550ta4s3kOYQCt52JECXo_HaSEeXKkWGeIF3mTVr8,2307
15
- ecopipeline-0.5.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
16
- ecopipeline-0.5.0.dist-info/top_level.txt,sha256=WOPFJH2LIgKqm4lk2OnFF5cgVkYibkaBxIxgvLgO7y0,12
17
- ecopipeline-0.5.0.dist-info/RECORD,,
13
+ ecopipeline-0.5.1.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ ecopipeline-0.5.1.dist-info/METADATA,sha256=BMxe3qd_Ym_Ym5G3QN1zKwPJaZme5g4aEl6LUnaNPjc,2307
15
+ ecopipeline-0.5.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
16
+ ecopipeline-0.5.1.dist-info/top_level.txt,sha256=WOPFJH2LIgKqm4lk2OnFF5cgVkYibkaBxIxgvLgO7y0,12
17
+ ecopipeline-0.5.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.6.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5