From 8939020f4a145ad91903d3e366144722d0a20731 Mon Sep 17 00:00:00 2001 From: Djalim Simaila <DjalimS.pro@outlook.fr> Date: Mon, 17 Apr 2023 14:56:19 +0200 Subject: [PATCH] added docstrings and changed how parsing normalisation check --- main.py | 40 ++++++++++++++++++++++++++++++++++------ utils/files/parsers.py | 11 ++++++----- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index af0dba5..850e6a3 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,23 @@ from utils.math import utils from utils.files import output from utils.files import parsers -from integration_tests import data_test +from utils.files.file_data import Object -def get_raw_data(obj, ndigits): +def get_raw_data(obj:Object, ndigits:int)->dict: + """ + Calculates data from the given object + + :param obj: Object to analyse + :param ndigits: Number of digits to keep after the comma + :return: dict(str:list) with the following keys: + - X (en mm) : list of x values + - Y (en mm) : list of y values + - Z (en mm) : list of z values + - teta (en rad) : list of teta values + - rayon (en mm) : list of radius values + - Xi-Xmoy : list of Xi-Xmoy values + - Yi-Ymoy : list of Yi-Ymoy values + """ colones = ["X (en mm)", "Y (en mm)", "Z (en mm)", "teta (en rad)", "rayon (en mm)","Xi-Xmoy","Yi-Ymoy"] data = {} for colone in colones: @@ -20,7 +34,19 @@ def get_raw_data(obj, ndigits): data["Yi-Ymoy"].append(round(y-mean_y, ndigits)) return data -def get_discrete_data(obj, ndigits): +def get_discrete_data(obj, ndigits)->dict: + """ + Calculates data from the given object + + :param obj: Object to analyse + :param ndigits: Number of digits to keep after the comma + :return: dict(str:list) with the following keys: + - X moy (en mm) : list of x mean values + - Y moy (en mm) : list of y mean values + - Z moy (en mm) : list of z mean values + - Rayon moyen (en mm) : list of mean radius values + - Rayon ecart type (en mm) : list of radius standard deviation values + """ colones = ["X moy (en mm)", "Y moy (en mm)", "Z moy (en mm)","Rayon moyen (en mm)","Rayon ecart type (en mm)"] data = {} for colone in colones: @@ -36,14 +62,16 @@ def get_discrete_data(obj, ndigits): def main(): - obj = parsers.parse_obj_file("datasets/Barette/3 - BARETTE v1.obj",normalised=True) + # Create an object from the given file + obj = parsers.parse_obj_file("datasets/Barette/3 - BARETTE v1.obj",normalised='z') + + # Calculate raw data and save it in a file data = get_raw_data(obj, 6) output.save_output_file('analyse_brute.txt', output.format_data(data, '\t', ["X (en mm)", "Y (en mm)", "Z (en mm)", "teta (en rad)", "rayon (en mm)","Xi-Xmoy","Yi-Ymoy"] )) - data_test.check_raw_data("datasets/Barette/BARETTE_Delta 1,0_analyse brute.txt", "analyse_brute.txt",eps=0.001) + # Calculate discrete data and save it in a file data = get_discrete_data(obj, 6) output.save_output_file('analyse_rayon.txt', output.format_data(data, '\t', ["X moy (en mm)", "Y moy (en mm)", "Z moy (en mm)","Rayon moyen (en mm)","Rayon ecart type (en mm)"] )) - data_test.check_discrete_data("datasets/Barette/BARETTE_Delta 1,0_analyse rayon.txt", "analyse_rayon.txt",eps=0.001) if __name__ == '__main__': diff --git a/utils/files/parsers.py b/utils/files/parsers.py index d5e9b7c..d5e3f06 100644 --- a/utils/files/parsers.py +++ b/utils/files/parsers.py @@ -3,7 +3,7 @@ This module contains functions to parse files. """ from utils.files.file_data import Object -def parse_obj_file(file_path:str,ratio:float = 1,normalised:bool = False)->Object: +def parse_obj_file(file_path:str,ratio:float = 1,normalised:str = '')->Object: """ Parse an OBJ file and return a dict with the vertices and faces @@ -24,17 +24,18 @@ def parse_obj_file(file_path:str,ratio:float = 1,normalised:bool = False)->Objec x.append(float(line.split()[1]) * ratio) y.append(float(line.split()[2]) * ratio) z.append(float(line.split()[3]) * ratio) - if normalised: - """ + + if 'x' in normalised: xmin = min(x) for count, value in enumerate(x): x[count] -= xmin + if 'y' in normalised: ymin = min(y) for count, value in enumerate(y): - y[count] -= ymin - """ + y[count] -= ymin + if 'z' in normalised: zmin = min(z) for count, value in enumerate(z): z[count] -= zmin -- GitLab