From 656698da8387b1c24f751e8ac4795605981ff636 Mon Sep 17 00:00:00 2001 From: Jussi Maatta Date: Sat, 25 Jan 2014 23:57:57 +0200 Subject: [PATCH] Add A-factor to E-factor conversion to SuperMemo import. The SuperMemo XML importer assumed that the A-factors used by SuperMemo map 1-1 with E-factors (which correspond to Ease in Anki). This resulted in too large E-factors for imported items. This change adds an A-factor to E-factor conversion to the importer. --- anki/importing/supermemo_xml.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/anki/importing/supermemo_xml.py b/anki/importing/supermemo_xml.py index 9a00438ce..ee1b3da7f 100644 --- a/anki/importing/supermemo_xml.py +++ b/anki/importing/supermemo_xml.py @@ -142,6 +142,28 @@ class SupermemoXmlImporter(NoteImporter): return unicode(btflsoup(s, selfClosingTags=['br','hr','img','wbr'], convertEntities=btflsoup.HTML_ENTITIES)) + def _afactor2efactor(self, af): + # Adapted from + + # Ranges for A-factors and E-factors + af_min = 1.2 + af_max = 6.9 + ef_min = 1.3 + ef_max = 3.3 + + # Sanity checks for the A-factor + if af < af_min: + af = af_min + elif af > af_max: + af = af_max + + # Scale af to the range 0..1 + af_scaled = (af - af_min) / (af_max - af_min) + # Rescale to the interval ef_min..ef_max + ef = ef_min + af_scaled * (ef_max - ef_min) + + return ef + ## DEFAULT IMPORTER METHODS def foreignNotes(self): @@ -191,7 +213,7 @@ class SupermemoXmlImporter(NoteImporter): nextDue = tLastrep + (float(item.Interval) * 86400.0) remDays = int((nextDue - time.time())/86400) card.due = self.col.sched.today+remDays - card.factor = int(float(item.AFactor.replace(',','.'))*1000) + card.factor = int(self._afactor2efactor(float(item.AFactor.replace(',','.')))*1000) note.cards[0] = card # categories & tags