Skip to content

Commit

Permalink
calculate total unique centers found
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhinav Sinha committed May 14, 2021
1 parent 3d32938 commit f3197fe
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ const SERVICE_PROVIDER = 'Gmail';
const RECIPIENT = '[email protected],[email protected],[email protected]';
```

Finally, you can also alter the date range with which the application will fetch vaccination slots by customising **DATE_RANGE** value in [`src/configs/schedulerConfig.js`](https://github.com/sinhadotabhinav/covid-19-vaccine-alerts-cowin/blob/master/src/configs/schedulerConfig.js) file. By default it is set to **7** but, you can change it to 10 or 15 for example, based on your need. The config file also allows changes in the periodic schedule with which the application runs. By default, **SCHEDULE** value depicts a cron schedule **every hour at minute 5 and second 0**. To alter this schedule, you need to be familiar with the [cron scheduler](https://linuxhint.com/cron_jobs_complete_beginners_tutorial/#:~:text=The%20scheduled%20commands%20and%20scripts,Task%20Scheduler%20in%20Windows%20OS). I use [Crontab Guru](https://crontab.guru) website to test my cron schedules.
Finally, you can also alter the date range with which the application will fetch vaccination slots by customising **DATE_RANGE** value in [`src/configs/schedulerConfig.js`](https://github.com/sinhadotabhinav/covid-19-vaccine-alerts-cowin/blob/master/src/configs/schedulerConfig.js) file. By default it is set to **7** but, you can change it to 10 or 15 for example, based on your need. The config file also allows changes in the periodic schedule with which the application runs. By default, **SCHEDULE** value depicts a cron schedule **every hour at minute 0 and minute 30; second 0**. To alter this schedule, you need to be familiar with the [cron scheduler](https://linuxhint.com/cron_jobs_complete_beginners_tutorial/#:~:text=The%20scheduled%20commands%20and%20scripts,Task%20Scheduler%20in%20Windows%20OS). I use [Crontab Guru](https://crontab.guru) website to test my cron schedules.

```
const SCHEDULE = '0 5 * * * *';
const SCHEDULE = '0 0,30 * * * *';
const DATE_RANGE = 7;
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "covid-19-vaccine-alerts-cowin",
"version": "1.0.3",
"version": "1.0.4",
"description": "This is an alerting application that sends email notifications to beneficiaries in India using COWIN platform for vaccine availability",
"main": "src/app.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async function sendEmailAlert(slotsArray) {
}
firstRun = false;
runCounter = runCounter + 1;
await dailyDigest.updateRunCounter(runCounter, vaccinationSlots);
await dailyDigest.updateRunStatistics(runCounter, outputArray);
await resetDailyCounter();
};

Expand Down
2 changes: 1 addition & 1 deletion src/configs/schedulerConfig.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const SCHEDULE = '0 5 * * * *';
const SCHEDULE = '0 0,30 * * * *';
const DATE_RANGE = 7;
const DATE_FORMAT = 'DD-MM-YYYY';
const DELAY = 60000;
Expand Down
20 changes: 15 additions & 5 deletions src/utilities/dailyDigest.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const htmlBuilder = require('../utilities/htmlBuilder');
const logger = require('../utilities/logger');

let runs = 0;
let slots = [];
let uniqueSlots = [];

async function prepareReport () {
let regionType = Boolean(appConfig.FINDBYPINCODE) ? 'pincode' : 'district';
let region = regionType == 'pincode' ? appConfig.PINCODE : appConfig.DISTRICT;
alerts.sendEmailAlert(mailConfig.DAILY_DIGEST_SUBJECT,
await htmlBuilder.prepareDailyDigestEmail(runs, slots.length, regionType, region), (error, result) => {
await htmlBuilder.prepareDailyDigestEmail(runs, uniqueSlots.length, regionType, region), (error, result) => {
if(error) {
console.log(logger.getLog(error));
} else {
Expand All @@ -20,9 +20,19 @@ async function prepareReport () {
});
}

async function updateRunCounter (runCounter, vaccinationSlots) {
async function updateRunStatistics (runCounter, outputArray) {
let slots = uniqueSlots;
let centersArray = await getCenters(outputArray);
uniqueSlots = [...new Set([...slots,...centersArray])];
runs = runCounter;
slots = vaccinationSlots;
}

module.exports = { prepareReport, updateRunCounter };
async function getCenters (outputArray) {
let centersArray = [];
for(let counter = 0; counter < outputArray.length; counter++) {
centersArray.push(outputArray[counter].center_id.toString());
}
return centersArray;
}

module.exports = { prepareReport, updateRunStatistics };
2 changes: 1 addition & 1 deletion src/utilities/htmlBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async function prepareDailyDigestEmail(runs, centers, regionType, region) {
<div style="display: block;">
<p>Welcome to the ${mailConfig.SENDER} daily digest. A summary of results obtained today are gathered and presented below:<\p>
<p>The application periodically checked for new vaccination slots ${runs} times today.<\p>
<p>Total number of vaccination centers with available slots found for ${regionType} \(${region}\) were: ${centers}<\p>
<p>Total number of vaccination centers with available slots found today for ${regionType} \(${region}\) were: ${centers}<\p>
<p>The application will continue to look for new slots in your requested region and send alerts tomorrow.<\p>
</div>
</body>\n
Expand Down

0 comments on commit f3197fe

Please sign in to comment.