Repository navigation
Expand file tree
/
Copy pathStatistics.java
More file actions
106 lines (85 loc) · 4.01 KB
/
Copy pathStatistics.java
File metadata and controls
106 lines (85 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package Codes;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Statistics {
// Statistics data
private int totalPlanesServed = 0;
private long totalPassengersBoarded = 0;
private final long startTime;
private final List<Long> waitingTimes = Collections.synchronizedList(new ArrayList<>());
public Statistics(long startTime) {
this.startTime = startTime;
}
// Record a plane served
//@param embarkingPassengers This plane's embarking passengers
public synchronized void logPlaneServed(int embarkingPassengers) {
totalPlanesServed++;
totalPassengersBoarded += embarkingPassengers;
}
// Record a waiting time
// @param waitTimeMs Waiting time (ms)
public void logWaitingTime(long waitTimeMs) {
waitingTimes.add(waitTimeMs);
}
//print final report
//@param aircraftOnGround Current number of aircraft on the ground
//@param gates All gate objects
public void printFinalReport(int aircraftOnGround, Gate[] gates) {
System.out.println("\n");
System.out.println("----------FINAL SIMULATION REPORT----------");
// Check system integrity
System.out.println("\n- - - - -Sanity Checks- - - - -");
boolean allGatesEmpty = true;
for (Gate gate : gates) {
if (!gate.isAvailable()) {
allGatesEmpty = false;
break;
}
}
boolean groundsEmpty = (aircraftOnGround == 0);
if (allGatesEmpty) {
System.out.println("All gates are empty. [OK]");
} else {
System.out.println("ERROR: Some gates are still occupied!");
for (Gate gate : gates) {
System.out.println(" " + gate.toString());
}
}
if (groundsEmpty) {
System.out.println("Airport grounds are empty. [OK]");
} else {
System.out.println("ERROR: " + aircraftOnGround + " aircraft still on the grounds!");
}
if (allGatesEmpty && groundsEmpty) {
System.out.println("System integrity verified. No resource leaks detected.");
} else {
System.out.println("WARNING: System integrity check failed!");
}
// Performance statistics
System.out.println("\n- - - - -Performance Statistics- - - - - ");
System.out.println(" - Total planes served: " + totalPlanesServed);
System.out.println(" - Total passengers boarded: " + totalPassengersBoarded);
// waiting time statistics
if (waitingTimes.isEmpty()) {
System.out.println("\n- - - - -Landing Wait Times- - - - -");
System.out.println(" - No planes waited for landing (all landed immediately).");
} else {
long minWait = Collections.min(waitingTimes);
long maxWait = Collections.max(waitingTimes);
double avgWait = waitingTimes.stream()
.mapToLong(Long::longValue)
.average()
.orElse(0.0);
System.out.println("\n- - - - -Landing Wait Times- - - - -");
System.out.println(" (Time from 'request landing' to 'permission granted')");
System.out.println(String.format(" - Minimum waiting time: %.2f s", minWait / 1000.0));
System.out.println(String.format(" - Average waiting time: %.2f s", avgWait / 1000.0));
System.out.println(String.format(" - Maximum waiting time: %.2f s", maxWait / 1000.0));
}
// Total runtime
long totalElapsed = System.currentTimeMillis() - this.startTime;
System.out.println(String.format("\nTotal simulation runtime: %.2f s", totalElapsed / 1000.0));
System.out.println("\n------------------------------\n");
}
}