David Pomerenke commited on
Commit
92d8154
·
1 Parent(s): 73c776c

Fix world map and apply filters for it

Browse files
evals/backend.py CHANGED
@@ -104,11 +104,11 @@ async def data(request: Request):
104
  # lang_results = pd.merge(languages, lang_results, on="bcp_47", how="outer")
105
  language_table = make_language_table(df, languages)
106
  datasets_df = pd.read_json("data/datasets.json")
107
- countries = make_country_table(language_table)
108
  if selected_languages:
109
- # the filtering is only applied for the model table
110
  df = df[df["bcp_47"].isin(lang["bcp_47"] for lang in selected_languages)]
111
  model_table = make_model_table(df, models)
 
112
  all_tables = {
113
  "model_table": serialize(model_table),
114
  "language_table": serialize(language_table),
 
104
  # lang_results = pd.merge(languages, lang_results, on="bcp_47", how="outer")
105
  language_table = make_language_table(df, languages)
106
  datasets_df = pd.read_json("data/datasets.json")
 
107
  if selected_languages:
108
+ # the filtering is only applied for the model table and the country data
109
  df = df[df["bcp_47"].isin(lang["bcp_47"] for lang in selected_languages)]
110
  model_table = make_model_table(df, models)
111
+ countries = make_country_table(make_language_table(df, languages))
112
  all_tables = {
113
  "model_table": serialize(model_table),
114
  "language_table": serialize(language_table),
frontend/src/App.js CHANGED
@@ -125,7 +125,7 @@ function App () {
125
  >
126
  <Carousel
127
  value={[
128
- <WorldMap data={data} />,
129
  <LanguagePlot data={data} />
130
  ]}
131
  numScroll={1}
 
125
  >
126
  <Carousel
127
  value={[
128
+ <WorldMap data={data.countries} />,
129
  <LanguagePlot data={data} />
130
  ]}
131
  numScroll={1}
frontend/src/components/LanguageTable.js CHANGED
@@ -134,7 +134,7 @@ const LanguageTable = ({ data, selectedLanguages, setSelectedLanguages }) => {
134
  selection={selectedLanguages}
135
  onSelectionChange={e => setSelectedLanguages(e.value)}
136
  frozenValue={selectedLanguages}
137
- virtualScrollerOptions={{ itemSize: 50 }}
138
  scrollable
139
  scrollHeight='600px'
140
  id='language-table'
@@ -145,7 +145,7 @@ const LanguageTable = ({ data, selectedLanguages, setSelectedLanguages }) => {
145
  field='language_name'
146
  header='Language'
147
  body={languageBodyTemplate}
148
- style={{ minWidth: '5rem' }}
149
  frozen
150
  />
151
  <Column
 
134
  selection={selectedLanguages}
135
  onSelectionChange={e => setSelectedLanguages(e.value)}
136
  frozenValue={selectedLanguages}
137
+ virtualScrollerOptions={{ itemSize: 100 }}
138
  scrollable
139
  scrollHeight='600px'
140
  id='language-table'
 
145
  field='language_name'
146
  header='Language'
147
  body={languageBodyTemplate}
148
+ style={{ minWidth: '10rem' }}
149
  frozen
150
  />
151
  <Column
frontend/src/components/WorldMap.js CHANGED
@@ -8,16 +8,16 @@ const smoothProgressBar = fraction => {
8
  const filledUnits = Math.round(fraction * totalUnits)
9
  const fullBlocks = Math.floor(filledUnits / 8)
10
  const remainder = filledUnits % 8
11
- return ('█'.repeat(fullBlocks) + (remainder > 0 ? blocks[remainder - 1] : '')) || '▏'
 
 
12
  }
13
 
14
  const makeTitle = data => d => {
15
- const languages = data.countries[
16
- d.properties?.ISO_A2_EH
17
- ]?.languages.toSorted((a, b) => b.population - a.population)
18
- const pop = languages
19
- ?.map(a => a.population)
20
- .reduce((prev, a) => prev + a, 0)
21
  const langstring =
22
  languages
23
  ?.slice(0, 10)
@@ -37,16 +37,20 @@ const WorldMap = ({ data }) => {
37
  }, [])
38
 
39
  useEffect(() => {
40
- if (mapData === undefined) return
41
- const countries = mapData
 
 
 
 
42
  const plot = Plot.plot({
43
  width: 750,
44
  height: 500,
45
  projection: 'equal-earth',
46
  marks: [
47
- Plot.geo(countries, {
48
- fill: d => data.countries[d.properties?.ISO_A2_EH]?.score,
49
- title: makeTitle(data),
50
  tip: true
51
  })
52
  ],
@@ -55,7 +59,7 @@ const WorldMap = ({ data }) => {
55
  unknown: 'gray',
56
  label: 'Score',
57
  legend: true,
58
- domain: [0, 0.5]
59
  },
60
  style: {
61
  fontFamily: 'monospace'
@@ -63,7 +67,7 @@ const WorldMap = ({ data }) => {
63
  })
64
  containerRef.current.append(plot)
65
  return () => plot.remove()
66
- }, [mapData])
67
 
68
  return (
69
  <div
@@ -73,7 +77,7 @@ const WorldMap = ({ data }) => {
73
  height: '100%',
74
  display: 'flex',
75
  alignItems: 'center',
76
- justifyContent: 'center',
77
  }}
78
  />
79
  )
 
8
  const filledUnits = Math.round(fraction * totalUnits)
9
  const fullBlocks = Math.floor(filledUnits / 8)
10
  const remainder = filledUnits % 8
11
+ return (
12
+ '█'.repeat(fullBlocks) + (remainder > 0 ? blocks[remainder - 1] : '') || '▏'
13
+ )
14
  }
15
 
16
  const makeTitle = data => d => {
17
+ const languages = data[d.properties?.ISO_A2_EH]?.languages.toSorted(
18
+ (a, b) => b.population - a.population
19
+ )
20
+ const pop = languages?.map(a => a.population).reduce((prev, a) => prev + a, 0)
 
 
21
  const langstring =
22
  languages
23
  ?.slice(0, 10)
 
37
  }, [])
38
 
39
  useEffect(() => {
40
+ console.log('countries', data)
41
+ if (mapData === undefined || data === undefined) return
42
+ const countriesDict = data.reduce((acc, country) => {
43
+ acc[country.iso2] = country
44
+ return acc
45
+ }, {})
46
  const plot = Plot.plot({
47
  width: 750,
48
  height: 500,
49
  projection: 'equal-earth',
50
  marks: [
51
+ Plot.geo(mapData, {
52
+ fill: d => countriesDict[d.properties?.ISO_A2_EH]?.score,
53
+ title: makeTitle(countriesDict),
54
  tip: true
55
  })
56
  ],
 
59
  unknown: 'gray',
60
  label: 'Score',
61
  legend: true,
62
+ domain: [0, 0.7]
63
  },
64
  style: {
65
  fontFamily: 'monospace'
 
67
  })
68
  containerRef.current.append(plot)
69
  return () => plot.remove()
70
+ }, [mapData, data])
71
 
72
  return (
73
  <div
 
77
  height: '100%',
78
  display: 'flex',
79
  alignItems: 'center',
80
+ justifyContent: 'center'
81
  }}
82
  />
83
  )