Files
HP_InHand_IG502/code snippets/alarmList.ipynb
2024-07-31 13:56:21 -05:00

74 lines
2.0 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"from openpyxl import Workbook\n",
"\n",
"# Load the JSON data\n",
"with open('/Users/nico/Documents/GitHub/thingsboard_vc/device_profile/836174d0-44f2-11ed-b441-bfcc3466332b.json') as f:\n",
" data = json.load(f)\n",
"\n",
"# Create a new Excel workbook\n",
"wb = Workbook()\n",
"ws = wb.active\n",
"\n",
"# Set the column headers\n",
"ws['A1'] = 'Alarm Type'\n",
"ws['B1'] = 'PLC Tag'\n",
"ws['C1'] = 'Priority'\n",
"ws['D1'] = 'Output'\n",
"\n",
"# Iterate through the alarms and create rows in the spreadsheet\n",
"row_num = 2\n",
"for alarm in data['entity']['profileData']['alarms']:\n",
" alarm_type = alarm['alarmType']\n",
" plc_tag = alarm['clearRule']['condition']['condition'][0]['key']['key']\n",
" priority_key = next(iter(alarm['createRules']))\n",
" priority = priority_key.upper()\n",
" output_map = {\n",
" 'CRITICAL': 'Voice, SMS, Email',\n",
" 'MAJOR': 'SMS, Email',\n",
" 'MINOR': 'Email'\n",
" }\n",
" output = output_map.get(priority, '')\n",
"\n",
" ws[f'A{row_num}'] = alarm_type\n",
" ws[f'B{row_num}'] = plc_tag\n",
" ws[f'C{row_num}'] = priority\n",
" ws[f'D{row_num}'] = output\n",
"\n",
" row_num += 1\n",
"\n",
"# Save the Excel file\n",
"wb.save('/Users/nico/Desktop/HR Tank Battery Alarms.xlsx')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "xlxs",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.1.-1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}