updated excel spreadsheet
This commit is contained in:
@@ -5,7 +5,7 @@ codeuri = "/Users/nico/Documents/GitHub/ThingsBoard/EKKO Reports/thunderbirdfs-d
|
|||||||
runtime = "python3.9"
|
runtime = "python3.9"
|
||||||
architecture = "x86_64"
|
architecture = "x86_64"
|
||||||
handler = "thunderbirdfsreport.lambda_handler"
|
handler = "thunderbirdfsreport.lambda_handler"
|
||||||
source_hash = "93b500c168f513a7a25cab048f85e186f10d9e9cd5e16384ba4c71c272648df0"
|
source_hash = "88b16cd7e5de563582281a46aab2ae8c8f286034857022c8856d0366eb522475"
|
||||||
manifest_hash = ""
|
manifest_hash = ""
|
||||||
packagetype = "Zip"
|
packagetype = "Zip"
|
||||||
functions = ["ThunderbirdFSReport"]
|
functions = ["ThunderbirdFSReport"]
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,31 @@
|
|||||||
|
# thunderbirdfsreport/tests/test_thunderbirdfsreport.py (24-30)
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
from thunderbirdfsreport import getDevices
|
||||||
|
from tb_rest_client.rest_client_ce import Customer, CustomerId, PageDataCustomer, PageDataDevice
|
||||||
|
class TestGetDevices(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.rest_client = MagicMock()
|
||||||
|
customer1Id = CustomerId(id="cid1",entity_type="CUSTOMER")
|
||||||
|
customer2Id = CustomerId(id="cid2",entity_type="CUSTOMER")
|
||||||
|
self.customer1 = Customer(id=customer1Id, name='customer1', title="customer1")
|
||||||
|
self.target_customer = Customer(id=customer2Id, name='target_customer', title="customer2")
|
||||||
|
self.customers = PageDataCustomer(data=[self.customer1, self.target_customer])
|
||||||
|
|
||||||
|
def test_get_devices_found_customer(self):
|
||||||
|
self.rest_client.get_customer_devices.return_value = {'devices': []}
|
||||||
|
devices = getDevices(self.rest_client, self.customers, 'target_customer')
|
||||||
|
self.assertEqual(devices, {"devices": []})
|
||||||
|
self.rest_client.get_customer_devices.assert_called_once_with(customer_id='cid2', page_size=500, page=0)
|
||||||
|
|
||||||
|
def test_get_devices_not_found_customer(self):
|
||||||
|
self.rest_client.get_customer_devices.return_value = {'devices': []}
|
||||||
|
devices = getDevices(self.rest_client, self.customers, 'non_target_customer')
|
||||||
|
self.assertEqual(devices, PageDataDevice())
|
||||||
|
self.assertFalse(self.rest_client.get_customer_devices.called)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import json
|
|
||||||
import logging, boto3, pytz, os, shutil
|
import logging, boto3, pytz, os, shutil
|
||||||
from openpyxl.utils.datetime import to_excel
|
from openpyxl.utils.datetime import to_excel
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
@@ -23,11 +22,18 @@ url = "https://www.enxlekkocloud.com" #"https://hp.henrypump.cloud"
|
|||||||
|
|
||||||
|
|
||||||
def getDevices(rest_client, customers,target_customer, page=0, pageSize=500):
|
def getDevices(rest_client, customers,target_customer, page=0, pageSize=500):
|
||||||
for c in customers.data:
|
try:
|
||||||
if c.name == target_customer:
|
cid = ""
|
||||||
cid = c.id.id
|
for c in customers.data:
|
||||||
devices = rest_client.get_customer_devices(customer_id=cid, page_size=pageSize, page=page)
|
if c.name == target_customer:
|
||||||
return devices #.to_dict()
|
cid = c.id.id
|
||||||
|
devices = rest_client.get_customer_devices(customer_id=cid, page_size=pageSize, page=page)
|
||||||
|
return devices #.to_dict()
|
||||||
|
return PageDataDevice()
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"Error occured in getDevices: {e}")
|
||||||
|
return PageDataDevice()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getDeviceKeys(rest_client, devices,target_device):
|
def getDeviceKeys(rest_client, devices,target_device):
|
||||||
@@ -94,15 +100,17 @@ def getThingsBoardData(url, username, password, targetCustomer, timeRequest):
|
|||||||
customers = rest_client.get_customers(page_size="500", page="0")
|
customers = rest_client.get_customers(page_size="500", page="0")
|
||||||
devices = getDevices(rest_client=rest_client, customers=customers, target_customer=targetCustomer)
|
devices = getDevices(rest_client=rest_client, customers=customers, target_customer=targetCustomer)
|
||||||
telemetry = {}
|
telemetry = {}
|
||||||
for d in devices.data:
|
if devices.data:
|
||||||
#print(d.name)
|
for d in devices.data:
|
||||||
device, keys, err = getDeviceKeys(rest_client=rest_client, devices=devices, target_device=d.name)
|
#print(d.name)
|
||||||
start_ts, end_ts = getTime(timeRequest)
|
device, keys, err = getDeviceKeys(rest_client=rest_client, devices=devices, target_device=d.name)
|
||||||
#print(keys)
|
start_ts, end_ts = getTime(timeRequest)
|
||||||
telemetry[d.name] = getTelemetry(rest_client=rest_client, device=device, keys=','.join(keys), start_ts=start_ts, end_ts=end_ts, limit=25000)
|
#print(keys)
|
||||||
latest = getLatestTelemetry(rest_client=rest_client, device=device, keys="manual_well,manual_tfs_lead,manual_copa_lead,manual_job_name")
|
telemetry[d.name] = getTelemetry(rest_client=rest_client, device=device, keys=','.join(keys), start_ts=start_ts, end_ts=end_ts, limit=25000)
|
||||||
telemetry[d.name].update(latest)
|
latest = getLatestTelemetry(rest_client=rest_client, device=device, keys="manual_well,manual_tfs_lead,manual_copa_lead,manual_job_name")
|
||||||
return telemetry
|
telemetry[d.name].update(latest)
|
||||||
|
return telemetry
|
||||||
|
return {}
|
||||||
except ApiException as e:
|
except ApiException as e:
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
return False
|
return False
|
||||||
@@ -119,7 +127,7 @@ def getMaxWidth():
|
|||||||
"Inlet Ph Temp": "INLET PH TEMP",
|
"Inlet Ph Temp": "INLET PH TEMP",
|
||||||
"Ait 102b H2s": "INLET H₂S",
|
"Ait 102b H2s": "INLET H₂S",
|
||||||
"At 109b H2s": "OUTLET H₂S",
|
"At 109b H2s": "OUTLET H₂S",
|
||||||
"At 109c Oil In Water": "OUTLET OIL IN WATER",
|
"Coriolis Density": "OUTLET OIL IN WATER",
|
||||||
"Ait 102a Turbitity": "INLET TURBIDITY",
|
"Ait 102a Turbitity": "INLET TURBIDITY",
|
||||||
"At 109a Turbidity": "OUTLET TURBIDITY",
|
"At 109a Turbidity": "OUTLET TURBIDITY",
|
||||||
"At 109e Orp": "OUTLET ORP"
|
"At 109e Orp": "OUTLET ORP"
|
||||||
@@ -149,7 +157,7 @@ def formatColumnName(telemetryName):
|
|||||||
"Ait 102a Turbitity": "INLET TURBIDITY",
|
"Ait 102a Turbitity": "INLET TURBIDITY",
|
||||||
"At 109a Turbidity": "OUTLET TURBIDITY",
|
"At 109a Turbidity": "OUTLET TURBIDITY",
|
||||||
"At 109e Orp": "OUTLET ORP",
|
"At 109e Orp": "OUTLET ORP",
|
||||||
"Ait 102d Oil In Water": "INLET DENSITY",
|
"Coriolis Density": "INLET DENSITY",
|
||||||
"Fit 106b Flow Rate": "SKIM FLOW RATE",
|
"Fit 106b Flow Rate": "SKIM FLOW RATE",
|
||||||
"Manual Sample Time": "manual_sample_time",
|
"Manual Sample Time": "manual_sample_time",
|
||||||
"Outlet Ph": "Outlet Ph"
|
"Outlet Ph": "Outlet Ph"
|
||||||
@@ -309,7 +317,7 @@ def lambda_handler(event, context):
|
|||||||
)
|
)
|
||||||
|
|
||||||
reportsheet = writer.book.worksheets[0]
|
reportsheet = writer.book.worksheets[0]
|
||||||
keys = ['ait_102a_turbitity','ait_102b_h2s', 'at_109a_turbidity', 'at_109b_h2s', 'at_109c_oil_in_water', 'at_109e_orp', 'fit_100_flow_rate', 'fit_109b_flow_rate', 'lit_116b_level', 'lit_116a_level', 'outlet_turbidity_temp', 'outlet_orp_temp', 'inlet_turbidity_temp', 'inlet_ph_temp', 'ait_102d_oil_in_water','outlet_ph','fit_106b_flow_rate']
|
keys = ['ait_102a_turbitity','ait_102b_h2s', 'at_109a_turbidity', 'at_109b_h2s', 'at_109c_oil_in_water', 'at_109e_orp', 'fit_100_flow_rate', 'fit_109b_flow_rate', 'lit_116b_level', 'lit_116a_level', 'outlet_turbidity_temp', 'outlet_orp_temp', 'inlet_turbidity_temp', 'inlet_ph_temp', 'coriolis_density','outlet_ph','fit_106b_flow_rate']
|
||||||
manual_keys = ['manual_bag_filter_changes', 'manual_cartridge_filter_changes', 'manual_clean_water_sold_per_job', 'manual_coagulant_on_hand', 'manual_diverted_water_time', 'manual_equipment_description', 'manual_equipment_time', 'manual_h202_on_hand', 'manual_issues_concerns', 'manual_next_pigging_scheduled', 'manual_skim_oil_discharged_per_job', 'manual_standby_time', 'manual_unit_uptime', 'manual_upright_tank_issues', 'manual_vac_truck_batches', 'manual_water_events', 'manual_water_events_time', 'manual_water_to_tanks_time',"manual_well", "manual_tfs_lead", "manual_copa_lead", "manual_job_name", "manual_summary", "manual_hse_spills", "manual_quality_issues"]
|
manual_keys = ['manual_bag_filter_changes', 'manual_cartridge_filter_changes', 'manual_clean_water_sold_per_job', 'manual_coagulant_on_hand', 'manual_diverted_water_time', 'manual_equipment_description', 'manual_equipment_time', 'manual_h202_on_hand', 'manual_issues_concerns', 'manual_next_pigging_scheduled', 'manual_skim_oil_discharged_per_job', 'manual_standby_time', 'manual_unit_uptime', 'manual_upright_tank_issues', 'manual_vac_truck_batches', 'manual_water_events', 'manual_water_events_time', 'manual_water_to_tanks_time',"manual_well", "manual_tfs_lead", "manual_copa_lead", "manual_job_name", "manual_summary", "manual_hse_spills", "manual_quality_issues"]
|
||||||
sample_keys = ['manual_sample_datapoint', 'manual_sample_lab', 'manual_sample_location', 'manual_sample_time', 'manual_sample_value']
|
sample_keys = ['manual_sample_datapoint', 'manual_sample_lab', 'manual_sample_location', 'manual_sample_time', 'manual_sample_value']
|
||||||
#Create a Sheet for each Device
|
#Create a Sheet for each Device
|
||||||
|
|||||||
Binary file not shown.
@@ -127,7 +127,7 @@ def getMaxWidth():
|
|||||||
"Inlet Ph Temp": "INLET PH TEMP",
|
"Inlet Ph Temp": "INLET PH TEMP",
|
||||||
"Ait 102b H2s": "INLET H₂S",
|
"Ait 102b H2s": "INLET H₂S",
|
||||||
"At 109b H2s": "OUTLET H₂S",
|
"At 109b H2s": "OUTLET H₂S",
|
||||||
"At 109c Oil In Water": "OUTLET OIL IN WATER",
|
"Coriolis Density": "OUTLET OIL IN WATER",
|
||||||
"Ait 102a Turbitity": "INLET TURBIDITY",
|
"Ait 102a Turbitity": "INLET TURBIDITY",
|
||||||
"At 109a Turbidity": "OUTLET TURBIDITY",
|
"At 109a Turbidity": "OUTLET TURBIDITY",
|
||||||
"At 109e Orp": "OUTLET ORP"
|
"At 109e Orp": "OUTLET ORP"
|
||||||
@@ -157,7 +157,7 @@ def formatColumnName(telemetryName):
|
|||||||
"Ait 102a Turbitity": "INLET TURBIDITY",
|
"Ait 102a Turbitity": "INLET TURBIDITY",
|
||||||
"At 109a Turbidity": "OUTLET TURBIDITY",
|
"At 109a Turbidity": "OUTLET TURBIDITY",
|
||||||
"At 109e Orp": "OUTLET ORP",
|
"At 109e Orp": "OUTLET ORP",
|
||||||
"Ait 102d Oil In Water": "INLET DENSITY",
|
"Coriolis Density": "INLET DENSITY",
|
||||||
"Fit 106b Flow Rate": "SKIM FLOW RATE",
|
"Fit 106b Flow Rate": "SKIM FLOW RATE",
|
||||||
"Manual Sample Time": "manual_sample_time",
|
"Manual Sample Time": "manual_sample_time",
|
||||||
"Outlet Ph": "Outlet Ph"
|
"Outlet Ph": "Outlet Ph"
|
||||||
@@ -317,7 +317,7 @@ def lambda_handler(event, context):
|
|||||||
)
|
)
|
||||||
|
|
||||||
reportsheet = writer.book.worksheets[0]
|
reportsheet = writer.book.worksheets[0]
|
||||||
keys = ['ait_102a_turbitity','ait_102b_h2s', 'at_109a_turbidity', 'at_109b_h2s', 'at_109c_oil_in_water', 'at_109e_orp', 'fit_100_flow_rate', 'fit_109b_flow_rate', 'lit_116b_level', 'lit_116a_level', 'outlet_turbidity_temp', 'outlet_orp_temp', 'inlet_turbidity_temp', 'inlet_ph_temp', 'ait_102d_oil_in_water','outlet_ph','fit_106b_flow_rate']
|
keys = ['ait_102a_turbitity','ait_102b_h2s', 'at_109a_turbidity', 'at_109b_h2s', 'at_109c_oil_in_water', 'at_109e_orp', 'fit_100_flow_rate', 'fit_109b_flow_rate', 'lit_116b_level', 'lit_116a_level', 'outlet_turbidity_temp', 'outlet_orp_temp', 'inlet_turbidity_temp', 'inlet_ph_temp', 'coriolis_density','outlet_ph','fit_106b_flow_rate']
|
||||||
manual_keys = ['manual_bag_filter_changes', 'manual_cartridge_filter_changes', 'manual_clean_water_sold_per_job', 'manual_coagulant_on_hand', 'manual_diverted_water_time', 'manual_equipment_description', 'manual_equipment_time', 'manual_h202_on_hand', 'manual_issues_concerns', 'manual_next_pigging_scheduled', 'manual_skim_oil_discharged_per_job', 'manual_standby_time', 'manual_unit_uptime', 'manual_upright_tank_issues', 'manual_vac_truck_batches', 'manual_water_events', 'manual_water_events_time', 'manual_water_to_tanks_time',"manual_well", "manual_tfs_lead", "manual_copa_lead", "manual_job_name", "manual_summary", "manual_hse_spills", "manual_quality_issues"]
|
manual_keys = ['manual_bag_filter_changes', 'manual_cartridge_filter_changes', 'manual_clean_water_sold_per_job', 'manual_coagulant_on_hand', 'manual_diverted_water_time', 'manual_equipment_description', 'manual_equipment_time', 'manual_h202_on_hand', 'manual_issues_concerns', 'manual_next_pigging_scheduled', 'manual_skim_oil_discharged_per_job', 'manual_standby_time', 'manual_unit_uptime', 'manual_upright_tank_issues', 'manual_vac_truck_batches', 'manual_water_events', 'manual_water_events_time', 'manual_water_to_tanks_time',"manual_well", "manual_tfs_lead", "manual_copa_lead", "manual_job_name", "manual_summary", "manual_hse_spills", "manual_quality_issues"]
|
||||||
sample_keys = ['manual_sample_datapoint', 'manual_sample_lab', 'manual_sample_location', 'manual_sample_time', 'manual_sample_value']
|
sample_keys = ['manual_sample_datapoint', 'manual_sample_lab', 'manual_sample_location', 'manual_sample_time', 'manual_sample_value']
|
||||||
#Create a Sheet for each Device
|
#Create a Sheet for each Device
|
||||||
|
|||||||
Reference in New Issue
Block a user