Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
SocialGouv
archifiltre
archifiltre-site
Commits
e840b5fd
Unverified
Commit
e840b5fd
authored
Jun 03, 2021
by
mehdilouraoui
Committed by
GitHub
Jun 03, 2021
Browse files
feat(stats): interpolate stats values (#200)
parent
b90ba3e4
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
39 additions
and
50 deletions
+39
-50
src/components/statistics/statistic-multiple.tsx
src/components/statistics/statistic-multiple.tsx
+0
-3
src/components/statistics/statistic-raw.tsx
src/components/statistics/statistic-raw.tsx
+8
-3
src/components/statistics/statistic.tsx
src/components/statistics/statistic.tsx
+2
-2
src/display-data/statistics.ts
src/display-data/statistics.ts
+9
-11
src/types/statistic-types.ts
src/types/statistic-types.ts
+8
-7
src/utils/statistics-util.ts
src/utils/statistics-util.ts
+12
-24
No files found.
src/components/statistics/statistic-multiple.tsx
View file @
e840b5fd
import
Box
from
"
@material-ui/core/Box
"
;
import
IconButton
from
"
@material-ui/core/IconButton
"
;
import
makeStyles
from
"
@material-ui/core/styles/makeStyles
"
;
import
Tooltip
from
"
@material-ui/core/Tooltip
"
;
import
Typography
from
"
@material-ui/core/Typography
"
;
import
InfoOutlinedIcon
from
"
@material-ui/icons/InfoOutlined
"
;
import
React
,
{
FC
,
ReactNode
}
from
"
react
"
;
import
{
RenderMultipleStatisticConfig
}
from
"
../../types/statistic-types
"
;
...
...
src/components/statistics/statistic-raw.tsx
View file @
e840b5fd
import
Box
from
"
@material-ui/core/Box
"
;
import
IconButton
from
"
@material-ui/core/IconButton
"
;
import
makeStyles
from
"
@material-ui/core/styles/makeStyles
"
;
import
Tooltip
from
"
@material-ui/core/Tooltip
"
;
import
Typography
from
"
@material-ui/core/Typography
"
;
import
InfoOutlinedIcon
from
"
@material-ui/icons/InfoOutlined
"
;
import
React
,
{
FC
,
ReactNode
}
from
"
react
"
;
import
{
RawStatisticConfig
}
from
"
../../types/statistic-types
"
;
...
...
@@ -26,6 +23,9 @@ const useDataStyle = makeStyles(({ palette: { type } }) => ({
const
useLabelStyle
=
makeStyles
({
root
:
{
"
& .label-inner
"
:
{
display
:
"
table
"
,
},
fontSize
:
"
15px
"
,
lineHeight
:
"
22px
"
,
marginTop
:
"
8px
"
,
...
...
@@ -48,6 +48,11 @@ const StatisticRaw: FC<StatisticRawProps> = ({ statistic }) => {
<
Box
display
=
"flex"
flexWrap
=
"wrap"
>
<
Typography
classes
=
{
useLabelStyle
()
}
color
=
"textSecondary"
>
{
statistic
.
label
}{
"
"
}
{
statistic
.
sublabel
&&
(
<
Typography
className
=
"label-inner"
>
{
statistic
.
sublabel
}
</
Typography
>
)
}
{
statistic
.
tooltip
&&
(
<
StatisticTooltip
tooltip
=
{
statistic
.
tooltip
}
/>
)
}
...
...
src/components/statistics/statistic.tsx
View file @
e840b5fd
...
...
@@ -2,8 +2,8 @@ import React, { FC } from "react";
import
{
isConnectedDots
,
isInterpolate
,
isMapChart
,
isMultiple
,
isPiechart
,
RenderingStatisticConfig
,
}
from
"
../../types/statistic-types
"
;
...
...
@@ -29,7 +29,7 @@ const getContent = (statistic: RenderingStatisticConfig) => {
return
<
StatisticsConnectedDots
statistic
=
{
statistic
}
/>;
}
if
(
is
Multipl
e
(
statistic
))
{
if
(
is
Interpolat
e
(
statistic
))
{
return
<
StatisticsMultiple
statistic
=
{
statistic
}
/>;
}
...
...
src/display-data/statistics.ts
View file @
e840b5fd
...
...
@@ -52,7 +52,7 @@ export const statisticsLayout: StatisticsGroup[] = [
fields
:
[
"
totalDropVolume
"
],
label
:
"
de données analysées
"
,
type
:
"
aggregated
"
,
unit
:
"
G
o
"
,
unit
:
"
T
o
"
,
},
],
title
:
"
Total
"
,
...
...
@@ -73,16 +73,14 @@ export const statisticsLayout: StatisticsGroup[] = [
size
:
4
,
statistics
:
[
{
fields
:
[
"
carbonFootprintInGrams
"
,
"
carbonFootprintPaperEquivalence
"
,
],
label
:
""
,
sublabel
:
"
Équivalence en feuilles A4 :
"
,
sublabel
:
"
Équivalence en feuilles A4 (en millions) : <%= carbonFootprintPaperEquivalence %>
"
,
tooltip
:
"
Données calculées à partir des formules exprimées par le Cyber World CleanUp Day et par monconvertisseurco2.fr
"
,
type
:
"
multiple
"
,
unit
:
"
gCO2e économisés
"
,
type
:
"
interpolate
"
,
unit
:
"
tonnes CO2eq économisées
"
,
value
:
"
<%= carbonFootprintInKilo %>
"
,
},
],
title
:
"
Donnée écologique
"
,
...
...
@@ -112,7 +110,7 @@ export const statisticsLayout: StatisticsGroup[] = [
label
:
"
de l'outil
"
,
type
:
"
raw
"
,
unit
:
"
présentations
"
,
value
:
10
1
,
value
:
10
2
,
},
],
title
:
"
Présentations
"
,
...
...
@@ -124,7 +122,7 @@ export const statisticsLayout: StatisticsGroup[] = [
label
:
"
par une session de présentation
"
,
type
:
"
raw
"
,
unit
:
"
personnes touchées
"
,
value
:
196
5
,
value
:
231
5
,
},
],
title
:
"
Personnes touchées
"
,
...
...
@@ -152,7 +150,7 @@ export const statisticsLayout: StatisticsGroup[] = [
statistics
:
[
{
field
:
"
visitsCount
"
,
label
:
"
sur le site web
depuis le 1 janvier 2020
"
,
label
:
"
sur le site web
"
,
type
:
"
simple
"
,
unit
:
"
visiteurs uniques
"
,
},
...
...
src/types/statistic-types.ts
View file @
e840b5fd
...
...
@@ -31,13 +31,14 @@ export type SimpleStatisticConfig = BaseStatisticConfig & {
export
type
RawStatisticConfig
=
BaseStatisticConfig
&
{
value
:
ReactNode
;
type
:
"
raw
"
;
sublabel
?:
string
;
formatting
?:
Formatting
;
unit
?:
string
;
};
export
type
Multipl
eStatisticConfig
=
BaseStatisticConfig
&
{
type
:
"
multipl
e
"
;
fields
?
:
string
[]
;
export
type
Interpolat
eStatisticConfig
=
BaseStatisticConfig
&
{
type
:
"
interpolat
e
"
;
value
:
string
;
unit
?:
string
;
sublabel
?:
string
;
};
...
...
@@ -46,7 +47,7 @@ export type StatisticConfig = (
|
SimpleStatisticConfig
|
AggregatedStatisticConfig
|
RawStatisticConfig
|
Multipl
eStatisticConfig
|
Interpolat
eStatisticConfig
)
&
{
switchDisplayConfig
?:
StatisticConfig
;
};
...
...
@@ -66,7 +67,7 @@ export type ConnectedDotsStatisticsConfig = RawStatisticConfig & {
value
:
Record
<
string
,
number
>
;
};
export
type
RenderMultipleStatisticConfig
=
Multipl
eStatisticConfig
&
{
export
type
RenderMultipleStatisticConfig
=
Interpolat
eStatisticConfig
&
{
value
:
Record
<
string
,
number
>
;
};
...
...
@@ -84,9 +85,9 @@ export const isRawStatistic = (
stat
:
StatisticConfig
):
stat
is
RawStatisticConfig
=>
stat
.
type
===
"
raw
"
;
export
const
is
Multipl
e
=
(
export
const
is
Interpolat
e
=
(
stat
:
StatisticConfig
):
stat
is
Multipl
eStatisticConfig
=>
stat
.
type
===
"
multipl
e
"
;
):
stat
is
Interpolat
eStatisticConfig
=>
stat
.
type
===
"
interpolat
e
"
;
export
const
isPiechart
=
(
stat
:
RenderingStatisticConfig
...
...
src/utils/statistics-util.ts
View file @
e840b5fd
// eslint-disable-next-line import/named
import
{
group
By
,
mapValues
,
sumBy
}
from
"
lodash
"
;
import
{
key
By
,
mapValues
,
template
}
from
"
lodash
"
;
// eslint-disable-next-line import/named
import
{
compose
}
from
"
lodash/fp
"
;
import
{
AggregatedStatisticConfig
,
isMultiple
,
InterpolateStatisticConfig
,
isInterpolate
,
isRawStatistic
,
MultipleStatisticConfig
,
RenderingStatisticConfig
,
SimpleStatisticConfig
,
Statistic
,
...
...
@@ -37,21 +37,6 @@ const extractSimpleStatisticProps = (
configItem
:
SimpleStatisticConfig
)
=>
findValueByLabel
(
statistics
,
configItem
.
field
);
const
extractMultipleStatisticProps
=
(
statistics
:
Statistic
[],
configItem
:
MultipleStatisticConfig
)
=>
{
const
filteredStatistics
=
statistics
.
filter
((
statistic
)
=>
configItem
?.
fields
?.
includes
(
statistic
.
label
)
);
const
groupedByStats
=
groupBy
(
filteredStatistics
,
"
label
"
);
const
mappedValues
=
mapValues
(
groupedByStats
,
(
statistic
)
=>
sumBy
(
statistic
,
"
value
"
)
);
const
[
firstValue
,
secondValue
]
=
Object
.
values
(
mappedValues
);
return
{
firstValue
,
secondValue
};
};
const
isAggregatedStatistic
=
(
configItem
:
StatisticConfig
):
configItem
is
AggregatedStatisticConfig
=>
configItem
.
type
===
"
aggregated
"
;
...
...
@@ -76,14 +61,17 @@ const formatAggregatedStatistic = (statistic: AggregatedStatisticConfig) => (
value
:
extractAggregatedStatisticProps
(
data
,
statistic
),
});
const
formatMultipleStatistic
=
(
statistic
:
MultipleStatisticConfig
)
=>
(
const
formatInterpolateData
=
(
data
:
Statistic
[]):
Record
<
string
,
number
>
=>
mapValues
(
keyBy
(
data
,
"
label
"
),
({
value
})
=>
value
);
const
formatInterpolateStatistic
=
(
statistic
:
InterpolateStatisticConfig
)
=>
(
data
:
Statistic
[]
):
RenderingStatisticConfig
=>
{
return
{
...
extractCommonProps
(
statistic
),
sublabel
:
statistic
.
sublabel
,
type
:
"
multiple
"
,
value
:
extractMultipleStatisticProps
(
data
,
statistic
),
sublabel
:
template
(
statistic
.
sublabel
||
""
)(
formatInterpolateData
(
data
))
,
type
:
"
raw
"
,
value
:
template
(
statistic
.
value
)(
formatInterpolateData
(
data
)
),
};
};
const
formatSimpleStatistic
=
(
statistic
:
SimpleStatisticConfig
)
=>
(
...
...
@@ -99,8 +87,8 @@ const baseFormatStatistic = (statistic: StatisticConfig) => {
return
formatAggregatedStatistic
(
statistic
);
}
if
(
is
Multipl
e
(
statistic
))
{
return
format
Multipl
eStatistic
(
statistic
);
if
(
is
Interpolat
e
(
statistic
))
{
return
format
Interpolat
eStatistic
(
statistic
);
}
if
(
isRawStatistic
(
statistic
))
{
return
()
=>
statistic
;
...
...
Social Groovy Bot
🤖
@SocialGroovyBot
mentioned in commit
00f2b696
·
Jun 03, 2021
mentioned in commit
00f2b696
mentioned in commit 00f2b69621b448d41468e5643a8c0debebddbe53
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment