added monthly reports and sheet name changes

This commit is contained in:
Nico Melone
2025-03-19 11:02:08 -05:00
parent cbdbccc699
commit 83eb9555fb
4 changed files with 201 additions and 93 deletions

View File

@@ -181,7 +181,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -194,6 +194,12 @@
" reportToList = {}\n",
" # Loop through each item in config, each item represents a report\n",
" for report in config:\n",
" runThisReport = True\n",
" if report[\"period\"] == \"Monthly\" and dt.now().day != 1:\n",
" runThisReport = False\n",
" if not report[\"emails\"]:\n",
" runThisReport = False\n",
" if runThisReport:\n",
" reportToList[report[\"name\"]] = report[\"emails\"]\n",
" for customer in report[\"customers\"].keys():\n",
" reportDeviceTypes = report[\"customers\"][customer][\"deviceTypes\"]\n",
@@ -208,6 +214,10 @@
" deviceId = device[\"id\"][\"id\"]\n",
" deviceType = device[\"type\"]\n",
" deviceName = device[\"name\"]\n",
" sheetName = deviceType\n",
" for x in reportDeviceTypes:\n",
" if x[\"deviceType\"] == deviceType:\n",
" sheetName = x[\"sheetName\"]\n",
" for reportDeviceType in reportDeviceTypes:\n",
" if reportDeviceType[\"deviceType\"] == deviceType:\n",
" keys = get_timeseries_keys(token, deviceId)\n",
@@ -218,8 +228,8 @@
" #Check for device type in config\n",
" if deviceType in list(map(lambda x: x[\"deviceType\"], reportDeviceTypes)):\n",
" #Check if deviceType in report\n",
" if not reportData[report[\"name\"]][report[\"customers\"][customer][\"name\"]].get(deviceType, None):\n",
" reportData[report[\"name\"]][report[\"customers\"][customer][\"name\"]][deviceType] = {}\n",
" if not reportData[report[\"name\"]][report[\"customers\"][customer][\"name\"]].get(sheetName, None):\n",
" reportData[report[\"name\"]][report[\"customers\"][customer][\"name\"]][sheetName] = {}\n",
" if keys:\n",
" deviceData = get_latest_telemetry(token, deviceId, keys)\n",
" for x in reportDeviceTypes:\n",
@@ -230,9 +240,9 @@
" labelled_data[v] = {}\n",
" for k,v in deviceData.items():\n",
" labelled_data[labels[k]] = v\n",
" reportData[report[\"name\"]][report[\"customers\"][customer][\"name\"]][deviceType][deviceName] = labelled_data\n",
" reportData[report[\"name\"]][report[\"customers\"][customer][\"name\"]][sheetName][deviceName] = labelled_data\n",
" else:\n",
" reportData[report[\"name\"]][report[\"customers\"][customer][\"name\"]][deviceType][deviceName] = {} \n",
" reportData[report[\"name\"]][report[\"customers\"][customer][\"name\"]][sheetName][deviceName] = {} \n",
" #Sort Data\n",
" reportDataSorted = sort_dict_keys(reportData)\n",
" #print(json.dumps(reportDataSorted,indent=4))\n",
@@ -246,7 +256,79 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\n",
" \"RRig-Energy-Water-Production-Monthly\": {\n",
" \"RRig-Energy\": {\n",
" \"Water Wells\": {\n",
" \"RRE #1 Water Well #1\": {\n",
" \"Month Volume\": [\n",
" {\n",
" \"ts\": 1742399400000,\n",
" \"value\": \"264738.0\"\n",
" }\n",
" ]\n",
" },\n",
" \"RRE #1 Water Well #2\": {\n",
" \"Month Volume\": [\n",
" {\n",
" \"ts\": 1742399400000,\n",
" \"value\": \"268991.0\"\n",
" }\n",
" ]\n",
" },\n",
" \"RRE #1 Water Well #3\": {\n",
" \"Month Volume\": [\n",
" {\n",
" \"ts\": 1742399400000,\n",
" \"value\": \"264242.5\"\n",
" }\n",
" ]\n",
" },\n",
" \"RRE #1 Water Well #4\": {\n",
" \"Month Volume\": [\n",
" {\n",
" \"ts\": 1742399400000,\n",
" \"value\": \"262723.5\"\n",
" }\n",
" ]\n",
" },\n",
" \"RRE #1 Water Well #5\": {\n",
" \"Month Volume\": [\n",
" {\n",
" \"ts\": 1742399400000,\n",
" \"value\": \"269209.5\"\n",
" }\n",
" ]\n",
" },\n",
" \"RRE #1 Water Well #6\": {\n",
" \"Month Volume\": [\n",
" {\n",
" \"ts\": 1742399400000,\n",
" \"value\": \"6203670.5\"\n",
" }\n",
" ]\n",
" }\n",
" }\n",
" }\n",
" }\n",
"}\n"
]
}
],
"source": [
"print(json.dumps(reportDataSorted, indent=4))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
@@ -258,7 +340,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
@@ -321,6 +403,13 @@
" print(spreadsheets)\n",
" \"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {

View File

@@ -9,6 +9,7 @@
"deviceTypes": [
{
"deviceType": "rigpump",
"sheetName": "Rig Pump",
"dataPoints": [
"vfd_current",
"vfd_frequency"
@@ -20,6 +21,7 @@
},
{
"deviceType": "cqwatertanks",
"sheetName": "Water Tanks",
"dataPoints": [
"fm_1_flow_rate",
"tank_1_level",
@@ -33,6 +35,7 @@
},
{
"deviceType": "piflow",
"sheetName": "Water Wells",
"dataPoints": [
"avgFrequency30Days",
"percentRunTime30Days",
@@ -48,6 +51,7 @@
},
{
"deviceType": "advvfdipp",
"sheetName": "Adv VFD IPP",
"dataPoints": [
"flowtotalyesterday",
"fluidlevel",
@@ -68,32 +72,37 @@
},
"filterDevicesIn": [],
"filterDevicesOut": [],
"name": "OxyRock-Daily-Report"
"name": "OxyRock-Daily-Report",
"period": "Daily"
},
{
"emails": [
"chris@rrigenergy.com",
"corey@rrigenergy.com",
"parker@rrigenergy.com",
"zack@rrigenergy.com",
"claire@rrigenergy.com"
],
"customers": {
"81083430-6988-11ec-a919-556e8dbef35c": {
"name": "Henry-Petroleum",
"4d4058a0-b25d-11ef-861c-8dbe77c636e1": {
"name": "RRig-Energy",
"deviceTypes": [
{
"deviceType": "abbflow",
"deviceType": "rr_well",
"sheetName": "Water Wells",
"dataPoints": [
"accumulated_volume"
"last_month_total"
],
"labels":{
"accumulated_volume": "Accumulated Volume"
"last_month_total": "Month Volume"
}
}
]
}
},
"filterDevicesIn": [
"0090dbd0-abb0-11ec-90c2-ad8278896f52"
],
"filterDevicesIn": [],
"filterDevicesOut": [],
"name": "Henry-Petroleum-Daily-Report"
"name": "RRig-Energy-Water-Production-Monthly",
"period": "Monthly"
}
]

View File

@@ -134,6 +134,12 @@ def lambda_handler(event, context):
reportToList = {}
# Loop through each item in config, each item represents a report
for report in config:
runThisReport = True
if report["period"] == "Monthly" and dt.now().day != 1:
runThisReport = False
if not report["emails"]:
runThisReport = False
if runThisReport:
reportToList[report["name"]] = report["emails"]
for customer in report["customers"].keys():
reportDeviceTypes = report["customers"][customer]["deviceTypes"]
@@ -148,6 +154,10 @@ def lambda_handler(event, context):
deviceId = device["id"]["id"]
deviceType = device["type"]
deviceName = device["name"]
sheetName = deviceType
for x in reportDeviceTypes:
if x["deviceType"] == deviceType:
sheetName = x["sheetName"]
for reportDeviceType in reportDeviceTypes:
if reportDeviceType["deviceType"] == deviceType:
keys = get_timeseries_keys(token, deviceId)
@@ -158,8 +168,8 @@ def lambda_handler(event, context):
#Check for device type in config
if deviceType in list(map(lambda x: x["deviceType"], reportDeviceTypes)):
#Check if deviceType in report
if not reportData[report["name"]][report["customers"][customer]["name"]].get(deviceType, None):
reportData[report["name"]][report["customers"][customer]["name"]][deviceType] = {}
if not reportData[report["name"]][report["customers"][customer]["name"]].get(sheetName, None):
reportData[report["name"]][report["customers"][customer]["name"]][sheetName] = {}
if keys:
deviceData = get_latest_telemetry(token, deviceId, keys)
for x in reportDeviceTypes:
@@ -170,9 +180,9 @@ def lambda_handler(event, context):
labelled_data[v] = {}
for k,v in deviceData.items():
labelled_data[labels[k]] = v
reportData[report["name"]][report["customers"][customer]["name"]][deviceType][deviceName] = labelled_data
reportData[report["name"]][report["customers"][customer]["name"]][sheetName][deviceName] = labelled_data
else:
reportData[report["name"]][report["customers"][customer]["name"]][deviceType][deviceName] = {}
reportData[report["name"]][report["customers"][customer]["name"]][sheetName][deviceName] = {}
#Sort Data
reportDataSorted = sort_dict_keys(reportData)
#print(json.dumps(reportDataSorted,indent=4))

View File

@@ -13,7 +13,7 @@ Resources:
TBReport:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
MemorySize: 128
MemorySize: 512
Timeout: 300
Environment:
Variables: