From 533dd4db1459f86870cb1d0e90c7876ef32ea946 Mon Sep 17 00:00:00 2001 From: ThibClnt Date: Fri, 19 Jan 2024 23:57:20 +0100 Subject: [PATCH] redo consumption types --- src/main/scala/Types.scala | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/main/scala/Types.scala b/src/main/scala/Types.scala index 049a5a2..7c72fdb 100644 --- a/src/main/scala/Types.scala +++ b/src/main/scala/Types.scala @@ -48,6 +48,38 @@ object Types { implicit val GWOrdering: Ordering[GW] = (x: GW, y: GW) => x.toFloat compare y.toFloat } + object Consumption { + type kWh = Float + type MWh = Float + type GWh = Float + + object kWh { + def apply(value: Float): kWh = value + def toMWh(value: kWh): MWh = value / 1000 + def toGWh(value: kWh): GWh = value / 1000000 + } + + object MWh { + def apply(value: Float): MWh = value + def tokWh(value: MWh): kWh = value * 1000 + def toGWh(value: MWh): GWh = value / 1000 + } + + object GWh { + def apply(value: Float): GWh = value + def tokWh(value: GWh): kWh = value * 1000000 + def toMWh(value: GWh): MWh = value * 1000 + } + + given Conversion[Float, kWh] = kWh(_) + given Conversion[Float, MWh] = MWh(_) + given Conversion[Float, GWh] = GWh(_) + + implicit val kWhOrdering: Ordering[kWh] = (x: kWh, y: kWh) => x.toFloat compare y.toFloat + implicit val MWhOrdering: Ordering[MWh] = (x: MWh, y: MWh) => x.toFloat compare y.toFloat + implicit val GWhOrdering: Ordering[GWh] = (x: GWh, y: GWh) => x.toFloat compare y.toFloat + } + object Temperature { type Celsius = Float