use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.
the class LearnQueuingManagerTest method testGetNewCardQueuingWithoutCategory.
@SmallTest
@Test
public void testGetNewCardQueuingWithoutCategory() throws Exception {
QueueManager queueManager = new LearnQueueManager.Builder(getContext(), TestHelper.SAMPLE_DB_PATH).setLearnQueueSize(10).setFilterCategory(null).setCacheSize(50).build();
Card cqueue = queueManager.dequeue();
assertEquals(1, (int) cqueue.getId());
queueManager.release();
}
use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.
the class QuizQueuingManagerTest method testUpdateCard.
@SmallTest
@Test
public void testUpdateCard() throws Exception {
Scheduler mockScheduler = mock(Scheduler.class);
// Create a quiz start the quiz size 3 from card 5
QueueManager queueManager = new QuizQueueManager.Builder().setDbOpenHelper(helper).setQuizSize(3).setStartCardOrd(5).setScheduler(mockScheduler).build();
Card card5 = queueManager.dequeue();
queueManager.remove(card5);
assertEquals(5, (int) card5.getOrdinal());
when(mockScheduler.isCardLearned(card5.getLearningData())).thenReturn(true);
queueManager.update(card5);
Card card6 = queueManager.dequeue();
queueManager.remove(card6);
assertEquals(6, (int) card6.getOrdinal());
when(mockScheduler.isCardLearned(card6.getLearningData())).thenReturn(false);
queueManager.update(card6);
Card card7 = queueManager.dequeue();
queueManager.remove(card7);
assertEquals(7, (int) card7.getOrdinal());
when(mockScheduler.isCardLearned(card7.getLearningData())).thenReturn(true);
queueManager.update(card7);
// Now cards in the queue is the card we failed
// and we succeed this time
Card card6Again = queueManager.dequeue();
queueManager.remove(card6Again);
assertEquals(6, (int) card6Again.getOrdinal());
when(mockScheduler.isCardLearned(card6.getLearningData())).thenReturn(true);
queueManager.update(card6Again);
// No cards in the queue
Card nullCard = queueManager.dequeue();
assertNull(nullCard);
}
use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.
the class QuizQueuingManagerTest method testFilterByGroup.
@SmallTest
@Test
public void testFilterByGroup() throws Exception {
// Create a quiz start the quiz size 3 from card 5
QueueManager queueManager = new QuizQueueManager.Builder().setDbOpenHelper(helper).setQuizSize(3).setStartCardOrd(5).build();
Card card5 = queueManager.dequeue();
queueManager.remove(card5);
assertEquals(5, (int) card5.getOrdinal());
Card card6 = queueManager.dequeue();
queueManager.remove(card6);
assertEquals(6, (int) card6.getOrdinal());
Card card7 = queueManager.dequeue();
queueManager.remove(card7);
assertEquals(7, (int) card7.getOrdinal());
// No cards in the queue
Card nullCard = queueManager.dequeue();
assertNull(nullCard);
}
use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.
the class Mnemosyne2CardsExporter method createXMLFile.
private void createXMLFile(String dbPath, File xmlFile) throws IOException {
AnyMemoDBOpenHelper helper = null;
PrintWriter outXml = null;
try {
helper = AnyMemoDBOpenHelperManager.getHelper(dbPath);
CardDao cardDao = helper.getCardDao();
CategoryDao categoryDao = helper.getCategoryDao();
LearningDataDao learningDataDao = helper.getLearningDataDao();
int cardCount = (int) cardDao.countOf();
outXml = new PrintWriter(new BufferedWriter(new FileWriter(xmlFile)));
outXml.printf("<openSM2sync number_of_entries=\"%d\">\n", cardCount);
// First card tags (categories)
Map<String, String> categoryOidMap = new HashMap<String, String>();
Map<Integer, String> cardIdOidMap = new HashMap<Integer, String>(cardCount * 4 / 3);
Iterator<Category> categoryIterator = categoryDao.iterator();
while (categoryIterator.hasNext()) {
Category category = categoryIterator.next();
String tagName = "__UNTAGGED__";
String oId = generateOid();
if (!Strings.isNullOrEmpty(category.getName())) {
tagName = category.getName();
}
categoryOidMap.put(tagName, oId);
outXml.printf("<log type=\"10\" o_id=\"%s\"><name>%s</name></log>\n", oId, AMStringUtils.encodeXML(tagName));
}
// Then cards
Iterator<Card> cardIterator = cardDao.iterator();
while (cardIterator.hasNext()) {
Card card = cardIterator.next();
String front = card.getQuestion();
String back = card.getAnswer();
String oId = generateOid();
cardIdOidMap.put(card.getId(), oId);
outXml.printf("<log type=\"16\" o_id=\"%s\"><b>%s</b><f>%s</f></log>\n", oId, AMStringUtils.encodeXML(back), AMStringUtils.encodeXML(front));
}
// Then learningData
// <log card_t="1" fact_v="1.1" e="2.5" gr="-1" tags="5SfWDFGwqrlnGLDQxHHyG0" rt_rp_l="0" lps="0" l_rp="-1" n_rp="-1" ac_rp_l="0" rt_rp="0" ac_rp="0" type="6" o_id="7IXjCysHuCDtXo8hlFrK55" fact="7xmRCBH0WP0DZaxeFn5NLw"></log>
Iterator<Card> cardIterator2 = cardDao.iterator();
while (cardIterator2.hasNext()) {
Card card = cardIterator2.next();
categoryDao.refresh(card.getCategory());
learningDataDao.refresh(card.getLearningData());
String fact = cardIdOidMap.get(card.getId());
String category = card.getCategory().getName();
if (Strings.isNullOrEmpty(category)) {
category = "__UNTAGGED__";
}
String tags = categoryOidMap.get(category);
String oId = generateOid();
// Needs to converter to unix time
LearningData learningData = card.getLearningData();
long l_rp = learningData.getLastLearnDate().getTime() / 1000;
long n_rp = learningData.getNextLearnDate().getTime() / 1000;
outXml.printf("<log card_t=\"1\" fact_v=\"1.1\" e=\"%f\" gr=\"%d\" tags=\"%s\" rt_rp_l=\"%d\" lps=\"%d\" l_rp=\"%d\" n_rp=\"%d\" ac_rp_l=\"%d\" rt_rp=\"%d\" ac_rp=\"%d\" type=\"6\" o_id=\"%s\" fact=\"%s\"></log>\n", learningData.getEasiness(), learningData.getGrade(), tags, learningData.getRetRepsSinceLapse(), learningData.getLapses(), l_rp, n_rp, learningData.getAcqRepsSinceLapse(), learningData.getRetReps(), learningData.getAcqReps(), oId, fact);
}
outXml.print("</openSM2sync>\n");
} finally {
if (helper != null) {
AnyMemoDBOpenHelperManager.releaseHelper(helper);
}
if (outXml != null) {
outXml.close();
}
}
}
use of org.liberty.android.fantastischmemo.entity.Card in project AnyMemo by helloworld1.
the class Mnemosyne2CardsImporter method convert.
@Override
public void convert(String src, String dest) throws Exception {
// Make the tmp directory tmp/[src file name]/
String srcFilename = FilenameUtils.getName(src);
File tmpDirectory = new File(AMEnv.DEFAULT_TMP_PATH + srcFilename);
FileUtils.deleteDirectory(tmpDirectory);
FileUtils.forceMkdir(tmpDirectory);
AnyMemoDBOpenHelper helper = null;
try {
// First unzip the file since cards is just a zip archive
// Example content of cards
// $ ls
// METADATA cards.xml musicnotes
AMZipUtils.unZipFile(new File(src), tmpDirectory);
// Make sure the XML file exists.
File xmlFile = new File(tmpDirectory + "/cards.xml");
if (!xmlFile.exists()) {
throw new Exception("Could not find the cards.xml after extracting " + src);
}
List<Card> cardList = xmlToCards(xmlFile);
if (!new File(dest).exists()) {
amFileUtil.createDbFileWithDefaultSettings(new File(dest));
}
helper = AnyMemoDBOpenHelperManager.getHelper(dest);
CardDao cardDao = helper.getCardDao();
cardDao.createCards(cardList);
// The last step is to see if there are images to import.
Collection<File> imageFiles = FileUtils.listFiles(tmpDirectory, new SuffixFileFilter(new String[] { "jpg", "png", "bmp" }, IOCase.INSENSITIVE), DirectoryFileFilter.DIRECTORY);
if (!imageFiles.isEmpty()) {
String destDbName = FilenameUtils.getName(dest);
File imageDir = new File(AMEnv.DEFAULT_IMAGE_PATH + destDbName);
FileUtils.forceMkdir(imageDir);
for (File imageFile : imageFiles) {
FileUtils.copyFileToDirectory(imageFile, imageDir);
}
}
} finally {
if (helper != null) {
AnyMemoDBOpenHelperManager.releaseHelper(helper);
}
FileUtils.deleteDirectory(tmpDirectory);
}
}
Aggregations