-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit_func.py
39 lines (30 loc) · 952 Bytes
/
streamlit_func.py
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
import util as utils
def streamlit_mapper(map_value, var_name) -> int:
"""This function is used to map feature to its mapper
The output depends on the mapper. The mapper can be found
in the configuration file.
Parameters
----------
map_value : str
The value that should be mapped
mapper : dict
The dictionary of mapped key to value
Return
------
map_value : int
The mapped value based on the pre-defined mapper
"""
config = utils.load_config()
binary_mapper = {0: "no", 1:"yes"}
mappers = {
"weekday": config["weekday_map"],
"season": config["season_map"],
"weathersit": config["weathersit_map"],
"holiday": binary_mapper,
"workingday": binary_mapper,
}
mapper = mappers[var_name]
key_list = list(mapper.keys())
val_list = list(mapper.values())
pos = val_list.index(map_value)
return key_list[pos]