diff --git a/TP2/imu_analysis/processing.py b/TP2/imu_analysis/processing.py index fe6271a..89193c9 100644 --- a/TP2/imu_analysis/processing.py +++ b/TP2/imu_analysis/processing.py @@ -2,3 +2,10 @@ Module pour le traitement des mesures ************************************* """ +def calculate_moving_average(data: list[float], interval: int): + moyenne_glissante = 0 + n = 4 + for i in range(n,interval+n): + moyenne_glissante = moyenne_glissante + list[n-i] + moyenne_glissante = moyenne_glissante / interval + return moyenne_glissante \ No newline at end of file diff --git a/TP3/person.py b/TP3/person.py index 26675b9..8639a35 100644 --- a/TP3/person.py +++ b/TP3/person.py @@ -2,10 +2,14 @@ class Person: - def __init__(self, first_name: str, last_name: str, age: int) -> None: + def __init__(self, first_name: str, last_name: str, age: int, email:str="non renseigné", phone:str="non renseigné") -> None: self.first_name = first_name.capitalize() self.last_name = last_name.upper() self.age = age + self.email = email + self.phone = phone + def __str__(self) -> str: + return f"{self.first_name} {self.last_name}" def main(): @@ -14,6 +18,5 @@ def main(): print(f"Last name: {john.last_name}") print(f"Age: {john.age}") - if __name__ == "__main__": main() diff --git a/TP3/person_2.py b/TP3/person_2.py index 002525b..215636b 100644 --- a/TP3/person_2.py +++ b/TP3/person_2.py @@ -23,7 +23,7 @@ def main(): print(f"Is Bob of age: {bob.is_of_age()}") print("Change the age of majority to 32") - # TODO + Person.AGE_MAJORITY = 32 print(f"Is John of age: {john.is_of_age()}") print(f"Is Bob of age: {bob.is_of_age()}") diff --git a/TP3/vectors.py b/TP3/vectors.py index 348de28..181cc77 100644 --- a/TP3/vectors.py +++ b/TP3/vectors.py @@ -1,6 +1,35 @@ """Manipulation of 2D-vectors.""" from __future__ import annotations +import numpy as np +from typing import Self + +class Point: + def __init__(self, x: float, y: float)-> None: + self.x = x + self.y = y + + def str(self) -> float: + return f"{self.x} {self.y}" + +class Vector: + def __init__(self, begin: Point, end: Point)-> None: + self.beginpoint = begin + self.endpoint = end + + self.x = end.x - begin.x + self.y = end.y - begin.y + + def norm(self) -> float: + """retourne la norme d'un vecteur""" + return np.squrt (self.x **2 + self.y **2) + + def dotprod(self, other: Vector) -> float: + return self.x * other.x + self.y * other.y + + def add(self, other: Vector) -> Vector: + return Vector(Point(self.x, self.y),Point(self.x + other.x, self.y + other.y)) + def main(): @@ -19,8 +48,8 @@ def main(): def main_2(): - v = Vector(1, 2) - v2 = Vector(1, 0) + v = Vector(Point(0,0),Point(1,2)) + v2 = Vector(Point(0,0),Point(1,0)) print(v.dot_prod(v2)) print(v2.dot_prod(v))