File tree Expand file tree Collapse file tree 3 files changed +38
-17
lines changed
backend/src/internal/usecase/queries Expand file tree Collapse file tree 3 files changed +38
-17
lines changed Original file line number Diff line number Diff line change @@ -3,16 +3,8 @@ import type { PersistencePort } from '../../core/port/PersistencePort.ts';
33
44export async function getAggregatedProfiles (
55 persistence : PersistencePort ,
6- ) : Promise <
7- {
8- createdAt : string ;
9- emotions : AggregatedEmotionProfile [ 'emotions' ] ;
10- tonalities : AggregatedEmotionProfile [ 'tonalities' ] ;
11- totalWeight : number ;
12- } [ ]
13- > {
6+ ) : Promise < AggregatedEmotionProfile [ ] > {
147 const snapshots = await persistence . getSnapshots ( ) ;
15-
168 return snapshots
179 . filter ( ( s ) => {
1810 const ok = ! ! s . aggregatedEmotionProfile ;
@@ -23,10 +15,5 @@ export async function getAggregatedProfiles(
2315 }
2416 return ok ;
2517 } )
26- . map ( ( s ) => ( {
27- createdAt : s . createdAt ,
28- emotions : s . aggregatedEmotionProfile . emotions ,
29- tonalities : s . aggregatedEmotionProfile . tonalities ,
30- totalWeight : s . aggregatedEmotionProfile . totalWeight ,
31- } ) ) ;
18+ . map ( ( s ) => s . aggregatedEmotionProfile ) ;
3219}
Original file line number Diff line number Diff line change 11import { useEffect , useState } from 'react' ;
2- import { assertRawEntries } from '../../types/Chart.ts' ;
2+ import {
3+ assertRawEntries ,
4+ type AggregatedEmotionProfile ,
5+ } from '../../types/Chart.ts' ;
36import { EMOTION_KEYS , TONALITY_KEYS } from './config.ts' ;
47import {
58 parseEmotions ,
@@ -20,7 +23,12 @@ export function useChartData() {
2023 void ( async ( ) => {
2124 try {
2225 const res = await fetch ( 'chart.json' ) ;
23- const raw : unknown = await res . json ( ) ;
26+ const agg = ( await res . json ( ) ) as AggregatedEmotionProfile [ ] ;
27+ const raw = agg . map ( ( p ) => ( {
28+ createdAt : p . date ,
29+ emotions : p . emotions ,
30+ tonalities : p . tonalities ,
31+ } ) ) ;
2432 assertRawEntries ( raw ) ;
2533 const emotions = parseEmotions ( raw ) ;
2634 const tonalities = parseTonalities ( raw ) ;
Original file line number Diff line number Diff line change @@ -18,3 +18,29 @@ export function assertRawEntries(x: unknown): asserts x is RawEntry[] {
1818 throw new Error ( 'Invalid chart.json shape' ) ;
1919 }
2020}
21+
22+ export interface EmotionScores {
23+ anger : number ;
24+ fear : number ;
25+ trust : number ;
26+ sadness : number ;
27+ joy : number ;
28+ disgust : number ;
29+ }
30+
31+ export interface TonalityScores {
32+ positive : number ;
33+ negative : number ;
34+ optimistic_anticipation : number ;
35+ pessimistic_anticipation : number ;
36+ positive_surprise : number ;
37+ negative_surprise : number ;
38+ }
39+
40+ export interface AggregatedEmotionProfile {
41+ date : string ;
42+ count : number ;
43+ totalWeight : number ;
44+ emotions : EmotionScores ;
45+ tonalities : TonalityScores ;
46+ }
You can’t perform that action at this time.
0 commit comments