From 7022918f0c0d85de8570e302daa07fc037cc9185 Mon Sep 17 00:00:00 2001 From: Jamie Gooding Date: Thu, 28 Sep 2023 15:40:03 +0200 Subject: [PATCH] Miscellaneous updates to source and testing commands --- .github/workflows/python-package-conda.yml | 5 +- src/whisk/_table.py | 59 ++++++++++++++++++++-- src/whisk/_whisk.py | 42 +++++++++++++-- 3 files changed, 96 insertions(+), 10 deletions(-) diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml index 384f9b7..aab7a46 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/python-package-conda.yml @@ -10,10 +10,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up Python 3.10 + - name: Set up Python 3.9 uses: actions/setup-python@v3 with: - python-version: '3.10' + python-version: '3.9' - name: Add conda to system path run: | # $CONDA is an environment variable pointing to the root of the miniconda directory @@ -30,5 +30,6 @@ jobs: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest run: | + pip install . conda install pytest pytest diff --git a/src/whisk/_table.py b/src/whisk/_table.py index 469b50d..cde3889 100644 --- a/src/whisk/_table.py +++ b/src/whisk/_table.py @@ -1,10 +1,59 @@ -from ROOT import RDataFrame - - +############################################################################### +# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration # +# # +# This software is distributed under the terms of the GNU General Public # +# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # +# # +# In applying this licence, CERN does not waive the privileges and immunities # +# granted to it by virtue of its status as an Intergovernmental Organization # +# or submit itself to any jurisdiction. # +############################################################################### def table( data: RDataFrame, - categories: dict + categories: Union[List[str], Dict[str, str]], + absolute: + output: bool = False, + totals: bool = False, + ): + if type(categories) == list: + return + spacing = 12 + combinations = prod([len(category) for category in categories.values()]) + header = "" + previous_categories = 1 + column_width = combinations + + labels = list(categories.keys()) + values_sets = list(categories.values()) + print(labels) + print(values_sets) + + + + if readable: + + + for n, (label, values) in enumerate(zip(labels, values_sets)): + previous_category_count = len(values_sets[n-1]) if n-1 > 0 and n < len(values_sets) else 1 + next_category_count = len(values_sets[n+1]) if n+1 < len(values_sets) else 1 + combinations = int(combinations / next_category_count) + header += f"{label : <{spacing * combinations * next_category_count}} | " + column_width = spacing * combinations + + for _ in range(previous_category_count): + for value in values: + header += f"{value : <{column_width}} | " + + #"catA | valA1 | valA2 | valA3" + #"catB | valB1 VALB2 | valB2 | valB3" + header += "\n" + print(label) + print(header) + + + print(combinations) + print('a') - return \ No newline at end of file + return True \ No newline at end of file diff --git a/src/whisk/_whisk.py b/src/whisk/_whisk.py index a258381..e6828c0 100644 --- a/src/whisk/_whisk.py +++ b/src/whisk/_whisk.py @@ -1,10 +1,46 @@ +############################################################################### +# (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration # +# # +# This software is distributed under the terms of the GNU General Public # +# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # +# # +# In applying this licence, CERN does not waive the privileges and immunities # +# granted to it by virtue of its status as an Intergovernmental Organization # +# or submit itself to any jurisdiction. # +############################################################################### + +from typing import Dict, List, Union from ROOT import RDataFrame +def whisk( + data: RDataFrame, + categories: Union[List[str], Dict[str, str]], +): + return -def whisk( +def _calculate_proportions( data: RDataFrame, - categories: dict + categories: Union[List[str], Dict[str, str]] ): + proportions = {} + if type(categories) == list: + return + + for category, values in categories: + for value in values: + proportions.extend({ + category: { + "total" : data.Filter(f"{category} == {value}").Count().getValue() + } + }) + + + return - return \ No newline at end of file + { + "red" : { + "total" : 1, + "square" : {"total": 1} + } + } \ No newline at end of file