Files
dashboard/mockData/batchProcessData.ts
Alberto-Audrix 32a36cceff
CI / lint-and-test (push) Canceled after 0s
first commit
2026-07-28 08:55:05 +07:00

141 lines
4.0 KiB
TypeScript

import { BatchService, BatchJob, BatchServiceType, BatchJobStatus } from '../types';
export const initialBatchServices: BatchService[] = [
{
id: 'service-1',
name: 'Sinkronisasi Stok Gudang (ERP)',
type: BatchServiceType.ERP_SYNC,
schedule: 'Setiap jam @ :30',
},
{
id: 'service-10',
name: 'Sinkronisasi Data Finansial (ERP)',
type: BatchServiceType.ERP_SYNC,
schedule: 'Setiap hari @ 04:00',
},
{
id: 'service-5',
name: 'Ingesti Data Sensor (Per Jam)',
type: BatchServiceType.DATA_INGESTION,
schedule: 'Setiap jam',
},
{
id: 'service-6',
name: 'Analisis CCTV: Hitung Ayam',
type: BatchServiceType.CCTV_CHICKEN_COUNT,
schedule: 'Setiap 15 menit',
},
{
id: 'service-7',
name: 'Analisis CCTV: Hitung Karung',
type: BatchServiceType.CCTV_SACK_COUNT,
schedule: 'Setiap 30 menit',
},
{
id: 'service-8',
name: 'Analisis Perilaku Harian',
type: BatchServiceType.BEHAVIOR_ANALYSIS,
schedule: 'Setiap hari @ 02:00',
},
{
id: 'service-9',
name: 'Analisis Data Timbangan Harian',
type: BatchServiceType.WEIGHT_ANALYSIS,
schedule: 'Setiap hari @ 02:30',
},
{
id: 'service-2',
name: 'Pelatihan Ulang Model Deteksi Mortalitas',
type: BatchServiceType.AI_TRAINING,
schedule: 'Setiap Minggu @ 03:00',
},
{
id: 'service-3',
name: 'Pembuatan Laporan Performa Mingguan',
type: BatchServiceType.REPORTING,
schedule: 'Setiap Senin @ 06:00',
},
{
id: 'service-4',
name: 'Optimasi Database',
type: BatchServiceType.DATABASE_MAINTENANCE,
schedule: 'Setiap hari @ 00:00',
},
];
export const initialBatchJobs: BatchJob[] = (() => {
const jobs: BatchJob[] = [];
let jobIdCounter = 1;
initialBatchServices.forEach((service) => {
let jobCount = 5;
let timeStep: { unit: 'days' | 'hours' | 'minutes'; value: number } = {
unit: 'days',
value: 1,
};
switch (service.type) {
case BatchServiceType.CCTV_CHICKEN_COUNT:
jobCount = 4 * 12; // 12 hours
timeStep = { unit: 'minutes', value: 15 };
break;
case BatchServiceType.CCTV_SACK_COUNT:
jobCount = 2 * 12; // 12 hours
timeStep = { unit: 'minutes', value: 30 };
break;
case BatchServiceType.ERP_SYNC:
case BatchServiceType.DATA_INGESTION:
if (service.schedule.includes('jam')) {
jobCount = 24;
timeStep = { unit: 'hours', value: 1 };
}
break;
case BatchServiceType.AI_TRAINING:
jobCount = 2; // Last 2 weeks
timeStep = { unit: 'days', value: 7 };
break;
}
for (let i = 0; i < jobCount; i++) {
const startTime = new Date();
if (timeStep.unit === 'days') {
startTime.setDate(startTime.getDate() - i * timeStep.value);
startTime.setHours(
parseInt(service.schedule.split('@')[1] || '0', 10),
Math.floor(Math.random() * 10)
);
} else if (timeStep.unit === 'hours') {
startTime.setHours(
startTime.getHours() - i * timeStep.value,
Math.floor(Math.random() * 5)
);
} else if (timeStep.unit === 'minutes') {
startTime.setMinutes(startTime.getMinutes() - i * timeStep.value);
}
const duration = (Math.random() * 5 + 1) * 60 * 1000; // 1-6 minutes
const endTime = new Date(startTime.getTime() + duration);
let status = BatchJobStatus.COMPLETED;
const rand = Math.random();
if (i === 0 && rand < 0.1) status = BatchJobStatus.RUNNING;
else if (rand < 0.05) status = BatchJobStatus.FAILED;
if (service.id === 'service-3' && i === 0) {
// Specific case for running reporting job
status = BatchJobStatus.RUNNING;
}
jobs.push({
id: `job-${jobIdCounter++}`,
serviceId: service.id,
status,
startTime,
endTime: status === BatchJobStatus.RUNNING ? null : endTime,
});
}
});
return jobs.sort((a, b) => b.startTime.getTime() - a.startTime.getTime());
})();