@@ -3,7 +3,6 @@ package nu.local4local.common
33import kotlinx.serialization.Serializable
44import kotlinx.serialization.json.Json
55import kotlinx.serialization.encodeToString
6- import kotlin.js.ExperimentalJsExport
76import kotlin.js.JsExport
87import kotlin.math.roundToInt
98
@@ -24,38 +23,29 @@ data class Pilot(
2423 val bufferPrice_eurpkWh
2524 get() = supplierCost.bufferPrice_eurpkWh
2625
27- // Create
28- fun create (asset : AssetType ): Pilot = when (asset) {
29- is HouseholdGroup -> copy(householdGroups = this .householdGroups + asset)
30- is SolarFarm -> copy(solarFarms = this .solarFarms + asset)
31- is WindFarm -> copy(windFarms = this .windFarms + asset)
32- is Battery -> copy(batteries = this .batteries + asset)
33- is HeatStorage -> copy(heatStorages = this .heatStorages + asset)
34- is BiogasGenerator -> copy(biogasGenerators = this .biogasGenerators + asset)
35- else -> throw Exception (" Unknown type" )
36- }
37-
38- // Delete
39- fun remove (asset : AssetType ): Pilot = when (asset) {
40- is HouseholdGroup -> copy(householdGroups = this .householdGroups - asset)
41- is SolarFarm -> copy(solarFarms = this .solarFarms - asset)
42- is WindFarm -> copy(windFarms = this .windFarms - asset)
43- is Battery -> copy(batteries = this .batteries - asset)
44- is HeatStorage -> copy(heatStorages = this .heatStorages - asset)
45- is BiogasGenerator -> copy(biogasGenerators = this .biogasGenerators - asset)
46- else -> throw Exception (" Unknown type" )
47- }
26+ fun addHouseHoldGroup (householdGroup : HouseholdGroup ) = copy(householdGroups = householdGroups + householdGroup)
27+ fun addCompany (company : Company ) = copy(companies = companies + company)
28+ fun addSolarFarm (solarFarm : SolarFarm ) = copy(solarFarms = solarFarms + solarFarm)
29+ fun addWindFarm (windFarm : WindFarm ) = copy(windFarms = windFarms + windFarm)
30+ fun addBattery (battery : Battery ) = copy(batteries = batteries + battery)
31+ fun addHeatStorage (heatStorage : HeatStorage ) = copy(heatStorages = heatStorages + heatStorage)
32+ fun addBiogasGenerator (biogasGenerator : BiogasGenerator ) = copy(biogasGenerators = biogasGenerators + biogasGenerator)
4833
49- // Generalized replace function
50- fun replaceAsset (newAsset : AssetType , index : Int ,): Pilot = when (newAsset) {
51- is HouseholdGroup -> copy(householdGroups = householdGroups.replaceAt(index, newAsset))
52- is SolarFarm -> copy(solarFarms = solarFarms.replaceAt(index, newAsset))
53- is WindFarm -> copy(windFarms = windFarms.replaceAt(index, newAsset))
54- is Battery -> copy(batteries = batteries.replaceAt(index, newAsset))
55- is HeatStorage -> copy(heatStorages = heatStorages.replaceAt(index, newAsset))
56- is BiogasGenerator -> copy(biogasGenerators = biogasGenerators.replaceAt(index, newAsset))
57- else -> throw Exception (" Unknown type" )
58- }
34+ fun removeHouseholdGroup (householdGroup : HouseholdGroup ) = copy(householdGroups = this .householdGroups - householdGroup)
35+ fun removeCompany (company : Company ) = copy(companies = companies - company)
36+ fun removeSolarFarm (solarFarm : SolarFarm ) = copy(solarFarms = this .solarFarms - solarFarm)
37+ fun removeWindFarm (windFarm : WindFarm ) = copy(windFarms = this .windFarms - windFarm)
38+ fun removeBattery (battery : Battery ) = copy(batteries = this .batteries - battery)
39+ fun removeHeatStorage (heatStorage : HeatStorage ) = copy(heatStorages = this .heatStorages - heatStorage)
40+ fun removeBiogasGenerator (biogasGenerator : BiogasGenerator ) = copy(biogasGenerators = this .biogasGenerators - biogasGenerator)
41+
42+ fun replaceHouseholdGroup (householdGroup : HouseholdGroup , index : Int ) = copy(householdGroups = householdGroups.replaceAt(index, householdGroup))
43+ fun replaceSolarFarm (solarFarm : SolarFarm , index : Int ) = copy(solarFarms = solarFarms.replaceAt(index, solarFarm))
44+ fun replaceWindFarm (windFarm : WindFarm , index : Int ) = copy(windFarms = windFarms.replaceAt(index, windFarm))
45+ fun replaceBattery (battery : Battery , index : Int ) = copy(batteries = batteries.replaceAt(index, battery))
46+ fun replaceHeatStorage (heatStorage : HeatStorage , index : Int ) = copy(heatStorages = heatStorages.replaceAt(index, heatStorage))
47+ fun replaceBiogasGenerator (biogasGenerator : BiogasGenerator , index : Int ) = copy(biogasGenerators = biogasGenerators.replaceAt(index, biogasGenerator))
48+ fun replaceCompany (old : Company , new : Company ) = copy(companies = companies.replace(old, new))
5949
6050 // Extension function for List replacement
6151 private fun <T > List<T>.replaceAt (index : Int , newValue : T ): List <T > {
@@ -67,12 +57,6 @@ data class Pilot(
6757
6858 fun withSupplierCost (supplierCost : SupplierCost ) = copy(supplierCost = supplierCost)
6959
70- fun addCompany (company : Company ) = copy(companies = companies + company)
71-
72- fun removeCompany (company : Company ) = copy(companies = companies - company)
73-
74- fun replaceCompany (old : Company , new : Company ) = copy(companies = companies.replace(old, new))
75-
7660 fun toJson (): String =
7761 Json .encodeToString(this )
7862}
@@ -104,10 +88,6 @@ data class SupplierCost (
10488 val feedInCompensation_eurpkWh : Double = 0.00 ,
10589)
10690
107- @JsExport
108- @Serializable
109- sealed interface AssetType
110-
11191@JsExport
11292@Serializable
11393data class AssetCost (
@@ -131,7 +111,7 @@ data class HouseholdGroup(
131111 val hasHomeBattery_r : Double ,
132112 /* *Jaarlijks gemiddeld basisverbruik zonder warmtepomp, elektrische voertuigen en zonnepanelen */
133113 val annualBaseConsumptionAvg_kWh : Double ,
134- ): AssetType {
114+ ) {
135115 fun hasPV_n () = (hasPV_r * households_n).roundToInt()
136116 fun hasHeatPump_n () = (hasHeatPump_r * households_n).roundToInt()
137117 fun hasChargePoint_n () = (hasChargePoint_r * households_n).roundToInt()
@@ -178,29 +158,29 @@ data class SolarFarm(
178158 val nominalPower_kW : Double ,
179159 val orientation : PVOrientation = PVOrientation .SOUTH ,
180160 val cost : AssetCost ,
181- ): AssetType
161+ )
182162
183163@JsExport
184164@Serializable
185165data class BiogasGenerator (
186166 val power_kW : Double ,
187167 val cost : AssetCost ,
188- ): AssetType
168+ )
189169
190170@JsExport
191171@Serializable
192172data class WindFarm (
193173 val nominalPower_kW : Double ,
194174 val cost : AssetCost ,
195- ): AssetType
175+ )
196176
197177@JsExport
198178@Serializable
199179data class Battery (
200180 val capacity_kWh : Double ,
201181 val peakPower_kW : Double ,
202182 val cost : AssetCost ,
203- ): AssetType
183+ )
204184
205185@JsExport
206186@Serializable
@@ -210,7 +190,7 @@ data class HeatStorage(
210190 val minTemp_degC : Double ,
211191 val maxTemp_degC : Double ,
212192 val cost : AssetCost ,
213- ): AssetType {
193+ ) {
214194 fun getCapacity_kWh (): Double {
215195 val specificHeatCapacity = 4.18 // kJ/kg/K
216196
0 commit comments