-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
119 lines (99 loc) · 3.73 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Analytics Dashboard</title>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<h1>Analytics Dashboard</h1>
<div>
<h2>Check-ins and Check-outs by Hour</h2>
<div id="checkins-checkouts-plot"></div>
</div>
<div>
<h2>Total Leave Days by Department</h2>
<div id="department-leave-plot"></div>
</div>
<div>
<h2>Login Frequency by Day of the Week</h2>
<div id="login-frequency-plot"></div>
</div>
<script>
async function fetchCheckinsAndCheckouts() {
const response = await fetch('/api/analytics/today');
const data = await response.json();
// Create the plot with Plotly
const checkIns = data.check_ins; // Assume your API returns this structure
const checkOuts = data.check_outs;
const trace1 = {
x: Object.keys(checkIns),
y: Object.values(checkIns),
type: 'bar',
name: 'Check-ins',
marker: { color: 'green' }
};
const trace2 = {
x: Object.keys(checkOuts),
y: Object.values(checkOuts),
type: 'bar',
name: 'Check-outs',
marker: { color: 'blue' }
};
const layout = {
title: 'Check-ins and Check-outs by Hour of Day (Today)',
barmode: 'group',
xaxis: { title: 'Hour of Day' },
yaxis: { title: 'Number of Check-ins and Check-outs' }
};
Plotly.newPlot('checkins-checkouts-plot', [trace1, trace2], layout);
}
async function fetchDepartmentLeaveCounts() {
const response = await fetch('/api/analytics/department-leave');
const data = await response.json();
// Create the plot with Plotly
const departments = Object.keys(data);
const leaveCounts = Object.values(data);
const trace = {
x: leaveCounts,
y: departments,
type: 'bar',
orientation: 'h',
marker: { color: 'lightblue' }
};
const layout = {
title: 'Total Leave Days by Department',
xaxis: { title: 'Total Leave Days' },
yaxis: { title: 'Department' }
};
Plotly.newPlot('department-leave-plot', [trace], layout);
}
async function fetchLoginFrequency() {
const response = await fetch('/api/analytics/login-frequency');
const data = await response.json();
// Create the plot with Plotly
const days = Object.keys(data);
const loginCounts = Object.values(data);
const trace = {
x: days,
y: loginCounts,
type: 'bar',
marker: { color: 'gray' }
};
const layout = {
title: 'Login Frequency by Day of the Week',
xaxis: { title: 'Day of the Week' },
yaxis: { title: 'Number of Logins' }
};
Plotly.newPlot('login-frequency-plot', [trace], layout);
}
// Fetch data when the page loads
window.onload = function() {
fetchCheckinsAndCheckouts();
fetchDepartmentLeaveCounts();
fetchLoginFrequency();
};
</script>
</body>
</html>