From d80dc6061cc416711cc4de83c623a0cbbddc905d Mon Sep 17 00:00:00 2001
From: VulcanixFR <vulcanix.gamingfr@gmail.com>
Date: Fri, 12 Jul 2024 10:40:14 +0200
Subject: [PATCH] Add Comments to Trace

---
 kuka/trace.py | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/kuka/trace.py b/kuka/trace.py
index 5b01fdd..996dab3 100644
--- a/kuka/trace.py
+++ b/kuka/trace.py
@@ -10,10 +10,18 @@ from pathlib import Path
 import pandas as pd
 
 class DatFile:
+    """This class represents the contents of a .dat file"""
 
+    # The sampling rate of the .r64 file
     sampling: float = 0
+
+    # The scale coefficient for each variable
     col241: List[float] = []
-    traces: List[float] = []
+
+    # The names of the variables
+    traces: List[str] = []
+    
+    # The number of samples in the file
     length: float = 0
 
     def __init__(self) -> None:
@@ -178,12 +186,15 @@ class KUKA_Trace:
         return None
 
     def translate (self, value: str) -> str:
+        """Translates a varaible name from German to English"""
+
         if value in self.translations:
             return self.translations[value]
         
         return value
 
     def copy_to_local (self, pairs: List[List[Path]], name: str):
+        """Copies a file pair form the robot to the ./temp folder"""
 
         src_folder = None
         if type (self.trace_root) == str :
@@ -232,7 +243,8 @@ class KUKA_Trace:
         return files
 
     def read_dat (self, dat: Path, suffix: str = "") -> DatFile:
-        
+        """Reads the contents of a .dat file"""
+
         out = DatFile()
 
         with open(dat, "r") as dat_file:
@@ -282,6 +294,7 @@ class KUKA_Trace:
         return out
 
     def convert_r64 (self, r64: Path, dat: DatFile) -> Dict[str, List[float]]:
+        """Converts a .r64 file to a dictionnary based on the .dat file contents"""
 
         out: Dict[str, List[float]] = {}
 
@@ -303,6 +316,9 @@ class KUKA_Trace:
         return out
     
     def linear_interpolation (self, data: List[float], ratio: int = 1):
+        """Basic linear interpolation to "upsample" traces with lower 
+        sampling rate than the main ones"""
+
         if ratio == 1:
             return data
         
@@ -330,6 +346,8 @@ class KUKA_Trace:
         return neo            
 
     def read_traces (self, name: str):
+        """Copies and reads the trace files and returns the contents
+        as a DataFrame"""
 
         pairs = self.find_pairs(name)
         self.copy_to_local(pairs, name)
@@ -376,6 +394,7 @@ class KUKA_Trace:
 
                 if ratio > 1:
                     
+                    # This variable has descrete values
                     if "AnalogOut" in col:
                         # Step interpolation
                         temp = np.zeros(len(values[col]) * ratio)
-- 
GitLab