From d6f5ef4cc5812c143c4842e6427a3aeed5c5e9d1 Mon Sep 17 00:00:00 2001 From: Alexander Polynomdivision Date: Tue, 2 Oct 2018 15:49:53 +0200 Subject: [PATCH] feat: Don't forget about the adverbs --- frontend/src/models/vocab.ts | 17 +++++++++++++---- frontend/src/pages/level.tsx | 2 +- frontend/src/pages/review.tsx | 27 +++++++++++++++++++-------- scripts/csv_vocab_to_mongo.py | 15 ++++++++++++++- 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/frontend/src/models/vocab.ts b/frontend/src/models/vocab.ts index eaeebb3..c28fc88 100644 --- a/frontend/src/models/vocab.ts +++ b/frontend/src/models/vocab.ts @@ -29,6 +29,10 @@ export interface IAdjektivData { endung_n: string; }; +export interface IAdverbData { + grundform: string; +}; + export interface IVocab { // If a word has multiple meanings german: string[]; @@ -36,7 +40,7 @@ export interface IVocab { mnemonic?: string; type: VocabType; - latin: INomenData | IVerbData | IAdjektivData; + latin: INomenData | IVerbData | IAdjektivData | IAdverbData; // This number is unique across all vocabulary items id: number; @@ -152,9 +156,14 @@ export function vocabToReviewCard(vocab: IVocab): IReviewCard[] { qtype: ReviewQType.ADJ_ENDUNG_N, id: vocab.id, }]; - default: - // TODO: Remove after removing Adverbien - return []; + case VocabType.ADVERB: + return [{ + // Latin -> German + question: vocab.latin.grundform, + answers: vocab.german, + qtype: ReviewQType.GERMAN, + id: vocab.id, + }]; } } diff --git a/frontend/src/pages/level.tsx b/frontend/src/pages/level.tsx index 4b0f14e..c188029 100644 --- a/frontend/src/pages/level.tsx +++ b/frontend/src/pages/level.tsx @@ -129,7 +129,7 @@ const LevelPageWithRouter = withRouter( Endung neutrum: {aData.endung_n} ; - default: + case VocabType.ADVERB: return
; } } diff --git a/frontend/src/pages/review.tsx b/frontend/src/pages/review.tsx index 4e1f282..3c6aae8 100644 --- a/frontend/src/pages/review.tsx +++ b/frontend/src/pages/review.tsx @@ -21,7 +21,9 @@ import CloseIcon from "@material-ui/icons/Close"; import { withRouter } from "react-router-dom"; -import { IVocab, IReviewCard, vocabToReviewCard, reviewQTypeToStr } from "../models/vocab"; +import { + IVocab, IReviewCard, vocabToReviewCard, reviewQTypeToStr, VocabType +} from "../models/vocab"; import { ReviewType, IReviewMetadata } from "../models/review"; import { levW } from "../algorithms/levenshtein"; @@ -139,10 +141,6 @@ const ReviewPageWithRouter = withRouter( }; } - vocabFromId = (id: number): IVocab | {} => { - return this.vocab.find((el) => el.id === this.props.current.id); - } - // When a vocabulary item has been answered, we need to update // the group's SuperMemo2-data. // We update based on the following State-Machine: (C = Correct; W = Wrong) @@ -275,12 +273,25 @@ const ReviewPageWithRouter = withRouter( const { question, qtype } = this.props.current; const questionTitle = `${question} (${reviewQTypeToStr(qtype)})`; - // TODO/NOTE: This assumes that each vocabulary item gets mapped to - // exactly 3 review cards + + // NOTE: This assumes that adverbs get mapped to only 1 card, + // while every other type of vocabulary gets mapped to + // exactly 3 cards each. // NOTE: The 'numCards === 0 ?' is neccessary as (for some reasdn) numCards // starts of by being 0, which results in progress === -Inifinity. // That looks weird as the user sees the progressbar jump. - const numCards = this.vocab.length * 3; + // NOTE: The arrow function needs the ': number' annotation as TS + // will then deduce the type of acc and curr to be '1|3', + // leads to compiler warnings, as a, b element {1, 3} is not + // element {1, 3}. + const numCards = this.vocab.map((vocab): number => { + if (vocab.type === VocabType.ADVERB) { + return 1; + } else { + return 3; + } + }).reduce((acc, curr) => acc + curr); + const progress = numCards === 0 ? ( 0 ) : ( diff --git a/scripts/csv_vocab_to_mongo.py b/scripts/csv_vocab_to_mongo.py index ac80588..12467e7 100644 --- a/scripts/csv_vocab_to_mongo.py +++ b/scripts/csv_vocab_to_mongo.py @@ -7,6 +7,7 @@ import pymongo TYPE_NOUNS = 0 TYPE_VERBS = 1 TYPE_ADJECTIVES = 2 +TYPE_ADVERB = 3 PATH_TO_VOCAB = "../data/vocab" @@ -92,7 +93,14 @@ def csv_to_vocab(filename, type, from_id): latin["endung_f"] = endung_f latin["endung_n"] = endung_n - + elif (type == TYPE_ADVERB): + # Adverb + bedeutungen = [row[1]] + if (row[2] != ""): + bedeutungen.append(row[2]) + if (row[3] != ""): + bedeutungen.append(row[3]) + # TODO: Hints and mnemonics vocab.append({ "id": id, @@ -130,6 +138,11 @@ adj, last_id = csv_to_vocab("Adjektive.csv", TYPE_ADJECTIVES, last_id) vocab += adj id = last_id +log("Adverbs...", tabs=1) +adj, last_id = csv_to_vocab("Adverbien.csv", TYPE_ADVERBS, last_id) +vocab += adj + + # Connect to the database log("Inserting vocabulary into database") log("Connecting...", tabs=1)