Skip to content

Commit

Permalink
wrong answers for non-ascii answers fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
domino14 committed Jun 4, 2019
1 parent 539576a commit 516216e
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 35 deletions.
12 changes: 9 additions & 3 deletions djAerolith/flashcards/templates/flashcards/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<!DOCTYPE html>
{% load value_from_settings %}
{% value_from_settings DEBUG as DEBUG %}

<html lang="en">
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -150,9 +152,13 @@ <h4 class="modal-title">Look up Word</h4>
'quizzes': "{{savedLists|escapejs}}"
};
</script>

{% include "flashcards_dynamic/flashcards_include.html" %}

{% if DEBUG %}
<script src="{{STATIC_SRV}}/static/dist/node_vendors~flashcardsapp~wordwallsapp.js"></script>
<script src="{{STATIC_SRV}}/static/dist/node_vendors~flashcardsapp.js"></script>
<script src="{{STATIC_SRV}}/static/dist/flashcardsapp.js"></script>
{% else %}
{% include "flashcards_dynamic/flashcards_include.html" %}
{% endif %}

</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,18 @@ describe('Internal functions', () => {
}
});
});

describe('alphagrammize', () => {
it('should alphagrammize properly', () => {
const testArray = [
['ROBINIA', 'ABIINOR'],
['ÑU', 'ÑU'],
['PERSPICACITY', 'ACCEIIPPRSTY'],
['ĆCZ13ŹÑ', 'CĆ1Ñ3ZŹ'],
];
for (let i = 0; i < testArray.length; i += 1) {
expect(Internal().alphagrammize(testArray[i][0])).toEqual(testArray[i][1]);
}
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,16 @@ class WordwallsAppContainer extends React.Component {
if (!game.answerExists(modifiedGuess)) {
// If the guess wasn't valid, don't bother submitting it to
// the server.
// console.log('not valid');
if (game.originalAnswerExists(modifiedGuess)) {
// console.log('original answer exists')
this.setState({
lastGuessCorrectness: GuessEnum.ALREADYGUESSED,
});
} else {
// console.log('does not exist')
if (game.markPotentialIncorrectGuess(modifiedGuess)) {
// console.log('game.markpotentialincorrectguess')
this.setState(state => ({
wrongAnswers: state.wrongAnswers + 1,
}));
}
// console.log('setting to incorrect')
this.setState({
lastGuessCorrectness: GuessEnum.INCORRECT,
});
Expand Down
32 changes: 22 additions & 10 deletions djAerolith/wordwalls/static/js/wordwalls/wordwalls_game.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,29 @@
import Immutable from 'immutable';
import _ from 'underscore';

const LETTER_SORT_MAP = {};
const SORT_STRING_ORDER = 'AĄBCĆ1DEĘFGHIJKLŁ2MNŃÑOÓPQR3SŚTUVWXYZŹŻ?';

function makeLetterSortMap() {
for (let i = 0; i < SORT_STRING_ORDER.length; i += 1) {
LETTER_SORT_MAP[SORT_STRING_ORDER[i]] = i;
}
}

/**
* Alphagrammize the word. Note - this is not necessarily in the correct
* sort order for non-english lexica, which means there may be a disconnect
* between how the alphagram question comes in, and what this function
* spits out. This should not be an issue if this function is used
* consistently.
* Alphagrammize the word. Note - this follows the same "ghetto" function
* used in models.py, and handles Spanish, English, and Polish. This may need
* to be reworked.
* @param {string} word
*/
function alphagrammize(word) {
return word.split('').sort().join('');
if (_.size(LETTER_SORT_MAP) === 0) {
makeLetterSortMap();
}
return word
.split('')
.sort((a, b) => LETTER_SORT_MAP[a] - LETTER_SORT_MAP[b])
.join('');
}

/**
Expand Down Expand Up @@ -193,8 +206,6 @@ class Game {
if (!question) {
return false;
}
// console.log('found question!!', question);
// console.log('updating in', this.origQuestions);
this.origQuestions = this.origQuestions.update(question, (aObj) => {
const newObj = aObj.set('wrongGuess', true);
return newObj;
Expand All @@ -213,8 +224,8 @@ class Game {
}

/**
* Return the specific question if the guess is an anagram of any of
* the unanswered questions, or null.
* Return the specific question string if the guess is an anagram of
* any of the unanswered questions, or null.
* @param {string} guess
* @return {string?}
*/
Expand Down Expand Up @@ -426,5 +437,6 @@ export function Internal() {
letterCounts,
anagramOfQuestions,
anagramOfQuestion,
alphagrammize,
};
}
11 changes: 9 additions & 2 deletions djAerolith/wordwalls/templates/wordwalls/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@


<body>
{% value_from_settings DEBUG as DEBUG %}

{% block content %}
<script>
// Our entry point will use window.TableGlobals to pass these in to the app.
// Figure out the socket server protocol.
{% value_from_settings DEBUG as DEBUG %}
{% if DEBUG %}
var protocol = 'ws://';
{% else %}
Expand Down Expand Up @@ -100,7 +101,13 @@
<div id="fade"></div>
<div id="infoDialog" title=""></div>

{% include "wordwalls_dynamic/wordwalls_include.html" %}
{% if DEBUG %}
<script src="{{STATIC_SRV}}/static/dist/node_vendors~flashcardsapp~wordwallsapp.js"></script>
<script src="{{STATIC_SRV}}/static/dist/node_vendors~wordwallsapp.js"></script>
<script src="{{STATIC_SRV}}/static/dist/wordwallsapp.js"></script>
{% else %}
{% include "wordwalls_dynamic/wordwalls_include.html" %}
{% endif %}

</body>
</html>
16 changes: 1 addition & 15 deletions webpack.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import path from 'path';

const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');

export default {
mode: 'development',
output: {
path: path.resolve(__dirname, 'djAerolith/static/dist/'),
filename: '[name].[contenthash].js',
filename: '[name].js',
publicPath: '/static/dist/',
},
devtool: 'source-map',
Expand Down Expand Up @@ -52,19 +51,6 @@ export default {
$: 'jquery',
jQuery: 'jquery',
}),
new webpack.HashedModuleIdsPlugin(),
// For wordwalls app:
new HtmlWebpackPlugin({
filename: path.resolve(__dirname, 'djAerolith/static/dist/templates/wordwalls_dynamic/wordwalls_include.html'),
inject: false,
template: path.resolve(__dirname, 'wordwalls_include_template.html'),
}),
// For flashcards app:
new HtmlWebpackPlugin({
filename: path.resolve(__dirname, 'djAerolith/static/dist/templates/flashcards_dynamic/flashcards_include.html'),
inject: false,
template: path.resolve(__dirname, 'flashcards_include_template.html'),
}),
],
devServer: {
port: 7000,
Expand Down

0 comments on commit 516216e

Please sign in to comment.