Yes, please: rw at pobox.com.
The code throwing the error is this:
// calculate duration of reviews by peeking at next in sequence
// (duration is review-start to review-start)
// NOTE: doesn't change duration of final review in array
const calculateDuration = (r: Review, i: number, array: Review[]): Review => {
if (array[i + 1]) {
const nextms = array[i + 1].started.getTime();
const thisms = r.started.getTime();
if (nextms < thisms) {
throw "Reviews not in sequential creation order!";
}
return { ...r, duration: nextms - thisms };
} else {
return r; // final review unchanged
}
};
I’m not sure what undefined value I’m trying to filter, though. Will continue poking.
EDIT:
It’s from the section where I parse recent reviews. There must be something interesting with your data (thanks for the API key, that will help me to track it down). I suspect that it’s a level-60 thing! <laugh>
FWIW, I think it’s the first line of this section of code where I calculate the counts each day:
export const calculateCounts = (reviews: Review[]): ReviewCount[] => {
const reviewsEachDay: Review[][] = reviews
// first filter to one review per unique day
.filter((r, i) =>
i > 0 ? !inSameDay(r.started, reviews[i - 1].started) : true
)
// convert those reviews to just a date
.map((r) => r.started)
// finally, convert those dates to array of reviews on that date
.map((date) => reviews.filter((r) => inSameDay(r.started, date)));
let counts: ReviewCount[] = [];
reviewsEachDay.forEach((reviewAry, i) => {
const readingCorrect = reviewAry
.filter((r) => r.reading_incorrect === 0)
.reduce((acc, r) => (acc += 1), 0);
const meaningCorrect = reviewAry
.filter((r) => r.meaning_incorrect === 0)
.reduce((acc, r) => (acc += 1), 0);
const bothCorrect = reviewAry
.filter((r) => r.meaning_incorrect + r.reading_incorrect === 0)
.reduce((acc, r) => (acc += 1), 0);
const questionCount = reviewAry.reduce((acc, r) => (acc += r.questions), 0);
const itemCount = reviewAry.length;
const count: ReviewCount = {
start: reviewAry[0].started,
end: reviewAry[reviewAry.length - 1].started,
review_count: reviewAry.length,
question_count: questionCount,
accuracy: bothCorrect / itemCount,
reading_accuracy: readingCorrect / itemCount,
meaning_accuracy: meaningCorrect / itemCount,
};
counts.push(count);
});
return counts;
};




