mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
fix stats calendar incorrect due to daylight savings time (#2456)
* fix stats calendar daylight saving time offset bug Previously, when computing counts for the calendar in the stats menu, it was assumed that days had 86,400 seconds. However, this assumption does not hold true on the day when daylight savings occurs. * add self to CONTRIBUTORS and about.py * fix stats calendar anki day to calendar day mapping Since Anki days don't necessarily roll over at midnight, mapping an Anki day into a calendar day needs to have a linear shift applied. By providing the frontend with access to the scheduler's rollover hour, we can account for this offset.
This commit is contained in:
parent
0e0436f850
commit
fe591f6be7
5 changed files with 12 additions and 4 deletions
|
@ -118,6 +118,7 @@ yellowjello <github.com/yellowjello>
|
|||
Ingemar Berg <github.com/ingemarberg>
|
||||
Ben Kerman <ben@kermanic.org>
|
||||
Euan Kemp <euank@euank.com>
|
||||
Kieran Black <kieranlblack@gmail.com>
|
||||
|
||||
********************
|
||||
|
||||
|
|
|
@ -141,6 +141,7 @@ message GraphsResponse {
|
|||
FutureDue future_due = 7;
|
||||
Added added = 8;
|
||||
ReviewCountsAndTimes reviews = 9;
|
||||
uint32 rollover_hour = 10;
|
||||
}
|
||||
|
||||
message GraphPreferences {
|
||||
|
|
|
@ -230,6 +230,7 @@ def show(mw: aqt.AnkiQt) -> QDialog:
|
|||
"hafatsat anki",
|
||||
"Carlos Duarte",
|
||||
"Edgar Benavent Català",
|
||||
"Kieran Black",
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -71,6 +71,7 @@ impl Collection {
|
|||
hours: Some(ctx.hours()),
|
||||
buttons: Some(ctx.buttons()),
|
||||
card_counts: Some(ctx.card_counts()),
|
||||
rollover_hour: self.rollover_for_current_scheduler()? as u32,
|
||||
};
|
||||
Ok(resp)
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import * as tr from "@tslib/ftl";
|
|||
import { localizedDate, weekdayLabel } from "@tslib/i18n";
|
||||
import { Stats } from "@tslib/proto";
|
||||
import type { CountableTimeInterval } from "d3";
|
||||
import { timeHour } from "d3";
|
||||
import {
|
||||
interpolateBlues,
|
||||
pointer,
|
||||
|
@ -29,6 +30,7 @@ export interface GraphData {
|
|||
reviewCount: Map<number, number>;
|
||||
timeFunction: CountableTimeInterval;
|
||||
weekdayLabels: number[];
|
||||
rolloverHour: number;
|
||||
}
|
||||
|
||||
interface DayDatum {
|
||||
|
@ -59,7 +61,7 @@ export function gatherData(
|
|||
weekdayLabels.push((firstDayOfWeek + i) % 7);
|
||||
}
|
||||
|
||||
return { reviewCount, timeFunction, weekdayLabels };
|
||||
return { reviewCount, timeFunction, weekdayLabels, rolloverHour: data.rolloverHour };
|
||||
}
|
||||
|
||||
export function renderCalendar(
|
||||
|
@ -85,7 +87,9 @@ export function renderCalendar(
|
|||
const dayMap: Map<number, DayDatum> = new Map();
|
||||
let maxCount = 0;
|
||||
for (const [day, count] of sourceData.reviewCount.entries()) {
|
||||
const date = new Date(now.getTime() + day * 86400 * 1000);
|
||||
let date = timeDay.offset(now, day);
|
||||
// anki day does not necessarily roll over at midnight, we account for this when mapping onto calendar days
|
||||
date = timeHour.offset(date, -1 * sourceData.rolloverHour);
|
||||
if (count > maxCount) {
|
||||
maxCount = count;
|
||||
}
|
||||
|
@ -105,12 +109,12 @@ export function renderCalendar(
|
|||
setDataAvailable(svg, true);
|
||||
}
|
||||
|
||||
// fill in any blanks
|
||||
// fill in any blanks, including the current calendar day even if the anki day has not rolled over
|
||||
const startDate = timeYear(nowForYear);
|
||||
const oneYearAgoFromNow = new Date(now);
|
||||
oneYearAgoFromNow.setFullYear(now.getFullYear() - 1);
|
||||
for (let i = 0; i < 365; i++) {
|
||||
const date = new Date(startDate.getTime() + i * 86400 * 1000);
|
||||
const date = timeDay.offset(startDate, i);
|
||||
if (date > now) {
|
||||
// don't fill out future dates
|
||||
continue;
|
||||
|
|
Loading…
Reference in a new issue