-
-
Notifications
You must be signed in to change notification settings - Fork 4
Support --subjects as csv #274
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
base: main
Are you sure you want to change the base?
Support --subjects as csv #274
Conversation
5dc0831
to
5bcb557
Compare
I think that we can write better code if we are having tow options
If this is done, we can handle |
29fff86
to
830229c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get how this code is supposed to work.
Can you please explain how to build (command to use) and provide a ZIM with only Biology exercises in English? I tried but it produced a ZIM with all exercises.
6f1c681
to
11d151f
Compare
@benoit74 , I've made some changes. Now you can try Please, try also a combination of subjects : |
steps/export/converters.ts
Outdated
@@ -13,6 +13,7 @@ import { iso6393To1 } from 'iso-639-3' | |||
import { options, extractResources, loadLanguages, createFileContentProvider } from './utils.js' | |||
import { rimraf } from 'rimraf' | |||
import { fileURLToPath } from 'url' | |||
import { categories } from 'steps/get/options.js' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should import options from export step, not get
README.md
Outdated
Available only on GET step: | ||
```bash | ||
--withoutLanguageVariants ... | ||
--subjects 'math,physics' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is misleading, text above says this is available only on GET step while --subjects
MUST be passed to both GET and EXPORT steps
return formatcsv(langs) | ||
} | ||
|
||
export const formatSubjects = (subjects: string): string[] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to slugify the subject? (not saying this is wrong, but it probably deserves a comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that each time I deal with subjects (as array), I need to slugify all subjects again. So, i preferred to slugify all subjects from the beginning.
It also will reduce calling slugify
to make code more readable.
Is it right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get it, sorry. Where are the subjects slugified in the first place? Why are they sluglified at this stage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First , When I need to verify subjects (ensure that inputs are already existed in cats) , I use cats
values (which are slugified). So, I need to slugify (input subjects). This happens in verifySubjects
function.
Second, When I return only matched cats, I need to slugify the input subjects again
Over all , I try to avoid this : calling formatcsv
(I prefer formatSubjects) and a lot of slugify(sub, {lower:true})
export const verifySubjects = (subjects: string): boolean => {
return formatcsv(subjects).every((subj) => {
return Object.values(cats).includes(slugify(subj, { lower: true }))
})
}
export const getMatchedCats = (input: string) => {
const formatedSubjects = formatcsv(input)
const catsKeys = Object.keys(cats)
const catsValues = Object.values(cats)
const validCats = {}
formatedSubjects.forEach((sub) => {
const indexCat = catsValues.indexOf(slugify(sub, { lower: true }))
if (indexCat >= 0) validCats[catsKeys[indexCat]] = catsValues[indexCat]
})
return validCats
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you think there's no need for that. It's totally OK.
return formatcsv(subjects).map((subject) => slugify(subject, { lower: true })) | ||
} | ||
|
||
export const verifySubjects = (subjects: string): boolean => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get why we lookup indexes to verify subject validity, wouldn't it be enough to check that all subjects are among categories?
11d151f
to
9092900
Compare
@benoit74 , I've fixed requested changes. |
Fix : #271
Approach:
--subjects
to parameterList as a CLI optionrootCategories
andcats
cats
androotCategories
values based on passed values.e.g :
--subjects 'math, physics'
cats : {4: 'physics', 15: 'math'}
rootCategories : [Math, Physics]
Note:
formatcsv
as a util function for all future csv parameters.