Remove .DS_Store files and update .gitignore

This commit is contained in:
Nico Melone
2024-11-13 08:12:09 -06:00
parent 3fda556b3e
commit 18cdc07af3
8 changed files with 121 additions and 110 deletions

BIN
.DS_Store vendored

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Widgets/.DS_Store vendored

Binary file not shown.

Binary file not shown.

View File

@@ -6,7 +6,10 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"import logging, json, xlsxwriter, boto3, pytz, math\n", "import logging, json, boto3, pytz, math, os, shutil\n",
"from openpyxl.utils import get_column_letter\n",
"from openpyxl.utils.datetime import from_ISO8601\n",
"from openpyxl.worksheet.table import Table\n",
"import pandas as pd\n", "import pandas as pd\n",
"from datetime import datetime as dt\n", "from datetime import datetime as dt\n",
"from datetime import timedelta as td\n", "from datetime import timedelta as td\n",
@@ -72,8 +75,8 @@
" return device, keys, None\n", " return device, keys, None\n",
" return None, None,\"Device Not Found\"\n", " return None, None,\"Device Not Found\"\n",
" except Exception as e:\n", " except Exception as e:\n",
" print(\"getDeviceKeys: Shit broke\")\n", " logging.error(\"Something went wrong in getDeviceKeys\")\n",
" print(e)\n", " logging.error(e)\n",
" return (None, None, e)" " return (None, None, e)"
] ]
}, },
@@ -87,8 +90,8 @@
" try:\n", " try:\n",
" return rest_client.get_timeseries(entity_id=device.id, keys=keys, start_ts=start_ts, end_ts=end_ts, limit=limit) #entity_type=entity_type, \n", " return rest_client.get_timeseries(entity_id=device.id, keys=keys, start_ts=start_ts, end_ts=end_ts, limit=limit) #entity_type=entity_type, \n",
" except Exception as e:\n", " except Exception as e:\n",
" print(\"getTelemetry: Shit broke\")\n", " logging.error(\"Something went wrong in getTelemetry\")\n",
" print(e)\n", " logging.error(e)\n",
" return False\n", " return False\n",
" " " "
] ]
@@ -115,6 +118,9 @@
" today_midnight = timezone.localize(today_midnight)\n", " today_midnight = timezone.localize(today_midnight)\n",
" start_ts = int(yesterday_midnight.timestamp()) * 1000\n", " start_ts = int(yesterday_midnight.timestamp()) * 1000\n",
" end_ts = int(today_midnight.timestamp()) * 1000\n", " end_ts = int(today_midnight.timestamp()) * 1000\n",
" elif timeRequest[\"type\"] == \"range\":\n",
" start_ts = timeRequest[\"ts_start\"]\n",
" end_ts = timeRequest[\"ts_end\"]\n",
" return (start_ts, end_ts)" " return (start_ts, end_ts)"
] ]
}, },
@@ -135,10 +141,10 @@
" devices = getDevices(rest_client=rest_client, customers=customers, target_customer=targetCustomer)\n", " devices = getDevices(rest_client=rest_client, customers=customers, target_customer=targetCustomer)\n",
" telemetry = {}\n", " telemetry = {}\n",
" for d in devices.data:\n", " for d in devices.data:\n",
" print(d.name)\n", " #print(d.name)\n",
" device, keys, err = getDeviceKeys(rest_client=rest_client, devices=devices, target_device=d.name)\n", " device, keys, err = getDeviceKeys(rest_client=rest_client, devices=devices, target_device=d.name)\n",
" start_ts, end_ts = getTime(timeRequest)\n", " start_ts, end_ts = getTime(timeRequest)\n",
" print(keys)\n", " #print(keys)\n",
" telemetry[d.name] = getTelemetry(rest_client=rest_client, device=device, keys=','.join(keys), start_ts=start_ts, end_ts=end_ts, limit=25000)\n", " telemetry[d.name] = getTelemetry(rest_client=rest_client, device=device, keys=','.join(keys), start_ts=start_ts, end_ts=end_ts, limit=25000)\n",
" return telemetry\n", " return telemetry\n",
" except ApiException as e:\n", " except ApiException as e:\n",
@@ -148,7 +154,38 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 22, "execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"def getMaxWidth():\n",
" label_mapping = {\n",
" \"Lit 116b Level\": \"WASTE TANK 1\",\n",
" \"Lit 116a Level\": \"WASTE TANK 2\",\n",
" \"Fit 100 Flow Rate\": \"INLET FLOW RATE\",\n",
" \"Fit 109b Flow Rate\": \"SALES FLOW RATE\",\n",
" \"Outlet Turbidity Temp\": \"OUTLET TURBIDITY TEMP\",\n",
" \"Outlet Orp Temp\": \"OUTLET ORP TEMP\",\n",
" \"Inlet Turbidity Temp\": \"INLET TURBIDITY TEMP\",\n",
" \"Inlet Ph Temp\": \"INLET PH TEMP\",\n",
" \"Ait 102b H2s\": \"INLET H₂S\",\n",
" \"At 109b H2s\": \"OUTLET H₂S\",\n",
" \"At 109c Oil In Water\": \"OUTLET OIL IN WATER\",\n",
" \"Ait 102a Turbitity\": \"INLET TURBIDITY\",\n",
" \"At 109a Turbidity\": \"OUTLET TURBIDITY\",\n",
" \"At 109e Orp\": \"OUTLET ORP\"\n",
" }\n",
" width = 0\n",
" for key,value in label_mapping.items():\n",
" if(len(value) > width):\n",
" width = len(value)\n",
"\n",
" return width"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -175,7 +212,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -185,7 +222,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 20, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -214,18 +251,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"ACW #1\n",
"['latitude', 'longitude', 'speed', 'a_current', 'b_current', 'c_current', 'scada_stop_cmd', 'pit_100a_pressure', 'pit_101a_pressure', 'pit_101b_pressure', 'pit_101c_pressure', 'fit_101_flow_rate', 'fi_101b_popoff', 'fcv_101a_valve', 'fcv_101b_valve', 'pit_102_pressure', 'pit_102_hi_alm', 'pit_102_hihi_alm', 'pit_102_hi_spt', 'pit_102_hihi_spt', 'p200_hand', 'p200_auto', 'xy_200_run', 'ct_200_run', 'pit_100_pressure', 'm106a_vfd_active', 'm106a_vfd_faulted', 'm106a_vfd_frequency', 'm106a_vfd_start', 'm106a_vfd_stop', 'pit_106a_pressure', 'fit_106a_flow_rate', 'm106b_vfd_active', 'm106b_vfd_faulted', 'm106b_vfd_frequency', 'm106b_vfd_start', 'm106b_vfd_stop', 'pit_106b_pressure', 'fit_106b_flow_rate', 'pit_106c_pressure', 'pit_106d_pressure', 'sdv106_open', 'sdv106_closed', 'bp_3a_auto', 'bp_3a_hand', 'bp_3a_run_cmd', 'bp_3a_run', 'bp_3a_fault', 'bp_3b_auto', 'bp_3b_hand', 'bp_3b_run_cmd', 'bp_3b_run', 'bp_3b_fault', 'pit_107a_pressure', 'fit_107a_flow_rate', 'pit_107b_pressure', 'fcv_001_valve', 'fit_107b_flow_rate', 'pit_107d_pressure', 'fcv_002_valve', 'pit_107c_pressure', 'pit_108a_pressure', 'pit_108b_pressure', 'dpi_108a_pressure', 'pit_108c_pressure', 'pit_108d_pressure', 'pdt_108b_pressure', 'pit_108e_pressure', 'pit_108f_pressure', 'pdt_108c_pressure', 'pit_108_pressure', 'pdt_108a_hi_alm', 'pdt_108a_hihi_alm', 'pdt_108b_hi_alm', 'pdt_108b_hihi_alm', 'pdt_108c_hi_alm', 'pdt_108c_hihi_alm', 'ait_102a_turbitity', 'ait_102b_h2s', 'ait_102c_ph', 'ait_102d_oil_in_water', 'fit_102_flow_rate', 'lit_112a_h2o2_level', 'lit_112b_nahso3_level', 'fis_112_h2o2_popoff', 'fit_112a_h2o2_flow_rate', 'fit_112b_nahso3_flow_rate', 'at_109a_turbidity', 'at_109b_h2s', 'at_109c_oil_in_water', 'at_109d_o2_in_water', 'at_109e_orp', 'fit_109a_flow_rate', 'fit_100_flow_rate', 'fit_100_hi_alm', 'fit_100_hihi_alm', 'fit_100_lo_alm', 'fit_111_flow_rate', 'pit_110_pressure', 'lit_170_level', 'lit_200_level', 'lit_101_level', 'li_103D_level_alm', 'lsh_120_hihi_alm', 'pit_050_pressure', 'pit_065_pressure', 'pdi_065_pressure', 'fit_104_n2_rate', 'p100_auto', 'p100_hand', 'sales_recirculate_sw', 'fit_109b_flow_rate', 'pit_111a_n2', 'pit_111b_n2', 'pit_111c_n2', 'ct_200_current', 'sdv_101a', 'xy_100_run', 'skim_total_barrels', 'dpi_108b_pressure', 'chemical_pump_01_run_status', 'chemical_pump_01_rate_offset', 'spt_pid_h2o2_chemical_rate', 'spt_chemical_manual_rate', 'chemical_pump_auto', 'esd_exists', 'n2_purity', 'n2_outlet_flow_rate', 'n2_outlet_temp', 'n2_inlet_pressure', 'compressor_controller_temp', 'compressor_ambient_temp', 'compressor_outlet_temp', 'compressor_outlet_pressure', 'n2_outlet_pressure', 'fit_109b_water_job', 'fit_109b_water_last_month', 'fit_109b_water_month', 'fit_109b_water_lifetime', 'fit_109b_water_today', 'fit_109b_water_yesterday', 'fit_100_water_job', 'fit_100_water_last_month', 'fit_100_water_month', 'fit_100_water_lifetime', 'fit_100_water_today', 'fit_100_water_yesterday', 'h2o2_chemical_rate', 'rmt_sd_alm', 'pnl_esd_alm', 'pit_111c_hihi_alm', 'pit_111b_hihi_alm', 'pit_111a_hihi_alm', 'pit_110_hihi_alm', 'pit_108g_hihi_alm', 'pit_108c_hihi_alm', 'pit_108b_hihi_alm', 'pit_108a_hihi_alm', 'pit_107b_lolo_alm', 'pit_107a_lolo_alm', 'pit_106b_hihi_alm', 'pit_106a_hihi_alm', 'pit_101b_transmitter_alm', 'pit_101b_hihi_alm', 'pit_101a_transmitter_alm', 'pit_101a_hihi_alm', 'pit_101a_hi_alm', 'pit_100_hihi_alm', 'pit_065_hihi_alm', 'pit_050_hihi_alm', 'pdi_065_lolo_alm', 'pdi_065_lo_alm', 'pdi_065_hihi_alm', 'm106b_vfd_faulted_alm', 'm106a_vfd_faulted_alm', 'lit_200_hihi_alm', 'lit_170_hihi_alm', 'fit_107b_lolo_alm', 'fit_107a_lolo_alm', 'fit_106b_hihi_alm', 'fit_106a_hihi_alm', 'fit_004_hihi_alm', 'bp_3b_run_fail_alm', 'bp_3a_run_fail_alm', 'ait_114c_hihi_alm', 'ait_114b_hihi_alm', 'ait_114a_hihi_alm', 'ac_volt', 'bc_volt', 'ab_volt', 'psd_alm', 'ait_114a_lolo_alm', 'ait_114a_lo_alm', 'ait_114r_lolo_alm', 'ait_114r_lo_alm', 'ait_114z_lo_alm', 'ait_114z_lolo_alm', 'ait_114x_lo_alm', 'ait_114x_lolo_alm', 'ait_114c_lolo_alm', 'ait_114c_lo_alm', 'ait_114l_lolo_alm', 'ait_114l_lo_alm', 'lit_116b_level', 'lit_116b_hihi_alm', 'lit_116b_hi_alm', 'lit_116a_level', 'lit_116a_hihi_alm', 'lit_116a_hi_alm', 'outlet_turbidity_temp', 'outlet_orp_temp', 'inlet_turbidity_temp', 'inlet_ph_temp']\n"
]
}
],
"source": [ "source": [
"time = {\n", "time = {\n",
" \"type\": \"last\",\n", " \"type\": \"last\",\n",
@@ -242,74 +270,38 @@
" \"type\": \"midnight-midnight\",\n", " \"type\": \"midnight-midnight\",\n",
" \"timezone\": \"US/Alaska\" \n", " \"timezone\": \"US/Alaska\" \n",
"}\n", "}\n",
"time = {\n",
" \"type\": \"range\",\n",
" \"timezone\": \"US/Alaska\" ,\n",
" \"ts_start\": 1728115200000,\n",
" \"ts_end\": 1728201600000\n",
"}\n",
"telemetry = getThingsBoardData(url, username, password, \"Thunderbird Field Services\", time)" "telemetry = getThingsBoardData(url, username, password, \"Thunderbird Field Services\", time)"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 24, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"ait_102a_turbitity INLET TURBIDITY\n",
"ait_102b_h2s INLET H₂S\n",
"at_109a_turbidity OUTLET TURBIDITY\n",
"at_109b_h2s OUTLET H₂S\n",
"at_109c_oil_in_water OUTLET OIL IN WATER\n",
"at_109e_orp OUTLET ORP\n",
"fit_100_flow_rate INLET FLOW RATE\n",
"fit_109b_flow_rate SALES FLOW RATE\n",
"lit_116b_level WASTE TANK 1\n",
"lit_116a_level WASTE TANK 2\n",
"outlet_turbidity_temp OUTLET TURBIDITY TEMP\n",
"outlet_orp_temp OUTLET ORP TEMP\n",
"inlet_turbidity_temp INLET TURBIDITY TEMP\n",
"inlet_ph_temp INLET PH TEMP\n",
"['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']\n",
"lit_116b_level WASTE TANK 1\n",
"lit_116a_level WASTE TANK 2\n",
"lit_116b_level WASTE TANK 1\n",
"lit_116a_level WASTE TANK 2\n",
"fit_100_flow_rate INLET FLOW RATE\n",
"fit_109b_flow_rate SALES FLOW RATE\n",
"fit_100_flow_rate INLET FLOW RATE\n",
"fit_109b_flow_rate SALES FLOW RATE\n",
"outlet_turbidity_temp OUTLET TURBIDITY TEMP\n",
"outlet_orp_temp OUTLET ORP TEMP\n",
"inlet_turbidity_temp INLET TURBIDITY TEMP\n",
"inlet_ph_temp INLET PH TEMP\n",
"outlet_turbidity_temp OUTLET TURBIDITY TEMP\n",
"outlet_orp_temp OUTLET ORP TEMP\n",
"inlet_turbidity_temp INLET TURBIDITY TEMP\n",
"inlet_ph_temp INLET PH TEMP\n",
"ait_102b_h2s INLET H₂S\n",
"at_109b_h2s OUTLET H₂S\n",
"at_109c_oil_in_water OUTLET OIL IN WATER\n",
"at_109e_orp OUTLET ORP\n",
"ait_102b_h2s INLET H₂S\n",
"at_109b_h2s OUTLET H₂S\n",
"at_109c_oil_in_water OUTLET OIL IN WATER\n",
"at_109e_orp OUTLET ORP\n",
"at_109e_orp OUTLET ORP\n",
"at_109e_orp OUTLET ORP\n",
"ait_102a_turbitity INLET TURBIDITY\n",
"at_109a_turbidity OUTLET TURBIDITY\n",
"ait_102a_turbitity INLET TURBIDITY\n",
"at_109a_turbidity OUTLET TURBIDITY\n"
]
}
],
"source": [ "source": [
"\n",
"# Create a Pandas Excel writer using XlsxWriter as the engine.\n", "# Create a Pandas Excel writer using XlsxWriter as the engine.\n",
"writer = pd.ExcelWriter(f\"/Users/nico/Documents/test/Thunderbird_{dt.today().strftime('%Y-%m-%d')}.xlsx\", engine=\"xlsxwriter\",\n", "shutil.copyfile(\"/Users/nico/Documents/test/ACW Daily Report Template.xlsx\", f\"/Users/nico/Documents/test/Thunderbird_{dt.today().strftime('%Y-%m-%d')}.xlsx\")\n",
"writer = pd.ExcelWriter(\n",
" f\"/Users/nico/Documents/test/Thunderbird_{dt.today().strftime('%Y-%m-%d')}.xlsx\", \n",
" engine=\"openpyxl\",\n",
" datetime_format=\"yyyy-mm-dd hh:mm:ss\",\n", " datetime_format=\"yyyy-mm-dd hh:mm:ss\",\n",
" date_format=\"yyyy-mm-dd\",engine_kwargs={'options': {'strings_to_numbers': True}})\n", " date_format=\"yyyy-mm-dd\",\n",
" #engine_kwargs={'options': {'strings_to_numbers': True}},\n",
" mode=\"a\",\n",
" if_sheet_exists=\"overlay\")\n",
"reportsheet = writer.book.worksheets[0]\n",
"\n",
"\"\"\"\n",
"chartsheet = writer.book.add_worksheet(\"Charts\")\n", "chartsheet = writer.book.add_worksheet(\"Charts\")\n",
"\"\"\"\n",
"ignore_keys = ['latitude', 'longitude', 'speed', 'a_current', 'b_current', 'c_current', 'scada_stop_cmd', 'pit_100a_pressure', 'pit_101a_pressure', 'pit_101b_pressure', 'pit_101c_pressure', 'fit_101_flow_rate', 'fi_101b_popoff', 'fcv_101a_valve', 'fcv_101b_valve', 'pit_102_pressure', 'pit_102_hi_alm', 'pit_102_hihi_alm', 'pit_102_hi_spt', 'pit_102_hihi_spt', 'p200_hand', 'p200_auto', 'xy_200_run', 'ct_200_run', 'pit_100_pressure', 'm106a_vfd_active', 'm106a_vfd_faulted', 'm106a_vfd_frequency', 'm106a_vfd_start', 'm106a_vfd_stop', 'pit_106a_pressure', 'fit_106a_flow_rate', 'm106b_vfd_active', 'm106b_vfd_faulted', 'm106b_vfd_frequency', 'm106b_vfd_start', 'm106b_vfd_stop', 'pit_106b_pressure', 'fit_106b_flow_rate', 'pit_106c_pressure', 'pit_106d_pressure', 'sdv106_open', 'sdv106_closed', 'bp_3a_auto', 'bp_3a_hand', 'bp_3a_run_cmd', 'bp_3a_run', 'bp_3a_fault', 'bp_3b_auto', 'bp_3b_hand', 'bp_3b_run_cmd', 'bp_3b_run', 'bp_3b_fault', 'pit_107a_pressure', 'fit_107a_flow_rate', 'pit_107b_pressure', 'fcv_001_valve', 'fit_107b_flow_rate', 'pit_107d_pressure', 'fcv_002_valve', 'pit_107c_pressure', 'pit_108a_pressure', 'pit_108b_pressure', 'dpi_108a_pressure', 'pit_108c_pressure', 'pit_108d_pressure', 'pdt_108b_pressure', 'pit_108e_pressure', 'pit_108f_pressure', 'pdt_108c_pressure', 'pit_108_pressure', 'pdt_108a_hi_alm', 'pdt_108a_hihi_alm', 'pdt_108b_hi_alm', 'pdt_108b_hihi_alm', 'pdt_108c_hi_alm', 'pdt_108c_hihi_alm', 'ait_102c_ph', 'ait_102d_oil_in_water', 'fit_102_flow_rate', 'lit_112a_h2o2_level', 'lit_112b_nahso3_level', 'fis_112_h2o2_popoff', 'fit_112a_h2o2_flow_rate', 'fit_112b_nahso3_flow_rate', 'at_109d_o2_in_water', 'fit_100_hi_alm', 'fit_100_hihi_alm', 'fit_100_lo_alm', 'fit_111_flow_rate', 'pit_110_pressure', 'lit_170_level', 'lit_200_level', 'lit_101_level', 'li_103D_level_alm', 'lsh_120_hihi_alm', 'pit_050_pressure', 'pit_065_pressure', 'pdi_065_pressure', 'fit_104_n2_rate', 'p100_auto', 'p100_hand', 'sales_recirculate_sw', 'fit_109a_flow_rate', 'pit_111a_n2', 'pit_111b_n2', 'pit_111c_n2', 'ct_200_current', 'sdv_101a', 'xy_100_run', 'skim_total_barrels', 'dpi_108b_pressure', 'chemical_pump_01_run_status', 'chemical_pump_01_rate_offset', 'spt_pid_h2o2_chemical_rate', 'spt_chemical_manual_rate', 'chemical_pump_auto', 'esd_exists', 'n2_purity', 'n2_outlet_flow_rate', 'n2_outlet_temp', 'n2_inlet_pressure', 'compressor_controller_temp', 'compressor_ambient_temp', 'compressor_outlet_temp', 'compressor_outlet_pressure', 'n2_outlet_pressure', 'fit_109b_water_job', 'fit_109b_water_last_month', 'fit_109b_water_month', 'fit_109b_water_lifetime', 'fit_109b_water_today', 'fit_109b_water_yesterday', 'fit_100_water_job', 'fit_100_water_last_month', 'fit_100_water_month', 'fit_100_water_lifetime', 'fit_100_water_today', 'fit_100_water_yesterday', 'h2o2_chemical_rate', 'rmt_sd_alm', 'pnl_esd_alm', 'pit_111c_hihi_alm', 'pit_111b_hihi_alm', 'pit_111a_hihi_alm', 'pit_110_hihi_alm', 'pit_108g_hihi_alm', 'pit_108c_hihi_alm', 'pit_108b_hihi_alm', 'pit_108a_hihi_alm', 'pit_107b_lolo_alm', 'pit_107a_lolo_alm', 'pit_106b_hihi_alm', 'pit_106a_hihi_alm', 'pit_101b_transmitter_alm', 'pit_101b_hihi_alm', 'pit_101a_transmitter_alm', 'pit_101a_hihi_alm', 'pit_101a_hi_alm', 'pit_100_hihi_alm', 'pit_065_hihi_alm', 'pit_050_hihi_alm', 'pdi_065_lolo_alm', 'pdi_065_lo_alm', 'pdi_065_hihi_alm', 'm106b_vfd_faulted_alm', 'm106a_vfd_faulted_alm', 'lit_200_hihi_alm', 'lit_170_hihi_alm', 'fit_107b_lolo_alm', 'fit_107a_lolo_alm', 'fit_106b_hihi_alm', 'fit_106a_hihi_alm', 'fit_004_hihi_alm', 'bp_3b_run_fail_alm', 'bp_3a_run_fail_alm', 'ait_114c_hihi_alm', 'ait_114b_hihi_alm', 'ait_114a_hihi_alm', 'ac_volt', 'bc_volt', 'ab_volt', 'psd_alm', 'ait_114a_lolo_alm', 'ait_114a_lo_alm', 'ait_114r_lolo_alm', 'ait_114r_lo_alm', 'ait_114z_lo_alm', 'ait_114z_lolo_alm', 'ait_114x_lo_alm', 'ait_114x_lolo_alm', 'ait_114c_lolo_alm', 'ait_114c_lo_alm', 'ait_114l_lolo_alm', 'ait_114l_lo_alm', 'lit_116b_hihi_alm', 'lit_116b_hi_alm', 'lit_116a_hihi_alm', 'lit_116a_hi_alm']\n", "ignore_keys = ['latitude', 'longitude', 'speed', 'a_current', 'b_current', 'c_current', 'scada_stop_cmd', 'pit_100a_pressure', 'pit_101a_pressure', 'pit_101b_pressure', 'pit_101c_pressure', 'fit_101_flow_rate', 'fi_101b_popoff', 'fcv_101a_valve', 'fcv_101b_valve', 'pit_102_pressure', 'pit_102_hi_alm', 'pit_102_hihi_alm', 'pit_102_hi_spt', 'pit_102_hihi_spt', 'p200_hand', 'p200_auto', 'xy_200_run', 'ct_200_run', 'pit_100_pressure', 'm106a_vfd_active', 'm106a_vfd_faulted', 'm106a_vfd_frequency', 'm106a_vfd_start', 'm106a_vfd_stop', 'pit_106a_pressure', 'fit_106a_flow_rate', 'm106b_vfd_active', 'm106b_vfd_faulted', 'm106b_vfd_frequency', 'm106b_vfd_start', 'm106b_vfd_stop', 'pit_106b_pressure', 'fit_106b_flow_rate', 'pit_106c_pressure', 'pit_106d_pressure', 'sdv106_open', 'sdv106_closed', 'bp_3a_auto', 'bp_3a_hand', 'bp_3a_run_cmd', 'bp_3a_run', 'bp_3a_fault', 'bp_3b_auto', 'bp_3b_hand', 'bp_3b_run_cmd', 'bp_3b_run', 'bp_3b_fault', 'pit_107a_pressure', 'fit_107a_flow_rate', 'pit_107b_pressure', 'fcv_001_valve', 'fit_107b_flow_rate', 'pit_107d_pressure', 'fcv_002_valve', 'pit_107c_pressure', 'pit_108a_pressure', 'pit_108b_pressure', 'dpi_108a_pressure', 'pit_108c_pressure', 'pit_108d_pressure', 'pdt_108b_pressure', 'pit_108e_pressure', 'pit_108f_pressure', 'pdt_108c_pressure', 'pit_108_pressure', 'pdt_108a_hi_alm', 'pdt_108a_hihi_alm', 'pdt_108b_hi_alm', 'pdt_108b_hihi_alm', 'pdt_108c_hi_alm', 'pdt_108c_hihi_alm', 'ait_102c_ph', 'ait_102d_oil_in_water', 'fit_102_flow_rate', 'lit_112a_h2o2_level', 'lit_112b_nahso3_level', 'fis_112_h2o2_popoff', 'fit_112a_h2o2_flow_rate', 'fit_112b_nahso3_flow_rate', 'at_109d_o2_in_water', 'fit_100_hi_alm', 'fit_100_hihi_alm', 'fit_100_lo_alm', 'fit_111_flow_rate', 'pit_110_pressure', 'lit_170_level', 'lit_200_level', 'lit_101_level', 'li_103D_level_alm', 'lsh_120_hihi_alm', 'pit_050_pressure', 'pit_065_pressure', 'pdi_065_pressure', 'fit_104_n2_rate', 'p100_auto', 'p100_hand', 'sales_recirculate_sw', 'fit_109a_flow_rate', 'pit_111a_n2', 'pit_111b_n2', 'pit_111c_n2', 'ct_200_current', 'sdv_101a', 'xy_100_run', 'skim_total_barrels', 'dpi_108b_pressure', 'chemical_pump_01_run_status', 'chemical_pump_01_rate_offset', 'spt_pid_h2o2_chemical_rate', 'spt_chemical_manual_rate', 'chemical_pump_auto', 'esd_exists', 'n2_purity', 'n2_outlet_flow_rate', 'n2_outlet_temp', 'n2_inlet_pressure', 'compressor_controller_temp', 'compressor_ambient_temp', 'compressor_outlet_temp', 'compressor_outlet_pressure', 'n2_outlet_pressure', 'fit_109b_water_job', 'fit_109b_water_last_month', 'fit_109b_water_month', 'fit_109b_water_lifetime', 'fit_109b_water_today', 'fit_109b_water_yesterday', 'fit_100_water_job', 'fit_100_water_last_month', 'fit_100_water_month', 'fit_100_water_lifetime', 'fit_100_water_today', 'fit_100_water_yesterday', 'h2o2_chemical_rate', 'rmt_sd_alm', 'pnl_esd_alm', 'pit_111c_hihi_alm', 'pit_111b_hihi_alm', 'pit_111a_hihi_alm', 'pit_110_hihi_alm', 'pit_108g_hihi_alm', 'pit_108c_hihi_alm', 'pit_108b_hihi_alm', 'pit_108a_hihi_alm', 'pit_107b_lolo_alm', 'pit_107a_lolo_alm', 'pit_106b_hihi_alm', 'pit_106a_hihi_alm', 'pit_101b_transmitter_alm', 'pit_101b_hihi_alm', 'pit_101a_transmitter_alm', 'pit_101a_hihi_alm', 'pit_101a_hi_alm', 'pit_100_hihi_alm', 'pit_065_hihi_alm', 'pit_050_hihi_alm', 'pdi_065_lolo_alm', 'pdi_065_lo_alm', 'pdi_065_hihi_alm', 'm106b_vfd_faulted_alm', 'm106a_vfd_faulted_alm', 'lit_200_hihi_alm', 'lit_170_hihi_alm', 'fit_107b_lolo_alm', 'fit_107a_lolo_alm', 'fit_106b_hihi_alm', 'fit_106a_hihi_alm', 'fit_004_hihi_alm', 'bp_3b_run_fail_alm', 'bp_3a_run_fail_alm', 'ait_114c_hihi_alm', 'ait_114b_hihi_alm', 'ait_114a_hihi_alm', 'ac_volt', 'bc_volt', 'ab_volt', 'psd_alm', 'ait_114a_lolo_alm', 'ait_114a_lo_alm', 'ait_114r_lolo_alm', 'ait_114r_lo_alm', 'ait_114z_lo_alm', 'ait_114z_lolo_alm', 'ait_114x_lo_alm', 'ait_114x_lolo_alm', 'ait_114c_lolo_alm', 'ait_114c_lo_alm', 'ait_114l_lolo_alm', 'ait_114l_lo_alm', 'lit_116b_hihi_alm', 'lit_116b_hi_alm', 'lit_116a_hihi_alm', 'lit_116a_hi_alm']\n",
"\"\"\"\n",
"unit_mapping = {\n", "unit_mapping = {\n",
" \"level\": \"ft\",\n", " \"level\": \"ft\",\n",
" \"flow\": \"bpd\",\n", " \"flow\": \"bpd\",\n",
@@ -323,54 +315,52 @@
" \"default\": \"H₂S and Oil in Water\"\n", " \"default\": \"H₂S and Oil in Water\"\n",
"}\n", "}\n",
"label_mapping = {\n", "label_mapping = {\n",
" \"LIT 116B LEVEL\": \"WASTE TANK 1\",\n", " \"LIT 116B LEVEL\": \"WASTE TANK 1\",\n",
" \"LIT 116A LEVEL\": \"WASTE TANK 2\",\n", " \"LIT 116A LEVEL\": \"WASTE TANK 2\",\n",
" \"FIT 100 FLOW RATE\": \"INLET FLOW RATE\",\n", " \"FIT 100 FLOW RATE\": \"INLET FLOW RATE\",\n",
" \"FIT 109B FLOW RATE\": \"SALES FLOW RATE\",\n", " \"FIT 109B FLOW RATE\": \"SALES FLOW RATE\",\n",
" \"OUTLET TURBIDITY TEMP\": \"OUTLET TURBIDITY TEMP\",\n", " \"OUTLET TURBIDITY TEMP\": \"OUTLET TURBIDITY TEMP\",\n",
" \"OUTLET ORP TEMP\": \"OUTLET ORP TEMP\",\n", " \"OUTLET ORP TEMP\": \"OUTLET ORP TEMP\",\n",
" \"INLET TURBIDITY TEMP\": \"INLET TURBIDITY TEMP\",\n", " \"INLET TURBIDITY TEMP\": \"INLET TURBIDITY TEMP\",\n",
" \"INLET PH TEMP\": \"INLET PH TEMP\",\n", " \"INLET PH TEMP\": \"INLET PH TEMP\",\n",
" \"AIT 102B H2S\": \"INLET H₂S\",\n", " \"AIT 102B H2S\": \"INLET H₂S\",\n",
" \"AT 109B H2S\": \"OUTLET H₂S\",\n", " \"AT 109B H2S\": \"OUTLET H₂S\",\n",
" \"AT 109C OIL IN WATER\": \"OUTLET OIL IN WATER\",\n", " \"AT 109C OIL IN WATER\": \"OUTLET OIL IN WATER\",\n",
" \"AIT 102A TURBITITY\": \"INLET TURBIDITY\",\n", " \"AIT 102A TURBITITY\": \"INLET TURBIDITY\",\n",
" \"AT 109A TURBIDITY\": \"OUTLET TURBIDITY\",\n", " \"AT 109A TURBIDITY\": \"OUTLET TURBIDITY\",\n",
" \"AT 109E ORP\": \"OUTLET ORP\"\n", " \"AT 109E ORP\": \"OUTLET ORP\"\n",
" }\n", "}\"\"\"\n",
"#Create a Sheet for each Device\n",
"for device in telemetry.keys():\n", "for device in telemetry.keys():\n",
" df = getDataFrame(telemetry[device], ignore_keys, time)\n", " df = getDataFrame(telemetry[device], ignore_keys, time)\n",
" \n", " \n",
" #df.index = [dt.fromtimestamp(x) for x in df.index ]\n",
" # Write the dataframe data to XlsxWriter. Turn off the default header and\n", " # Write the dataframe data to XlsxWriter. Turn off the default header and\n",
" # index and skip one row to allow us to insert a user defined header.\n", " # index and skip one row to allow us to insert a user defined header.\n",
" df.to_excel(writer, sheet_name=device, startrow=1, header=False, index=True)\n", " df.to_excel(writer, sheet_name=device, startrow=0, header=True, index=True)\n",
"\n", "\n",
" # Get the xlsxwriter workbook and worksheet objects.\n", " # Get the xlsxwriter workbook and worksheet objects.\n",
" workbook = writer.book\n", " workbook = writer.book\n",
" worksheet = writer.sheets[device]\n", " worksheet = writer.sheets[device]\n",
"\n", " for row in worksheet.iter_rows(min_row=2, max_col=1):\n",
" # Get the dimensions of the dataframe.\n", " for cell in row:\n",
" (max_row, max_col) = df.shape\n", " cell.number_format = 'yyyy-mm-dd hh:mm:ss'\n",
" for row in worksheet.iter_rows(min_row=2, min_col=2):\n",
" for cell in row:\n",
" cell.number_format = '#,##0.00'\n",
" \n",
" \n", " \n",
" # Create a list of column headers, to use in add_table().\n", "\"\"\"\n",
" column_settings = [{\"header\": column} for column in df.columns]\n",
" # Add the Excel table structure. Pandas will add the data.\n",
" worksheet.add_table(0, 0, max_row, max_col, {\"columns\": [{'header': 'Date'}] + column_settings})\n",
"\n",
" # Make the columns wider for clarity.\n",
" #worksheet.autofit()\n",
" worksheet.set_column(0, max_col , 18)\n",
"\n",
"chart_keys = list(telemetry[device].keys())\n", "chart_keys = list(telemetry[device].keys())\n",
"for key in ignore_keys:\n", "for key in ignore_keys:\n",
" if key in chart_keys:\n", " if key in chart_keys:\n",
" chart_keys.remove(key)\n", " chart_keys.remove(key)\n",
"print(chart_keys)\n", "#print(chart_keys)\n",
"charts = [\n", "charts = [\n",
" {\"chartType\": \"line\",\"columnNames\": ['lit_116b_level', 'lit_116a_level'], \"unit\": \"FT\", \"title\": \"Levels\"},\n", " {\"chartType\": \"line\",\"columnNames\": ['lit_116b_level', 'lit_116a_level'], \"unit\": \"FT\", \"title\": \"Levels\"},\n",
" {\"chartType\": \"line\",\"columnNames\": ['fit_100_flow_rate', 'fit_109b_flow_rate'], \"unit\": \"bpd\", \"title\": \"Flow Rates\"},\n", " {\"chartType\": \"line\",\"columnNames\": ['fit_100_flow_rate', 'fit_109b_flow_rate'], \"unit\": \"bpd\", \"title\": \"Flow Rates\"},\n",
" {\"chartType\": \"line\",\"columnNames\": ['outlet_turbidity_temp', 'outlet_orp_temp', 'inlet_turbidity_temp', 'inlet_ph_temp'], \"unit\": \"°F\", \"title\": \"Temperatures\"},\n", " {\"chartType\": \"line\",\"columnNames\": ['outlet_turbidity_temp', 'outlet_orp_temp', 'inlet_turbidity_temp', 'inlet_ph_temp'], \"unit\": \"°F\", \"title\": \"Temperatures\"},\n",
" {\"chartType\": \"line\",\"columnNames\": ['ait_102b_h2s','at_109b_h2s', 'at_109c_oil_in_water','at_109e_orp'], \"unit\": \"ppm\", \"title\": \"H₂S and Oil in Water\"},\n", " {\"chartType\": \"line\",\"columnNames\": ['ait_102b_h2s','at_109b_h2s', 'at_109c_oil_in_water'], \"unit\": \"ppm\", \"title\": \"H₂S and Oil in Water\"},\n",
" {\"chartType\": \"line\",\"columnNames\": ['at_109e_orp'], \"unit\": \"mV\", \"title\": \"ORP\"},\n", " {\"chartType\": \"line\",\"columnNames\": ['at_109e_orp'], \"unit\": \"mV\", \"title\": \"ORP\"},\n",
" {\"chartType\": \"line\", \"columnNames\": ['ait_102a_turbitity','at_109a_turbidity'], \"unit\": \"NTU\", \"title\": \"Turbidity\"}\n", " {\"chartType\": \"line\", \"columnNames\": ['ait_102a_turbitity','at_109a_turbidity'], \"unit\": \"NTU\", \"title\": \"Turbidity\"}\n",
" ]\n", " ]\n",
@@ -401,8 +391,8 @@
" 'categories': [device, 1,0,max_row,0],\n", " 'categories': [device, 1,0,max_row,0],\n",
" 'name': label_mapping.get(formatChartName(cn))\n", " 'name': label_mapping.get(formatChartName(cn))\n",
" })\n", " })\n",
" \n",
" chart.set_x_axis({\"name\": c[\"title\"],'text_axis': True, 'interval_unit': 60, 'interval_tick': 60, \"num_format\": \"mm/dd hh:mm\", 'num_font': {\"rotation\": -45}})\n", " chart.set_x_axis({\"name\": c[\"title\"],'text_axis': True, 'interval_unit': 60, 'interval_tick': 60, \"num_format\": \"mm/dd hh:mm\", 'num_font': {\"rotation\": -45}})\n",
" unit = unit_mapping.get(cn.split(\"_\")[2], \"ppm\")\n",
" chart.set_y_axis({\"name\": c[\"unit\"], \"crossing\": min, \"min\": min,'major_gridlines': {'visible': True}, \"major_unit\": math.ceil(max/12)})\n", " chart.set_y_axis({\"name\": c[\"unit\"], \"crossing\": min, \"min\": min,'major_gridlines': {'visible': True}, \"major_unit\": math.ceil(max/12)})\n",
" elif c[\"chartType\"] == \"pie\":\n", " elif c[\"chartType\"] == \"pie\":\n",
" #pie charts don't allow data from multiple worksheets need to make a new worksheet with all the desired data so add the data to the worksheet here\n", " #pie charts don't allow data from multiple worksheets need to make a new worksheet with all the desired data so add the data to the worksheet here\n",
@@ -421,8 +411,29 @@
" \n", " \n",
" chartsheet.insert_chart('A' + str(position), chart, {'x_scale': 3, 'y_scale': 2})\n", " chartsheet.insert_chart('A' + str(position), chart, {'x_scale': 3, 'y_scale': 2})\n",
" position += 30\n", " position += 30\n",
"\"\"\"\n",
"\n",
"reportsheet[\"B9\"] = dt.fromtimestamp(getTime(time)[0]/1000).strftime('%m/%d/%Y')\n",
"reportsheet[\"B10\"] = \"Test Well Name\"\n",
"reportsheet[\"B11\"] = \"Test Well Lead\"\n",
"reportsheet[\"B12\"] = \"Test COPA Lead\"\n",
"reportsheet[\"B13\"] = \"Test Job Name\"\n",
"\n",
"reportsheet[\"B16\"]= \"Test Events or Spills\"\n",
"reportsheet[\"B18\"] = \"Test Issues\"\n",
"\n",
"reportsheet[\"E10\"] = \"A very large summary test text to put into perspective the amount\\n of work that is having to be done to this sheet\\n for this to work\"\n",
"# Close the Pandas Excel writer and output the Excel file.\n", "# Close the Pandas Excel writer and output the Excel file.\n",
"writer.close()" "writer.close()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"type(df.index[0])"
] ]
}, },
{ {