-
-
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.
Add concrete transformations per hour metrics chart.
- Loading branch information
Showing
4 changed files
with
82 additions
and
4 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
55 changes: 55 additions & 0 deletions
55
src/main/java/community/leaf/survival/concretemixer/metrics/TransformationsPerHour.java
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,55 @@ | ||
/* | ||
* Copyright © 2022, RezzedUp and Contributors <https://github.com/LeafCommunity/ConcreteMixer> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package community.leaf.survival.concretemixer.metrics; | ||
|
||
import community.leaf.survival.concretemixer.Config; | ||
|
||
import java.time.Instant; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.Iterator; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
public class TransformationsPerHour | ||
{ | ||
private final Map<Instant, Integer> countersByMinute = new LinkedHashMap<>(); | ||
|
||
private final Config config; | ||
|
||
public TransformationsPerHour(Config config) | ||
{ | ||
this.config = config; | ||
} | ||
|
||
public void transformed(int totalPowderToConcrete) | ||
{ | ||
if (totalPowderToConcrete < 0) { throw new IllegalArgumentException(); } | ||
if (!config.getOrDefault(Config.METRICS)) { return; } | ||
|
||
Instant minute = Instant.now().truncatedTo(ChronoUnit.MINUTES); | ||
int counter = countersByMinute.computeIfAbsent(minute, k -> 0); | ||
countersByMinute.put(minute, counter + totalPowderToConcrete); | ||
} | ||
|
||
public int totalTransformationsInTheLastHour() | ||
{ | ||
int total = 0; | ||
Instant now = Instant.now(); | ||
Iterator<Map.Entry<Instant, Integer>> it = countersByMinute.entrySet().iterator(); | ||
|
||
while (it.hasNext()) | ||
{ | ||
Map.Entry<Instant, Integer> entry = it.next(); | ||
|
||
if (ChronoUnit.MINUTES.between(entry.getKey(), now) >= 60) { it.remove(); } | ||
else { total += entry.getValue(); } | ||
} | ||
|
||
return total; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/community/leaf/survival/concretemixer/metrics/package-info.java
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,11 @@ | ||
/* | ||
* Copyright © 2022, RezzedUp and Contributors <https://github.com/LeafCommunity/ConcreteMixer> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
@NonNullPackage | ||
package community.leaf.survival.concretemixer.metrics; | ||
|
||
import pl.tlinkowski.annotation.basic.NonNullPackage; |