Commit 513fa821 authored by Emmanuel Raviart's avatar Emmanuel Raviart
Browse files

Search View & API: Add years max facets.

parent fb92ac75
......@@ -2,6 +2,7 @@
import RangeSlider from "svelte-range-slider-pips"
export let countByYear: { [year: string]: number } | undefined = undefined
export let maxYearsCount: number | undefined = undefined
let dataViz: { x: number; y: number; year: number }[] = []
const interval = 5
......@@ -28,11 +29,12 @@
<!-- Vertical bars with formula -->
<svg
class="h-3/5 w-full"
viewBox="0 0 {(maxYear + 1 - minYear) * interval} 100"
preserveAspectRatio="none"
viewBox="0 0 {(maxYear + 1 - minYear) * interval} {maxYearsCount ?? 100}"
>
{#each dataViz as xy}
<!-- Attention: Si la valeur de y2 est < 3, (mais pas zero), on la met à 3 pour mieux voir -->
<!-- Si non, le code classique pour calculer y2 serait : y2={100 - xy["y"]} -->
<!-- Si non, le code classique pour calculer y2 serait : y2={maxYearsCount - xy["y"]} -->
<line
class={xy.year >= yearsRange[0] && xy.year <= yearsRange[1]
? "text-gray-400"
......@@ -41,9 +43,12 @@
stroke-width={interval - 1}
title={xy.year}
x1={xy["x"]}
y1="100"
y1={maxYearsCount ?? 100}
x2={xy["x"]}
y2={100 - (xy["y"] === 0 ? 0 : Math.max(xy["y"], 3))}
y2={(maxYearsCount ?? 100) -
(xy["y"] === 0
? 0
: Math.max(xy["y"], (3 * (maxYearsCount ?? 100)) / 100))}
/>
{/each}
</svg>
......
......@@ -14,7 +14,9 @@ export enum Facet {
Series_producers = "Series.producers",
Series_topics = "Series.topics",
Series_years = "Series.years",
Series_years_count_max = "Series.years_count_max",
Studies = "studies",
Studies_years_count_max = "Studies.years_count_max",
Study_data_kinds = "Study.data_kinds",
Study_depositors = "Study.depositors",
Study_distributors = "Study.distributors",
......@@ -30,6 +32,7 @@ export enum Facet {
Variable_topics = "Variable.topics",
Variable_years = "Variable.years",
Variables = "variables",
Variables_years_count_max = "Variables.years_count_max",
}
export const allFacets = Object.values(Facet)
......
......@@ -149,6 +149,7 @@
studies?: number
terms?: { [relation: string]: { [label: string]: number } }
variables?: number
yearsMax?: number
} = {}
let expandedByRelation: { [relation: string]: boolean } = {}
const { page, session } = stores()
......@@ -237,6 +238,7 @@
Facet.Series_producers,
Facet.Series_topics,
Facet.Series_years,
Facet.Series_years_count_max,
Facet.Studies,
Facet.Variables,
]
......@@ -244,6 +246,7 @@
return [
Facet.Series,
Facet.Studies,
Facet.Studies_years_count_max,
Facet.Study_data_kinds,
// Facet.Study_depositors,
Facet.Study_distributors,
......@@ -265,6 +268,7 @@
Facet.Variable_topics,
Facet.Variable_years,
Facet.Variables,
Facet.Variables_years_count_max,
]
default:
assertNeverSearchResultType(type)
......@@ -365,7 +369,10 @@
<div class="mb-1 py-2 px-2 content-center h-40 w-1/3 bg-gray-100">
<!-- the left element with image -->
<div class="flex">
<YearsSlider countByYear={counts.terms?.year} />
<YearsSlider
countByYear={counts.terms?.year}
maxYearsCount={counts.yearsMax}
/>
</div>
</div>
......
......@@ -140,6 +140,12 @@ facetsWebSocketServer.on("connection", async (webSocket, request) => {
seriesTermRelations,
)
: null,
facets.has(Facet.Series_years_count_max)
? sendSeriesYearsCountMax(
webSocket,
query as ValidWebSocketsFacetsQuery,
)
: null,
facets.has(Facet.Studies)
? sendStudiesCount(webSocket, query as ValidWebSocketsFacetsQuery)
......@@ -158,6 +164,12 @@ facetsWebSocketServer.on("connection", async (webSocket, request) => {
studyTermRelations,
)
: null,
facets.has(Facet.Studies_years_count_max)
? sendStudiesYearsCountMax(
webSocket,
query as ValidWebSocketsFacetsQuery,
)
: null,
facets.has(Facet.Variables)
? sendVariablesCount(webSocket, query as ValidWebSocketsFacetsQuery)
......@@ -176,6 +188,12 @@ facetsWebSocketServer.on("connection", async (webSocket, request) => {
variableTermRelations,
)
: null,
facets.has(Facet.Variables_years_count_max)
? sendVariablesYearsCountMax(
webSocket,
query as ValidWebSocketsFacetsQuery,
)
: null,
].filter(Boolean),
)
......@@ -426,6 +444,33 @@ async function sendSeriesTermsCount(
webSocket.send(JSON.stringify({ terms: counts }))
}
async function sendSeriesYearsCountMax(
webSocket: WebSocket,
query: ValidWebSocketsFacetsQuery,
) {
const { language } = query
const { max } = await db.one(
dedent`
SELECT max(count) as max
FROM (
SELECT count(*) as count
FROM series_term_associations
WHERE
language = $<language>
AND relation = 'year'
GROUP BY term_label
) as series_count_by_year
`,
{ language },
)
webSocket.send(
JSON.stringify({
yearsMax: parseInt(max),
}),
)
}
async function sendStudiesCount(
webSocket: WebSocket,
query: ValidWebSocketsFacetsQuery,
......@@ -593,6 +638,33 @@ async function sendStudiesTermsCount(
webSocket.send(JSON.stringify({ terms: counts }))
}
async function sendStudiesYearsCountMax(
webSocket: WebSocket,
query: ValidWebSocketsFacetsQuery,
) {
const { language } = query
const { max } = await db.one(
dedent`
SELECT max(count) as max
FROM (
SELECT count(*) as count
FROM study_term_associations
WHERE
language = $<language>
AND relation = 'year'
GROUP BY term_label
) as study_count_by_year
`,
{ language },
)
webSocket.send(
JSON.stringify({
yearsMax: parseInt(max),
}),
)
}
async function sendVariablesCount(
webSocket: WebSocket,
query: ValidWebSocketsFacetsQuery,
......@@ -763,3 +835,32 @@ async function sendVariablesTermsCount(
webSocket.send(JSON.stringify({ terms: counts }))
}
async function sendVariablesYearsCountMax(
webSocket: WebSocket,
query: ValidWebSocketsFacetsQuery,
) {
const { language } = query
const { max } = await db.one(
dedent`
SELECT max(count) as max
FROM (
SELECT count(*) as count
FROM variables
INNER JOIN study_term_associations
ON variables.study_path = study_term_associations.study_path
WHERE
language = $<language>
AND relation = 'year'
GROUP BY term_label
) as variable_count_by_year
`,
{ language },
)
webSocket.send(
JSON.stringify({
yearsMax: parseInt(max),
}),
)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment