Skip to content

Commit

Permalink
Speed Performance improvement for question load and permutation count.
Browse files Browse the repository at this point in the history
Filters removed for the time being.
At a useable state but ready for new adjectives
  • Loading branch information
LandonJPGinn committed May 12, 2024
1 parent 1453610 commit 88504c4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 46 deletions.
20 changes: 13 additions & 7 deletions conjugation/drill.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,24 @@ <h4 class="text-left mt-2 mb-4">Forms</h4>
<div class="col-md-6 text-center">
<div class="form-group">
<div style="display: inline-block">
<h4 class="text-left mt-2 mb-4">Verbs</h4>
<h4 class="text-left mt-2 mb-4">Regular Verbs</h4>
<div class="text-left ml-1 form-check"><input class="form-check-input" type="checkbox" id="godan"
checked><label for="godan" class="form-check-label">Godan verbs</label></div>
<div class="text-left ml-1 form-check"><input class="form-check-input" type="checkbox" id="ichidan"
checked><label for="ichidan" class="form-check-label">Ichidan verbs</label></div>
<div class="text-left ml-1 specials">Special cases</div>
<div class="text-left ml-1 form-check"><input class="form-check-input" type="checkbox" id="iku"
checked><label for="iku" class="form-check-label">行く verb</label></div>

<div class="text-left ml-1 specials">Irregular Verbs</div>
<div class="text-left ml-1 form-check"><input class="form-check-input" type="checkbox" id="suru"
checked><label for="suru" class="form-check-label">する verbs</label></div>
<div class="text-left ml-1 form-check"><input class="form-check-input" type="checkbox" id="kuru"
checked><label for="kuru" class="form-check-label">来る verb</label></div>
<div class="text-left ml-1 form-check"><input class="form-check-input" type="checkbox" id="iku"
checked><label for="iku" class="form-check-label">行く verb</label></div>
<div class="text-left ml-1 form-check"><input class="form-check-input" type="checkbox" id="aru"
checked><label for="aru" class="form-check-label">ある verb</label></div>
<div class="text-left ml-1 form-check"><input class="form-check-input" type="checkbox" id="iru"
checked><label for="iru" class="form-check-label">いる verbs</label></div>
<div class="text-left ml-1 form-check"><input class="form-check-input" type="checkbox" id="suru"
checked><label for="suru" class="form-check-label">する verbs</label></div>

</div>
</div>
</div>
Expand All @@ -158,7 +160,7 @@ <h4 class="text-left mt-2 mb-4">Adjectives</h4>
id="i-adjective"><label for="i-adjective" class="form-check-label">い adjectives</label></div>
<div class="text-left ml-1 form-check"><input class="form-check-input" type="checkbox"
id="na-adjective"><label for="na-adjective" class="form-check-label">な adjectives</label></div>
<div class="text-left ml-1 specials">Special cases</div>
<div class="text-left ml-1 specials">Irregular Adjectives</div>
<div class="text-left ml-1 form-check"><input class="form-check-input" type="checkbox" id="ii"><label
for="ii" class="form-check-label">いい adjective</label></div>
<div class="text-left ml-1 specials">Filters</div>
Expand Down Expand Up @@ -186,6 +188,10 @@ <h4 class="text-left mt-2 mb-4">Adjectives</h4>
<div class="text-center mb-2">You must select at least one of 'Plain' and 'Polite'.</div>
</div>

<div id="noQuestionError" style="display: none">
<div class="text-center mb-2">Not enough available questions.</div>
</div>

<div class="row justify-content-center mt-3 ml-2 mr-2">
<div id="voice_select_options" class="form-check" style="display: none">
<label class="form-check-label" for="voice_select">Select voice (Notice: Online voices may incur data charges!)</label>
Expand Down
70 changes: 38 additions & 32 deletions conjugation/drill.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import grp_sample from './grp_sample.json' assert { type: 'json' };


var transformations = [];
var question_pool = [];

var log;

Expand Down Expand Up @@ -160,7 +161,6 @@ function getVerbForms(entry) {
"hiragana": {},
"furigana": {}
};

Object.keys(words[entry].conjugations).forEach(function (key) {
result["kanji"][key] = kanjiForm(words[entry].conjugations[key].forms);
result["hiragana"][key] = kanaForm(words[entry].conjugations[key].forms);
Expand Down Expand Up @@ -397,17 +397,22 @@ function generateQuestion() {
var from_form;
var forms;
var options = getOptions();

var word_selection = question_pool.slice();
var count = 0;

while (true) {

if (count++ == 100) {
if (count++ == 800) {
showSplash();
return;
}

entry = Object.keys(words).randomElement();
entry = word_selection.randomElement();
if (entry === undefined) {
word_selection = question_pool.slice();
entry = word_selection.randomElement();
}

var transformation = transformations.randomElement();

from_form = transformation.from;
Expand All @@ -417,6 +422,11 @@ function generateQuestion() {

var valid = validQuestion(entry, forms, transformation, getOptions());

if (!valid) {
var index = word_selection.indexOf(entry);
word_selection.splice(index, 1);
}

// Modify the chance of trick questions so that they appear on average 25%
// of the time. When trick questions are active then 50% of the
// transformation structure are trick questions and so a 33% filter here
Expand Down Expand Up @@ -1033,8 +1043,22 @@ function calculateTransitions() {
transformations = transformations.concat(trick_forms);
}

function updateOptionSummary() {

function updateQuestionPool() {
var options = getOptions();
var active_options = Object.keys(options).filter(function (key) { return options[key] == true; });
question_pool = [];

Object.keys(words).forEach(function (word) {
if (active_options.includes(words[word].group)) {
question_pool.push(word);
return;
}
});
}

function updateOptionSummary() {
updateQuestionPool();
// Calculate how many questions will apply
// Use the json count_dict
var applicable = 0;
Expand All @@ -1044,19 +1068,25 @@ function updateOptionSummary() {
Object.keys(grp_sample).forEach(function (word) {

var forms = getVerbForms(word);
let modifier = 0;

transformations.forEach(function (transformation) {

if (validQuestion(word, forms, transformation, options)) {
// This is calculating too much
var modifier = count_dict[grp_sample[word].group];
modifier = count_dict[grp_sample[word].group];
applicable += modifier;
}
});
});

$("#questionCount").text(applicable);

if (applicable < $('#numQuestions').val()) {
document.querySelector('#noQuestionError').style.display = 'block';
} else {
document.querySelector('#noQuestionError').style.display = 'none';
}

if (!options.plain && !options.polite) {
document.querySelector('#politePlainError').style.display = 'block';
} else {
Expand Down Expand Up @@ -1187,27 +1217,3 @@ $('window').ready(function () {
window.processAnswer = processAnswer;
window.proceed = proceed;
window.explain = explain;
// window.checkAnswer = checkAnswer;
// window.startQuiz = startQuiz;
// window.endQuiz = endQuiz;
// window.updateVoiceSelect = updateVoiceSelect;
// window.updateVoiceSelection = updateVoiceSelection;
// window.loadOptions = loadOptions;
// window.restoreDefaults = restoreDefaults;
// window.updateOptionSummary = updateOptionSummary;
// window.saveOptions = saveOptions;
// window.calculateTransitions = calculateTransitions;
// window.getOptions = getOptions;
// window.loadVoiceList = loadVoiceList;
// window.populateVoiceList = populateVoiceList;
// window.textToSpeech = textToSpeech;
// window.arrayDifference = arrayDifference;
// window.arrayUnique = arrayUnique;
// window.updateProgressBar = updateProgressBar;
// window.updateHistoryView = updateHistoryView;
// window.resetLog = resetLog;
// window.commaList = commaList;
// window.wordWithFurigana = wordWithFurigana;
// window.kanaForm = kanaForm;
// window.getVoiceConfig = getVoiceConfig;
// document.querySelector('quizForm').addEventListener('action', processAnswer);
13 changes: 6 additions & 7 deletions todo
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@


Next Up:

- [ ] Get the counter to math properly
- [ ] Disable the Go Button when the pool is too small (give it a note)

# very time consuming step, may require a spreadsheet
- [ ] Add Top 100 most common verbs
- [ ] Add all verbs
Expand All @@ -14,20 +10,23 @@ Next Up:


Complete:
- [X] Add hover to see meaning - included in explanation
- [X] Add hover to see meaning - included in explanation instead
- [X] decouple verb db
- [X] add aru and iru
- [X] add conditional -tara
- [X] add provisional conditional -eba
- [X] color face lift - minor
- [X] Add support for random generated sentences with simple A is B and A does B structures - provide exampe sentence
- [x] Add support for filtering by meta data ( jlpt, common, industry, etc)
- [x] Question Count should work off of a cache not dynamic reading ( cicd )
- [x] Get the counter to math properly
- [x] fix bug that randomly chooses a word and validates it to find one that applies.
this is causes issues when there are hundreds of words but our options only allows one


Ideas:
- Add da (desu)
- dyanmically generated sentence based on correct answer form
- dynamically generated sentence based on correct answer form
- add option to see what they even did
- [ ] Add support for filtering by meta data ( jlpt, common, industry, etc)


0 comments on commit 88504c4

Please sign in to comment.