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}`;
}
function makeQuery(
data: HistogramData,
binIdx: number,
): string {
function makeQuery(data: HistogramData, binIdx: number): string {
const start = Math.abs(data.bins[binIdx].x0!) + 1;
const include = `added:${start}`
const include = `"added:${start}"`;
if (start === 1) {
return include
return include;
}
const end = Math.abs(data.bins[binIdx].x1!) + 1;
const exclude = `-added:${end}`
return `${include} ${exclude}`
const exclude = `-"added:${end}"`;
return `${include} AND ${exclude}`;
}
return [
{ scale, bins, total: totalInPeriod, hoverText, makeQuery, colourScale, showArea: true },
{
scale,
bins,
total: totalInPeriod,
hoverText,
makeQuery,
colourScale,
showArea: true,
},
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[] = [
[
i18n.tr(i18n.TR.STATISTICS_COUNTS_NEW_CARDS),
newCards,
true,
`is:new${extraQuery}`,
`"is:new"${extraQuery}`,
],
[
i18n.tr(i18n.TR.STATISTICS_COUNTS_LEARNING_CARDS),
learn,
true,
`(-is:review is:learn)${extraQuery}`,
`(-"is:review" AND "is:learn")${extraQuery}`,
],
[
i18n.tr(i18n.TR.STATISTICS_COUNTS_RELEARNING_CARDS),
relearn,
true,
`(is:review is:learn)${extraQuery}`,
`("is:review" AND "is:learn")${extraQuery}`,
],
[
i18n.tr(i18n.TR.STATISTICS_COUNTS_YOUNG_CARDS),
young,
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),
mature,
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),
suspended,
separateInactive,
"is:suspended",
'"is:suspended"',
],
[
i18n.tr(i18n.TR.STATISTICS_COUNTS_BURIED_CARDS),
buried,
separateInactive,
"is:buried",
'"is:buried"',
],
];

View File

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

View File

@ -25,10 +25,7 @@ export interface HistogramData {
cumulative: number,
percent: number
) => string;
makeQuery?: (
data: HistogramData,
binIdx: number,
) => string;
makeQuery?: (data: HistogramData, binIdx: number) => string;
showArea: boolean;
colourScale: ScaleSequential<string>;
binValue?: (bin: Bin<any, any>) => number;
@ -39,7 +36,7 @@ export function histogramGraph(
svgElem: SVGElement,
bounds: GraphBounds,
data: HistogramData | null,
dispatch: any,
dispatch: any
): void {
const svg = select(svgElem);
const trans = svg.transition().duration(600) as any;
@ -149,7 +146,8 @@ export function histogramGraph(
}
// hover/tooltip
const hoverzone = svg.select("g.hoverzone")
const hoverzone = svg
.select("g.hoverzone")
.selectAll("rect")
.data(data.bins)
.join("rect")
@ -168,7 +166,7 @@ export function histogramGraph(
hoverzone
.attr("class", "clickable")
.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)}%`;
}
function makeQuery(
data: HistogramData,
binIdx: number,
): string {
function makeQuery(data: HistogramData, binIdx: number): string {
const bin = data.bins[binIdx];
const start = bin.x0!;
const end = bin.x1! - 1;
if (start === end) {
return `"prop:ivl=${start}"`
return `"prop:ivl=${start}"`;
}
const fromQuery = `"prop:ivl>=${start}"`
const tillQuery = `"prop:ivl<=${end}"`
const fromQuery = `"prop:ivl>=${start}"`;
const tillQuery = `"prop:ivl<=${end}"`;
return `${fromQuery} AND ${tillQuery}`
return `${fromQuery} AND ${tillQuery}`;
}
const meanInterval = Math.round(mean(allIntervals) ?? 0);
@ -161,7 +158,15 @@ export function prepareIntervalData(
},
];
return [
{ scale, bins, total: totalInPeriod, hoverText, makeQuery, colourScale, showArea: true },
{
scale,
bins,
total: totalInPeriod,
hoverText,
makeQuery,
colourScale,
showArea: true,
},
tableData,
];
}