-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
110 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
from typing import Any, Callable | ||
|
||
from pydantic import BaseModel | ||
|
||
from mvp.server.core.constants import * | ||
from mvp.server.core.game.OperationalParameters import OperationalParameters | ||
from mvp.server.core.math_utils import constrain_from_0_to_100 | ||
|
||
|
||
def get_purchasable_sensors() -> set[str]: | ||
return {"temperature", "oil_age", "mechanical_wear"} | ||
|
||
|
||
def get_purchasable_predictions() -> set[str]: | ||
return {"predicted_rul"} | ||
|
||
|
||
class MachineState(BaseModel): | ||
predicted_rul: int | None = None | ||
health_percentage: float | ||
operational_parameters: OperationalParameters | ||
|
||
@staticmethod | ||
def new_machine_state() -> "MachineState": | ||
return MachineState( | ||
health_percentage=100, | ||
operational_parameters=OperationalParameters( | ||
temperature=TEMPERATURE_STARTING_POINT, | ||
oil_age=0, | ||
mechanical_wear=0 | ||
) | ||
) | ||
|
||
def update_parameters(self, timestep: int) -> None: | ||
self.operational_parameters.update(timestep) | ||
self.health_percentage = self.compute_health_percentage(timestep) | ||
|
||
def update_prediction(self, timestep: int, | ||
rul_predictor: Callable[[int, OperationalParameters, list[str]], int | None] = None, | ||
available_sensors: list[str] = None | ||
) -> None: | ||
self.predicted_rul = rul_predictor(timestep, self.operational_parameters, available_sensors) | ||
|
||
def compute_health_percentage(self, current_timestep: int) -> float: | ||
return self.operational_parameters.compute_health_percentage(current_timestep, self.health_percentage) | ||
|
||
def do_maintenance(self) -> None: | ||
self.operational_parameters = OperationalParameters( | ||
temperature=TEMPERATURE_STARTING_POINT, | ||
oil_age=0, | ||
mechanical_wear=self.operational_parameters.mechanical_wear / MECHANICAL_WEAR_REDUCTION_FACTOR_ON_MAINTENANCE | ||
) | ||
self.health_percentage = constrain_from_0_to_100(self.health_percentage * HEALTH_RECOVERY_FACTOR_ON_MAINTENANCE) | ||
|
||
def is_broken(self) -> bool: | ||
return self.health_percentage <= 0 | ||
|
||
@staticmethod | ||
def from_dict(json: dict[str, Any]) -> "MachineState": | ||
return MachineState( | ||
predicted_rul=json.get("predicted_rul", None), | ||
health_percentage=json.get("health_percentage", 0), | ||
operational_parameters=OperationalParameters.from_dict( | ||
json.get("operational_parameters", {}) | ||
) | ||
) | ||
|
||
def __str__(self) -> str: | ||
return (f"MachineState(predicted_rul={self.predicted_rul}, health_percentage={self.health_percentage}, " | ||
f"operational_parameters={self.operational_parameters})") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.