GWM : Automation for Survey and iip calculation

This commit is contained in:
Gowtham M 2026-02-03 11:48:53 +05:30
parent 9edfaa5ca5
commit 2d4c8f8b11
2 changed files with 30 additions and 0 deletions

View File

@ -55,6 +55,10 @@ module.exports = (sequelize, DataTypes) => {
assigned: { type: DataTypes.INTEGER },
responded: { type: DataTypes.INTEGER },
not_responded: { type: DataTypes.INTEGER },
ipi_calculated:{
type: DataTypes.BOOLEAN,
defaultValue: false,
},
},
{
tableName: "quarterly_windows_configuration_master",

View File

@ -41,6 +41,7 @@ class AutomatedSchedulerService {
end_date,
start_date
FROM quarterly_windows_configuration_master
WHERE ipi_calculated = 0
ORDER BY year DESC,
CASE quarter
WHEN 'Q1' THEN 1
@ -145,6 +146,28 @@ class AutomatedSchedulerService {
}
}
/**
* Update ipi_calculated flag in quarterly_windows_configuration_master
*/
async updateIPICalculatedFlag(year, quarter) {
const connection = await this.pool.getConnection();
try {
const query = `
UPDATE quarterly_windows_configuration_master
SET ipi_calculated = 1
WHERE year = ? AND quarter = ?
`;
await connection.query(query, [year, quarter]);
console.log(`[${new Date().toISOString()}] Updated ipi_calculated flag to 1 for ${year} ${quarter}`);
} catch (error) {
console.error(`[${new Date().toISOString()}] Error updating ipi_calculated flag:`, error);
throw error;
} finally {
connection.release();
}
}
/**
* Main scheduler logic - runs daily
*/
@ -197,6 +220,9 @@ class AutomatedSchedulerService {
latestWindow.quarter
);
// Step 5: Update ipi_calculated flag to 1
await this.updateIPICalculatedFlag(latestWindow.year, latestWindow.quarter);
console.log(`[${new Date().toISOString()}] ========================================`);
console.log(`[${new Date().toISOString()}] All scheduled tasks completed successfully`);
console.log(`[${new Date().toISOString()}] Survey Result:`, JSON.stringify(surveyResult, null, 2));