Initial commit of SOP Monitoring Dashboard

This commit is contained in:
2026-07-28 12:50:28 +05:30
commit 0894a9c21e
40 changed files with 5676 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
const xlsx = require('xlsx');
const fs = require('fs');
const filePath = 'd:\\Projects\\AI SOP Monitoring\\Consolidated_report_v2_with_feed-names (1).xlsx';
const workbook = xlsx.readFile(filePath);
console.log("Sheets found:", workbook.SheetNames);
const timeMatrixSheet = workbook.SheetNames.find(s => s.toLowerCase() === 'time matrix');
if (timeMatrixSheet) {
console.log("First 10 rows of Time Matrix:");
const sheet = workbook.Sheets[timeMatrixSheet];
const data = xlsx.utils.sheet_to_json(sheet, { header: 1 });
console.log(data.slice(0, 10));
} else {
console.log("Time Matrix sheet not found.");
}
+279
View File
@@ -0,0 +1,279 @@
{
"name": "ingestion",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "ingestion",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"dotenv": "^17.4.2",
"pg": "^8.22.0",
"xlsx": "^0.18.5"
}
},
"node_modules/adler-32": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/adler-32/-/adler-32-1.3.1.tgz",
"integrity": "sha512-ynZ4w/nUUv5rrsR8UUGoe1VC9hZj6V5hU9Qw1HlMDJGEJw5S7TfTErWTjMys6M7vr0YWcPqs3qAr4ss0nDfP+A==",
"license": "Apache-2.0",
"engines": {
"node": ">=0.8"
}
},
"node_modules/cfb": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/cfb/-/cfb-1.2.2.tgz",
"integrity": "sha512-KfdUZsSOw19/ObEWasvBP/Ac4reZvAGauZhs6S/gqNhXhI7cKwvlH7ulj+dOEYnca4bm4SGo8C1bTAQvnTjgQA==",
"license": "Apache-2.0",
"dependencies": {
"adler-32": "~1.3.0",
"crc-32": "~1.2.0"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/codepage": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/codepage/-/codepage-1.15.0.tgz",
"integrity": "sha512-3g6NUTPd/YtuuGrhMnOMRjFc+LJw/bnMp3+0r/Wcz3IXUuCosKRJvMphm5+Q+bvTVGcJJuRvVLuYba+WojaFaA==",
"license": "Apache-2.0",
"engines": {
"node": ">=0.8"
}
},
"node_modules/crc-32": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz",
"integrity": "sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ==",
"license": "Apache-2.0",
"bin": {
"crc32": "bin/crc32.njs"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/dotenv": {
"version": "17.4.2",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.4.2.tgz",
"integrity": "sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw==",
"license": "BSD-2-Clause",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/frac": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/frac/-/frac-1.1.2.tgz",
"integrity": "sha512-w/XBfkibaTl3YDqASwfDUqkna4Z2p9cFSr1aHDt0WoMTECnRfBOv2WArlZILlqgWlmdIlALXGpM2AOhEk5W3IA==",
"license": "Apache-2.0",
"engines": {
"node": ">=0.8"
}
},
"node_modules/pg": {
"version": "8.22.0",
"resolved": "https://registry.npmjs.org/pg/-/pg-8.22.0.tgz",
"integrity": "sha512-8wih1vVIBMxoUM2oB4soJsD9tDnDpLv4OXBJ+EJzFsvycD+lfyIreC2gGHq78f8jbLLt+bvlPTFdFZfJkOuzAA==",
"license": "MIT",
"dependencies": {
"pg-connection-string": "^2.14.0",
"pg-pool": "^3.14.0",
"pg-protocol": "^1.15.0",
"pg-types": "2.2.0",
"pgpass": "1.0.5"
},
"engines": {
"node": ">= 16.0.0"
},
"optionalDependencies": {
"pg-cloudflare": "^1.4.0"
},
"peerDependencies": {
"pg-native": ">=3.0.1"
},
"peerDependenciesMeta": {
"pg-native": {
"optional": true
}
}
},
"node_modules/pg-cloudflare": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.4.0.tgz",
"integrity": "sha512-Vo7z/6rrQYxpNRylp4Tlob2elzbh+N/MOQbxFVWCxS7oEx6jF53GTJFxK2WWpKuBRkmiin4Mt+xofFDjx09R0A==",
"license": "MIT",
"optional": true
},
"node_modules/pg-connection-string": {
"version": "2.14.0",
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.14.0.tgz",
"integrity": "sha512-XwWDGcLRGCXAR8F/AM5bG7Q+A3Wm2s6QeEjlOKZLlH3UYcguiqCWKyWXVag5TLTIjR7oOJUY8kcADaZgWPyLeg==",
"license": "MIT"
},
"node_modules/pg-int8": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==",
"license": "ISC",
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/pg-pool": {
"version": "3.14.0",
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.14.0.tgz",
"integrity": "sha512-gKtPkFdQPU3DksooVLi9LsjZxrsBUZIpa+7aVx+LV5pNh0KzP4Zleud2po+ConrxbuXGBJ6Hfer6hdgpIBpBaw==",
"license": "MIT",
"peerDependencies": {
"pg": ">=8.0"
}
},
"node_modules/pg-protocol": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.15.0.tgz",
"integrity": "sha512-cq9sECI5s0+uPUXjbz8ioyPJni6RzsRib0US67i5IoTZKw8fNeYlVE7u8F4dG7vEJJtc5wdD1K189lCCUwqWTQ==",
"license": "MIT"
},
"node_modules/pg-types": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
"license": "MIT",
"dependencies": {
"pg-int8": "1.0.1",
"postgres-array": "~2.0.0",
"postgres-bytea": "~1.0.0",
"postgres-date": "~1.0.4",
"postgres-interval": "^1.1.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/pgpass": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz",
"integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==",
"license": "MIT",
"dependencies": {
"split2": "^4.1.0"
}
},
"node_modules/postgres-array": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==",
"license": "MIT",
"engines": {
"node": ">=4"
}
},
"node_modules/postgres-bytea": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.1.tgz",
"integrity": "sha512-5+5HqXnsZPE65IJZSMkZtURARZelel2oXUEO8rH83VS/hxH5vv1uHquPg5wZs8yMAfdv971IU+kcPUczi7NVBQ==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/postgres-date": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz",
"integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==",
"license": "MIT",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/postgres-interval": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
"license": "MIT",
"dependencies": {
"xtend": "^4.0.0"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/split2": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz",
"integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==",
"license": "ISC",
"engines": {
"node": ">= 10.x"
}
},
"node_modules/ssf": {
"version": "0.11.2",
"resolved": "https://registry.npmjs.org/ssf/-/ssf-0.11.2.tgz",
"integrity": "sha512-+idbmIXoYET47hH+d7dfm2epdOMUDjqcB4648sTZ+t2JwoyBFL/insLfB/racrDmsKB3diwsDA696pZMieAC5g==",
"license": "Apache-2.0",
"dependencies": {
"frac": "~1.1.2"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/wmf": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wmf/-/wmf-1.0.2.tgz",
"integrity": "sha512-/p9K7bEh0Dj6WbXg4JG0xvLQmIadrner1bi45VMJTfnbVHsc7yIajZyoSoK60/dtVBs12Fm6WkUI5/3WAVsNMw==",
"license": "Apache-2.0",
"engines": {
"node": ">=0.8"
}
},
"node_modules/word": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/word/-/word-0.3.0.tgz",
"integrity": "sha512-OELeY0Q61OXpdUfTp+oweA/vtLVg5VDOXh+3he3PNzLGG/y0oylSOC1xRVj0+l4vQ3tj/bB1HVHv1ocXkQceFA==",
"license": "Apache-2.0",
"engines": {
"node": ">=0.8"
}
},
"node_modules/xlsx": {
"version": "0.18.5",
"resolved": "https://registry.npmjs.org/xlsx/-/xlsx-0.18.5.tgz",
"integrity": "sha512-dmg3LCjBPHZnQp5/F/+nnTa+miPJxUXB6vtk42YjBBKayDNagxGEeIdWApkYPOf3Z3pm3k62Knjzp7lMeTEtFQ==",
"license": "Apache-2.0",
"dependencies": {
"adler-32": "~1.3.0",
"cfb": "~1.2.1",
"codepage": "~1.15.0",
"crc-32": "~1.2.1",
"ssf": "~0.11.2",
"wmf": "~1.0.1",
"word": "~0.3.0"
},
"bin": {
"xlsx": "bin/xlsx.njs"
},
"engines": {
"node": ">=0.8"
}
},
"node_modules/xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
"license": "MIT",
"engines": {
"node": ">=0.4"
}
}
}
}
+17
View File
@@ -0,0 +1,17 @@
{
"name": "ingestion",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^17.4.2",
"pg": "^8.22.0",
"xlsx": "^0.18.5"
}
}
+137
View File
@@ -0,0 +1,137 @@
const xlsx = require('xlsx');
const { Client } = require('pg');
const path = require('path');
const filePath = path.join(__dirname, '..', 'Consolidated_report_v2_with_feed-names (1).xlsx');
const client = new Client({
user: 'admin',
host: 'localhost',
database: 'sop_monitoring',
password: 'password',
port: 5432,
});
function parseDuration(durationStr) {
if (!durationStr) return 0;
const hMatch = durationStr.match(/(\d+)h/);
const mMatch = durationStr.match(/(\d+)m/);
const sMatch = durationStr.match(/(\d+)s/);
let seconds = 0;
if (hMatch) seconds += parseInt(hMatch[1]) * 3600;
if (mMatch) seconds += parseInt(mMatch[1]) * 60;
if (sMatch) seconds += parseInt(sMatch[1]);
return seconds;
}
function parseCellEvents(cellText, cameraZone, startTime, endTime, totalDuration) {
if (!cellText) return [];
const events = [];
const blocks = cellText.split(/\r?\n---\r?\n/);
for (const block of blocks) {
const lines = block.split(/\r?\n/);
if (lines.length === 0) continue;
let eventDesc = lines[0];
let state = 'Active';
let stateDuration = totalDuration;
if (lines.length > 1) {
const stateMatch = lines[1].match(/(Active|Waste|Idle|Load waiting|Start point):\s*(.*)/i);
if (stateMatch) {
let stateText = stateMatch[1];
if (stateText.toLowerCase() === 'load waiting') state = 'Load waiting';
else if (stateText.toLowerCase() === 'waste') state = 'Waste';
else if (stateText.toLowerCase() === 'idle') state = 'Idle';
else if (stateText.toLowerCase() === 'start point') state = 'Active';
else state = 'Active';
if (stateText.toLowerCase() !== 'start point') {
stateDuration = parseDuration(stateMatch[2]);
}
}
}
events.push({
start_time: startTime,
end_time: endTime,
duration_seconds: totalDuration,
camera_zone: cameraZone,
event_description: eventDesc.trim(),
state,
state_duration_seconds: stateDuration
});
}
return events;
}
async function run() {
await client.connect();
// Create table if not exists (in case it wasn't created yet)
await client.query('DROP TABLE IF EXISTS events;');
await client.query(`
CREATE TABLE IF NOT EXISTS events (
id SERIAL PRIMARY KEY,
changeover_id VARCHAR(100),
changeover_date DATE,
start_time TIME,
end_time TIME,
duration_seconds INTEGER,
camera_zone VARCHAR(50),
event_description TEXT,
state VARCHAR(50),
state_duration_seconds INTEGER
);
`);
await client.query('TRUNCATE TABLE events RESTART IDENTITY;');
const wb = xlsx.readFile(filePath);
const sheet = wb.Sheets['Time Matrix'];
const data = xlsx.utils.sheet_to_json(sheet, { header: 1, raw: false, dateNF: 'yyyy-mm-dd hh:mm:ss' });
// Start from row index 8 (skipping headers in the new file format)
let allEvents = [];
for (let i = 8; i < data.length; i++) {
const row = data[i];
let startTime = row[1];
let endTime = row[2];
let durationStr = row[4];
if (!startTime || !endTime) continue; // Skip empty rows
// Handle "0s / start marker"
let totalDuration = row[3] ? parseInt(row[3]) : parseDuration(durationStr);
// CO
if (row[5]) allEvents.push(...parseCellEvents(row[5], 'CO', startTime, endTime, totalDuration));
// Mill
if (row[6]) allEvents.push(...parseCellEvents(row[6], 'Mill', startTime, endTime, totalDuration));
// Conveyor
if (row[7]) allEvents.push(...parseCellEvents(row[7], 'Conveyor', startTime, endTime, totalDuration));
}
const changeoverId = 'CO-DEMO-1';
const changeoverDate = '2026-07-28';
for (const ev of allEvents) {
try {
await client.query(
`INSERT INTO events (changeover_id, changeover_date, start_time, end_time, duration_seconds, camera_zone, event_description, state, state_duration_seconds)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
[changeoverId, changeoverDate, ev.start_time, ev.end_time, ev.duration_seconds, ev.camera_zone, ev.event_description, ev.state, ev.state_duration_seconds]
);
} catch(err) {
console.error("Error inserting:", ev, err);
}
}
console.log(`Inserted ${allEvents.length} events into the database.`);
await client.end();
}
run().catch(console.error);
+4
View File
@@ -0,0 +1,4 @@
const { Client } = require('pg');
const client = new Client({ user: 'admin', host: 'localhost', database: 'sop_monitoring', password: 'password', port: 5432 });
client.connect().then(() => client.query("SELECT * FROM events WHERE camera_zone = 'Conveyor' ORDER BY start_time ASC"))
.then(res => { console.log(res.rows); client.end(); }).catch(console.error);