-
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.
Observer to receive data throughout the simulation. #14
- Loading branch information
1 parent
1c3ee0f
commit a7a4cdb
Showing
21 changed files
with
323 additions
and
264 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/// Enum representing the possible event phases. | ||
/// | ||
/// This enumeration is used to track and distinguish different event status | ||
/// during the lifecycle of the simulation. | ||
enum EventPhase { | ||
/// The event was called for the first time. | ||
called, | ||
|
||
/// The event was resumed after being paused. | ||
resumed, | ||
|
||
yielded, | ||
|
||
finished; | ||
|
||
/// Returns the string representation of the status. | ||
@override | ||
String toString() { | ||
return name; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -12,4 +12,7 @@ class CompleterAction extends TimeAction { | |
void execute() { | ||
complete.call(); | ||
} | ||
|
||
@override | ||
void dispose() {} | ||
} |
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 |
---|---|---|
|
@@ -14,4 +14,6 @@ abstract class TimeAction { | |
final int order; | ||
|
||
void execute(); | ||
|
||
void dispose(); | ||
} |
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,50 @@ | ||
import 'package:simdart/src/event_phase.dart'; | ||
|
||
/// A base class for observing simulation. | ||
abstract class SimObserver { | ||
/// Called when there is a change in resource usage. | ||
/// | ||
/// [name] - The name of the resource whose usage is being reported. | ||
/// [usage] - The percentage of resource usage, typically between 0 and 100. | ||
void onResourceUsage({required String name, required double usage}); | ||
|
||
/// Called when an event occurs in the simulation. | ||
/// | ||
/// [name] - The name of the event being processed. This can be null if the event does not have a name. | ||
/// [time] - The simulation time when the event occurred, usually in ticks or arbitrary units depending on the simulation. | ||
/// [phase] - The phase during which the event occurred. This helps categorize the event's context in the simulation lifecycle. | ||
/// [executionHash] - The hash of the event execution. | ||
void onEvent( | ||
{required String name, | ||
required int time, | ||
required EventPhase phase, | ||
required int executionHash}); | ||
|
||
void onStart() {} | ||
} | ||
|
||
mixin SimObserverMixin implements SimObserver { | ||
@override | ||
void onStart() {} | ||
@override | ||
void onResourceUsage({required String name, required double usage}) {} | ||
@override | ||
void onEvent( | ||
{required String name, | ||
required int time, | ||
required EventPhase phase, | ||
required int executionHash}) {} | ||
} | ||
|
||
class ConsoleEventObserver with SimObserverMixin { | ||
ConsoleEventObserver(); | ||
|
||
@override | ||
void onEvent( | ||
{required String name, | ||
required int time, | ||
required EventPhase phase, | ||
required int executionHash}) { | ||
print('[time:$time][event:$name][phase:${phase.name}]'); | ||
} | ||
} |
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.