Refactor code structure for improved readability and maintainability

This commit is contained in:
2025-04-28 00:52:40 +02:00
parent b6e0080caa
commit 93026436a9
48 changed files with 2116 additions and 126 deletions

View File

@@ -0,0 +1,52 @@
@startuml Architecture Générale du Système Timelapse
!define ICONURL https://raw.githubusercontent.com/tupadr3/plantuml-icon-font-sprites/v2.4.0
!include ICONURL/common.puml
!include ICONURL/devicons/python.puml
!include ICONURL/font-awesome-5/raspberry_pi.puml
!include ICONURL/font-awesome-5/cloud.puml
!include ICONURL/font-awesome-5/camera.puml
!include ICONURL/font-awesome-5/database.puml
skinparam {
BackgroundColor white
ArrowColor #666666
BorderColor #666666
FontName "Arial"
}
rectangle "Système Raspberry Pi" as raspi {
DEV_PYTHON(pyonline, "timelapse_online.py") #lightblue
DEV_PYTHON(pyoffline, "timelapse_offline.py") #lightgreen
rectangle "timelapse/" {
DEV_PYTHON(config, "config.py") #lightyellow
DEV_PYTHON(apiclient, "api_client.py") #pink
DEV_PYTHON(capture, "capture.py") #lightcyan
DEV_PYTHON(sensors, "sensors.py") #lightyellow
}
FA5_DATABASE(localdb, "CONFIG/config.json") #lightgrey
FA5_CAMERA(camera, "Caméra") #white
}
cloud "Serveur Distant" {
rectangle "API REST" as api #pink
database "Base de données" as db #lightgrey
}
pyonline --> config : utilise
pyoffline --> config : utilise
pyonline --> apiclient : utilise
pyonline --> capture : utilise
pyoffline --> capture : utilise
capture --> config : lit/écrit
capture --> sensors : utilise
apiclient --> api : communique
config --> localdb : lit/écrit
sensors --> camera : contrôle
note bottom of pyonline : "Mode connecté"
note bottom of pyoffline : "Mode hors ligne"
note right of api : "Authentification\net gestion des données"
note bottom of camera : "Capture des images"
@enduml

View File

@@ -0,0 +1,77 @@
@startuml Flux du Processus de Capture d'Images
skinparam {
BackgroundColor white
ArrowColor #666666
BorderColor #666666
FontName "Arial"
}
start
if (Connexion internet disponible?) then (oui)
:Mode connecté (timelapse_online.py);
:Récupération du statut depuis l'API;
if (Serveur accessible?) then (oui)
:Mise à jour de la configuration locale;
if (Mode maintenance?) then (oui)
:Arrêt du processus;
stop
else (non)
if (Demande d'arrêt?) then (oui)
:Confirmation de l'arrêt au serveur;
:Réinitialisation de la configuration;
stop
else (non)
if (Configuration active?) then (oui)
:Capture d'image;
:Lecture des données environnementales;
:Envoi au serveur;
if (Envoi réussi?) then (oui)
:Décrémenter le nombre d'images restantes;
else (non)
:Sauvegarder en mode hors-ligne;
endif
if (Toutes images capturées?) then (oui)
:Notification au serveur;
:Désactivation de la configuration;
stop
else (non)
:Attente du prochain cycle;
endif
else (non)
:Mode IDLE, aucune action;
stop
endif
endif
endif
else (non)
:Fonctionnement en mode dégradé;
endif
else (non)
:Mode hors ligne (timelapse_offline.py);
if (Configuration active?) then (oui)
if (Images restantes > 0?) then (oui)
:Capture d'image;
:Lecture des données environnementales;
:Sauvegarde en local;
:Décrémenter le nombre d'images restantes;
if (Toutes images capturées?) then (oui)
:Désactivation de la configuration;
stop
else (non)
:Envoi de l'intervalle au microcontrôleur;
:Attente du prochain cycle;
endif
else (non)
:Désactivation de la configuration;
stop
endif
else (non)
:Aucune configuration active;
stop
endif
endif
stop
@enduml

View File

@@ -0,0 +1,91 @@
@startuml Structure des Classes et Composants
skinparam {
BackgroundColor white
ClassBackgroundColor lightcyan
ClassBorderColor gray
ClassFontName Arial
ClassFontSize 12
}
class Config {
+ BASE_DIR : string
+ CONFIG_DIR : string
+ PROJECT_DIR : string
+ LOG_FILE : string
+ CONFIG_FILE : string
+ API_BASE_URL : string
+ API_ENDPOINTS : dict
+ DEFAULT_CONFIG : dict
--
+ ensure_directories()
+ setup_logging()
+ load_config()
+ save_config()
+ update_config(new_config)
+ get(key, default)
+ set(key, value)
+ delete_config_file()
+ decrement_remaining_images()
}
class APIClient {
- base_url : string
- headers : dict
--
+ get_camera_status()
+ upload_measurement(image_path, timestamp, temperature, humidity)
+ confirm_stop()
+ update_camera_config(status)
+ check_connection()
}
class TimelapseCaptureManager {
- offline_dir : string
--
+ single_capture(online)
+ run_capture_sequence(online)
+ sync_offline_captures()
+ count_offline_captures()
- _move_to_offline(image_path, json_path)
- _cleanup_local_capture(image_path, json_path)
}
class "timelapse_online.py" as TimelapseOnline {
+ main()
}
class "timelapse_offline.py" as TimelapseOffline {
+ main()
}
package "sensors" {
class EnvironmentalSensor {
+ read_data()
}
class Camera {
+ capture_image()
}
class MicroController {
+ send_interval(interval)
}
}
Config "1" <-- "1" TimelapseOnline : utilise
Config "1" <-- "1" TimelapseOffline : utilise
Config "1" <-- "1" TimelapseCaptureManager : utilise
APIClient "1" <-- "1" TimelapseOnline : utilise
TimelapseCaptureManager "1" <-- "1" TimelapseOnline : utilise
TimelapseCaptureManager "1" <-- "1" TimelapseOffline : utilise
TimelapseCaptureManager "1" --> "1" EnvironmentalSensor : utilise
TimelapseCaptureManager "1" --> "1" Camera : utilise
APIClient "1" --> "1" Config : utilise
TimelapseOffline ..> MicroController : utilise
note bottom of Config : "Gestion de la configuration\nlocale et persistance"
note bottom of APIClient : "Communication avec\nle serveur distant"
note bottom of TimelapseCaptureManager : "Orchestration du processus\nde capture d'images"
@enduml

View File

@@ -0,0 +1,78 @@
@startuml Séquence de Synchronisation des Données
skinparam {
BackgroundColor white
SequenceGroupBorderColor gray
SequenceGroupBodyBackgroundColor whitesmoke
ParticipantBackgroundColor lightblue
ParticipantBorderColor gray
LifeLineBorderColor gray
ArrowColor #666666
}
actor "Système" as System
participant "sync_offline_data.py" as Sync
participant "APIClient" as API
participant "TimelapseCaptureManager" as Manager
participant "Config" as Config
database "Stockage local" as Storage
database "Serveur API" as Server
System -> Sync : Exécution du script
activate Sync
Sync -> API : check_connection()
activate API
API --> Sync : Connexion disponible
deactivate API
Sync -> Manager : count_offline_captures()
activate Manager
Manager -> Storage : Listing des dossiers offline
Storage --> Manager : Liste des captures
Manager --> Sync : Nombre de captures hors ligne
deactivate Manager
alt Captures hors ligne disponibles
Sync -> Manager : sync_offline_captures()
activate Manager
loop Pour chaque capture hors ligne
Manager -> Storage : Lire données JSON
activate Storage
Storage --> Manager : Données (timestamp, température, etc.)
deactivate Storage
Manager -> Storage : Lire image
activate Storage
Storage --> Manager : Fichier image
deactivate Storage
Manager -> API : upload_measurement()
activate API
API -> Server : POST /camera/upload
alt Upload réussi
Server --> API : Confirmation (ID image)
API --> Manager : Succès
Manager -> Storage : Suppression des fichiers locaux
Manager -> Config : Mise à jour du statut
else Échec de l'upload
Server --> API : Erreur
API --> Manager : Échec
note right: Conservation des fichiers locaux\npour tentative ultérieure
end
deactivate API
end
Manager --> Sync : Nombre de captures synchronisées
deactivate Manager
else Aucune capture à synchroniser
Sync -> Sync : Fin sans action
end
Sync --> System : Rapport de synchronisation
deactivate Sync
@enduml

View File

@@ -0,0 +1,69 @@
@startuml infra_raspi
skinparam {
BackgroundColor white
NodeBackgroundColor lightyellow
NodeBorderColor gray
AgentBackgroundColor lightcyan
AgentBorderColor gray
ArrowColor #666666
ComponentBackgroundColor lightblue
ComponentBorderColor gray
}
artifact "Raspbian OS" as linux
node "Raspberry Pi" as raspi {
agent "Service Systemd" as service
artifact "timelapse.service" as timelapseService
artifact "script.sh" as script
service --> timelapseService : gère
service --> script : exécute
component "Scripts Python" as scripts {
artifact "timelapse_online.py" as pyOnline
artifact "timelapse_offline.py" as pyOffline
artifact "sync_offline_data.py" as pySync
}
component "Modules Timelapse" as modules {
artifact "config.py" as config
artifact "api_client.py" as apiClient
artifact "capture.py" as capture
artifact "sensors.py" as sensors
}
artifact "Caméra Pi" as cam
artifact "Microcontrôleur" as micro
}
cloud "Internet" as internet {
node "Serveur API" as api_server {
database "Base de données" as db
folder "Stockage d'images" as images
}
}
linux --> service : exécute
service --> script : lance
script --> scripts : appelle selon\nétat connexion
scripts --> modules : utilisent
modules --> cam : contrôle
modules --> micro : communique
modules --> internet : envoie données
internet --> modules : récupère configuration
note right of service : "Démarrage au boot\net exécution périodique"
note right of scripts : "Sélection auto du mode\nselon connectivité"
note bottom of cam : "Capture des images\ndu timelapse"
note bottom of micro : "Gestion de l'intervalle\nde capture"
legend right
<b>Infrastructure de Déploiement Timelapse</b>
Ce diagramme représente l'infrastructure complète
du système timelapse, depuis le service systemd
jusqu'à la communication avec le serveur distant.
endlegend
@enduml