Skip to content

Commit

Permalink
Merge pull request #29 from ssenart/develop
Browse files Browse the repository at this point in the history
Prepare for 1.0.2
  • Loading branch information
ssenart committed Nov 25, 2021
2 parents 28dc042 + 4453762 commit c05b41a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.2](https://github.com/ssenart/PyGazpar/compare/1.0.1...1.0.2) - 2021-11-25
### Fixed
- Fix broken command line pygazpar caused by adding the new lastNDays parameter.
- Fix the error : ValueError: could not convert string to float: 'Index de début de période (m3)'. It occurs because the records in the Excel file now starts at line 10 instead of line 8 before (thanks to [DEFAYArnaud](https://github.com/DEFAYArnaud) for having spotted the issue and bringing the fix).

### Changed
- In the Excel file, if a cell is empty, then no corresponding key will be inserted in the result dictionary (before we inserted a key with an empty string).

## [1.0.1](https://github.com/ssenart/PyGazpar/compare/1.0.0...1.0.1) - 2021-11-24
### Fixed
- Fix typo warning from Pylance preventing 1.0.0 to be published.
Expand Down
8 changes: 7 additions & 1 deletion pygazpar/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ def main():
type=lambda frequency: pygazpar.Frequency[frequency], choices=list(pygazpar.Frequency),
default="DAILY",
help="Meter reading frequency (DAILY, WEEKLY, MONTHLY)")
parser.add_argument("-d", "--lastNDays",
required=False,
type=int,
default=365,
help="Get only the last N days of records (default: 365 days)")
parser.add_argument("--testMode",
required=False,
action='store_true',
Expand Down Expand Up @@ -78,9 +83,10 @@ def main():
logging.info(f"--lastNRows {int(args.lastNRows)}")
logging.info(f"--headfull {bool(args.headfull)}")
logging.info(f"--frequency {args.frequency}")
logging.info(f"--lastNDays {args.lastNDays}")
logging.info(f"--testMode {bool(args.testMode)}")

client = pygazpar.Client(args.username, args.password, args.webdriver, int(args.wait_time), args.tmpdir, int(args.lastNRows), not bool(args.headfull), args.frequency, bool(args.testMode))
client = pygazpar.Client(args.username, args.password, args.webdriver, int(args.wait_time), args.tmpdir, int(args.lastNRows), not bool(args.headfull), args.frequency, int(args.lastNDays), bool(args.testMode))

try:
client.update()
Expand Down
11 changes: 6 additions & 5 deletions pygazpar/datafileparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from openpyxl import load_workbook


FIRST_DATA_LINE_NUMBER = 10


# ------------------------------------------------------------------------------------------------------------
class DataFileParser:

Expand Down Expand Up @@ -56,8 +59,6 @@ def __fillRow(row: dict, propertyName: str, cell: Cell, isNumber: bool):
row[propertyName] = float(cell.value)
else:
row[propertyName] = cell.value
else:
row[propertyName] = ""

# ------------------------------------------------------
@staticmethod
Expand All @@ -73,7 +74,7 @@ def __parseDaily(worksheet: Worksheet, lastNRows: int) -> list:
# Timestamp of the data.
data_timestamp = datetime.now().isoformat()

minRowNum = max(8, len(worksheet['B']) + 1 - lastNRows) if lastNRows > 0 else 8
minRowNum = max(FIRST_DATA_LINE_NUMBER, len(worksheet['B']) + 1 - lastNRows) if lastNRows > 0 else FIRST_DATA_LINE_NUMBER
maxRowNum = len(worksheet['B'])
for rownum in range(minRowNum, maxRowNum + 1):
row = {}
Expand Down Expand Up @@ -102,7 +103,7 @@ def __parseWeekly(worksheet: Worksheet, lastNRows: int) -> list:
# Timestamp of the data.
data_timestamp = datetime.now().isoformat()

minRowNum = max(8, len(worksheet['B']) + 1 - lastNRows) if lastNRows > 0 else 8
minRowNum = max(FIRST_DATA_LINE_NUMBER, len(worksheet['B']) + 1 - lastNRows) if lastNRows > 0 else FIRST_DATA_LINE_NUMBER
maxRowNum = len(worksheet['B'])
for rownum in range(minRowNum, maxRowNum + 1):
row = {}
Expand All @@ -126,7 +127,7 @@ def __parseMonthly(worksheet: Worksheet, lastNRows: int) -> list:
# Timestamp of the data.
data_timestamp = datetime.now().isoformat()

minRowNum = max(8, len(worksheet['B']) + 1 - lastNRows) if lastNRows > 0 else 8
minRowNum = max(FIRST_DATA_LINE_NUMBER, len(worksheet['B']) + 1 - lastNRows) if lastNRows > 0 else FIRST_DATA_LINE_NUMBER
maxRowNum = len(worksheet['B'])
for rownum in range(minRowNum, maxRowNum + 1):
row = {}
Expand Down
15 changes: 12 additions & 3 deletions tests/test_datafileparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@ class TestDataFileParser:

def test_daily_sample(self):
data = DataFileParser.parse("tests/resources/Donnees_informatives_PCE_DAILY.xlsx", Frequency.DAILY, 10)
assert(len(data) > 0)
assert(len(data) == 10)

data = DataFileParser.parse("tests/resources/Donnees_informatives_PCE_DAILY.xlsx", Frequency.DAILY, 0)
assert(len(data) == 363)

def test_weekly_sample(self):
data = DataFileParser.parse("tests/resources/Donnees_informatives_PCE_WEEKLY.xlsx", Frequency.WEEKLY, 10)
assert(len(data) > 0)
assert(len(data) == 10)

data = DataFileParser.parse("tests/resources/Donnees_informatives_PCE_WEEKLY.xlsx", Frequency.WEEKLY, 0)
assert(len(data) == 53)

def test_monthly_sample(self):
data = DataFileParser.parse("tests/resources/Donnees_informatives_PCE_MONTHLY.xlsx", Frequency.MONTHLY, 10)
assert(len(data) > 0)
assert(len(data) == 10)

data = DataFileParser.parse("tests/resources/Donnees_informatives_PCE_MONTHLY.xlsx", Frequency.MONTHLY, 0)
assert(len(data) == 13)

0 comments on commit c05b41a

Please sign in to comment.