Skip to content
Snippets Groups Projects
Commit 8939020f authored by Djalim Simaila's avatar Djalim Simaila
Browse files

added docstrings and changed how parsing normalisation check

parent 2968922f
No related branches found
No related tags found
1 merge request!1Functionnal main functionnalities
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__':
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment