-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tutorial with exercises #6
base: exercises
Are you sure you want to change the base?
Changes from all commits
18c997d
6be2651
a588c8c
8ffe6c3
1a268a1
237a080
41748f2
93730e4
d6bd22c
96a3716
15a584b
2515c3d
a40e493
1df9086
0ba42c3
5d0c018
5f01840
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,14 +12,53 @@ | |
import java.util.Iterator; | ||
|
||
public class UnitAgent extends AbstractAgent { | ||
|
||
// TODO: implement new Value Lane(s) for stats | ||
|
||
// HINT: start by declaring @SwimLane("name") | ||
// HINT: Use the valueLane() method to instantiate the lane | ||
// HINT: Use the .didSet() lifecycle callback to log a message showing updates to stats | ||
|
||
|
||
// consider creating more value lanes for stats with single values such as | ||
// @SwimLane("avg") | ||
// private final ValueLane<Long> avg = this.<Long>valueLane() | ||
|
||
|
||
// you may also prefer one value lane with more than one statistic stored as a Value | ||
// @SwimLane("stats") | ||
// private final ValueLane<Value> stats = this.<Value>valueLane() | ||
|
||
@SwimLane("histogram") | ||
private final MapLane<Long, Value> histogram = this.<Long, Value>mapLane() | ||
.didUpdate((k, n, o) -> { | ||
logMessage("histogram: replaced " + k + "'s value to " + Recon.toString(n) + " from " + Recon.toString(o)); | ||
|
||
// TODO: update stats with update logic | ||
|
||
// HINT: access new data sent to histogram with | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's replace this with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if the comments from (41-48) get too overwhelming. If so, I can remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually like the RECOMMENDED and ALTERNATIVELY! |
||
|
||
// RECOMMENDED, to get a value by specifying its key: | ||
// n.get("count").longValue() | ||
|
||
// ALTERNATIVELY, to get the first Item slot (equivalent result here as ^): | ||
// n.getItem(0).longValue() | ||
|
||
|
||
// HINT: use this data to calculate stats such as mean, variance, std dev, etc | ||
|
||
|
||
// HINT: send new data to stats lane by calling | ||
// stats.set($TRANSFORMED_DATA) | ||
|
||
dropOldData(); | ||
|
||
@SwimLane("histogram") | ||
private final MapLane<Long, Value> histogram = this.<Long, Value>mapLane() | ||
.didUpdate((k, n, o) -> { | ||
logMessage("histogram: replaced " + k + "'s value to " + Recon.toString(n) + " from " + Recon.toString(o)); | ||
dropOldData(); | ||
}); | ||
}) | ||
.didRemove((k,o) -> { | ||
// TODO: update stats with remove logic | ||
|
||
}); | ||
|
||
@SwimLane("history") | ||
private final ListLane<Value> history = this.<Value>listLane() | ||
.didUpdate((idx, newValue, oldValue) -> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding some hints for intermediary statistic lanes here-ish would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully the following comments (lines 23-30) better explain one's options for how to implement lanes. (Let me know if the wording can be made clearer.)