За смену
@@ -23,25 +23,23 @@
Под нагрузкой
-
- 0ч.
-
+ 0 ч.
Без нагрузки
-
- 0ч.
+ 0 ч.
Не работала
-
0ч.
@@ -50,7 +48,7 @@
Общее время работы
-
0ч.
@@ -74,7 +72,7 @@
Под нагрузкой
-
0ч.
@@ -83,7 +81,7 @@
Без нагрузки
-
0ч.
@@ -92,7 +90,7 @@
Не работала
-
0ч.
@@ -101,7 +99,7 @@
Общее время работы
-
0ч.
@@ -125,7 +123,7 @@
Под нагрузкой
-
0ч.
@@ -134,7 +132,7 @@
Без нагрузки
-
0ч.
@@ -143,7 +141,7 @@
Не работала
-
0ч.
@@ -152,7 +150,7 @@
Общее время работы
-
0ч.
diff --git a/app/static/js/charts/worktime.js b/app/static/js/charts/worktime.js
index 757a8c8..36c8c9d 100644
--- a/app/static/js/charts/worktime.js
+++ b/app/static/js/charts/worktime.js
@@ -1,4 +1,73 @@
(function () {
+
+ function parseDuration(durationStr) {
+ // Разбиваем строку по символам времени
+ const parts = durationStr.match(/\d+(?=DT|H|M|S)/g);
+ let days = 0, hours = 0, minutes = 0, seconds = 0;
+
+ if (parts) {
+ days = parseInt(parts[0]) || 0;
+ hours = parseInt(parts[1]) || 0;
+ minutes = parseInt(parts[2]) || 0;
+ seconds = parseInt(parts[3]) || 0;
+ }
+
+ return {
+ days: days,
+ hours: hours,
+ minutes: minutes,
+ seconds: seconds
+ };
+ }
+
+ function addDurations(duration1, duration2) {
+ // Складываем соответствующие поля двух объектов длительности
+ let totalSeconds = duration1.seconds + duration2.seconds;
+ let totalMinutes = duration1.minutes + duration2.minutes;
+ let totalHours = duration1.hours + duration2.hours;
+ let totalDays = duration1.days + duration2.days;
+
+ // Учет переполнений
+ if (totalSeconds >= 60) {
+ totalMinutes += Math.floor(totalSeconds / 60);
+ totalSeconds %= 60;
+ }
+
+ if (totalMinutes >= 60) {
+ totalHours += Math.floor(totalMinutes / 60);
+ totalMinutes %= 60;
+ }
+
+ if (totalHours >= 24) {
+ totalDays += Math.floor(totalHours / 24);
+ totalHours %= 24;
+ }
+
+ return {
+ days: totalDays,
+ hours: totalHours,
+ minutes: totalMinutes,
+ seconds: totalSeconds
+ };
+ }
+
+ function makeTimeString(timeObj) {
+ let timeString = ''
+ if (timeObj.days !== 0) {
+ timeString += `${timeObj.days} д. `
+ }
+ if (timeObj.hours !== 0) {
+ timeString += `${timeObj.hours} ч. `
+ }
+ if (timeObj.minutes !== 0) {
+ timeString += `${timeObj.minutes} м. `
+ }
+ if (timeString === '') {
+ timeString = '0 ч. 0 м.'
+ }
+ return timeString
+ }
+
const workTimeChartOptions = {
chart: {
type: 'donut',
@@ -34,30 +103,33 @@
monthlyWorkChart.render();
function fetchWorkTime() {
- fetch('worktime/').then(response => {
+ fetch('worktime/durations').then(response => {
return response.json()
}).then(json => {
for (let item in json) {
for (let status in json[item]) {
let chartElement = document.querySelector(`#${item}${status}`)
- chartElement.textContent = json[item][status] + ' ч.'
+ let timeObj = parseDuration(json[item][status])
+ chartElement.textContent = makeTimeString(timeObj)
}
- let chartElementSUM = document.querySelector(`#${item}SUM`)
- chartElementSUM.textContent = (json[item]['WO'] + json[item]['WA']).toFixed(0) + ' ч.'
- let workedWO = json[item]['WO']
- let workedWA = json[item]['WA']
- let workedNW = json[item]['NW']
+ let workedWO = parseDuration(json[item]['WO'])
+ let workedWA = parseDuration(json[item]['WA'])
+ let workedNW = parseDuration(json[item]['NW'])
+ const sumObj = addDurations(workedWO, workedWA)
+ const sumTimeString = makeTimeString(sumObj)
+ const spanSum = document.querySelector(`#${item}SUM`)
+ spanSum.textContent = sumTimeString
switch (item) {
case 'daily':
- dailyWorkChart.updateSeries([workedWO, workedWA, workedNW])
+ dailyWorkChart.updateSeries([workedWO.hours, workedWA.hours, workedNW.hours])
break
case 'weekly':
- weeklyWorkChart.updateSeries([workedWO, workedWA, workedNW])
+ weeklyWorkChart.updateSeries([workedWO.hours, workedWA.hours, workedNW.hours])
break
case 'monthly':
- monthlyWorkChart.updateSeries([workedWO, workedWA, workedNW])
+ monthlyWorkChart.updateSeries([workedWO.hours, workedWA.hours, workedNW.hours])
break
}
}