Skip to content

Commit

Permalink
[MODIFY] fix eslint style problems
Browse files Browse the repository at this point in the history
  • Loading branch information
yosoycentli committed Jan 19, 2022
1 parent 77816d7 commit c9c2f11
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 124 deletions.
2 changes: 1 addition & 1 deletion routes/v3/covid-19/apiVariants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { redis, keys } = require('../../instances');

router.get('/v3/covid-19/variants/countries/:country?', async (req, res) => {
const { allowNull } = req.query;
const { country: countryName } = req.params;
const { country: countryName } = req.params;
if (countryName) {
const standardizedCountryName = nameUtils.getCountryData(countryName.trim()).country || countryName.trim();
const data = JSON.parse(await redis.hget(keys.variants, standardizedCountryName));
Expand Down
106 changes: 53 additions & 53 deletions scrapers/covid-19/getVariants.js
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;
76 changes: 38 additions & 38 deletions tests/mochaSetup.spec.js
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.');
}
});
63 changes: 31 additions & 32 deletions tests/v3/covid-19/api_variants.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,41 @@ const chai = require('chai');
const chaiHttp = require('chai-http');
const app = require('../../../server');
const { testBasicProperties } = require('../../testingFunctions');
const { should } = require('chai');

chai.use(chaiHttp);

const countries = [
"Austria",
"Belgium",
"Bulgaria",
"Croatia",
"Cyprus",
"Czechia",
"Denmark",
"Estonia",
"Finland",
"France",
"Germany",
"Greece",
"Hungary",
"Iceland",
"Ireland",
"Italy",
"Latvia",
"Liechtenstein",
"Lithuania",
"Luxembourg",
"Malta",
"Netherlands",
"Norway",
"Poland",
"Portugal",
"Romania",
"Slovakia",
"Slovenia",
"Spain",
"Sweden"
];
'Austria',
'Belgium',
'Bulgaria',
'Croatia',
'Cyprus',
'Czechia',
'Denmark',
'Estonia',
'Finland',
'France',
'Germany',
'Greece',
'Hungary',
'Iceland',
'Ireland',
'Italy',
'Latvia',
'Liechtenstein',
'Lithuania',
'Luxembourg',
'Malta',
'Netherlands',
'Norway',
'Poland',
'Portugal',
'Romania',
'Slovakia',
'Slovenia',
'Spain',
'Sweden'
];

describe('TESTING /v3/covid-19/variants/countries general', () => {
it('/v3/covid-19/variants/countries/ correct countries', (done) => {
Expand Down

0 comments on commit c9c2f11

Please sign in to comment.