Answer the question
In order to leave comments, you need to log in
How to display the length of the list for the last day and the last hour?
On each request to flask, I store the current time in a list:
list.append(round(time.time()))
[1628179279, 1628179280, 1628179281, 1628179282, 1628179283, 1628179284, 1628179285, 1628179287, 1628179288, 1628179928179290, 1628179291, 162991, 162991, 162991, 162991, 162991, 162991, 16ARD
Answer the question
In order to leave comments, you need to log in
Well, it's not that difficult.
First you need to count what time it was exactly a day ago
And then start the usual cycle
time.time()-(60*60*24)
time_day_before = time()-(60*60*24)
n = 0
for x in lst:
if x < time_day_before:
break
n += 1
print(n)
The most economical way is to have 2 counters: for a day and for an hour.
They need to be reset to zero, respectively, at the beginning of the day and at the beginning of the hour.
When adding a new time, increase the counters. That's all. The data will always be up-to-date and there will be no need to look at the list.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question