Django - Как отслеживать прогресс пользователя в течение нескольких дней?
У меня есть модель django, которая обновляется с текущим временем, проведенным пользователем на сайте:
totallearningtime = models.DecimalField(default = 0, decimal_places=2, max_digits=100) # total time user spent on website
У меня есть следующий chart.js, который я хочу заполнить totallearningtime в течение недели и сбросить в начале следующей недели:
(в настоящее время имеет значения-заполнители)
Вот код для графика:
<script>
const ctx = document.getElementById("myChart");
// <block:setup:1>
const DATA_COUNT = 12;
const labels = [
"Mon",
"Tue",
"Wen",
"Thur",
"Fri",
"Sat",
"Sun",
];
const datapoints = [
0, 20, 20, 60, 60, 120, 140, 180, 120, 125, 105, 110, 170,
];
const data = {
labels: labels,
datasets: [
{
label: "Learning Time",
data: datapoints,
// borderColor: red,
fill: false,
cubicInterpolationMode: "monotone",
tension: 0.4,
},
],
};
new Chart(ctx, {
type: "line",
data: data,
options: {
responsive: true,
maintainAspectRatio: true,
plugins: {
title: {
display: false,
text: "Total Time: 5h 45m",
},
},
interaction: {
intersect: false,
},
scales: {
x: {
display: true,
title: {
display: true,
},
},
y: {
display: true,
title: {
display: true,
text: "Hours",
},
suggestedMin: 0,
suggestedMax: 200,
},
},
},
});
</script>
Однако я не могу понять, как это сделать. Я хочу сделать так, чтобы я мог отслеживать totallearningtime пользователя в течение недели и обнулять его в начале следующей недели