Files
OpenBB/openbb_terminal/core/library/trail_map.py
Chavithra b93671ad0b SDK : faster and simpler architecture (#3289)
* SDK : split features

* Fix linting

* SDK : remove functions

* SDK : update openbb object building

* SDK : comments

* Typing

* Typing

* Typing

* SDK : update logs

* SDK : Breadcrumb

* SDK : Breadcrumb + Operation

* SDK : spell

* Linting

* Tests : SDK

* SDK : Operation

* SDK : Operation

* Linting

* enable wrong import position

* added logging info

* added log supression

* reverted the order

* SDK : update trail_map

* log suppresion as configuration

* changes reports to use the new sdk

* changes dashboards to use the new sdk

* changes dashboards to use the new sdk

* updated the documentation

* Tests + Linting

* Replace old sdk by new sdk

* Linting

* SDK : import + map_dict

* Linting

* Linting

* SDK : sdk + trail_map

* Linting

* SDK : forecasting

* SDK : update import path

* SDK

* SDK : md

* Linting

* removed unused functions

* trunc args to a max of 100 characters

* added logging when exceptions

* .md files

* SDK : add signature on operation + linting + remove trail on Breadcrumb

* Linting

* Move tests

* Linting

* Linting

* Linting

* Linting

* Linting

* Linting

* Linting

Co-authored-by: Henrique Joaquim <h.joaquim@campus.fct.unl.pt>
2022-11-09 22:25:12 +01:00

54 lines
1.6 KiB
Python

from pathlib import Path
from typing import Dict
import pandas as pd
from openbb_terminal.core.config.paths import MISCELLANEOUS_DIRECTORY
try:
import darts # pylint: disable=W0611 # noqa: F401
# If you just import darts this will pass during pip install, this creates
# Failures later on, also importing utils ensures that darts is installed correctly
from darts import utils # pylint: disable=W0611 # noqa: F401
FORECASTING = True
except ImportError:
FORECASTING = False
class TrailMap:
MAP_PATH = MISCELLANEOUS_DIRECTORY / "library" / "trail_map.csv"
MAP_FORECASTING_PATH = (
MISCELLANEOUS_DIRECTORY / "library" / "trail_map_forecasting.csv"
)
@classmethod
def load_csv(cls, path: Path = None) -> Dict[str, Dict[str, str]]:
path = path or cls.MAP_PATH
df = pd.read_csv(path, keep_default_na=False)
df.set_index("trail", inplace=True)
return df.to_dict(orient="index")
@classmethod
def save_csv(cls, map_dict: Dict[str, Dict[str, str]], path: Path = None) -> None:
path = path or cls.MAP_PATH
df = pd.DataFrame.from_dict(data=map_dict, orient="index")
df.index.name = "trail"
df.to_csv(path_or_buf=path)
@property
def map_dict(self) -> Dict[str, Dict[str, str]]:
return self.__map_dict
def load(self):
map_dict = self.load_csv(path=self.MAP_PATH)
if FORECASTING:
map_forecasting_dict = self.load_csv(path=self.MAP_FORECASTING_PATH)
map_dict = {**map_dict, **map_forecasting_dict}
self.__map_dict = map_dict
def __init__(self):
self.load()