Skip to content

Commit 5a4c68c

Browse files
author
Adrian Immel
committed
Fixed percent not in decimals and wayting 2 min befor fetching data from LRZ
1 parent a356b96 commit 5a4c68c

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package app.betterhm.backend.v1.models.capacity;
22

3-
public record CapacityApiElement(String enum_name, int clients, int percentage, String updated) {}
3+
public record CapacityApiElement(String enum_name, int clients, double percentage, String updated) {}

src/main/java/app/betterhm/backend/v1/models/capacity/LrzJsonAccesspoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public record LrzJsonAccesspoint(String target, ArrayList<ArrayList<Integer>> da
88
* @return Connected devices from index datapoint
99
*/
1010
public Integer getConnectedDevices(int index) {
11-
Integer returnvalue = datapoints.get(index).get(0);
11+
Integer returnvalue = datapoints.get(index).getFirst();
1212
return returnvalue == null ? 0: returnvalue;
1313
}
1414
/**

src/main/java/app/betterhm/backend/v1/services/CapacityService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public CapacityApiElement getSingleCapacityElement(String enum_nameToFind){
5555
}
5656

5757
/**
58-
* Method to update the Capacity Elements every 5 Minutes
58+
* Method to update the Capacity Elements every 5 Minutes (in the 59th second of the 5th minute)
5959
*/
60-
@Scheduled(cron = "0 */5 * * * *")
60+
@Scheduled(cron = "0 2-59/5 * ? * *")
6161
public void updateCapacity(){
6262
List<CapacityApiElement> newElementList = new ArrayList<>();
6363
capacityConfigRecordList.forEach(Element -> newElementList.add(getUpdatedCapacityElement(Element)));
@@ -83,10 +83,10 @@ private CapacityApiElement getUpdatedCapacityElement(CapacityConfigRecord capaci
8383
}
8484

8585

86-
int capacityLevelInPercent = (clients / capacityConfigRecord.static_max_clients());
86+
double capacityLevelInPercent = ((double) (clients * 100 / capacityConfigRecord.static_max_clients())/100); // calculates the capacity level in percent with 2 decimal places
8787
//filter out everything over "100%"
88-
if(capacityLevelInPercent > 1){
89-
capacityLevelInPercent = 1;
88+
if(capacityLevelInPercent > 1.0){
89+
capacityLevelInPercent = 1.0;
9090
}
9191

9292
return new CapacityApiElement(capacityConfigRecord.enum_name(), clients, capacityLevelInPercent, timestamp.toString());

0 commit comments

Comments
 (0)