Skip to content

Commit

Permalink
Merge commit '795ba2a8458700522a4cd73c61af8ae974a9f7f7' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
ahonestla committed Dec 11, 2024
2 parents a003729 + 795ba2a commit c1f5518
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 22 deletions.
8 changes: 8 additions & 0 deletions client/src/api/trends/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const CONFIG = {
"entity-fishing": {
field: "domains.id_name.keyword",
},
"open-alex": {
field: "topics.display_name.keyword",
},
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { postHeaders, publicationsIndex } from "../../../config/api"
import { ElasticAggregation, ElasticBucket, ElasticBuckets } from "../../../types/commons"
import { TrendsArgs } from "../../../types/trends"
import { publicationsTrends, citationsTrends } from "../../trends"
import { FIELDS } from "../_utils/constants"
import { postHeaders, publicationsIndex } from "../../config/api"
import { ElasticAggregation, ElasticBucket, ElasticBuckets } from "../../types/commons"
import { TrendsArgs } from "../../types/trends"
import { FIELDS } from "../publications/_utils/constants"
import { CONFIG } from "./config"
import { citationsTrends, publicationsTrends } from "./trends"

type TrendsAggregation = Array<ElasticBucket & { model: ElasticAggregation }>

Expand All @@ -26,7 +27,7 @@ export async function getPublicationsTrends({ model, query, years, filters, norm
years: {
terms: { field: "year", size: years.length },
aggs: {
model: { terms: { field: `${model}.id_name.keyword`, size: 60000 / years.length } },
model: { terms: { field: CONFIG[model].field, size: 60000 / years.length } },
},
},
},
Expand Down Expand Up @@ -75,7 +76,7 @@ export async function getCitationsTrends({ model, query, years, filters, normali
},
aggs: {
model: {
terms: { field: `${model}.id_name.keyword`, size: 10000 },
terms: { field: CONFIG[model].field, size: 10000 },
aggs: {
...years.reduce(
(acc, year) => (acc = { ...acc, [`citationsIn${year}`]: { sum: { field: `cited_by_counts_by_year.${year}` } } }),
Expand Down Expand Up @@ -110,4 +111,3 @@ export async function getCitationsTrends({ model, query, years, filters, normali
const trends = citationsTrends(aggregation, years, normalized)
return trends
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export function citationsTrends(aggregation: ElasticBuckets, years: Array<number
// Items citations count by year
const _items: Record<string, Record<string, any>> = aggregation.reduce((acc, item) => {
years.forEach((year) => {
const [id, label] = item.key.split("###")
const id = item.key.split("###")[0]
const label = item.key.split("###")?.[1] || id
const citationsCount = item?.[`citationsIn${year}`]?.value
acc[id] = {
...acc?.[id],
Expand All @@ -33,7 +34,8 @@ export function publicationsTrends(aggregation: TrendsAggregation, years: Array<
// Items count by year
const _items: Record<string, Record<string, any>> = aggregation.reduce((acc, bucket) => {
bucket?.model?.buckets.forEach((item) => {
const [id, label] = item.key.split("###")
const id = item.key.split("###")[0]
const label = item.key.split("###")?.[1] || id
acc[id] = {
...acc?.[id],
id: id,
Expand Down
10 changes: 5 additions & 5 deletions client/src/pages/trends/components/select-model/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@ import { useTrendsContext } from "../../context"

export default function TrendsSelectModelModal() {
const intl = useIntl()
const { setModel } = useTrendsContext()
const { model, setModel } = useTrendsContext()
const id = "trends-options-select-model-modal"

return (
<Modal id={id} size="lg" title={intl.formatMessage({ id: "trends.select-model.modal.title" })}>
<Container fluid className="fr-mb-4w">
<Listbox
selectedKeys={["entity-fishing"]}
selectedKeys={[model]}
selectionMode="single"
onSelectionChange={(value) => {
const selected = Object.values(value)[0]
selected && setModel("entity-fishing")
selected && setModel(selected)
// @ts-expect-error dsfr does not have types
window.dsfr(document.getElementById(id)).modal.conceal()
}}
>
<ListboxItem
key={"entity-fishing"}
startContent={<span className={`fr-mr-3v fr-icon--lg fr-icon-book-2-line`} />}
description="Thématiques détectées par entity-fishing"
description={intl.formatMessage({ id: "trends.select-model.entity-fishing.description" })}
>
{intl.formatMessage({ id: "trends.select-model.entity-fishing" })}
</ListboxItem>
<ListboxItem
key={"open-alex"}
startContent={<span className={`fr-mr-3v fr-icon--lg fr-icon-book-2-line`} />}
description="Thématiques détectées par OpenAlex"
description={intl.formatMessage({ id: "trends.select-model.open-alex.description" })}
>
{intl.formatMessage({ id: "trends.select-model.open-alex" })}
</ListboxItem>
Expand Down
4 changes: 2 additions & 2 deletions client/src/pages/trends/components/select-source/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ export default function TrendsSelectSourceModal() {
<ListboxItem
key={"publications"}
startContent={<span className={`fr-mr-3v fr-icon--lg fr-icon-article-line`} />}
description="Nombre de publications"
description={intl.formatMessage({ id: "trends.select-source.publications.description" })}
>
{intl.formatMessage({ id: "trends.select-source.publications" })}
</ListboxItem>
<ListboxItem
key={"citations"}
startContent={<span className={`fr-mr-3v fr-icon--lg fr-icon-chat-3-line`} />}
description="Nombre de citations"
description={intl.formatMessage({ id: "trends.select-source.citations.description" })}
>
{intl.formatMessage({ id: "trends.select-source.citations" })}
</ListboxItem>
Expand Down
8 changes: 4 additions & 4 deletions client/src/pages/trends/hooks/useTrends.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMemo } from "react"
import { useQuery } from "@tanstack/react-query"
import { getCitationsTrends, getPublicationsTrends } from "../../../api/trends/publications"
import { useTrendsContext } from "../context"
import { getPublicationsTrends, getCitationsTrends } from "../../../api/publications/trends"
import useUrl from "../../search/hooks/useUrl"
import { MAX_YEAR, MIN_YEAR } from "../config/years"
import { rangeArray } from "../../../utils/helpers"
Expand All @@ -13,18 +13,18 @@ const API_MAPPING = {

export default function useTrends() {
const { currentQuery, currentFilters, filters } = useUrl()
const { source, normalized } = useTrendsContext()
const { model, source, normalized } = useTrendsContext()

const trendsYears = {
min: Number(currentFilters?.year?.values?.[0]?.value || MIN_YEAR),
max: Number(currentFilters?.year?.values?.[1]?.value || MAX_YEAR),
}

const { data, error, isFetching } = useQuery({
queryKey: ["trends", currentQuery, filters, source, normalized],
queryKey: ["trends", source, model, currentQuery, model, filters, normalized],
queryFn: () =>
API_MAPPING[source]({
model: "domains",
model: model,
query: currentQuery,
years: rangeArray(trendsYears.min, trendsYears.max),
filters: filters,
Expand Down
81 changes: 81 additions & 0 deletions client/src/pages/trends/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"trends.header.breadcrumb.home": "Home",
"trends.header.breadcrumb.analyze": "Analyze Trends",
"trends.header.title": "Explore trends through publication analysis",
"trends.trending": "Trending",
"trends.fading": "Declining",
"trends.stable": "Stable",
"trends.search-bar.button.label.anything": "Anything",
"trends.search-bar.modal.title": "Search",
"trends.select-model.modal.title": "Themes",
"trends.select-source.modal.title": "Source",
"trends.filters.button.label": "Filters",
"trends.parameters.button.label": "Parameters",
"trends.parameters.modal.title": "Parameters",
"trends.parameters.modal.display": "Display Trends",
"trends.parameters.modal.reset": "Reset Parameters",
"trends.search-bar.button-label": "Search",
"trends.search-bar.label": "Search",
"trends.search-bar.label-graph": "Start exploring research and innovation networks",
"trends.search-bar.placeholder": "\"one health\" OR \"global health\"",
"trends.select-model.label": "Themes",
"trends.select-model.entity-fishing.description": "Themes detected by entity-fishing",
"trends.select-model.open-alex": "OpenAlex",
"trends.select-model.open-alex.description": "Themes detected by OpenAlex",
"trends.select-source.label": "Volume",
"trends.select-source.publications": "Publications",
"trends.select-source.publications.description": "Number of publications",
"trends.select-source.citations": "Citations",
"trends.select-source.citations.description": "Number of citations",
"trends.views.header.domains": "Themes",
"trends.views.header.count": "Volume ({max})",
"trends.views.header.diff": "Variation (1 year)",
"trends.views.header.trend": "Trend ({count} years)",
"trends.line-chart.xAxis.accessibility.description": "Years from {min, number} to {max, number}",
"trends.line-chart.yAxis.accessibility.description": "Number of {source}",
"trends.line-chart.yAxis.title.text": "Number of {source}",
"trends.line-chart.series.regression.name": "Trend Curve",
"trends.line-chart.title": "Temporal Evolution for ''{label}''",
"trends.line-chart.description.publications": "Number of publications per year where ''{label}'' was detected",
"trends.line-chart.description.citations": "Number of citations of publications per year where ''{label}'' was detected",
"trends.parameters.title": "Advanced Parameters",
"trends.parameters.toggle-normalize.label": "Normalization",
"trends.parameters.toggle-normalize.hint": "Normalizes trends relative to their total volume",
"trends.filters-button-label": "Filter",
"trends.filters.add": "Add Filters",
"trends.filters.clear": "Reset Filters",
"trends.filters.current.no-filter": "No active filters",
"trends.filters.current.publications.affiliations.id": "Affiliations",
"trends.filters.current.publications.affiliations.country": "Country",
"trends.filters.current.publications.authors.person": "Authors",
"trends.filters.current.publications.type": "Publication Type",
"trends.filters.current.publications.year": "Publication Years",
"trends.filters.current.publications.projects.type": "Funding Type",
"trends.filters.current.publications.tags.id": "Tags",
"trends.filters.display": "Display Results",
"trends.filters.title": "Filters",
"trends.filters.active-filter-title": "Active Filters",
"trends.filters.active-filter-empty": "No active filters",
"trends.filters.modal.publications.title": "Filter Publications",
"trends.filters.modal.display": "Display Trends",
"trends.filters.modal.clear": "Reset Filters",
"search.filters.selected": "Selected",
"search.filters.publications.by-year": "Filter by Year",
"search.filters.publications.by-year-description": "Selected period {min} - {max}",
"search.filters.publications.by-year-tooltip": "Publications in {year}",
"search.filters.publications.by-project": "Filter by Funding Types",
"search.filters.publications.by-project-description": "Select one or more funding types",
"search.filters.publications.by-type": "Filter by Publication Type",
"search.filters.publications.by-type-description": "Select one or more publication types",
"search.filters.publications.filters-modal-title": "Filters",
"search.filters.publications.by-author": "Filter by Author",
"search.filters.publications.by-author-description": "Select one or more authors",
"search.filters.publications.by-is-oa": "Open Access",
"search.filters.publications.by-is-oa-label": "Show only open access publications",
"search.filters.publications.by-organization": "Filter by Affiliation",
"search.filters.publications.by-organization-description": "Select one or more affiliations",
"search.filters.publications.by-country": "Filter by Country",
"search.filters.publications.by-country-description": "Select one or more countries",
"search.filters.publications.by-tag": "Filter by Tag",
"search.filters.publications.by-tag-description": "Select one or more tags"
}
5 changes: 4 additions & 1 deletion client/src/pages/trends/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
"trends.search-bar.placeholder": "\"one health\" OR \"santé mondiale\"",
"trends.select-model.label": "Thématiques",
"trends.select-model.entity-fishing": "Wikidata",
"trends.select-model.entity-fishing.description": "Thématiques détectées par entity-fishing",
"trends.select-model.open-alex": "OpenAlex",
"trends.select-model.open-alex.description": "Thématiques détectées par OpenAlex",
"trends.select-source.label": "Volume",
"trends.select-source.publications": "Publications",
"trends.select-source.publications.description": "Nombre de publications",
"trends.select-source.citations": "Citations",
"trends.select-source.citations.description": "Nombre de citations",
"trends.views.header.domains": "Thématiques",
"trends.views.header.authors": "Auteurs",
"trends.views.header.count": "Volume ({max})",
"trends.views.header.diff": "Variation (1 an)",
"trends.views.header.trend": "Tendance ({count} ans)",
Expand Down

0 comments on commit c1f5518

Please sign in to comment.