Skip to content

alexandrvl/elv-tariffs-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ELV Network Service Tariff Calculator

This Java library provides functionality to calculate network service costs based on ELV's tariff packages.

Requirements

  • Java 17 or higher
  • Gradle 7.x or higher

Setup

  1. Clone the repository
  2. Build the project:
./gradlew build

Dependencies

  • SnakeYAML (2.2) - YAML configuration parsing
  • Jakarta Validation API (3.0.2) - Validation framework
  • Hibernate Validator (8.0.1.Final) - Validation implementation
  • Lombok (1.18.30) - Boilerplate code reduction
  • JUnit Jupiter (5.10.1) - Testing framework
  • AssertJ (3.24.2) - Testing assertions

Tariff Packages

The calculator supports three types of network service packages:

  1. Basic Package

    • Single rate for all hours
    • Fixed monthly fee
    • Suitable for customers with regular consumption patterns
  2. Time of Day Package

    • Different rates for day and night hours
    • Fixed monthly fee
    • Beneficial for customers who can shift consumption to night hours
  3. Peak Package

    • Higher rates during peak hours in winter months (November-March)
    • Peak hours on workdays: 9:00-12:00 and 16:00-20:00
    • Peak hours on weekends/holidays: 16:00-20:00
    • Different rates for base, day, night, and peak periods
    • Considers holidays as non-peak days
    • Fixed monthly fee

Configuration

The application uses YAML configuration (application.yml) with the following structure:

time:
  default:
    day-start: "07:00"    # Default day period start
    night-start: "23:00"  # Default night period start

tariffs:
  basic:
    day-rate: 0.0435     # Rate in EUR/kWh
    monthly-fee: 1.99    # Monthly fee in EUR
    main-fuse-size: 32   # Ampere size

  peak:
    base-rate: 0.0385    # Base rate for all consumption
    day-rate: 0.0495     # Regular day rate
    night-rate: 0.0285   # Night rate
    peak-day-rate: 0.0695    # Peak rate for workdays
    peak-weekend-rate: 0.0485 # Peak rate for weekends
    monthly-fee: 1.99

settings:
  decimal:
    scale: 2             # Decimal places for calculations
    rounding-mode: HALF_UP
  timezone: "Europe/Tallinn"

  peak-season:           # Peak tariff settings
    start-month: "NOVEMBER"
    end-month: "MARCH"
    workday-peak:
      - start: "09:00"
        end: "12:00"
      - start: "16:00"
        end: "20:00"
    weekend-peak:
      start: "16:00"
      end: "20:00"

See the full configuration example in src/main/resources/application.yml.

Usage Examples

Basic Package Calculation

TariffCalculationPort calculator = new TariffCalculatorAdapter();

TariffRate basicRate = TariffRate.builder()
    .dayRate(new BigDecimal("0.0435"))
    .nightRate(new BigDecimal("0.0435"))
    .ampereFee(BigDecimal.ZERO)
    .monthlyFee(new BigDecimal("1.99"))
    .mainFuseSize(32)
    .build();

BigDecimal consumption = new BigDecimal("300");
BigDecimal cost = calculator.calculateBasicPackageCost(basicRate, consumption);

Time of Day Package Calculation

TariffRate timeOfDayRate = TariffRate.builder()
    .dayRate(new BigDecimal("0.0495"))
    .nightRate(new BigDecimal("0.0285"))
    .ampereFee(BigDecimal.ZERO)
    .monthlyFee(new BigDecimal("1.99"))
    .mainFuseSize(32)
    .build();

ConsumptionSplit consumption = ConsumptionSplit.builder()
    .dayAmount(new BigDecimal("200"))
    .nightAmount(new BigDecimal("100"))
    .build();

BigDecimal cost = calculator.calculateTimeOfDayPackageCost(timeOfDayRate, consumption);

Peak Package Calculation

TariffRate peakRate = TariffRate.builder()
    .baseRate(new BigDecimal("0.0385"))    // Base rate for all consumption
    .dayRate(new BigDecimal("0.0495"))     // Regular day rate
    .nightRate(new BigDecimal("0.0285"))   // Night rate
    .peakDayRate(new BigDecimal("0.0695")) // Peak rate for workdays
    .peakWeekendRate(new BigDecimal("0.0485")) // Peak rate for weekends
    .monthlyFee(new BigDecimal("1.99"))
    .mainFuseSize(32)
    .build();

ConsumptionSplit consumption = ConsumptionSplit.builder()
    .baseAmount(new BigDecimal("100"))
    .dayAmount(new BigDecimal("200"))
    .nightAmount(new BigDecimal("300"))
    .peakDayAmount(new BigDecimal("50"))
    .peakWeekendAmount(new BigDecimal("30"))
    .build();

BigDecimal cost = calculator.calculatePeakPackageCost(peakRate, consumption);

Project Structure

src/
├── main/java/com/elv/tariff/
│   ├── adapters/
│   │   ├── input/
│   │   │   └── TariffCalculatorAdapter.java
│   │   └── output/
│   │       ├── HolidayUtil.java
│   │       └── TimeZoneAdapter.java
│   ├── calculator/
│   │   ├── impl/
│   │   │   ├── BasicTariffCalculator.java
│   │   │   ├── PeakTariffCalculator.java
│   │   │   └── TimeOfDayTariffCalculator.java
│   │   ├── AbstractTariffCalculator.java
│   │   └── TariffCalculator.java
│   ├── domain/
│   │   ├── model/
│   │   └── service/
│   └── ports/
│       ├── input/
│       │   └── TariffCalculationPort.java
│       └── output/
│           ├── HolidayServicePort.java
│           └── TimeZonePort.java

Important Notes

  • All monetary values are in euros (EUR)
  • All calculations exclude VAT
  • Consumption values should be provided in kilowatt-hours (kWh)
  • Negative consumption values are not allowed
  • Results are rounded to 2 decimal places using HALF_UP rounding mode
  • The application uses Europe/Tallinn timezone by default
  • Holidays are considered as non-peak days for tariff calculations

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages