Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scripts): save multi-language forms report to tsv files #7027

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions scripts/20220217_multi-language-stats/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const MongoClient = require('mongodb').MongoClient,
ObjectId = require('mongodb').ObjectId,
_ = require('lodash')
_ = require('lodash'),
fs = require('fs')

const categories = ['un', 'cn', 'ta', 'ms', 'en']

Expand Down Expand Up @@ -111,7 +112,7 @@ async function getStats(db) {
]),
)

const printFormTSVReport = async (header, filter) => {
const outputFormTSVReport = async (header, filename, filter) => {
console.log('========================================')
console.log(header)
const formIds = Object.keys(formsById).filter(filter)
Expand All @@ -126,29 +127,34 @@ async function getStats(db) {
form.agency = await getAgencyFromAdminId(form.admin)
}

console.log(
formIds
.map((id) =>
[
id,
formsById[id].title,
[...formsById[id].langs].sort().join('+'),
`${formsById[id].agency.shortName} (${formsById[id].agency.fullName})`,
formsById[id].status,
formsById[id].numSubmissions,
].join('\t'),
)
.join('\n'),
)
const reportContent = formIds
.map((id) =>
[
id,
formsById[id].title,
[...formsById[id].langs].sort().join('+'),
`${formsById[id].agency.shortName} (${formsById[id].agency.fullName})`,
formsById[id].status,
formsById[id].numSubmissions,
].join('\t'),
)
.join('\n')

// 1. print report to console
console.log(reportContent)
// 2. save report to file
fs.writeFileSync(filename, reportContent)
}

await printFormTSVReport(
await outputFormTSVReport(
'Getting agency and number of submissions for forms with multi-languages',
'forms_multi_languages.tsv',
(id) => formsById[id].langs.size > 1,
)

await printFormTSVReport(
await outputFormTSVReport(
'Getting agency and number of submissions for non-english forms',
'forms_non_english_single_language.tsv',
(id) =>
formsById[id].langs.size === 1 &&
!formsById[id].langs.has('en') &&
Expand Down
Loading