Skip to content

Commit

Permalink
Only allow one flat fee per session (#72)
Browse files Browse the repository at this point in the history
* only allow one flat fee per session

* add test

* update changelog and ammend readme
  • Loading branch information
remkop22 authored Aug 19, 2024
1 parent 5c0bd46 commit ab6a147
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to this project will be documented in this file.

## Unreleased

- Fixed bug where multiple flat fees are generated during the session. Instead
we now only use the first time a flat fee becomes active.

## 0.6.0 2024-06-04

- Upgrade dependencies.
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,24 @@ classDiagram
TariffElement "1" --o "0..1" TariffRestriction
```

## Interpretation

This implementation aims to follow the OCPI specification as closely as
possible. However, as with any specification, details might be left open to
interpretation. The following is a list of assumptions that have been made in
this implementation:

- We assume that a `FLAT` price component can only be active once in a session.
The first time a `FLAT` price component becomes active it will be used and
subsequent active `FLAT` components will be ignored. Although this is not
explicitly mentioned in the OCPI 2.*.* specs, we feel it is the correct
interpretation.

- We assume that the charging periods provided as input are well-formed.
Meaning, each period in the session that has a different price must be
provided as a separate charging period in the CDR. No attempt will be made
to subdivide or interpolate data inside a single provided period.

## Contributing

We welcome community contributions to this project.
Expand Down
12 changes: 11 additions & 1 deletion ocpi-tariffs/src/pricer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,18 @@ impl<'a> Pricer<'a> {
let mut total_charging_time = HoursDecimal::zero();
let mut total_parking_time = HoursDecimal::zero();

let mut has_flat_fee = false;

for (index, period) in cdr.periods.iter().enumerate() {
let components = tariff.active_components(period);
let mut components = tariff.active_components(period);

if components.flat.is_some() {
if has_flat_fee {
components.flat = None;
} else {
has_flat_fee = true;
}
}

step_size.update(index, &components, period);

Expand Down
45 changes: 45 additions & 0 deletions ocpi-tariffs/test_data/multiple_flat_fees/cdr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"country_code": "BE",
"start_date_time": "2015-06-29T15:00:00Z",
"end_date_time": "2015-06-29T16:30:00Z",
"currency": "EUR",
"tariffs": [],
"cdr_location": {
"country": "NLD"
},
"charging_periods": [
{
"start_date_time": "2015-06-29T15:00:00Z",
"dimensions": [{
"type": "TIME",
"volume": 0.5
}]
},
{
"start_date_time": "2015-06-29T15:30:00Z",
"dimensions": [{
"type": "TIME",
"volume": 0.5
}]
},
{
"start_date_time": "2015-06-29T16:00:00Z",
"dimensions": [{
"type": "TIME",
"volume": 0.5
}]
}
],
"total_fixed_cost": {
"excl_vat": 1.0,
"incl_vat": 1.0
},
"total_cost": {
"excl_vat": 1.0,
"incl_vat": 1.0
},
"total_energy": 0,
"total_time": 1.5,
"total_parking_time": 0,
"last_updated": "2015-06-29T22:01:13Z"
}
15 changes: 15 additions & 0 deletions ocpi-tariffs/test_data/multiple_flat_fees/tariff.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"country_code": "DE",
"party_id": "ALL",
"id": "12",
"currency": "EUR",
"elements": [{
"price_components": [{
"type": "FLAT",
"price": 1.00,
"vat": 0.0,
"step_size": 0
}]
}],
"last_updated": "2015-06-29T20:39:09Z"
}

0 comments on commit ab6a147

Please sign in to comment.