-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77816d7
commit c9c2f11
Showing
4 changed files
with
123 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,70 @@ | ||
const axios = require("axios"); | ||
const logger = require("../../utils/logger"); | ||
const csvUtils = require("../../utils/csvUtils"); | ||
const axios = require('axios'); | ||
const logger = require('../../utils/logger'); | ||
const csvUtils = require('../../utils/csvUtils'); | ||
|
||
const PATH = | ||
"https://opendata.ecdc.europa.eu/covid19/virusvariant/csv/data.csv"; | ||
const PATH | ||
= 'https://opendata.ecdc.europa.eu/covid19/virusvariant/csv/data.csv'; | ||
|
||
/** | ||
* Requests and parses csv data that is used to populate the data table on the European Centre for Disease Prevention and Control (ECDPC) site | ||
*/ | ||
const europeanCountriesData = async () => { | ||
try { | ||
const europeRes = (await axios.get(PATH)).data; | ||
const parsedEuropeanCountriesData = await csvUtils.parseCsvData( | ||
europeRes | ||
); | ||
return parsedEuropeanCountriesData.map((country) => ({ | ||
updated: Date.now(), | ||
country: country.country, | ||
yearWeek: country.year_week, | ||
source: country.source, | ||
newCases: parseInt(country.new_cases) || null, | ||
numberSequenced: parseInt(country.number_sequenced) || null, | ||
percentSequenced: parseFloat(country.percent_sequenced) || null, | ||
validDenominator: country.valid_denominator, | ||
variant: country.variant, | ||
numberDetectionsVariant: | ||
try { | ||
const europeRes = (await axios.get(PATH)).data; | ||
const parsedEuropeanCountriesData = await csvUtils.parseCsvData( | ||
europeRes | ||
); | ||
return parsedEuropeanCountriesData.map((country) => ({ | ||
updated: Date.now(), | ||
country: country.country, | ||
yearWeek: country.year_week, | ||
source: country.source, | ||
newCases: parseInt(country.new_cases) || null, | ||
numberSequenced: parseInt(country.number_sequenced) || null, | ||
percentSequenced: parseFloat(country.percent_sequenced) || null, | ||
validDenominator: country.valid_denominator, | ||
variant: country.variant, | ||
numberDetectionsVariant: | ||
parseInt(country.number_detections_variant) || null, | ||
numberSequencedKnownVariant: | ||
numberSequencedKnownVariant: | ||
parseInt(country.number_sequenced_known_variant) || null, | ||
percentVariant: parseFloat(country.percent_variant) || null, | ||
})); | ||
} catch (err) { | ||
logger.err("Error: Requesting ECDC Data failed!", err); | ||
return null; | ||
} | ||
percentVariant: parseFloat(country.percent_variant) || null | ||
})); | ||
} catch (err) { | ||
logger.err('Error: Requesting ECDC Data failed!', err); | ||
return null; | ||
} | ||
}; | ||
|
||
const variantsData = async (keys, redis) => { | ||
try { | ||
const countriesData = await europeanCountriesData(); | ||
try { | ||
const countriesData = await europeanCountriesData(); | ||
|
||
const dataByCountry = countriesData | ||
.map((obj) => obj.country) | ||
.reduce((obj, country) => { | ||
const groupByCountry = countriesData.filter( | ||
(item) => item.country === country | ||
); | ||
obj[country] = groupByCountry; | ||
return obj; | ||
}, {}); | ||
const dataByCountry = countriesData | ||
.map((obj) => obj.country) | ||
.reduce((obj, country) => { | ||
const groupByCountry = countriesData.filter( | ||
(item) => item.country === country | ||
); | ||
obj[country] = groupByCountry; | ||
return obj; | ||
}, {}); | ||
|
||
const uniquesCountries = countriesData | ||
.map((country) => country.country) | ||
.filter((value, index, self) => self.indexOf(value) === index); | ||
console.log(uniquesCountries); | ||
const uniquesCountries = countriesData | ||
.map((country) => country.country) | ||
.filter((value, index, self) => self.indexOf(value) === index); | ||
console.log(uniquesCountries); | ||
|
||
for (var i in uniquesCountries) { | ||
await redis.hset( | ||
keys.variants, | ||
uniquesCountries[i], | ||
JSON.stringify(dataByCountry[uniquesCountries[i]]) | ||
); | ||
} | ||
} catch (err) { | ||
logger.err("Error: Formating ECDC data failed!", err); | ||
} | ||
for (var i in uniquesCountries) { | ||
await redis.hset( | ||
keys.variants, | ||
uniquesCountries[i], | ||
JSON.stringify(dataByCountry[uniquesCountries[i]]) | ||
); | ||
} | ||
} catch (err) { | ||
logger.err('Error: Formating ECDC data failed!', err); | ||
} | ||
}; | ||
|
||
module.exports = variantsData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
const { | ||
scraper: { | ||
executeScraper, | ||
executeScraperNYTData, | ||
excecuteScraperAppleData, | ||
excecuteScraperGov, | ||
excecuteScraperInfluenza, | ||
excecuteScraperVaccineCoverage, | ||
excecuteScraperVaccineStateCoverage, | ||
executeScraperVariants, | ||
}, | ||
redis, | ||
} = require("../routes/instances"); | ||
const logger = require("../utils/logger"); | ||
scraper: { | ||
executeScraper, | ||
executeScraperNYTData, | ||
excecuteScraperAppleData, | ||
excecuteScraperGov, | ||
excecuteScraperInfluenza, | ||
excecuteScraperVaccineCoverage, | ||
excecuteScraperVaccineStateCoverage, | ||
executeScraperVariants | ||
}, | ||
redis | ||
} = require('../routes/instances'); | ||
const logger = require('../utils/logger'); | ||
|
||
const [arg] = process.argv[5].split("/").slice(-1); | ||
const argValue = arg.substring(arg.indexOf("_") + 1, arg.indexOf(".")); | ||
const [arg] = process.argv[5].split('/').slice(-1); | ||
const argValue = arg.substring(arg.indexOf('_') + 1, arg.indexOf('.')); | ||
const mapArgToScraper = { | ||
worldometers: executeScraper, | ||
jhucsse: executeScraper, | ||
historical: executeScraper, | ||
nyt: executeScraperNYTData, | ||
apple: excecuteScraperAppleData, | ||
gov: excecuteScraperGov, | ||
influenza: excecuteScraperInfluenza, | ||
vaccine: excecuteScraperVaccineCoverage, | ||
vaccinestate: excecuteScraperVaccineStateCoverage, | ||
worldometers: executeScraper, | ||
jhucsse: executeScraper, | ||
historical: executeScraper, | ||
nyt: executeScraperNYTData, | ||
apple: excecuteScraperAppleData, | ||
gov: excecuteScraperGov, | ||
influenza: excecuteScraperInfluenza, | ||
vaccine: excecuteScraperVaccineCoverage, | ||
vaccinestate: excecuteScraperVaccineStateCoverage, | ||
variants: executeScraperVariants | ||
}; | ||
|
||
// eslint-disable-next-line | ||
before(async () => { | ||
await redis.flushall(); | ||
logger.info("Finished flushing all data from redis."); | ||
if (argValue in mapArgToScraper) { | ||
await mapArgToScraper[argValue](); | ||
} else { | ||
await executeScraper(); | ||
await executeScraperNYTData(); | ||
await excecuteScraperAppleData(); | ||
await excecuteScraperGov(); | ||
await excecuteScraperInfluenza(); | ||
await excecuteScraperVaccineCoverage(); | ||
await excecuteScraperVaccineStateCoverage(); | ||
logger.info("Scraping all data finished."); | ||
} | ||
await redis.flushall(); | ||
logger.info('Finished flushing all data from redis.'); | ||
if (argValue in mapArgToScraper) { | ||
await mapArgToScraper[argValue](); | ||
} else { | ||
await executeScraper(); | ||
await executeScraperNYTData(); | ||
await excecuteScraperAppleData(); | ||
await excecuteScraperGov(); | ||
await excecuteScraperInfluenza(); | ||
await excecuteScraperVaccineCoverage(); | ||
await excecuteScraperVaccineStateCoverage(); | ||
logger.info('Scraping all data finished.'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters