Skip to content

Commit

Permalink
WIP test validations
Browse files Browse the repository at this point in the history
  • Loading branch information
Erikvv committed Dec 3, 2024
1 parent c351429 commit 61cf74f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ElectricityTest {
)
)

assertEquals(electricity.getContractedConnectionCapacityKw(), 3 * 80.0 * 230.0 * 0.001)
assertEquals(electricity.getContractedDeliveryCapacityKw(), 3 * 80.0 * 230.0 * 0.001)
}

@Test
Expand All @@ -27,6 +27,6 @@ class ElectricityTest {
)
)

assertEquals(electricity.getContractedConnectionCapacityKw(), 400.0)
assertEquals(electricity.getContractedDeliveryCapacityKw(), 400.0)
}
}
18 changes: 13 additions & 5 deletions zummon/src/commonMain/kotlin/companysurvey/Electricity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data class Electricity (
fun getHasConnection(): Boolean {
return hasConnection ?: false
}

/**
* Contracted capacity for delivery of electricity from grid to company.
*/
Expand All @@ -54,14 +54,22 @@ data class Electricity (
}
}

fun getContractedDeliveryCapacityKw(): Double? {
return when (kleinverbruikOrGrootverbruik) {
KleinverbruikOrGrootverbruik.GROOTVERBRUIK -> grootverbruik?.contractedConnectionDeliveryCapacity_kW?.toDouble()
KleinverbruikOrGrootverbruik.KLEINVERBRUIK -> kleinverbruik?.connectionCapacity?.toKw()
else -> kleinverbruik?.connectionCapacity?.toKw() ?: grootverbruik?.contractedConnectionDeliveryCapacity_kW?.toDouble()
}
}

/**
* Contracted capacity for feed-in of electricity from company to grid.
*/
fun getContractedFeedInCapacityKw(): Double? {
when (kleinverbruikOrGrootverbruik) {
KleinverbruikOrGrootverbruik.GROOTVERBRUIK -> return grootverbruik?.contractedConnectionFeedInCapacity_kW?.toDouble()
KleinverbruikOrGrootverbruik.KLEINVERBRUIK -> return kleinverbruik?.connectionCapacity?.toKw()
else -> return kleinverbruik?.connectionCapacity?.toKw() ?: grootverbruik?.contractedConnectionFeedInCapacity_kW?.toDouble()
return when (kleinverbruikOrGrootverbruik) {
KleinverbruikOrGrootverbruik.GROOTVERBRUIK -> grootverbruik?.contractedConnectionFeedInCapacity_kW?.toDouble()
KleinverbruikOrGrootverbruik.KLEINVERBRUIK -> kleinverbruik?.connectionCapacity?.toKw()
else -> kleinverbruik?.connectionCapacity?.toKw() ?: grootverbruik?.contractedConnectionFeedInCapacity_kW?.toDouble()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions zummon/src/commonMain/kotlin/companysurvey/TimeSeries.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ data class TimeSeries (
return maxNullSequence
}

fun getPeak(): DataPoint = DataPoint(values.max(), unit, timeStep)

/**
* Get a full calendar year of data if it is present.
Expand Down
29 changes: 19 additions & 10 deletions zummon/src/commonMain/kotlin/companysurvey/Validation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ class GridConnectionValidator : Validator<GridConnection> {
gridConnection.transport.vans.powerPerChargePointKw
).map { (it ?: 0).toFloat() }.sum()

val contractedCapacity = (gridConnection.electricity.getContractedConnectionCapacityKw() ?: 0.0).toFloat()
val contractedCapacity = (gridConnection.electricity.getContractedDeliveryCapacityKw() ?: 0.0).toFloat()
val batteryPower = (gridConnection.storage.batteryPowerKw ?: 0.0).toFloat()

return if (totalPowerChargePoints < (contractedCapacity + batteryPower)) {
listOf(ValidationResult(Status.VALID, translate("gridConnection.totalPowerChargePoints")))
listOf(ValidationResult(Status.VALID, translate("gridConnection.totalPowerChargePointsValid")))
} else {
listOf(ValidationResult(Status.INVALID, translate("gridConnection.totalPowerChargePointsInvalid", totalPowerChargePoints, contractedCapacity + batteryPower)))
}
Expand Down Expand Up @@ -235,7 +235,7 @@ class ElectricityValidator : Validator<Electricity> {

// Validator for contracted delivery capacity <= physical capacity
fun validateContractedCapacity(electricity: Electricity): ValidationResult {
val contractedCapacity = electricity.getContractedConnectionCapacityKw()
val contractedCapacity = electricity.getContractedDeliveryCapacityKw()
val physicalCapacity = electricity.getPhysicalConnectionCapacityKw()

return when {
Expand Down Expand Up @@ -289,7 +289,12 @@ class ElectricityValidator : Validator<Electricity> {
} ?: false

if (isCloseEnough) {
ValidationResult(Status.VALID, translate("electricity.annualFeedInValid", electricity.annualElectricityFeedIn_kWh, totalQuarterHourlyFeedIn))
ValidationResult(
Status.VALID, message(
nl = "Jaarwaarde teruglevering ${electricity.annualElectricityFeedIn_kWh} kWh komt overeen met het totaal van de kwartierwaarden ${totalQuarterHourlyFeedIn} kWh",
en = "Annual feed-in of ${electricity.annualElectricityFeedIn_kWh} kWh matches total of quarter-hourly feed-in ${totalQuarterHourlyFeedIn} kWh",
)
)
} else {
ValidationResult(Status.INVALID, translate("electricity.annualFeedInMismatch", electricity.annualElectricityFeedIn_kWh, totalQuarterHourlyFeedIn))
}
Expand Down Expand Up @@ -366,7 +371,10 @@ class ElectricityValidator : Validator<Electricity> {
nl = "Peak of quarter-hourly delivery ${peakDelivery.kWh()} kWh does not exceed contracted capacity ${contractedCapacity_kW} kW",
))
} else {
ValidationResult(Status.INVALID, translate("electricity.quarterHourlyDeliveryHighContractedCapacityKw", contractedCapacity))
ValidationResult(Status.INVALID, message(
nl = "Piek van kwartierwaarden levering ${peakDelivery.kWh()} kWh mag niet hoger zijn dan gecontracteerd vermogen levering ${contractedCapacity_kW} kW",
en = "Peak of quarter-hourly ${peakDelivery.kWh()} kWh delivery should be below contracted capacity ${contractedCapacity_kW} Kw",
))
}
}

Expand Down Expand Up @@ -569,7 +577,12 @@ class TransportValidator {
fun validateTotalElectricVans(transport: Transport): ValidationResult {
return when {
((transport.vans.numElectricVans ?: 0) > (transport.vans.numVans ?: 0)) -> ValidationResult(Status.INVALID, translate("transport.electricVansInvalid", transport.vans.numElectricVans, transport.vans.numVans))
else -> ValidationResult(Status.VALID, translate("transport.electricVansValid"))
else -> ValidationResult(
Status.VALID, message(
en = "Number of electric vans does not exceed the total number of Vans",
nl = "Aantal elektrische bestelwagens valt binnen het totale aantal bestelwagens"
)
)
}
}
}
Expand Down Expand Up @@ -698,11 +711,7 @@ val translations: Map<Language, Map<String, Map<String, String>>> = mapOf(
"electricTrucksValid" to "Number of Electric Trucks is lower than the total of Trucks",
"electricTrucksInvalid" to "Number of electric trucks %d exceeds the total number of trucks %d",

"electricVansValid" to "Number of Electric Vans is lower than the total of Vans",
"electricVansInvalid" to "Number of electric vans %d exceeds the total number of vans %d",

"quarterHourlyDeliveryLowContractedCapacityKw" to "Kwartuur levering blijft lager dan de Contractuele CapaciteitKw (%d)",
"quarterHourlyDeliveryHighContractedCapacityKw" to "Kwartuur levering mag niet hoger zijn dan de Contractuele CapaciteitKw (%d)",
),
),
Language.nl to mapOf(
Expand Down

0 comments on commit 61cf74f

Please sign in to comment.