Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import ElecIcon from '../assets/icons/visu/elec.svg'
import WaterIcon from '../assets/icons/visu/water.svg'
import GasIcon from '../assets/icons/visu/gas.svg'
import ElecSmallIcon from '../assets/icons/visu/elec-small.svg'
import WaterSmallIcon from '../assets/icons/visu/water-small.svg'
import GasSmallIcon from '../assets/icons/visu/gas-small.svg'
import AddElecIcon from 'assets/icons/ico/add-elec.svg'
import AddWaterIcon from 'assets/icons/ico/add-water.svg'
import AddGasIcon from 'assets/icons/ico/add-gas.svg'
import ElecParamIcon from 'assets/icons/visu/elec-param.svg'
import WaterParamIcon from 'assets/icons/visu/water-param.svg'
import GasParamIcon from 'assets/icons/visu/gas-param.svg'
import { FluidType } from '../enum/fluid.enum'
import { DateTime } from 'luxon'
import { ENEDIS_DAY_DOCTYPE } from 'doctypes'
import { ITimePeriod, TimeStep } from '../services/dataConsumptionContracts'
import { UserChallenge } from 'services/dataChallengeContracts'
/**
* Return an icon corresponding to FuildType enum
* @param type FluidType
*/
export function getPicto(type: FluidType, small = false) {
switch (type) {
case FluidType.ELECTRICITY:
return small ? ElecSmallIcon : ElecIcon
case FluidType.WATER:
return small ? WaterSmallIcon : WaterIcon
case FluidType.GAS:
return small ? GasSmallIcon : GasIcon
default:
return ElecIcon
}
}
/**
* Return an icon corresponding to add FuildType enum
* @param type FluidType
*/
export function getAddPicto(type: FluidType) {
switch (type) {
case FluidType.ELECTRICITY:
return AddElecIcon
case FluidType.WATER:
return AddWaterIcon
case FluidType.GAS:
return AddGasIcon
default:
return ElecIcon
}
}
export function getParamPicto(type: FluidType) {
switch (type) {
case FluidType.ELECTRICITY:
return ElecParamIcon
case FluidType.WATER:
return WaterParamIcon
case FluidType.GAS:
return GasParamIcon
default:
return ElecParamIcon
}
}
/**
* Return a string corresponding to Fuild style
* @param type FluidType
*/
export function getCardColor(type: FluidType) {
switch (type) {
case FluidType.ELECTRICITY:
return 'card orange'
case FluidType.WATER:
return 'card blue'
case FluidType.GAS:
return 'card green'
default:
return 'card'
}
}
/**
* Return a string corresponding to Fuild style
* @param fluidTypes FluidType[]
*/
export function getColorClass(fluidTypes: FluidType[]) {
if (fluidTypes.length === 1) {
switch (fluidTypes[0]) {
case FluidType.ELECTRICITY:
return 'var(--elecColor)'
case FluidType.WATER:
return 'var(--waterColor)'
case FluidType.GAS:
return 'var(--gasColor)'
default:
return 'var(--elecColor)'
}
}
return styles.multiColor
}
/**
* Return a FuildType corresponding to type string
* @param type string
*/
export function getFuildType(type: string) {
switch (type.toUpperCase()) {
case 'ELECTRICITY':
return FluidType.ELECTRICITY
case 'WATER':
return FluidType.WATER
case 'GAS':
return FluidType.GAS
default:
return FluidType.ELECTRICITY
}
}
export function formatNumberValues(value: number) {
return value.toLocaleString('fr-FR', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
})
}
export function compareDates(dateA: DateTime, dateB: DateTime) {
return dateA < dateB ? -1 : 1
}
export function getDoctype(fluid: FluidType) {
// TODO add doctypes
return ENEDIS_DAY_DOCTYPE
}
export const formatCompareChallengeDate = (challenge: UserChallenge) => {
let durationTimeStep = ''
let duration = 0
if (challenge && challenge.challengeType) {
durationTimeStep = Object.keys(challenge.challengeType.duration)[0]
duration = (challenge.challengeType.duration as any)[durationTimeStep]
}
const delay = { [durationTimeStep]: -duration }
const startDate = challenge.startingDate.plus(delay)
const endDate = challenge.startingDate.plus({ days: -1 }).endOf('day')
return ` (du ${startDate.toFormat('dd/MM')} au ${endDate.toFormat('dd/MM')})`
}
export const convertDateByTimeStep = (
timeperiod: ITimePeriod | null,
timeStep: TimeStep,
header = false
): string => {
if (!timeperiod) return ''
switch (timeStep) {
case TimeStep.HALF_AN_HOUR:
return ' du ' + timeperiod.startDate.toFormat('dd/MM')
case TimeStep.HOUR:
return ' du ' + timeperiod.startDate.toFormat('dd/MM')
case TimeStep.DAY:
return (
(!header ? 'semaine ' : '') +
' du ' +
timeperiod.startDate.toFormat('dd/MM') +
' au ' +
timeperiod.endDate.toFormat('dd/MM')
)
case TimeStep.MONTH:
return ' du ' + timeperiod.startDate.toFormat('MM/y')
case TimeStep.YEAR:
return ' de ' + timeperiod.startDate.toFormat('y')
default:
return ''
}
}