From 9cf925f0de1fdf874426eee0cb0fadfaec48130c Mon Sep 17 00:00:00 2001 From: ACX <8075870+acx10@users.noreply.github.com> Date: Sun, 1 Mar 2026 00:27:23 -0700 Subject: [PATCH] replace decades covered with golden era, most common year, and rarity score insights (#3139) --- .../publication-timeline-chart.component.html | 22 +++++++--- .../publication-timeline-chart.component.scss | 35 ++++++++++++---- .../publication-timeline-chart.component.ts | 42 +++++++++++++++++-- .../reading-journey-chart.component.scss | 4 +- booklore-ui/src/i18n/en/stats-library.json | 8 +++- booklore-ui/src/i18n/es/stats-library.json | 8 +++- 6 files changed, 96 insertions(+), 23 deletions(-) diff --git a/booklore-ui/src/app/features/stats/component/library-stats/charts/publication-timeline-chart/publication-timeline-chart.component.html b/booklore-ui/src/app/features/stats/component/library-stats/charts/publication-timeline-chart/publication-timeline-chart.component.html index 87ffa186e..fe52b7d31 100644 --- a/booklore-ui/src/app/features/stats/component/library-stats/charts/publication-timeline-chart/publication-timeline-chart.component.html +++ b/booklore-ui/src/app/features/stats/component/library-stats/charts/publication-timeline-chart/publication-timeline-chart.component.html @@ -48,9 +48,15 @@ {{ insights.newestBook.title }} } + +
+ {{ t('insightMostCommonYear') }} + {{ insights.mostCommonYear.year }} + {{ t('insightMostCommonYearBooks', { count: insights.mostCommonYear.count }) }} +
-
+
{{ t('insightTimeSpan') }} {{ insights.timeSpan }} @@ -63,10 +69,16 @@ {{ t('insightPeakDecadeBooks', { count: insights.peakDecadeCount }) }}
-
- {{ t('insightDecadesCovered') }} - {{ insights.decadesCovered }} - {{ t('insightDifferentEras') }} +
+ {{ t('insightGoldenEra') }} + {{ insights.goldenEra.start }}-{{ insights.goldenEra.end }} + {{ t('insightGoldenEraRange', { count: insights.goldenEra.count }) }} +
+ +
+ {{ t('insightRarityScore') }} + {{ insights.rarityScore }}% + {{ t('insightRarePicks') }}
diff --git a/booklore-ui/src/app/features/stats/component/library-stats/charts/publication-timeline-chart/publication-timeline-chart.component.scss b/booklore-ui/src/app/features/stats/component/library-stats/charts/publication-timeline-chart/publication-timeline-chart.component.scss index fc46befcc..cf8e8ee72 100644 --- a/booklore-ui/src/app/features/stats/component/library-stats/charts/publication-timeline-chart/publication-timeline-chart.component.scss +++ b/booklore-ui/src/app/features/stats/component/library-stats/charts/publication-timeline-chart/publication-timeline-chart.component.scss @@ -33,15 +33,12 @@ } .insights-row { - display: flex; - justify-content: space-between; - gap: 1rem; - flex-wrap: wrap; + display: grid; + grid-template-columns: repeat(4, 1fr); + gap: 0.75rem; } .insight-item { - flex: 1; - min-width: 120px; display: flex; flex-direction: column; align-items: center; @@ -105,14 +102,26 @@ } } - &.decades { + &.golden-era { .insight-value { color: #fb923c; } } + + &.common-year { + .insight-value { + color: #34d399; + } + } + + &.rarity { + .insight-value { + color: #f87171; + } + } } -.insights-row.secondary { +.insights-row + .insights-row { margin-top: 0.75rem; } @@ -125,6 +134,11 @@ gap: 0.75rem; } + .insights-row { + grid-template-columns: repeat(4, 1fr); + gap: 0.5rem; + } + .insight-item { padding: 0.6rem; @@ -148,8 +162,11 @@ padding: 0.3rem 0.75rem; } + .insights-row { + grid-template-columns: repeat(2, 1fr); + } + .insight-item { - min-width: 90px; padding: 0.5rem; .insight-value { diff --git a/booklore-ui/src/app/features/stats/component/library-stats/charts/publication-timeline-chart/publication-timeline-chart.component.ts b/booklore-ui/src/app/features/stats/component/library-stats/charts/publication-timeline-chart/publication-timeline-chart.component.ts index f03def95a..6c504140e 100644 --- a/booklore-ui/src/app/features/stats/component/library-stats/charts/publication-timeline-chart/publication-timeline-chart.component.ts +++ b/booklore-ui/src/app/features/stats/component/library-stats/charts/publication-timeline-chart/publication-timeline-chart.component.ts @@ -27,7 +27,9 @@ interface TimelineInsights { peakDecade: string; peakDecadeCount: number; centuryBreakdown: { c21: number; c20: number; older: number }; - decadesCovered: number; + goldenEra: { start: number; end: number; count: number }; + mostCommonYear: { year: number; count: number }; + rarityScore: number; } type TimelineChartData = ChartData<'bar', number[], string>; @@ -338,13 +340,45 @@ export class PublicationTimelineChartComponent implements OnInit, OnDestroy { let peakDecadeCount = 0; for (const [decade, count] of decadeCounts) { if (count > peakDecadeCount) { - peakDecade = decade === 'pre1900' ? 'Pre-1900' : decade.toUpperCase(); + peakDecade = decade === 'pre1900' ? 'Pre-1900' : decade; peakDecadeCount = count; } } const timeSpan = oldest && newest ? newest.year - oldest.year : 0; + // Golden Era: best 20-year window + let goldenEra = {start: 0, end: 0, count: 0}; + if (years.length > 0) { + for (let i = 0; i < years.length; i++) { + const windowStart = years[i]; + const windowEnd = windowStart + 19; + const windowCount = years.filter(y => y >= windowStart && y <= windowEnd).length; + if (windowCount > goldenEra.count) { + goldenEra = {start: windowStart, end: windowEnd, count: windowCount}; + } + } + } + + // Most Common Year + const yearCounts = new Map(); + for (const y of years) { + yearCounts.set(y, (yearCounts.get(y) || 0) + 1); + } + let mostCommonYear = {year: 0, count: 0}; + for (const [y, c] of yearCounts) { + if (c > mostCommonYear.count) { + mostCommonYear = {year: y, count: c}; + } + } + + // Rarity Score: % of books in decades with fewer than 3 books + let rareBooks = 0; + for (const [_, count] of decadeCounts) { + if (count < 3) rareBooks += count; + } + const rarityScore = years.length > 0 ? Math.round((rareBooks / years.length) * 100) : 0; + return { oldestBook: oldest, newestBook: newest, @@ -355,7 +389,9 @@ export class PublicationTimelineChartComponent implements OnInit, OnDestroy { peakDecade, peakDecadeCount, centuryBreakdown: {c21, c20, older}, - decadesCovered: decadeCounts.size + goldenEra, + mostCommonYear, + rarityScore }; } diff --git a/booklore-ui/src/app/features/stats/component/library-stats/charts/reading-journey-chart/reading-journey-chart.component.scss b/booklore-ui/src/app/features/stats/component/library-stats/charts/reading-journey-chart/reading-journey-chart.component.scss index 72221f785..6e9c7e73a 100644 --- a/booklore-ui/src/app/features/stats/component/library-stats/charts/reading-journey-chart/reading-journey-chart.component.scss +++ b/booklore-ui/src/app/features/stats/component/library-stats/charts/reading-journey-chart/reading-journey-chart.component.scss @@ -57,13 +57,13 @@ } .insight-value { - font-size: 1.4rem; + font-size: 1.5rem; font-weight: 600; color: var(--text-color, #ffffff); } .insight-detail { - font-size: 0.7rem; + font-size: 0.75rem; color: var(--text-secondary-color); margin-top: 0.25rem; white-space: nowrap; diff --git a/booklore-ui/src/i18n/en/stats-library.json b/booklore-ui/src/i18n/en/stats-library.json index bf210ee86..d5f4dc4d8 100644 --- a/booklore-ui/src/i18n/en/stats-library.json +++ b/booklore-ui/src/i18n/en/stats-library.json @@ -87,8 +87,12 @@ "insightYearsOfLiterature": "years of literature", "insightPeakDecade": "Peak Decade", "insightPeakDecadeBooks": "{{ count }} books", - "insightDecadesCovered": "Decades Covered", - "insightDifferentEras": "different eras" + "insightGoldenEra": "Golden Era", + "insightGoldenEraRange": "{{ count }} books", + "insightMostCommonYear": "Most Common Year", + "insightMostCommonYearBooks": "{{ count }} books", + "insightRarityScore": "Rarity Score", + "insightRarePicks": "rare picks" }, "publicationTrend": { "title": "Publication Trend", diff --git a/booklore-ui/src/i18n/es/stats-library.json b/booklore-ui/src/i18n/es/stats-library.json index d5d159afc..04a7412b5 100644 --- a/booklore-ui/src/i18n/es/stats-library.json +++ b/booklore-ui/src/i18n/es/stats-library.json @@ -87,8 +87,12 @@ "insightYearsOfLiterature": "anos de literatura", "insightPeakDecade": "Decada pico", "insightPeakDecadeBooks": "{{ count }} libros", - "insightDecadesCovered": "Decadas cubiertas", - "insightDifferentEras": "diferentes epocas" + "insightGoldenEra": "Epoca dorada", + "insightGoldenEraRange": "{{ count }} libros", + "insightMostCommonYear": "Ano mas comun", + "insightMostCommonYearBooks": "{{ count }} libros", + "insightRarityScore": "Puntuacion de rareza", + "insightRarePicks": "selecciones raras" }, "publicationTrend": { "title": "Tendencia de publicacion",