-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHome.java
More file actions
165 lines (120 loc) · 5.27 KB
/
Copy pathHome.java
File metadata and controls
165 lines (120 loc) · 5.27 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package dashboard;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Home {
private static final String FILE_SEPARATOR = File.separator;
public static void page() {
CodeUtil.clearScreen();
announcements();
System.out.println("\n");
tasks();
System.out.println("\n");
displayServerStatsGraph();
System.out.println("\n");
displayStatuses();
//Waiting for user input to move forward:
System.out.print("\nPress any key to go to the Navigation page...");
waitForUserInput();
Navigation.navbar();
}
private static void waitForUserInput() {
try {
System.in.read();
} catch (IOException e) {
System.out.println("Error while waiting for user input: " + e.getMessage());
}
}
//Shows announcements from the file:
public static void announcements(){
String path = null;
try {
path = new File(".").getCanonicalPath();
} catch (IOException e) {
System.out.println("Error: while getting the path of the program.");
}
System.out.println("Recent Announcements:\n");
File announcementsFile = new File(path + FILE_SEPARATOR + "dashboard" + FILE_SEPARATOR + "files"+ FILE_SEPARATOR + "announcements.txt");
try (BufferedReader reader = new BufferedReader(new FileReader(announcementsFile))) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (FileNotFoundException e) {
System.out.println("-");
} catch (IOException e) {
System.out.println("Error reading announcements file: " + e.getMessage());
}
}
//shows server statuses:
public static void displayStatuses() {
//Following code is for getting specific path to avoid future errors...
String path = null;
try {
path = new File(".").getCanonicalPath();
} catch (IOException e) {
System.out.println("Error: while getting the path of the program.");
}
System.out.println("Server Status:\n");
File statusesFile = new File(path + FILE_SEPARATOR + "dashboard" + FILE_SEPARATOR + "files" + FILE_SEPARATOR + "statuses.csv");
StatusData statusData = new StatusData();
statusData.load(statusesFile.getAbsolutePath());
StatusData[] statuses = statusData.getStatuses();
if (statuses != null && statuses.length > 0) {
// Displaying the titles with proper formatting:
System.out.printf("%-15s%-20s%-15s%-10s%-10s%-20s%-15s\n",
"ServerName", "ServerAddress", "CPUUsage", "Cycles", "IO", "LastUpdate", "ServerHealth");
// Displaying the data with proper formatting...
for (StatusData status : statuses) {
//used printf to get better option of displaying and spacing:
System.out.printf("%-15s%-20s%-15s%-10s%-10s%-20s%-15s\n",
status.getServerName(), status.getServerAddress(), status.getCpuUsage(),
status.getCycles(), status.getIo(), status.getLastUpdate(), status.getServerHealth());
}
} else {
System.out.println("No status data available.");
}
}
//shows a small graph by using '*':
public static void displayServerStatsGraph() {
String path = null;
try {
path = new File(".").getCanonicalPath();
} catch (IOException e) {
System.out.println("Error: while getting the path of the program.");
}
System.out.println("Server Statistics Bar Graph:\n");
File serverStatsFile = new File(path + FILE_SEPARATOR + "dashboard" + FILE_SEPARATOR + "files" + FILE_SEPARATOR + "monthstats.csv");
ServerStats serverStats = new ServerStats();
serverStats.load(serverStatsFile.getAbsolutePath());
ServerStats[] servers = serverStats.getServers();
if (servers != null && servers.length > 0) {
ServerStats.displayBarGraph(servers);
} else {
System.out.println("No server statistics available.");
}
}
//Shows assigned tasks:
public static void tasks(){
String path = null;
try {
path = new File(".").getCanonicalPath();
} catch (IOException e) {
System.out.println("Error: while getting the path of the program.");
}
System.out.println("Assigned to You:\n");
File assignmentsFile = new File(path + FILE_SEPARATOR + "dashboard" + FILE_SEPARATOR + "files"+ FILE_SEPARATOR + "assignments.txt");
try (BufferedReader reader = new BufferedReader(new FileReader(assignmentsFile))) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (FileNotFoundException e) {
System.out.println("-");
} catch (IOException e) {
System.out.println("Error reading assignments file: " + e.getMessage());
}
}
}