What we have is one row in the word_schedule table, with the _id of
1098, last review date of 2001-01-01 and a next review date of
2011-07-19. So, when this comes up for test, we will get it wrong.
That should change the next review date - actually, what I need to do
is create a spreadsheet with all the conditions I need to check.
Let's see:
1) last review date null, answer right, slow
2) last review date null, answer right, fast
3) last review date null, answer wrong
4) last review date null, timeout
5) last review date not null, answer right, slow
6) last review date not null, answer right, fast
8) last review date not null, answer wrong
9) last review date not null, timeout
- make sure that a scheduled review date doesn't show up until it's supposed
Ok, if we get those tested, we're off to a pretty good start.
Ok, I set the number of questions in the level to just one, the first, and it is ことor fact, which is the one that came up in the quiz, and I answered wrong.
動物園 or zoo, also came up, which is id 1098, the one I describe above.
I answered both of the incorrectly.
So, now there should be row on the schedule database for each of them. The last review data and the schedule review date should be the same on both of them, today, 2011-07-20. Let's check it out, using adb copy to bring it on board to the macbook for easy inspection by razorSQL.
adb pull sdcard/data/com.kanjisoft.jlpt/jlpt .
Yes, it's exactly right.
That covers these conditions:
3) last review date null, answer wrong
8) last review date not null, answer wrong
Now, we can answer both right, one fast and one slow. This should schedule them both for the future, one more than the other. Actually, I just realized, that if there is a zero difference in the last review date, then the calculation won't work. I want the minium date for the future to be 5 days in advance on a right date, 2 days slow right, and today on a wrong or a timeout.
So, let's tweak the algorithme to check check of the result is less then the minimum, and substitute the minimum if so.
Ok, so, we'll get one fast right, and the other slow right. The corresponding future dates should be 5 and 3 days into the future, respectively. Let's try it.
Rat's. A crash - array out of bounds.
/AndroidRuntime(29559): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
E/AndroidRuntime(29559): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:257)
E/AndroidRuntime(29559): at java.util.ArrayList.get(ArrayList.java:311)
E/AndroidRuntime(29559): at com.jlptquiz.app.QuestionActivity.incrementQuestion(QuestionActivity.java:502)
E/AndroidRuntime(29559): at com.jlptquiz.app.QuestionActivity.onResume(QuestionActivity.java:92)
The code is:
appState.currentQuestion = appState.quizSequence.get(
appState.quizSequenceIndex).intValue();
This might indicate that there are no questions to ask. That does have to be handled, but in this case, there should be two questions which are selected.
Ah, right, it would appear I still haven't completely gotten out of test mode, as the selection data is still hard coded.
ArrayList
jlptLevel, "2011-07-19");
Let's fix that:
String selectionDate = DateUtils.getTodayYYYYMMDD();
ArrayList
jlptLevel, selectionDate);
And try it again:
Well, zoo timed out because my press didn't take, and koto cause a crash. Let's look at logcat.
E/AndroidRuntime(29637): at com.jlptquiz.app.DateUtils.stringToDate(DateUtils.java:29)
E/AndroidRuntime(29637): at com.jlptquiz.app.DateUtils.getDateDiff(DateUtils.java:44)
E/AndroidRuntime(29637): FATAL EXCEPTION: main
E/AndroidRuntime(29637): java.lang.IllegalArgumentException: Unknown pattern character 'Y'
It didn't like my formatting. Ah, java like small y's for years and day: "yyyy-MM-dd"
Ok, good, according to the trace, it was exactly where it should be.
Let's try again.
Ok, another crash.
t com.jlptquiz.app.DateUtils.addDaysToDate(DateUtils.java:82)
/AndroidRuntime(29713): java.lang.IllegalArgumentException: Unknown pattern character 'Y'
E
Right. Same problem, different method.
Ok, the rest of the formattings look ok. It looks like I was slower than I thought - secs remaining was > 5.
Oddly, the start button no longer seems to respond.
Finally, it worked, after multiple trys. That's the first time I've seen that behavior, and it's very troubling. Actually, I noticed a bit of it the last time. There was nothing funny in the log, but I'll take out some debug statement. We'll get back to it.
Oops - the next review date looks a bit funky.
Maybe we need to walk through it in the debugger to see where it's getting messed up. Let's start from the basic data.
Rats. There seems to be a problem in the getDateDiff routine - Calendar's dateBefore(date) is returning true when they're the same. How does that work?
Well, let's keep going.
This one:
String tempScheduledDate = DateUtils.addDaysToDate(DateUtils.getTodayYYYYMMDD(), (int) (1.5 * dateDiff));
Worked fine.
Rats - I blew right past the buggy routine, this one:
public static String addDaysToDate(String inDate, int daysToAdd) {
// convert it to date
Date date1 = stringToDate(inDate);
// convert date to cal
Calendar startDate = Calendar.getInstance();
startDate.set(date1.getYear(), date1.getMonth(), date1.getDay());
Calendar date = (Calendar) startDate.clone();
int cntr = 0;
while (cntr < daysToAdd) {
date.add(Calendar.DAY_OF_MONTH, 1);
cntr++;
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
return formatter.format(date.getTime());
}
Ok, no we're getting aan NPE - on a right answer.
AndroidRuntime(31247): FATAL EXCEPTION: main
E/AndroidRuntime(31247): java.lang.NullPointerException
E/AndroidRuntime(31247): at com.jlptquiz.app.UpdateSRSUtil.getScheduledDate(UpdateSRSUtil.java:70)
And, also, depending on which crash I'm getting:
E/AndroidRuntime(31625): java.lang.IllegalArgumentException
E/AndroidRuntime(31625): at java.text.DateFormat.format(DateFormat.java:365)
E/AndroidRuntime(31625): at java.text.Format.format(Format.java:93)
E/AndroidRuntime(31625): at com.jlptquiz.app.DateUtils.addDaysToDate(DateUtils.java:91)
E/
Ok, to try to get at part 2, I'm going with this:
startDate.set(date1.getYear(), date1.getMonth(), date1.getDay());
Date tempDate = startDate.getTime();
Log.d(TAG, "s>>>>>>>>>>>>>>>>>>>>>> startDate is: " + formatter.format(tempDate));
Because it seem formatter will take a date.
I'm checking for number 1 with this:
if (null == scheduleRow){
Log.d(TAG, ">>>>>>>>>>>>>>>>>>>>>> sceduleRow is null");
}
Ok, the schedule row is null. How could that be?
Here's where it comes from, in question activity:
UpdateSRSUtil.updateSRSschedule(this.mQuestion, this.mMillisUntilFinished, correct, this.mAppState);
All right, due to my probably incorrect decision not include the scheduling data in the question, I will always have this extra wrinkle of checking if the word-schedule row exists, which is the cause of this problem. I had to refactor in the middle of solving a problem though. I like to work from a position of strength, you know?
Ok, and the other problem is this:
Calendar startDate = Calendar.getInstance();
startDate.set(date1.getYear(), date1.getMonth(), date1.getDay());
Date tempDate = startDate.getTime();
Log.d(TAG, "s>>>>>>>>>>>>>>>>>>>>>> startDate is: " + formatter.format(tempDate));
I'm not converting from date to calendar, and it's coming out with funky value.
So, this should help:
startDate.setTime(date1);
Ok, finally, it's not crashing anymore. Let's take a look at how our records look.
Ok, one of them was a day out, and one two days out. The minimum for correct answers is two days out, and I'm thinking of switching it to 3. Let's do this. We'll start out answering getting both questions wrong, giving them an even starting date. The, we'll answer them really fast, and see how far out that put them. It should be 5 days.
Well, the went out 3 days, which makes it look like a slow answer. But, I know what the problem is. I've been looking at millesecs instead of second. I will just divid it rounded by 1000, like so:
UpdateSRSUtil.updateSRSschedule(this.mQuestion,
(this.mMillisUntilFinished / 1000), correct, this.mAppState);
Ok, I'm falling asleep. I'll clean all this up tomorrow!
No comments:
Post a Comment