diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2019-10-02 12:17:15 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2019-10-02 12:17:15 +0100 |
commit | add4a2a054771aa11642c74e13b5e6d3da47a68a (patch) | |
tree | 738c9c6bda2995ba9309b0220635f6df0910321d /datamaps/plugins/dft | |
parent | e8739589d3c5a895037c1faa79c751e11503f31e (diff) |
refactored api to move dft stuff into plugins package - still test on missing sheet failing
Diffstat (limited to '')
-rw-r--r-- | datamaps/plugins/dft/__init__.py | 0 | ||||
-rw-r--r-- | datamaps/plugins/dft/master.py (renamed from datamaps/core/master.py) | 10 | ||||
-rw-r--r-- | datamaps/plugins/dft/portfolio.py | 45 |
3 files changed, 50 insertions, 5 deletions
diff --git a/datamaps/plugins/dft/__init__.py b/datamaps/plugins/dft/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/datamaps/plugins/dft/__init__.py diff --git a/datamaps/core/master.py b/datamaps/plugins/dft/master.py index 1fbfe90..744cc27 100644 --- a/datamaps/core/master.py +++ b/datamaps/plugins/dft/master.py @@ -5,9 +5,9 @@ import unicodedata from pathlib import Path from typing import List, Tuple, Iterable, Optional, Any -from ..utils import project_data_from_master -from ..process.cleansers import DATE_REGEX_4 -from .temporal import Quarter +from datamaps.plugins.dft.portfolio import project_data_from_master +from datamaps.process.cleansers import DATE_REGEX_4 +from datamaps.core.temporal import Quarter from openpyxl import load_workbook @@ -80,13 +80,13 @@ def _convert_str_date_to_object(d_str: tuple) -> Tuple[str, Optional[datetime.da class Master: - """A Master object, representing the main central data item in ``bcompiler``. + """A Master object, representing the main central data item in ``datamaps``. Args: quarter (:py:class:`bcompiler.api.Quarter`): creating using ``Quarter(1, 2017)`` for example. path (str): path to the master xlsx file - A master object is a composition between a :py:class:`bcompiler.api.Quarter` object and an + A master object is a composition between a :py:class:`datamaps.api.Quarter` object and an actual master xlsx file on disk. You create one, either by creating the Quarter object first, and using that as the first diff --git a/datamaps/plugins/dft/portfolio.py b/datamaps/plugins/dft/portfolio.py new file mode 100644 index 0000000..40bb010 --- /dev/null +++ b/datamaps/plugins/dft/portfolio.py @@ -0,0 +1,45 @@ +from collections import OrderedDict +from datetime import date +from datetime import datetime + +from openpyxl import load_workbook + +from datamaps.process import Cleanser + + +def project_data_from_master(master_file: str, opened_wb=False): + if opened_wb is False: + wb = load_workbook(master_file) + ws = wb.active + else: + wb = master_file + ws = wb.active + # cleanse the keys + for cell in ws["A"]: + # we don't want to clean None... + if cell.value is None: + continue + c = Cleanser(cell.value) + cell.value = c.clean() + p_dict = {} + for col in ws.iter_cols(min_col=2): + project_name = "" + o = OrderedDict() + for cell in col: + if cell.row == 1: + project_name = cell.value + p_dict[project_name] = o + else: + val = ws.cell(row=cell.row, column=1).value + if type(cell.value) == datetime: + d_value = date(cell.value.year, cell.value.month, + cell.value.day) + p_dict[project_name][val] = d_value + else: + p_dict[project_name][val] = cell.value + # remove any "None" projects that were pulled from the master + try: + del p_dict[None] + except KeyError: + pass + return p_dict
\ No newline at end of file |