Skip to content

Commit

Permalink
Update heading for statistics output
Browse files Browse the repository at this point in the history
  • Loading branch information
rexruan committed Nov 14, 2023
1 parent ea78833 commit a5c6491
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ Swegram is a tool that offers the ability to annotate and analyse Swedish and En


## Setup ENVIRONMENT VARIABLES
```console
```bash
export SWEGRAM_WORKSPACE=$(pwd)
```


## Install swegram command line interface

Before installation, it is strongly recommended to use a virtual environment
```
```bash
python3 -m venv venv
source venv/bin/activate
```

```console
```bash
# Install swegram package
pip install swegram --upgrade

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path
from setuptools import setup, find_packages
from typing import List

from swegram_main.version import VERSION

Base = Path(__file__).parent.resolve()

Expand All @@ -15,7 +15,7 @@ def get_requirements() -> List[str]:

setup(
name="swegram",
version="1.0.2",
version=VERSION,
description="CLI library for Swegram",
long_description=(Base / "README.md").read_text(encoding="utf-8"),
packages=find_packages(exclude=["tools*", "test*", "swegram/*", "swegram_django*"]),
Expand Down
2 changes: 1 addition & 1 deletion setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

# setup environment variables

export PYTHONPATH="$PYTHONPATH:$(pwd):$(pwd)/tools/efselab"
export SWEGRAM_WORKSPACE=$(pwd)
22 changes: 18 additions & 4 deletions swegram_main/handler/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def filter(
self.outfile_name = self.outdir.joinpath(f"statistic-{self.input_path.with_suffix(f'.{save_as}').name}")
if save_as == "txt" or pprint:
self.save(data)
elif save_as == "json":
if save_as == "json":
with open(self.outfile_name, code="w", encoding="utf-8") as output_file:
data["metadata"] = self.get_json_info()
json_object = json.dumps(self.serialize_json_data(data), indent=4)
Expand Down Expand Up @@ -152,8 +152,9 @@ def save(self, data: OrderedDict) -> None:
print()

def save_instance(self, index: Optional[str], unit: str, aspect_instances: List[OrderedDict]) -> None:
self._save_instance_head()
for aspect_name, instance in zip(self.aspects, aspect_instances):
self.save_title(unit, aspect_name, index)
self.save_aspect_title(unit, aspect_name, index)
for fn, f in instance.items():
self.save_feature(fn, f)
if self.pprint:
Expand All @@ -163,7 +164,7 @@ def save_instance(self, index: Optional[str], unit: str, aspect_instances: List[
if self.save_as == "txt":
self.append_in_text("")

def save_title(self, unit: str, aspect_name: str, index: Optional[str]) -> None:
def save_aspect_title(self, unit: str, aspect_name: str, index: Optional[str]) -> None:
title = f"{' ':>2}{'-'.join(e for e in (unit.title(), index, aspect_name) if e):>40}" \
f"{'|':>4}{'-'*13}|{'-'*13}|{'-'*13}|"
if self.pprint:
Expand All @@ -181,6 +182,18 @@ def c(v: Any) -> Any:
if self.save_as == "txt":
self.append_in_text(feature)

def _save_instance_head(self):
af = "UNIT-ASPECT/Features"
scalar = "Scalar"
mean = "Mean"
median = "Median"

heading = f"{' ':>2}{af:>40}{'|':>4}{scalar:>10}{'|':>4}{mean:>10}{'|':>4}{median:>10}{'|':>4}"
if self.pprint:
print(heading)
if self.save_as == "txt":
self.append_in_text(heading)


class XlsxStatisticWriter(XlsxClient):

Expand Down Expand Up @@ -210,7 +223,8 @@ def load_unit(self, unit: str, aspects: Any) -> None:
def load_aspects(self, sheet: worksheet, row: int, unit: str, aspects: Any) -> int:
if isinstance(aspects[0], OrderedDict):
for aspect, features in zip(self.aspects, aspects):
self.dump_cell(sheet, row, 1, f"{unit}-{aspect}")
for col, content in enumerate([f"{unit}-{aspect}", "Scalar", "Mean", "Median"], 1):
self.dump_cell(sheet, row, col, content)
row += 1
for feature_name, feature in features.items():
self.dump_column_list(sheet, row, 1, [feature_name, feature.scalar, feature.mean, feature.median])
Expand Down
3 changes: 3 additions & 0 deletions swegram_main/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""version module"""

VERSION = "1.0.3"

0 comments on commit a5c6491

Please sign in to comment.