-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* new branch after rebasing for evaluator module * update, moved module to task 1 * no diff in check_stop_condition * failed a check, reran tests
- Loading branch information
Showing
5 changed files
with
169 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
Abstract class for evaluating drone conditions | ||
""" | ||
|
||
import abc | ||
|
||
|
||
class Condition(abc.ABC): | ||
""" | ||
Wrapper for different classes to check conditions | ||
""" | ||
|
||
@abc.abstractmethod | ||
def evaluate_condition(self) -> bool: | ||
""" | ||
The appropriate evaluate method depending on the child | ||
""" | ||
|
||
@abc.abstractmethod | ||
def message(self) -> None: | ||
""" | ||
A message to output when the condition evalues to true | ||
""" |
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,36 @@ | ||
""" | ||
Module to evaluate multiple Evaluator objects | ||
""" | ||
|
||
from . import condition | ||
|
||
|
||
class ConditionEvaluator: | ||
""" | ||
Attributes: | ||
condition_list : A list of EvaluateCondition objects, representing all the | ||
conditions to evaluate | ||
""" | ||
|
||
def __init__(self, condition_list: "list[condition.Condition]") -> None: | ||
""" | ||
Constructor | ||
Parameters: | ||
condition_list : A list of EvaluateCondition objects, representing conditions | ||
to evaluate | ||
""" | ||
self.evaluate_object_list = condition_list | ||
|
||
def evaluate_all_conditions(self) -> bool: | ||
""" | ||
Runs all the evaluate objects. If any of the evaluations return true, evaluate_all outputs | ||
status messages to the console and returns true. | ||
""" | ||
evaluation = False | ||
for evaluate_object in self.evaluate_object_list: | ||
if evaluate_object.evaluate_condition(): | ||
evaluation = True | ||
evaluate_object.message() | ||
|
||
return evaluation |
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,69 @@ | ||
""" | ||
Checks whether the drone has reached its max flight time and sends it back to launch. | ||
""" | ||
|
||
import time | ||
|
||
from . import condition | ||
|
||
|
||
class MissionTimeCondition(condition.Condition): | ||
""" | ||
Checks if drone exceeds the maximum flight time limit, inherits from Evaluate class | ||
""" | ||
|
||
__create_key = object() | ||
|
||
@classmethod | ||
def create( | ||
cls, start_time: "float | None", maximum_flight_time: "float | None" | ||
) -> "tuple[bool, MissionTimeCondition | None]": | ||
""" | ||
start_time: float | ||
The time the drone started the mission in seconds. | ||
maximum_flight_time: float | ||
Max flight time for drone in seconds. | ||
""" | ||
if start_time is None: | ||
return False, None | ||
|
||
if maximum_flight_time is None: | ||
return False, None | ||
|
||
return True, MissionTimeCondition(cls.__create_key, start_time, maximum_flight_time) | ||
|
||
def __init__( | ||
self, class_private_create_key: object, start_time: float, maximum_flight_time: float | ||
) -> None: | ||
""" | ||
Private constructor, use create() method | ||
""" | ||
assert class_private_create_key is MissionTimeCondition.__create_key | ||
self.start_time = start_time | ||
self.maximum_flight_time = maximum_flight_time | ||
|
||
def evaluate_condition(self) -> bool: | ||
""" | ||
Evaluates whether the drone should land based on time remaining. | ||
""" | ||
current_time = time.time() | ||
if current_time - self.start_time < self.maximum_flight_time: | ||
return False | ||
|
||
return True | ||
|
||
def output_time_elapsed(self) -> None: | ||
""" | ||
Outputs the total time elapsed during the mission. | ||
""" | ||
current_time = time.time() | ||
print(f"Elapsed time (s): {current_time - self.start_time}") | ||
|
||
def message(self) -> None: | ||
""" | ||
Outputs status when the drone has exceeded the time limit. | ||
""" | ||
print("This mission has exceeded the maximum flight time limit.") | ||
print(f"Specified maximum flight time limit: {self.maximum_flight_time}") | ||
print(f"Mission start time: {self.start_time}") | ||
print(f"Time when condition was met: {time.time()}") |
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