Author SHA1 Message Date
brian 1d641288e5 Merge pull request 'Make login token last 8 hours' (#35) from make-login-token-last-8-hours into main
Build and Push Docker Image / build-and-push (push) Successful in 26s
Python Code Quality / python-code-quality (push) Successful in 10s
Python Test / python-test (push) Successful in 18s
Reviewed-on: #35
2025-11-13 14:49:10 +01:00
Brian Bjarke Jensen e58a58e766 centrally defined TTL and cleanup of imports
Build and Push Docker Image / build-and-push (pull_request) Successful in 58s
Python Code Quality / python-code-quality (pull_request) Successful in 10s
Python Test / python-test (pull_request) Successful in 18s
2025-11-13 14:45:28 +01:00
brian e0bcda6e7c Merge pull request 'fixed updating charts with selected time range' (#34) from fix-sleep-overview-not-updating into main
Build and Push Docker Image / build-and-push (push) Successful in 26s
Python Code Quality / python-code-quality (push) Successful in 9s
Python Test / python-test (push) Successful in 18s
Reviewed-on: #34
2025-11-13 14:12:13 +01:00
Brian Bjarke Jensen f4419f6a72 fixed updating charts with selected time range
Build and Push Docker Image / build-and-push (pull_request) Successful in 1m7s
Python Code Quality / python-code-quality (pull_request) Successful in 10s
Python Test / python-test (pull_request) Successful in 17s
2025-11-13 14:10:09 +01:00
Brian Bjarke Jensen 6de91fa6a9 added env vars
Python Code Quality / python-code-quality (push) Successful in 10s
Python Test / python-test (push) Successful in 18s
Build and Push Docker Image / build-and-push (push) Successful in 26s
Refresh Showcase Data / refresh-data (push) Successful in 18s
2025-11-12 18:24:35 +01:00
brian a1a914ee4d Merge pull request 'added showcase data, users and CI workflow to refresh data daily' (#33) from add-showcase-data-and-users into main
Build and Push Docker Image / build-and-push (push) Successful in 26s
Python Code Quality / python-code-quality (push) Successful in 10s
Python Test / python-test (push) Successful in 18s
Reviewed-on: #33
2025-11-12 18:20:06 +01:00
7 changed files with 38 additions and 17 deletions
@@ -28,6 +28,8 @@ jobs:
- name: Run showcase data seeding script
env:
ADMIN_USERNAME: ${{ secrets.ADMIN_USERNAME }}
ADMIN_PASSWORD: ${{ secrets.ADMIN_PASSWORD }}
POSTGRES_URI: ${{ secrets.POSTGRES_URI }}
run: |
uv run python scripts/seed_showcase_data.py
@@ -6,7 +6,7 @@ import logging
from baby_monitor.repositories.interfaces import (
TokenRepositoryInterface,
)
from baby_monitor.repositories.token.memory_token import (
from baby_monitor.repositories.token import (
InMemoryTokenRepository,
)
@@ -43,7 +43,7 @@ def _initialize_token_repository() -> TokenRepositoryInterface:
) from e
try:
from baby_monitor.repositories.token.redis_token import (
from baby_monitor.repositories.token import (
RedisTokenRepository,
)
@@ -0,0 +1,11 @@
"""Token repository implementations and configurations."""
from .default_ttl import DEFAULT_TTL
from .memory_token import InMemoryTokenRepository
from .redis_token import RedisTokenRepository
__all__ = [
"DEFAULT_TTL",
"InMemoryTokenRepository",
"RedisTokenRepository",
]
@@ -0,0 +1,3 @@
"""Definition of Token default TTL."""
DEFAULT_TTL = 28800 # seconds -> 8 hours
@@ -3,6 +3,7 @@
from datetime import datetime, timedelta, UTC
from baby_monitor.repositories.interfaces import TokenRepositoryInterface
from baby_monitor.repositories.token import DEFAULT_TTL
class InMemoryTokenRepository(TokenRepositoryInterface):
@@ -16,9 +17,8 @@ class InMemoryTokenRepository(TokenRepositoryInterface):
def __init__(self) -> None:
# token -> (user_id, expiry_time)
self._tokens: dict[str, tuple[int, datetime]] = {}
self._default_ttl = 3600 # Store default TTL for sliding expiration
def store(self, token: str, user_id: int, ttl: int = 3600) -> None:
def store(self, token: str, user_id: int, ttl: int = DEFAULT_TTL) -> None:
"""Store a token with TTL (time to live in seconds)."""
expiry = datetime.now(UTC) + timedelta(seconds=ttl)
self._tokens[token] = (user_id, expiry)
@@ -39,7 +39,7 @@ class InMemoryTokenRepository(TokenRepositoryInterface):
return None
# Sliding expiration: extend the token lifetime
new_expiry = datetime.now(UTC) + timedelta(seconds=self._default_ttl)
new_expiry = datetime.now(UTC) + timedelta(seconds=DEFAULT_TTL)
self._tokens[token] = (user_id, new_expiry)
return user_id
@@ -3,14 +3,14 @@
from typing import Any
from baby_monitor.repositories.interfaces import TokenRepositoryInterface
from baby_monitor.repositories.token import DEFAULT_TTL
class RedisTokenRepository(TokenRepositoryInterface):
"""
Redis-based token storage.
Requires redis package: pip install redis
Set REDIS_URI environment variable (e.g., redis://localhost:6379/0)
This implementation uses Redis to store tokens with TTL. Implements sliding expiration.
"""
def __init__(self, redis_client: Any) -> None:
@@ -21,9 +21,8 @@ class RedisTokenRepository(TokenRepositoryInterface):
redis_client: Redis client instance from redis.from_url()
"""
self.redis = redis_client
self.default_ttl = 3600 # Store default TTL for sliding expiration
def store(self, token: str, user_id: int, ttl: int = 3600) -> None:
def store(self, token: str, user_id: int, ttl: int = DEFAULT_TTL) -> None:
"""Store a token with TTL (time to live in seconds)."""
key = f"token:{token}"
self.redis.setex(key, ttl, str(user_id))
@@ -37,7 +36,7 @@ class RedisTokenRepository(TokenRepositoryInterface):
user_id_str = self.redis.get(key)
if user_id_str:
# Sliding expiration: extend the token lifetime
self.redis.expire(key, self.default_ttl)
self.redis.expire(key, DEFAULT_TTL)
return int(user_id_str)
return None
+10 -4
View File
@@ -345,13 +345,16 @@
}
}
document
.getElementById("timeRangeFilter")
.addEventListener("change", function () {
function attachTimeRangeListener() {
const timeRangeFilter = document.getElementById("timeRangeFilter");
if (timeRangeFilter) {
timeRangeFilter.addEventListener("change", function () {
// Save selection to localStorage
localStorage.setItem("lastSleepTimeRange", this.value);
loadData();
renderCharts();
});
}
}
async function loadData() {
try {
@@ -443,6 +446,9 @@
attachChildFilterListener();
}
// Always attach time range listener after recreating the controls
attachTimeRangeListener();
renderCharts();
} catch (error) {
console.error("Error loading data:", error);