From 0e98bd7db2d558b087994430ce7c6bd3cc2807e9 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Fri, 8 Jan 2021 14:28:38 +0100 Subject: [PATCH] Normalize the remaining queries --- ts/graphs/added.ts | 23 ++++++++++++++--------- ts/graphs/card-counts.ts | 16 ++++++++-------- ts/graphs/future-due.ts | 13 +++++-------- ts/graphs/histogram-graph.ts | 12 +++++------- ts/graphs/intervals.ts | 23 ++++++++++++++--------- 5 files changed, 46 insertions(+), 41 deletions(-) diff --git a/ts/graphs/added.ts b/ts/graphs/added.ts index 0e9b8f2fe..c22ea73a7 100644 --- a/ts/graphs/added.ts +++ b/ts/graphs/added.ts @@ -102,24 +102,29 @@ export function buildHistogram( return `${day}:
${cards}
${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, ]; } diff --git a/ts/graphs/card-counts.ts b/ts/graphs/card-counts.ts index 12b0b7799..0eb2fba8f 100644 --- a/ts/graphs/card-counts.ts +++ b/ts/graphs/card-counts.ts @@ -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"', ], ]; diff --git a/ts/graphs/future-due.ts b/ts/graphs/future-due.ts index 085a987e6..d1f09018e 100644 --- a/ts/graphs/future-due.ts +++ b/ts/graphs/future-due.ts @@ -145,22 +145,19 @@ export function buildHistogram( return `${days}:
${cards}
${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!; diff --git a/ts/graphs/histogram-graph.ts b/ts/graphs/histogram-graph.ts index 8a4b90d90..93f5ddad9 100644 --- a/ts/graphs/histogram-graph.ts +++ b/ts/graphs/histogram-graph.ts @@ -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; binValue?: (bin: Bin) => 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) }); }); } } diff --git a/ts/graphs/intervals.ts b/ts/graphs/intervals.ts index 4ef512fae..b31f88def 100644 --- a/ts/graphs/intervals.ts +++ b/ts/graphs/intervals.ts @@ -134,22 +134,19 @@ export function prepareIntervalData( return `${interval}
${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, ]; }