David Pomerenke
commited on
Commit
·
f52ec6e
1
Parent(s):
b54f543
Add model history plot
Browse files- frontend/src/App.js +6 -3
- frontend/src/components/HistoryPlot.js +80 -0
- results.json +0 -0
frontend/src/App.js
CHANGED
@@ -8,6 +8,7 @@ import WorldMap from './components/WorldMap'
|
|
8 |
import AutoComplete from './components/AutoComplete'
|
9 |
import LanguagePlot from './components/LanguagePlot'
|
10 |
import SpeakerPlot from './components/SpeakerPlot'
|
|
|
11 |
import { Carousel } from 'primereact/carousel'
|
12 |
|
13 |
function App () {
|
@@ -123,20 +124,22 @@ function App () {
|
|
123 |
flex: '100vw 100vw 100vw',
|
124 |
maxWidth: 'min(100vw, 800px)',
|
125 |
alignItems: 'center',
|
126 |
-
justifyContent: 'center'
|
|
|
127 |
}}
|
128 |
>
|
129 |
<Carousel
|
130 |
value={[
|
131 |
<WorldMap data={data.countries} />,
|
132 |
<LanguagePlot data={data} />,
|
133 |
-
<SpeakerPlot data={data}
|
|
|
134 |
]}
|
135 |
numScroll={1}
|
136 |
numVisible={1}
|
137 |
itemTemplate={item => item}
|
138 |
circular
|
139 |
-
style={{ width: '
|
140 |
/>
|
141 |
</div>
|
142 |
</>
|
|
|
8 |
import AutoComplete from './components/AutoComplete'
|
9 |
import LanguagePlot from './components/LanguagePlot'
|
10 |
import SpeakerPlot from './components/SpeakerPlot'
|
11 |
+
import HistoryPlot from './components/HistoryPlot'
|
12 |
import { Carousel } from 'primereact/carousel'
|
13 |
|
14 |
function App () {
|
|
|
124 |
flex: '100vw 100vw 100vw',
|
125 |
maxWidth: 'min(100vw, 800px)',
|
126 |
alignItems: 'center',
|
127 |
+
justifyContent: 'center',
|
128 |
+
width: '100%'
|
129 |
}}
|
130 |
>
|
131 |
<Carousel
|
132 |
value={[
|
133 |
<WorldMap data={data.countries} />,
|
134 |
<LanguagePlot data={data} />,
|
135 |
+
<SpeakerPlot data={data} />,
|
136 |
+
<HistoryPlot data={data} />,
|
137 |
]}
|
138 |
numScroll={1}
|
139 |
numVisible={1}
|
140 |
itemTemplate={item => item}
|
141 |
circular
|
142 |
+
style={{ width: '100%', minHeight: '650px' }}
|
143 |
/>
|
144 |
</div>
|
145 |
</>
|
frontend/src/components/HistoryPlot.js
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { useRef, useEffect } from 'react'
|
2 |
+
import * as Plot from '@observablehq/plot'
|
3 |
+
|
4 |
+
const HistoryPlot = ({ data }) => {
|
5 |
+
const containerRef = useRef()
|
6 |
+
const models = data.model_table
|
7 |
+
.sort((a, b) => new Date(a.creation_date) - new Date(b.creation_date))
|
8 |
+
.reduce((acc, curr) => {
|
9 |
+
const last = acc[acc.length - 1]?.maxAverage || 0
|
10 |
+
acc.push({
|
11 |
+
...curr,
|
12 |
+
maxAverage: Math.max(last, curr.average),
|
13 |
+
newRecord: curr.average > last
|
14 |
+
})
|
15 |
+
return acc
|
16 |
+
}, [])
|
17 |
+
console.log(models)
|
18 |
+
useEffect(() => {
|
19 |
+
const plot = Plot.plot({
|
20 |
+
width: 750,
|
21 |
+
height: 500,
|
22 |
+
subtitle: 'Model performance over time',
|
23 |
+
x: {
|
24 |
+
label: 'Date',
|
25 |
+
type: 'time',
|
26 |
+
tickFormat: '%Y-%m'
|
27 |
+
},
|
28 |
+
y: {
|
29 |
+
label: 'Language Proficiency Score'
|
30 |
+
},
|
31 |
+
color: {
|
32 |
+
legend: true
|
33 |
+
},
|
34 |
+
marks: [
|
35 |
+
Plot.dot(models, {
|
36 |
+
x: d => d.creation_date,
|
37 |
+
y: d => d.average,
|
38 |
+
fill: d => d.provider_name,
|
39 |
+
title: d =>
|
40 |
+
`${d.provider_name} - ${d.name} (${
|
41 |
+
d.size?.toLocaleString('en-US', { notation: 'compact' }) || '?B'
|
42 |
+
})\nPublished: ${d.creation_date}\nScore: ${d.average.toFixed(2)}`,
|
43 |
+
tip: true
|
44 |
+
}),
|
45 |
+
Plot.line(
|
46 |
+
[
|
47 |
+
...models.filter(d => d.newRecord),
|
48 |
+
{
|
49 |
+
creation_date: new Date(),
|
50 |
+
maxAverage: models[models.length - 1].maxAverage
|
51 |
+
}
|
52 |
+
],
|
53 |
+
{
|
54 |
+
x: d => d.creation_date,
|
55 |
+
y: d => d.maxAverage,
|
56 |
+
curve: 'step-after',
|
57 |
+
strokeOpacity: 0.5
|
58 |
+
}
|
59 |
+
)
|
60 |
+
]
|
61 |
+
})
|
62 |
+
containerRef.current.append(plot)
|
63 |
+
return () => plot.remove()
|
64 |
+
}, [])
|
65 |
+
|
66 |
+
return (
|
67 |
+
<div
|
68 |
+
ref={containerRef}
|
69 |
+
style={{
|
70 |
+
width: '100%',
|
71 |
+
height: '100%',
|
72 |
+
display: 'flex',
|
73 |
+
alignItems: 'center',
|
74 |
+
justifyContent: 'center'
|
75 |
+
}}
|
76 |
+
/>
|
77 |
+
)
|
78 |
+
}
|
79 |
+
|
80 |
+
export default HistoryPlot
|
results.json
CHANGED
The diff for this file is too large to render.
See raw diff
|
|