Skip to content

Commit

Permalink
Merge #516
Browse files Browse the repository at this point in the history
516: p2p_statement_parser.py: add debug for parsed value r=ChrisRBe a=ChrisRBe

also write debug output for the value read from the csv input file.

Co-authored-by: ChrisRBe <[email protected]>
Co-authored-by: ChrisRBe <[email protected]>
  • Loading branch information
3 people authored Apr 3, 2022
2 parents 22d556c + 75d59ae commit 6586e95
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ jobs:
python -m pip install --upgrade pip
pip install -U pipenv
pipenv install --system --skip-lock --dev --site-packages
- name: Install additional locale
run: |
sudo apt-get update && sudo apt-get install tzdata locales -y && sudo locale-gen de_DE.UTF-8
sudo update-locale
echo "Testing language settings"
echo "All languages..."
locale -a
echo "Actual locale"
locale
echo "Actual numeric settings"
locale -c -k LC_NUMERIC
- name: Format with black
run: |
black -l 119 --check --diff .
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 22.1.0
rev: 22.3.0
hooks:
- id: black
language_version: python3
Expand Down
13 changes: 7 additions & 6 deletions src/p2p_statement_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,20 @@ def __aggregate_statements(self, formatted_account_entry, comment, monthly=True)
entry_date = entry_date.replace(day=last_day)

entry_type = formatted_account_entry[PP_FIELDNAMES[3]]
logger.debug("entry type is %s. new entry date is %s", entry_type, entry_date)
entry_value = formatted_account_entry[PP_FIELDNAMES[1]]
entry_currency = formatted_account_entry[PP_FIELDNAMES[2]]

logger.debug("entry type is %s. new entry date is %s. value of entry: %s", entry_type, entry_date, entry_value)
if entry_date not in self.aggregation_data:
self.aggregation_data[entry_date] = {}
if entry_type in self.aggregation_data[entry_date]:
logger.debug("add to existing entry")
self.aggregation_data[entry_date][entry_type][PP_FIELDNAMES[1]] += formatted_account_entry[
PP_FIELDNAMES[1]
]
self.aggregation_data[entry_date][entry_type][PP_FIELDNAMES[1]] += entry_value
else:
self.aggregation_data[entry_date][entry_type] = {
PP_FIELDNAMES[0]: entry_date,
PP_FIELDNAMES[1]: formatted_account_entry[PP_FIELDNAMES[1]],
PP_FIELDNAMES[2]: formatted_account_entry[PP_FIELDNAMES[2]],
PP_FIELDNAMES[1]: entry_value,
PP_FIELDNAMES[2]: entry_currency,
PP_FIELDNAMES[3]: entry_type,
PP_FIELDNAMES[4]: comment,
}
Expand Down
7 changes: 6 additions & 1 deletion src/portfolio_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import codecs
import csv
import io
import locale
import logging
from decimal import Decimal


PP_FIELDNAMES = ["Datum", "Wert", "Buchungswährung", "Typ", "Notiz"]
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -49,8 +52,10 @@ def update_output(self, statement_dict):
key value pair
:return:
"""
logger.debug("Current locale: %s", locale.getlocale())
if statement_dict:
statement_dict[PP_FIELDNAMES[1]] = "{0:.8f}".format(statement_dict[PP_FIELDNAMES[1]]).replace(".", ",")
value = Decimal(statement_dict[PP_FIELDNAMES[1]])
statement_dict[PP_FIELDNAMES[1]] = f"{value:.8n}"
self.out_csv_writer.writerow(statement_dict)

def write_pp_csv_file(self, outfile="portfolio_performance.csv"):
Expand Down
27 changes: 23 additions & 4 deletions src/test/test_portfolio_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Copyright 2018-04-29 ChrisRBe
"""
import codecs
import locale
import os
import tempfile
from unittest import TestCase
Expand All @@ -27,31 +28,49 @@ def test_init_output(self):

def test_update_output(self):
"""test update_output"""
locale.setlocale(locale.LC_ALL, "de_DE.utf-8")
test_entry = {
PP_FIELDNAMES[0]: "date",
PP_FIELDNAMES[1]: 0,
PP_FIELDNAMES[1]: 123.456789,
PP_FIELDNAMES[2]: "currency",
PP_FIELDNAMES[3]: "category",
PP_FIELDNAMES[4]: "note",
}
self.pp_writer.update_output(test_entry)
self.assertEqual(
'Datum,Wert,Buchungswährung,Typ,Notiz\r\ndate,"0,00000000",currency,category,note',
'Datum,Wert,Buchungswährung,Typ,Notiz\r\ndate,"123,45679",currency,category,note',
self.pp_writer.out_string_stream.getvalue().strip(),
)

def test_update_output_umlaut(self):
"""test update_output with umlauts"""
locale.setlocale(locale.LC_ALL, "de_DE.utf-8")
test_entry = {
PP_FIELDNAMES[0]: "date",
PP_FIELDNAMES[1]: 0,
PP_FIELDNAMES[1]: 0.123456789,
PP_FIELDNAMES[2]: "currency",
PP_FIELDNAMES[3]: "category",
PP_FIELDNAMES[4]: "Laiamäe Pärnaõie Užutekio",
}
self.pp_writer.update_output(test_entry)
self.assertEqual(
'Datum,Wert,Buchungswährung,Typ,Notiz\r\ndate,"0,00000000",currency,category,Laiamäe Pärnaõie Užutekio',
'Datum,Wert,Buchungswährung,Typ,Notiz\r\ndate,"0,12345679",currency,category,Laiamäe Pärnaõie Užutekio',
self.pp_writer.out_string_stream.getvalue().strip(),
)

def test_update_output_umlaut_en_us(self):
"""test update_output with umlauts"""
locale.setlocale(locale.LC_ALL, "en_US.utf-8")
test_entry = {
PP_FIELDNAMES[0]: "date",
PP_FIELDNAMES[1]: 0.123456789,
PP_FIELDNAMES[2]: "currency",
PP_FIELDNAMES[3]: "category",
PP_FIELDNAMES[4]: "Laiamäe Pärnaõie Užutekio",
}
self.pp_writer.update_output(test_entry)
self.assertEqual(
"Datum,Wert,Buchungswährung,Typ,Notiz\r\ndate,0.12345679,currency,category,Laiamäe Pärnaõie Užutekio",
self.pp_writer.out_string_stream.getvalue().strip(),
)

Expand Down

0 comments on commit 6586e95

Please sign in to comment.