-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from ciatph/dev
v1.3.3
- Loading branch information
Showing
10 changed files
with
152 additions
and
19 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
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
111 changes: 111 additions & 0 deletions
111
app/__tests__/municipalities/municipalitiesPerProvinceCount.js
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 |
---|---|---|
@@ -0,0 +1,111 @@ | ||
require('dotenv') | ||
const path = require('path') | ||
|
||
const ExcelFile = require('../../src/classes/excel') | ||
const ColorLog = require('../../src/classes/colorlog') | ||
const logger = new ColorLog() | ||
|
||
const checkClass = require('../classInitialization/checkClass') | ||
const { arrayToString } = require('../../src/lib/utils') | ||
|
||
/* eslint-disable no-undef */ | ||
describe('Municipalities per province count match', () => { | ||
// Test using the latest 10-day PAGASA Excel file | ||
const excelFile = new ExcelFile({ | ||
pathToFile: path.join(__dirname, 'excelfiledownload2.xlsx'), | ||
url: process.env.EXCEL_FILE_URL | ||
}) | ||
|
||
it('number of parsed/processed municipalities per province should match per province count from original data', async () => { | ||
jest.setTimeout(15000) | ||
|
||
// Start file download | ||
await excelFile.init() | ||
|
||
checkClass({ | ||
excelInstance: excelFile, | ||
isRemote: true, | ||
classType: ExcelFile | ||
}) | ||
|
||
// Parsed/processed provinces from the Excel file | ||
const allProvinces = excelFile.listAllProvinces(true) | ||
|
||
// Provinces from the PAGASA seasonal config file | ||
const allProvincesConfig = excelFile.listAllProvinces() | ||
|
||
// Parsed/processed municipalities by province | ||
const allMunicipalities = excelFile.listMunicipalities({ | ||
provinces: allProvinces | ||
}) | ||
|
||
// Total parsed municipalities count | ||
const countMunicipalities = Object.values(allMunicipalities) | ||
.reduce( | ||
(sum, item) => (sum += item.length), 0 | ||
) | ||
|
||
const missing = [] | ||
const matches = [] | ||
|
||
// Compare parsed municipalities per province count vs. original (unprocessed) data | ||
allProvinces.forEach((province) => { | ||
// Total parsed count | ||
const countParsed = allMunicipalities[province].length | ||
|
||
// Total count from unprocessed data | ||
const countRaw = excelFile.data.filter(row => | ||
row[excelFile.options.SHEETJS_COL]?.includes(`(${province.trim()})`) | ||
) | ||
|
||
if (countRaw.length > 0) { | ||
const countLog = { | ||
province, | ||
loaded: countRaw.length, | ||
parsed: countParsed | ||
} | ||
|
||
if (countParsed !== countRaw.length) { | ||
missing.push(countLog) | ||
} else { | ||
matches.push(countLog) | ||
} | ||
} | ||
}) | ||
|
||
expect(missing).toHaveLength(0) | ||
|
||
let totalLoaded = 0 | ||
let totalParsed = 0 | ||
|
||
const message = matches.reduce((list, item) => { | ||
totalLoaded += item.loaded | ||
totalParsed += item.parsed | ||
list += `${item.province}: loaded=${item.loaded}, parsed=${item.parsed}\n` | ||
return list | ||
}, []) | ||
|
||
const total = `Total loaded: ${totalLoaded}\nTotal parsed: ${totalParsed}/${countMunicipalities}` | ||
|
||
logger.log(message) | ||
logger.log(total, { color: ColorLog.COLORS.TEXT.CYAN }) | ||
|
||
// Log missing/mismatching provinces from 10-day Excel and PAGASA seasonal config file | ||
if (allProvinces.length !== allProvincesConfig.length) { | ||
const missingInParsed = allProvincesConfig.filter(item => !allProvinces.includes(item)) | ||
const missingInConfig = allProvinces.filter(item => !allProvincesConfig.includes(item)) | ||
|
||
if (missingInParsed.length > 0) { | ||
let msg = `[WARNING]: ${missingInParsed.length} province(s) in the 10-Day Excel file are missing\n` | ||
msg += `in the (PAGASA seasonal) config: ${arrayToString(missingInParsed)}` | ||
logger.log(msg, { color: ColorLog.COLORS.TEXT.YELLOW }) | ||
} | ||
|
||
if (missingInConfig.length > 0) { | ||
let msg = `[WARNING]: ${missingInConfig.length} province(s) in the (PAGASA seasonal) config are missing\n` | ||
msg += `in the 10-Day Excel file: ${arrayToString(missingInConfig)}` | ||
logger.log(msg, { color: ColorLog.COLORS.TEXT.YELLOW }) | ||
} | ||
} | ||
}) | ||
}) |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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