Skip to content

Commit

Permalink
tare for both boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanSST committed Sep 29, 2023
1 parent 79b418a commit 74f4106
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ This code will run on a Raspberry PI in a chicken barn. There are scales under t
* Story: switch to feign client
* Story: fix disabled test
* Story: Integration test with whole process (testing)
* Story: maybe distinct discovey result

* Story: (done) tare for both boxes
* Story: (done) maybe distinct discovey result
* Story: (done) keep state of box to prevent multiple messages
* Story: (done) using Lombok to log
* Story: (done) respect both boxes in Schedule
Expand All @@ -33,6 +34,7 @@ This code will run on a Raspberry PI in a chicken barn. There are scales under t


### Epic v2: Recognize chicken
* Story: UI for all webservices
* Story: connect load cell UID with box number
* Story: persist chicken weight, box weight, uid-box-mapping to file
* Story: manage chickens and box
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class MeasureController {
private static final String EMPTY_STRING = "";
private static final String MEASURE = "Weight of box %s (%s) is %s";
private static final String CALIBRATE = "Calibrated box %s, result: %s.";
private static final String TARE = "Tared box %s, result: %s.";
private static final String TARE = "Tared box %s, result: %s";

private final AtomicLong counter = new AtomicLong();

Expand Down Expand Up @@ -51,7 +51,14 @@ public Message calibrate(@RequestParam(value = "uid") String uid) {

@GetMapping("/tare")
public Message tare(@RequestParam(value = "uid") String uid) {
return new Message(counter.incrementAndGet(), String.format(TARE, uid, scaleService.tare(uid)));
String message = boxService.getBoxes().stream()//
.filter(b -> uid == null || b.getId().equals(uid))//
.map(b -> {
String result = scaleService.tare(b.getId());
return String.format(TARE, b.getId(), b.getDescription(), result);
})//
.collect(Collectors.joining(COMMA, EMPTY_STRING, POINT));
return new Message(counter.incrementAndGet(), message);
}

@GetMapping("/send")
Expand Down

0 comments on commit 74f4106

Please sign in to comment.