Saturday dropped in presence graph

parent a6901cdf
......@@ -32,7 +32,7 @@ class PresenceGraph(Drawing):
gradient = list(COLOR_CLOSE.range_to(COLOR_OPEN, NUMBER_COLORS))
# For each day of the week
for i in range(0, 6):
for i in range(0, 5):
# Make a vertical linear gradient
lg = LinearGradient((0, 0), (0, 1), id="grad_{}".format(i))
......@@ -56,14 +56,14 @@ class PresenceGraph(Drawing):
def _add_rect(self) -> None:
g = self.add(Group(id="rects"))
for i in range(0, 6):
g.add(self.rect((i * 100 / 6, 0), (100 / 6, 100), fill="url(#grad_{})".format(i)))
for i in range(0, 5):
g.add(self.rect((i * 100 / 5, 0), (100 / 5, 100), fill="url(#grad_{})".format(i)))
def _add_grid(self) -> None:
g = self.add(Group(id="grid", stroke="black"))
for i in range(1, 6):
g.add(Line((i * 100 / 6, 0), (i * 100 / 6, 100)))
for i in range(1, 5):
g.add(Line((i * 100 / 5, 0), (i * 100 / 5, 100)))
def _add_hours(self) -> None:
pass
from datetime import datetime, timedelta, time, date
from pprint import pprint
from typing import Tuple, List
import numpy
......@@ -25,12 +24,14 @@ class Presence():
datetime.combine(datetime.now().date(), time()) - WINDOW_WIDTH,
datetime.combine(datetime.now().date(), time()))
data = [[], [], [], [], [], []]
data = [[], [], [], [], []]
with session_scope() as session:
for i in range(7):
current_day = window_date[1] - timedelta(days=(1 + i))
if (current_day.weekday() == 6): continue
# Skip saturday and sunday
if (current_day.weekday() == 5 or current_day.weekday() == 6): continue
while current_day > window_date[0]:
current_limit = (
......@@ -52,13 +53,13 @@ class Presence():
def get_data(self) -> List[List[List[int]]]:
# Prepare the final structure for the data
data = [[], [], [], [], [], []]
data = [[], [], [], [], []]
# Get the raw data from the db
raw_data = self._get_raw_data_from_db()
# For each day of the week
for i in range(6):
for i in range(5):
# Get the data for the day
day_data = raw_data[i]
......@@ -85,10 +86,10 @@ class Presence():
def get_prevision(self) -> List[List[float]]:
raw_data = self.get_data()
data = [[], [], [], [], [], []]
data = [[], [], [], [], []]
# For each day of the week
for i in range(6):
for i in range(5):
day_data = raw_data[i]
for j, _ in enumerate(day_data):
data[i].append(numpy.average(day_data[j], weights=DATA_WEIGHTS[:len(day_data[j])]))
......@@ -98,7 +99,7 @@ class Presence():
def _status(self, data: List[Tuple[time, bool]], hour: time) -> bool:
status = False
for i in [(time(hour=0),False), *data]:
for i in [(time(hour=0), False), *data]:
if i[0] > hour:
return status
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment