mirror of
https://github.com/OkaeriPoland/okaeri-timings.git
synced 2026-01-18 03:28:20 +01:00
Update timings_okaeri_cloud_v1_parse.json
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "timings.okaeri.cloud/v1/parse",
|
"name": "api.timings.okaeri.cloud/v1/parse",
|
||||||
"nodes": [
|
"nodes": [
|
||||||
{
|
{
|
||||||
"parameters": {},
|
"parameters": {},
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"functionCode": "const parseReport = (text) => {\n\n const start = new Date();\n const lines = text.split(/\\r?\\n/);\n\n const metadata = {};\n let header = null;\n const records = [];\n\n for (const line of lines) {\n\n // empty\n if (!line) {\n continue\n }\n\n // metadata\n if (line.startsWith(\"#\")) {\n if (!line.includes(\":\")) {\n continue;\n }\n const parts = line.substring(1).split(\":\", 2);\n if (parts.length !== 2) {\n return {error: `Invalid metadata: '${line}'`};\n }\n const key = parts[0].trim().toLowerCase();\n metadata[key] = parts[1].trim();\n continue;\n }\n\n // header\n if (header === null) {\n const parts = line.split(\",\");\n if (parts.length < 2) {\n return {error: `Invalid header: '${line}'`};\n }\n header = parts;\n continue;\n }\n\n // data\n const parts = line.split(\",\");\n if (parts.length !== header.length) {\n return {error: `Invalid record: '${line}'`};\n }\n\n records.push(parts.map(value => {\n const floatValue = parseFloat(value);\n if (Number.isNaN(floatValue)) {\n return {error: `Invalid number '${value}' in: '${line}'`}\n }\n return floatValue;\n }));\n }\n\n if (header === null || records.length < 2) {\n return {error: \"Invalid report\"};\n }\n\n return {\n meta: metadata,\n header: header,\n data: records,\n stats: {\n parseTime: `PT${((new Date() - start) / 1000)}S`\n }\n }\n};\n\nif (items.length === 0) {\n items[0].json = {error: \"No report file found in the request.\"};\n} else if (items.length > 1) {\n items[0].json = {error: \"More than one file found in the request.\"}\n} else {\n const data = items[0].binary.file.data;\n const text = Buffer.from(data, \"base64\").toString(\"utf8\");\n items[0].json = parseReport(text)\n}\n\nreturn items;\n"
|
"functionCode": "const parseReport = (text) => {\n\n const start = new Date();\n const lines = text.split(/\\r?\\n/);\n\n const metadata = {};\n let header = null;\n const records = [];\n\n for (const line of lines) {\n\n // empty\n if (!line) {\n continue\n }\n\n // metadata\n if (line.startsWith(\"#\")) {\n if (!line.includes(\":\")) {\n continue;\n }\n const parts = line.substring(1).split(\":\", 2);\n if (parts.length !== 2) {\n return {error: `Invalid metadata: '${line}'`};\n }\n const key = parts[0].trim().toLowerCase();\n metadata[key] = parts[1].trim();\n continue;\n }\n\n // header\n if (header === null) {\n const parts = line.split(\",\");\n if (parts.length < 2) {\n return {error: `Invalid header: '${line}'`};\n }\n header = parts;\n continue;\n }\n\n // data\n const parts = line.split(\",\");\n if (parts.length !== header.length) {\n return {error: `Invalid record: '${line}'`};\n }\n\n records.push(parts.map(value => {\n const floatValue = parseFloat(value);\n if (Number.isNaN(floatValue)) {\n return {error: `Invalid number '${value}' in: '${line}'`}\n }\n return floatValue;\n }));\n }\n\n if (header === null || records.length < 2) {\n return {error: \"Invalid report\"};\n }\n\n return {\n meta: metadata,\n header: header,\n data: records,\n stats: {\n parseTime: `PT${((new Date() - start) / 1000)}S`\n }\n }\n};\n\nif (items.length === 0) {\n items[0].json = {error: \"No report file found in the request.\"};\n} else if (items.length > 1) {\n items[0].json = {error: \"More than one file found in the request.\"}\n} else {\n const data = items[0].binary.file.data;\n const text = Buffer.from(data, \"base64\").toString(\"utf8\");\n items[0].json = parseReport(text)\n}\n\n// noinspection JSAnnotator\nreturn items;\n"
|
||||||
},
|
},
|
||||||
"name": "Function",
|
"name": "Function",
|
||||||
"type": "n8n-nodes-base.function",
|
"type": "n8n-nodes-base.function",
|
||||||
@@ -56,4 +56,4 @@
|
|||||||
"active": true,
|
"active": true,
|
||||||
"settings": {},
|
"settings": {},
|
||||||
"id": 1
|
"id": 1
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user