Normalize the remaining queries

This commit is contained in:
Henrik Giesel 2021-01-08 14:28:38 +01:00
parent fd58f73f13
commit 0e98bd7db2
5 changed files with 46 additions and 41 deletions

View File

@ -102,24 +102,29 @@ export function buildHistogram(
return `${day}:<br>${cards}<br>${total}: ${totalCards}`; return `${day}:<br>${cards}<br>${total}: ${totalCards}`;
} }
function makeQuery( function makeQuery(data: HistogramData, binIdx: number): string {
data: HistogramData,
binIdx: number,
): string {
const start = Math.abs(data.bins[binIdx].x0!) + 1; const start = Math.abs(data.bins[binIdx].x0!) + 1;
const include = `added:${start}` const include = `"added:${start}"`;
if (start === 1) { if (start === 1) {
return include return include;
} }
const end = Math.abs(data.bins[binIdx].x1!) + 1; const end = Math.abs(data.bins[binIdx].x1!) + 1;
const exclude = `-added:${end}` const exclude = `-"added:${end}"`;
return `${include} ${exclude}` return `${include} AND ${exclude}`;
} }
return [ return [
{ scale, bins, total: totalInPeriod, hoverText, makeQuery, colourScale, showArea: true }, {
scale,
bins,
total: totalInPeriod,
hoverText,
makeQuery,
colourScale,
showArea: true,
},
tableData, tableData,
]; ];
} }

View File

@ -86,50 +86,50 @@ function countCards(
} }
} }
const extraQuery = separateInactive ? " -(is:buried or is:suspended)" : ""; const extraQuery = separateInactive ? 'AND -("is:buried" OR "is:suspended")' : "";
const counts: Count[] = [ const counts: Count[] = [
[ [
i18n.tr(i18n.TR.STATISTICS_COUNTS_NEW_CARDS), i18n.tr(i18n.TR.STATISTICS_COUNTS_NEW_CARDS),
newCards, newCards,
true, true,
`is:new${extraQuery}`, `"is:new"${extraQuery}`,
], ],
[ [
i18n.tr(i18n.TR.STATISTICS_COUNTS_LEARNING_CARDS), i18n.tr(i18n.TR.STATISTICS_COUNTS_LEARNING_CARDS),
learn, learn,
true, true,
`(-is:review is:learn)${extraQuery}`, `(-"is:review" AND "is:learn")${extraQuery}`,
], ],
[ [
i18n.tr(i18n.TR.STATISTICS_COUNTS_RELEARNING_CARDS), i18n.tr(i18n.TR.STATISTICS_COUNTS_RELEARNING_CARDS),
relearn, relearn,
true, true,
`(is:review is:learn)${extraQuery}`, `("is:review" AND "is:learn")${extraQuery}`,
], ],
[ [
i18n.tr(i18n.TR.STATISTICS_COUNTS_YOUNG_CARDS), i18n.tr(i18n.TR.STATISTICS_COUNTS_YOUNG_CARDS),
young, young,
true, true,
`(is:review -is:learn) prop:ivl<21${extraQuery}`, `("is:review" AND -"is:learn") AND "prop:ivl<21"${extraQuery}`,
], ],
[ [
i18n.tr(i18n.TR.STATISTICS_COUNTS_MATURE_CARDS), i18n.tr(i18n.TR.STATISTICS_COUNTS_MATURE_CARDS),
mature, mature,
true, true,
`(is:review -is:learn) prop:ivl>=21${extraQuery}`, `("is:review" -"is:learn") AND "prop:ivl>=21"${extraQuery}`,
], ],
[ [
i18n.tr(i18n.TR.STATISTICS_COUNTS_SUSPENDED_CARDS), i18n.tr(i18n.TR.STATISTICS_COUNTS_SUSPENDED_CARDS),
suspended, suspended,
separateInactive, separateInactive,
"is:suspended", '"is:suspended"',
], ],
[ [
i18n.tr(i18n.TR.STATISTICS_COUNTS_BURIED_CARDS), i18n.tr(i18n.TR.STATISTICS_COUNTS_BURIED_CARDS),
buried, buried,
separateInactive, separateInactive,
"is:buried", '"is:buried"',
], ],
]; ];

View File

@ -145,22 +145,19 @@ export function buildHistogram(
return `${days}:<br>${cards}<br>${totalLabel}: ${cumulative}`; return `${days}:<br>${cards}<br>${totalLabel}: ${cumulative}`;
} }
function makeQuery( function makeQuery(data: HistogramData, binIdx: number): string {
data: HistogramData,
binIdx: number,
): string {
const bin = data.bins[binIdx]; const bin = data.bins[binIdx];
const start = bin.x0!; const start = bin.x0!;
const end = bin.x1! - 1; const end = bin.x1! - 1;
if (start === end) { if (start === end) {
return `"prop:due=${start}"` return `"prop:due=${start}"`;
} }
const fromQuery = `"prop:due>=${start}"` const fromQuery = `"prop:due>=${start}"`;
const tillQuery = `"prop:due<=${end}"` const tillQuery = `"prop:due<=${end}"`;
return `${fromQuery} AND ${tillQuery}` return `${fromQuery} AND ${tillQuery}`;
} }
const periodDays = xMax! - xMin!; const periodDays = xMax! - xMin!;

View File

@ -25,10 +25,7 @@ export interface HistogramData {
cumulative: number, cumulative: number,
percent: number percent: number
) => string; ) => string;
makeQuery?: ( makeQuery?: (data: HistogramData, binIdx: number) => string;
data: HistogramData,
binIdx: number,
) => string;
showArea: boolean; showArea: boolean;
colourScale: ScaleSequential<string>; colourScale: ScaleSequential<string>;
binValue?: (bin: Bin<any, any>) => number; binValue?: (bin: Bin<any, any>) => number;
@ -39,7 +36,7 @@ export function histogramGraph(
svgElem: SVGElement, svgElem: SVGElement,
bounds: GraphBounds, bounds: GraphBounds,
data: HistogramData | null, data: HistogramData | null,
dispatch: any, dispatch: any
): void { ): void {
const svg = select(svgElem); const svg = select(svgElem);
const trans = svg.transition().duration(600) as any; const trans = svg.transition().duration(600) as any;
@ -149,7 +146,8 @@ export function histogramGraph(
} }
// hover/tooltip // hover/tooltip
const hoverzone = svg.select("g.hoverzone") const hoverzone = svg
.select("g.hoverzone")
.selectAll("rect") .selectAll("rect")
.data(data.bins) .data(data.bins)
.join("rect") .join("rect")
@ -168,7 +166,7 @@ export function histogramGraph(
hoverzone hoverzone
.attr("class", "clickable") .attr("class", "clickable")
.on("click", function (this: any, _d: any, idx: number) { .on("click", function (this: any, _d: any, idx: number) {
dispatch("search", { query: data.makeQuery!(data, idx) }) dispatch("search", { query: data.makeQuery!(data, idx) });
}); });
} }
} }

View File

@ -134,22 +134,19 @@ export function prepareIntervalData(
return `${interval}<br>${total}: \u200e${percent.toFixed(1)}%`; return `${interval}<br>${total}: \u200e${percent.toFixed(1)}%`;
} }
function makeQuery( function makeQuery(data: HistogramData, binIdx: number): string {
data: HistogramData,
binIdx: number,
): string {
const bin = data.bins[binIdx]; const bin = data.bins[binIdx];
const start = bin.x0!; const start = bin.x0!;
const end = bin.x1! - 1; const end = bin.x1! - 1;
if (start === end) { if (start === end) {
return `"prop:ivl=${start}"` return `"prop:ivl=${start}"`;
} }
const fromQuery = `"prop:ivl>=${start}"` const fromQuery = `"prop:ivl>=${start}"`;
const tillQuery = `"prop:ivl<=${end}"` const tillQuery = `"prop:ivl<=${end}"`;
return `${fromQuery} AND ${tillQuery}` return `${fromQuery} AND ${tillQuery}`;
} }
const meanInterval = Math.round(mean(allIntervals) ?? 0); const meanInterval = Math.round(mean(allIntervals) ?? 0);
@ -161,7 +158,15 @@ export function prepareIntervalData(
}, },
]; ];
return [ return [
{ scale, bins, total: totalInPeriod, hoverText, makeQuery, colourScale, showArea: true }, {
scale,
bins,
total: totalInPeriod,
hoverText,
makeQuery,
colourScale,
showArea: true,
},
tableData, tableData,
]; ];
} }