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 11d5609 commit 84af1aa
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 37 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)
}
}
30 changes: 15 additions & 15 deletions zummon/src/commonMain/kotlin/companysurvey/Electricity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,28 @@ data class Electricity (
fun getHasConnection(): Boolean {
return hasConnection ?: false
}
fun getContractedConnectionCapacityKw(): Double? {
when(kleinverbruikOrGrootverbruik) {
KleinverbruikOrGrootverbruik.GROOTVERBRUIK -> return grootverbruik?.contractedConnectionDeliveryCapacity_kW?.toDouble()
KleinverbruikOrGrootverbruik.KLEINVERBRUIK -> return kleinverbruik?.connectionCapacity?.toKw()
else -> return kleinverbruik?.connectionCapacity?.toKw() ?: grootverbruik?.contractedConnectionDeliveryCapacity_kW?.toDouble()

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

fun getPhysicalConnectionCapacityKw(): Double? {
when(kleinverbruikOrGrootverbruik) {
KleinverbruikOrGrootverbruik.GROOTVERBRUIK -> return grootverbruik?.physicalCapacityKw?.toDouble()
KleinverbruikOrGrootverbruik.KLEINVERBRUIK -> return kleinverbruik?.connectionCapacity?.toKw()
else -> return kleinverbruik?.connectionCapacity?.toKw() ?: grootverbruik?.physicalCapacityKw?.toDouble()
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()
}
}

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
28 changes: 28 additions & 0 deletions zummon/src/commonMain/kotlin/companysurvey/TimeSeries.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlinx.datetime.Instant
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import kotlin.js.JsExport
import kotlin.time.Duration.Companion.hours


/**
Expand Down Expand Up @@ -76,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 Expand Up @@ -166,3 +168,29 @@ enum class TimeSeriesType {
ELECTRICITY_PRODUCTION,
GAS_DELIVERY,
}

/**
* Represents a single point within the time series.
* Improvement: add timestamp
*/
data class DataPoint (
val value: Float,
val unit: TimeSeriesUnit,
val timeStep: kotlin.time.Duration,
) {
fun kWh(): Double {
if (this.unit != TimeSeriesUnit.KWH) {
throw UnsupportedOperationException("Can only get the kWh from a kWh data point")
}

return value.toDouble()
}

fun kW(): Double {
if (this.unit != TimeSeriesUnit.KWH) {
throw UnsupportedOperationException("Can only get the kW from a kWh data point")
}

return value * (this.timeStep / 1.hours)
}
}
62 changes: 42 additions & 20 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 @@ -339,14 +344,35 @@ class ElectricityValidator : Validator<Electricity> {
}
}

//peak of delivery should be less than contracted capacity
// peak of delivery should be less than contracted capacity
fun quarterHourlyDeliveryLowContractedCapacity(electricity: Electricity): ValidationResult {
val contractedCapacity = (electricity.getContractedConnectionCapacityKw() ?: 0.0).toFloat()
val pickDelivery = electricity.quarterHourlyDelivery_kWh?.values?.maxOrNull() ?: Float.MIN_VALUE
return if ( pickDelivery <= contractedCapacity) {
ValidationResult(Status.VALID, translate("electricity.quarterHourlyDeliveryLowContractedCapacityKw", contractedCapacity))
val contractedCapacity_kW = electricity.getContractedDeliveryCapacityKw()
if (contractedCapacity_kW == null) {
return ValidationResult(Status.MISSING_DATA, message(
en = "Gecontracteerd vermogen levering ontbreek",
nl = "Contracted delivery capacity missing",
))
}

if (electricity.quarterHourlyDelivery_kWh == null) {
return ValidationResult(Status.MISSING_DATA, message(
en = "Kwartierwaarden levering ontbreek",
nl = "Quarter-hourly delivery missing",
))
}

val peakDelivery = electricity.quarterHourlyDelivery_kWh.getPeak()

return if ( peakDelivery.kW() <= contractedCapacity_kW) {
ValidationResult(Status.VALID, message(
en = "Piek van kwartierwaarden levering ${peakDelivery.kWh()} kWh valt binnen gecontracteerd vermogen levering ${contractedCapacity_kW} kW",
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 @@ -528,7 +554,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 @@ -594,11 +625,6 @@ val translations: Map<Language, Map<String, Map<String, String>>> = mapOf(
// quarter
"notEnoughValues" to "Not enough values for year: needed %d got %d",
"annualFeedInMismatch" to "Annual feed in (%d) mismatch the total quarter hourly feed in (%d)",
"annualFeedInMismatch" to "Annual feed in (%d) matches the total quarter hourly feed in (%d)",

"quarterHourlyDeliveryLowContractedCapacityKw" to "Quarter-hourly stays lower than the Contracted CapacityKw (%d)",
"quarterHourlyDeliveryHighContractedCapacityKw" to "Quarter-hourly shouldn't go higher than the Contracted CapacityKw (%d)"

),
"grootverbruik" to mapOf(
"notProvided" to "Large consumption data is not provided",
Expand Down Expand Up @@ -661,11 +687,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 84af1aa

Please sign in to comment.