Changed history export to csv file.
This commit is contained in:
parent
6682cea030
commit
88bdae9da4
@ -692,22 +692,7 @@
|
|||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"custom": {
|
"custom": {
|
||||||
"rawData": [
|
"rawData": []
|
||||||
{
|
|
||||||
"style": {
|
|
||||||
"backgroundColor": "#ffeb3b"
|
|
||||||
},
|
|
||||||
"value": {
|
|
||||||
"Description": "MCM01 Hello world",
|
|
||||||
"Duration": "01:42:53",
|
|
||||||
"EventTimestamp": "2025-06-20 15:07:03",
|
|
||||||
"Location": "MCM01",
|
|
||||||
"NumberID": 35,
|
|
||||||
"Priority": "Low",
|
|
||||||
"Tag": "MCM01.HMI.Beacon_Light"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"meta": {
|
"meta": {
|
||||||
"name": "Table"
|
"name": "Table"
|
||||||
@ -1404,7 +1389,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"filter": {
|
"filter": {
|
||||||
"enabled": true
|
"enabled": true,
|
||||||
|
"results": {
|
||||||
|
"enabled": true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"selection": {
|
"selection": {
|
||||||
"mode": "multiple interval"
|
"mode": "multiple interval"
|
||||||
@ -2434,17 +2422,17 @@
|
|||||||
"$": [
|
"$": [
|
||||||
"ts",
|
"ts",
|
||||||
192,
|
192,
|
||||||
1750417660924
|
1750428991104
|
||||||
],
|
],
|
||||||
"$ts": 1750417660924
|
"$ts": 1750428991104
|
||||||
},
|
},
|
||||||
"startDate": {
|
"startDate": {
|
||||||
"$": [
|
"$": [
|
||||||
"ts",
|
"ts",
|
||||||
192,
|
192,
|
||||||
1750417660924
|
1750428991104
|
||||||
],
|
],
|
||||||
"$ts": 1750414060924
|
"$ts": 1750414591104
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"meta": {
|
"meta": {
|
||||||
@ -2617,7 +2605,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"props": {
|
"props": {
|
||||||
"formattedValue": "Jun 20, 2025 2:07 PM",
|
"formattedValue": "Jun 20, 2025 2:16 PM",
|
||||||
"style": {
|
"style": {
|
||||||
"margin": 15
|
"margin": 15
|
||||||
}
|
}
|
||||||
@ -2702,7 +2690,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"props": {
|
"props": {
|
||||||
"formattedValue": "Jun 20, 2025 3:07 PM",
|
"formattedValue": "Jun 20, 2025 6:16 PM",
|
||||||
"maxDate": {
|
"maxDate": {
|
||||||
"$": [
|
"$": [
|
||||||
"ts",
|
"ts",
|
||||||
@ -2718,9 +2706,9 @@
|
|||||||
"$": [
|
"$": [
|
||||||
"ts",
|
"ts",
|
||||||
192,
|
192,
|
||||||
1750417660924
|
1750428991104
|
||||||
],
|
],
|
||||||
"$ts": 1750417660924
|
"$ts": 1750428991104
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -2910,17 +2898,17 @@
|
|||||||
"$": [
|
"$": [
|
||||||
"ts",
|
"ts",
|
||||||
192,
|
192,
|
||||||
1750417660924
|
1750428991105
|
||||||
],
|
],
|
||||||
"$ts": 1750414060924
|
"$ts": 1750414591104
|
||||||
},
|
},
|
||||||
"time_to_filter": {
|
"time_to_filter": {
|
||||||
"$": [
|
"$": [
|
||||||
"ts",
|
"ts",
|
||||||
192,
|
192,
|
||||||
1750417660924
|
1750428991105
|
||||||
],
|
],
|
||||||
"$ts": 1750417660924
|
"$ts": 1750428991104
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"meta": {
|
"meta": {
|
||||||
@ -3721,6 +3709,36 @@
|
|||||||
"enabled": true,
|
"enabled": true,
|
||||||
"results": {
|
"results": {
|
||||||
"data": [
|
"data": [
|
||||||
|
{
|
||||||
|
"Description": "MCM01 - Hello world",
|
||||||
|
"Duration": "00:00:32",
|
||||||
|
"EndTimestamp": 1750427866000,
|
||||||
|
"ID": 39,
|
||||||
|
"Location": "MCM01",
|
||||||
|
"Priority": "Low",
|
||||||
|
"StartTimestamp": 1750427834000,
|
||||||
|
"Tag": "MCM01.HMI.Beacon_Light"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Description": "MCM01 - Hello world",
|
||||||
|
"Duration": "02:49:21",
|
||||||
|
"EndTimestamp": 1750427784000,
|
||||||
|
"ID": 35,
|
||||||
|
"Location": "MCM01",
|
||||||
|
"Priority": "Low",
|
||||||
|
"StartTimestamp": 1750417623000,
|
||||||
|
"Tag": "MCM01.HMI.Beacon_Light"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Description": "MCM01 - Hello world",
|
||||||
|
"Duration": "02:49:21",
|
||||||
|
"EndTimestamp": 1750427784000,
|
||||||
|
"ID": 36,
|
||||||
|
"Location": "MCM01",
|
||||||
|
"Priority": "Low",
|
||||||
|
"StartTimestamp": 1750417623000,
|
||||||
|
"Tag": "MCM01.HMI.Beacon_Light"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"Description": "MCM01 - Hello world",
|
"Description": "MCM01 - Hello world",
|
||||||
"Duration": "00:00:06",
|
"Duration": "00:00:06",
|
||||||
@ -4212,12 +4230,12 @@
|
|||||||
"data": [
|
"data": [
|
||||||
{
|
{
|
||||||
"Description": "MCM01 - Hello world",
|
"Description": "MCM01 - Hello world",
|
||||||
"Duration": "01:42:53",
|
"Duration": "00:00:32",
|
||||||
"EndTimestamp": null,
|
"EndTimestamp": 1750427866000,
|
||||||
"ID": 35,
|
"ID": 39,
|
||||||
"Location": "MCM01",
|
"Location": "MCM01",
|
||||||
"Priority": "Low",
|
"Priority": "Low",
|
||||||
"StartTimestamp": 1750417623000,
|
"StartTimestamp": 1750427834000,
|
||||||
"Tag": "MCM01.HMI.Beacon_Light"
|
"Tag": "MCM01.HMI.Beacon_Light"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -4346,17 +4364,17 @@
|
|||||||
"$": [
|
"$": [
|
||||||
"ts",
|
"ts",
|
||||||
192,
|
192,
|
||||||
1750417660924
|
1750428991105
|
||||||
],
|
],
|
||||||
"$ts": 1750414060924
|
"$ts": 1750414591104
|
||||||
},
|
},
|
||||||
"time_to_filter": {
|
"time_to_filter": {
|
||||||
"$": [
|
"$": [
|
||||||
"ts",
|
"ts",
|
||||||
192,
|
192,
|
||||||
1750417660924
|
1750428991105
|
||||||
],
|
],
|
||||||
"$ts": 1750417660924
|
"$ts": 1750428991104
|
||||||
},
|
},
|
||||||
"type_filters": null
|
"type_filters": null
|
||||||
},
|
},
|
||||||
@ -4364,7 +4382,7 @@
|
|||||||
"component": {
|
"component": {
|
||||||
"onActionPerformed": {
|
"onActionPerformed": {
|
||||||
"config": {
|
"config": {
|
||||||
"script": " try:\n # Get filtered data from table (array of dicts)\n filtered_results \u003d self.parent.parent.getChild(\"Table\").getChild(\"Table\").props.filter.results\n filtered_data \u003d filtered_results.data\n \n # Ensure data is valid\n if not filtered_data:\n return\n \n # Get columns from first record\n columns \u003d filtered_data[0].keys()\n \n # Create a list of rows\n rows \u003d []\n for i in range(len(filtered_data)):\n row_dict \u003d filtered_data[i]\n row \u003d [row_dict.get(col) for col in columns]\n rows.append(row)\n \n # Convert to dataset and export\n dataset \u003d system.dataset.toDataSet(columns, rows)\n html_data \u003d system.dataset.dataSetToHTML(1, dataset, \"Filtered Results\")\n system.perspective.download(\"filtered_alarms_history.html\", html_data)\n \n print \"Export completed successfully! Exported\", len(rows), \"records.\"\n \n except Exception as e:\n print \"Export failed:\", str(e)\n\n\t"
|
"script": "\n from datetime import datetime\n def format_date(value):\n\t\tif isinstance(value, (int, long)) and value \u003e 10000000:\n\t\t\ttimestamp \u003d system.date.fromMillis(value)\n\t\t\treturn system.date.format(timestamp, \"yyyy-MM-dd HH:mm:ss\")\n\t\t\t\n\t\t# If value is not a valid timestamp, return as-is\n\t\treturn str(value)\n \n try:\n\n # Get filtered data\n table \u003d self.parent.parent.getChild(\"Table\").getChild(\"Table\")\n filtered_data \u003d table.props.filter.results.data\n\n if not filtered_data or len(filtered_data) \u003d\u003d 0:\n system.perspective.print(\"No filtered data to export.\")\n return\n\n # Get correct column order from the table\u0027s column config\n column_order \u003d [col[\"field\"] for col in table.props.columns if \"field\" in col]\n\n csv_content \u003d \",\".join(column_order) + \"\\n\"\n\n # Build rows\n for row_dict in filtered_data:\n row \u003d []\n for col in column_order:\n raw_val \u003d row_dict.get(col, \"\")\n value \u003d format_date(raw_val)\n value \u003d value.replace(\",\", \";\") # CSV safety\n row.append(value)\n csv_content +\u003d \",\".join(row) + \"\\n\"\n\n # Export CSV\n csv_bytes \u003d csv_content.encode(\"utf-8\")\n system.perspective.download(\"filtered_alarms_history.csv\", csv_bytes)\n\n system.perspective.print(\"CSV export completed successfully. Exported %d records.\" % len(filtered_data))\n\n except Exception as e:\n system.perspective.print(\"Export failed: \" + str(e))"
|
||||||
},
|
},
|
||||||
"scope": "G",
|
"scope": "G",
|
||||||
"type": "script"
|
"type": "script"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user