Skip to content
Snippets Groups Projects
Verified Commit 8ba372c9 authored by Réthelyi Bálint's avatar Réthelyi Bálint :no_mouth:
Browse files

add lastChanged feature

parent 9ff49bbc
No related branches found
No related tags found
No related merge requests found
Pipeline #19774 passed
......@@ -10,7 +10,6 @@ import java.util.*
data class Machine(
var id: Int = 0,
var kindOf: Kind = Kind.Unknown,
var status: Status = Status.LostInSpace,
var lastQueryTime: Instant = Clock.System.now(),
var lastChanged: Instant = Clock.System.now(),
val power: MutableList<Int> = mutableListOf(),
......@@ -29,18 +28,33 @@ enum class Kind {
Unknown,
}
fun Machine.addPower(newPower: Int) {
power += newPower
val Machine.status: Status get() {
var averagePower = 0
power.forEach { p -> averagePower += p
power.forEach { p ->
averagePower += p
}
averagePower /= power.size
status = if (averagePower > threshold) {
return if (averagePower > threshold) {
Status.NotAvailable
} else {
Status.Available
}
}
fun Machine.addPower(newPower: Int) {
val oldStatus = status
power += newPower
var averagePower = 0
power.forEach { p ->
averagePower += p
}
averagePower /= power.size
if (status != oldStatus) {
lastChanged = Clock.System.now()
}
if (power.size > 1000) {
power -= power.first()
......
......@@ -28,9 +28,13 @@ object UDPListener {
val floor = floors[level] ?: Floor()
floor.id = level
if (floor.machines.isNotEmpty()) {
floor.machines.forEach() { machine ->
if (machine.kindOf == Kind.Dryer) machine.addPower(dryerPower)
else machine.addPower(washerPower) }
floor.machines.forEach { machine ->
when (machine.kindOf) {
Kind.Dryer -> machine.addPower(dryerPower)
Kind.Washer -> machine.addPower(washerPower)
else -> throw Error("Enum value not implemented")
}
}
} else {
val dryer = Machine(
id = level * 100 + 1,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment