Skip to content
Snippets Groups Projects
Commit f72532c9 authored by VulcanixFR's avatar VulcanixFR
Browse files

Add comments to the code

parent b6da070c
No related merge requests found
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -6,26 +6,42 @@ import os ...@@ -6,26 +6,42 @@ import os
class DataFile: class DataFile:
# Raw path to the file
raw_path: str = "" raw_path: str = ""
# Path to the file. Can be absolute or relative
file_path: Path file_path: Path
# Name of the file
file_name: str = "" file_name: str = ""
# "Group" of the file
group: str = "" group: str = ""
# Is the file Trace data ?
trace: bool = False trace: bool = False
# Which robot produced the file
robot: str = "" robot: str = ""
# Sampling period used in the file
sampling_time: int = 12 sampling_time: int = 12
# Number of movement iteration per motor
iterations: List[int] = [] iterations: List[int] = []
# Speed at which the file was sampled
speed: int | slice speed: int | slice
# Load applied to the robot
class_number: int class_number: int
# Year of the file collection
year: int = 2024 year: int = 2024
# Month of the file collection
month: int = 7 month: int = 7
# Day of the file collection
day: int = 2 day: int = 2
# Name of the sample
name: str = "data" name: str = "data"
def __init__ (self, file_path: str): def __init__ (self, file_path: str):
"""Reads the file name to get the neeeded informations
"""
self.raw_path = file_path self.raw_path = file_path
self.file_path = Path(file_path) self.file_path = Path(file_path)
...@@ -70,6 +86,8 @@ class DataFile: ...@@ -70,6 +86,8 @@ class DataFile:
@staticmethod @staticmethod
def isDataFile (file_path: str): def isDataFile (file_path: str):
""" Checks if a file has the right naming scheme and extension
"""
path = Path(file_path) path = Path(file_path)
if not path.exists(): if not path.exists():
......
...@@ -5,6 +5,10 @@ import os ...@@ -5,6 +5,10 @@ import os
from pathlib import Path from pathlib import Path
import numpy as np import numpy as np
"""
The classes in this file should be entirely redone.
"""
class CorrectionCoefficient: class CorrectionCoefficient:
motor: int motor: int
......
...@@ -37,6 +37,19 @@ QUERY_ROBOTS = "SELECT DISTINCT `Robot` from DataFiles" ...@@ -37,6 +37,19 @@ QUERY_ROBOTS = "SELECT DISTINCT `Robot` from DataFiles"
# %% - Computation for one run # %% - Computation for one run
def compute_run (DB: Database, robot: int, run: int, t0: int, date: str, next: Callable[[str], None] = None): def compute_run (DB: Database, robot: int, run: int, t0: int, date: str, next: Callable[[str], None] = None):
""" Computes the indicators and health index for a specific run.
Args:
DB (Database): Database class
robot (int): Number of the robot cell
run (int): Number of the run
t0 (int): Timestamp of the run start
date (str): Run collection date
next (Callable[[str], None], optional): Method used to update GUI status.
Returns:
The computed indicators and health index for the run
"""
if next is not None: if next is not None:
next(f"Robot {robot} run n°{run} from {date}") next(f"Robot {robot} run n°{run} from {date}")
...@@ -76,6 +89,16 @@ def compute_run (DB: Database, robot: int, run: int, t0: int, date: str, next: C ...@@ -76,6 +89,16 @@ def compute_run (DB: Database, robot: int, run: int, t0: int, date: str, next: C
# %% - Transformation function # %% - Transformation function
def compute_indicators (DB: Database, robot: int, next: Callable[[str], None] = None): def compute_indicators (DB: Database, robot: int, next: Callable[[str], None] = None):
"""Computes the indicators and health index for all runs from one robot
Args:
DB (Database): Database class
robot (int): Number of the robot
next (Callable[[str], None], optional): Method used to update the GUI.
Returns:
A dataframe containing all indicators and health index from a robot
"""
if not (1 <= robot <= 3): if not (1 <= robot <= 3):
print("Robot must be between 1 and 3") print("Robot must be between 1 and 3")
...@@ -106,6 +129,12 @@ def compute_indicators (DB: Database, robot: int, next: Callable[[str], None] = ...@@ -106,6 +129,12 @@ def compute_indicators (DB: Database, robot: int, next: Callable[[str], None] =
#%% #%%
def compute_indicators_all_robots (DB: Database, next: Callable[[str], None] = None): def compute_indicators_all_robots (DB: Database, next: Callable[[str], None] = None):
"""Computes the indicators and health index for the whole database.
Args:
DB (Database): The database
next (Callable[[str], None], optional): Method to update the GUI.
"""
if (next is not None): if (next is not None):
print("Has next function") print("Has next function")
......
...@@ -53,11 +53,17 @@ def from_class_to_text (class_number: int): ...@@ -53,11 +53,17 @@ def from_class_to_text (class_number: int):
return "0.0 kg" return "0.0 kg"
class Chronometer: class Chronometer:
"""Simple chronometer class"""
def __init__ (self): def __init__ (self):
# Initializes the first time point
self.time = time_ns() self.time = time_ns()
def tick (self, print=False): def tick (self, print=False):
"""Computes the time delta from the last time point, then sets
the internal clock to now. If print=True, this function
prints the time delta.
"""
now = time_ns() now = time_ns()
dt = now - self.time dt = now - self.time
...@@ -69,6 +75,11 @@ class Chronometer: ...@@ -69,6 +75,11 @@ class Chronometer:
return dt return dt
def _print_dt (self, dt: int): def _print_dt (self, dt: int):
"""Prints a time delta with formatting
Args:
dt (int): Time delta
"""
if dt > 1e9 * 3600: # Hours if dt > 1e9 * 3600: # Hours
print("{:.02f} hours".format(dt / (1e9 * 3600))) print("{:.02f} hours".format(dt / (1e9 * 3600)))
......
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