validation package¶
Submodules¶
validation.constraints module¶
constraints¶
Module containing functions that check the constraints of GeometryParameters and the BikeGeometry in general
Author: Javier Chiyah, Heriot-Watt University, 2019
-
datavalidation.validation.constraints.check_parameter_constraints(parameter_name: str, bike_geometry: datavalidation.core.bikegeometry.BikeGeometry) → bool[source]¶ Checks that the GeometryParameter satisfies all the geometry constraints. It also checks the geometry statistics, so even if the parameter does NOT satisfy the geometry constraints, this function may return True when the issue is likely to be from another parameter of the bike geometry.
Parameters: - parameter_name – name of the GeometryParameter
- bike_geometry – BikeGeometry
Returns: bool, True if the GeometryParameter satisfies constraints (or the issue is with another parameter)
-
datavalidation.validation.constraints.filter_by_constraints(value_list: list, parameter_name: str, bike_geometry: datavalidation.core.bikegeometry.BikeGeometry) → list[source]¶ Filters a list of values depending on the BikeGeometry constraints and the GeometryParameter they belong to. It returns the filtered list, which can be empty if no values passed the checks.
This is used to, for instance, filter the solutions to the equations to only those that are possible.
Parameters: - value_list – list of possible values
- parameter_name – name of the GeometryParameter to which the values would apply to
- bike_geometry – the BikeGeometry
Returns: filtered list of values, it can be empty []
-
datavalidation.validation.constraints.get_parameter_deviation(parameter: datavalidation.core.geometryparameter.GeometryParameter, invert: bool = False)[source]¶ Gets the parameter deviation from the normal geometry statistics. Deviation is in the range of 0 to 1.
Parameters: - parameter – GeometryParameter
- invert – bool, give True to calculate the inverted deviation (1 - dev) when dev is not None. False by default
Returns: float or None
validation.equations module¶
equations¶
Module containing functions that get and solve equations for a given GeometryParameter.
Author: Javier Chiyah, Heriot-Watt University, 2019
-
datavalidation.validation.equations.filter_equations(equation_list: list, filter_by: list = None, parameter_name: str = None) → list[source]¶ Filters a list of equations depending on a list of the GeometryParameters available.
Parameters: - equation_list – list of equations
- filter_by – list of available GeometryParameters that are not empty
- parameter_name – name of the parameter that you want to use (if known)
Returns: list of filtered equations, [] if none left after filtering
-
datavalidation.validation.equations.get_equations(parameter_name: str, filter_by: list = None) → list[source]¶ Gets a list of equations for the given GeometryParameter name. If a list of parameters is given as the filter, it will return only those equations that can be calculated using that list. For instance, if to calculate chainstay we need wheelbase and bb_drop, it will return the equation if the filter_by list contains both the wheelbase and the bb_drop.
Parameters: - parameter_name – name of the GeometryParameter
- filter_by – list of GeometryParameters available that are not empty
Returns: list of equations, [] if none could be found
-
datavalidation.validation.equations.solve_equation(formula, symbol_to_solve: str, bike_geometry: datavalidation.core.bikegeometry.BikeGeometry, force_constraints: bool = True) → list[source]¶ Solves an equation and returns the possible solutions. This is the main function used to calculate parameter values. Equations with square roots return multiple solutions, increasing exponentially with additional square roots in the equation.
Examples:
>> formula = { "equation": "SQRT({bb_drop}^2 + ({wheelbase} - SQRT( {front_centre}^2 - {bb_drop}^2 ))^2 ) - {chainstay}", "parameters": [ "bb_drop", "chainstay", "wheelbase", "front_centre" ] } # get all solutions >> solve_equation(formula, "chainstay", bike_geometry, force_constraints=False) [-200, 500, 1500] # get solutions filtered by constraints >> solve_equation(formula, "chainstay", bike_geometry, force_constraints=True) [500]
It is safe to use in parallel as it only reads values, it does not modify anything inside the BikeGeometry or its GeometryParameters.
Parameters: - formula – a formula dict with an equation
- symbol_to_solve – name of the GeometryParameter to solve the equation for
- bike_geometry – the BikeGeometry
- force_constraints – if the solutions returned should enforce geometry constraints, True by default
Returns: list of possible solutions, [] if no solutions found
-
datavalidation.validation.equations.substitute_operators(equation)[source]¶ Substitutes the operators in an equation (e.g. TAN for sympy.tan). It accepts both an equation as a string or a list of equation strings.
Parameters: equation – equation as a string or a list Returns: equation as a string or a list
-
datavalidation.validation.equations.substitute_parameters(equation, parameter_list: list, symbol_to_solve: str, bike_geometry: datavalidation.core.bikegeometry.BikeGeometry)[source]¶ Substitutes the GeometryParameters of an equation using the values from the BikeGeometry. In other words, it substitutes the variables like {bb_drop} by their actual numeric value in the equation.
Parameters: - equation – equation as a string or a list
- parameter_list – list of parameters of the equation
- symbol_to_solve – GeometryParameter name to solve the equation for (aka the X)
- bike_geometry – the BikeGeometry
Returns: equation as a string or a list
validation.formulae module¶
equations¶
File containing different formulae and equations to validate bike geometries.
Author: Javier Chiyah, Heriot-Watt University, 2019
validation.validate module¶
validate¶
Module with the main functionality of the validation process. It validates BikeGeometries and GeometryParameters, and calculates the GeometryParameters missing if possible.
Author: Javier Chiyah, Heriot-Watt University, 2019
-
datavalidation.validation.validate.calculate_missing_parameters(bike_geometry: datavalidation.core.bikegeometry.BikeGeometry, include_invalid: bool = True)[source]¶ Calculates missing GeometryParameters of a BikeGeometry if possible. It modifies the BikeGeometry in place!
Missing parameters are defined in the function BikeGeometry.get_missing_parameter_list(). It also includes invalid parameters, from the function get_invalid_parameters().
Parameters: - bike_geometry – the BikeGeometry
- include_invalid – if it should calculate invalid parameters too, default is True
Returns: None
-
datavalidation.validation.validate.calculate_parameter(parameter_name: str, bike_geometry: datavalidation.core.bikegeometry.BikeGeometry)[source]¶ Calculates the value of a parameter and sets it confidence value if it can derived from the geometry statistics. It modifies the GeometryParameter given in the BikeGeometry (or creates one if it does not exists).
Parameters: - parameter_name – name of the GeometryParameter
- bike_geometry – the BikeGeometry
Returns: None
-
datavalidation.validation.validate.get_invalid_parameters(bike_geometry: datavalidation.core.bikegeometry.BikeGeometry) → list[source]¶ Gets a list with the names of invalid GeometryParameters of a BikeGeometry that are numbers (that can be calculated). An invalid parameters is defined by the function is_parameter_invalid().
Note: this function should be inside BikeGeometry, but is_parameter_invalid() uses the geometry constraints, thus it is best to keep the core of the datavalidation module (BikeGeometry) separated from the constraints module.
Parameters: bike_geometry – the BikeGeometry Returns: list of invalid parameters (list of str)
-
datavalidation.validation.validate.get_value_similarity(value1, value2) → float[source]¶ Gets the similarity between two values. The similarity is a number between 0 and 1 as a percentage where 1 means that the values are the same and 0 means that the values are completely different. This function is duplicated in the constraints module. A common utility file could improve this…
Parameters: - value1 – value
- value2 – value
Returns: (0 to 1) percentage float of how close value1 is to value2
-
datavalidation.validation.validate.is_parameter_invalid(parameter: datavalidation.core.geometryparameter.GeometryParameter, bike_geometry: datavalidation.core.bikegeometry.BikeGeometry) → bool[source]¶ Checks if a GeometryParameter is invalid.
A GeometryParameter is invalid if:
- The parameter has very low confidence.
- The parameter does not satisfy geometry constraints.
- The parameter is too deviated from normal constraints.
Note: this function should be inside BikeGeometry, but it uses the geometry constraints, thus it is best to keep the core of the datavalidation module (BikeGeometry) separated from the constraints module.
Parameters: - parameter – GeometryParameter to check
- bike_geometry – BikeGeometry to make the comparison
Returns: bool, True if the parameter IS invalid
-
datavalidation.validation.validate.validate_bike_geometry(bike_geometry: datavalidation.core.bikegeometry.BikeGeometry)[source]¶ Validates a BikeGeometry. Be careful as it modifies the BikeGeometry in place!
After calling this function, the BikeGeometry has been modified in the following way:
- The GeometryParameters from inside the BikeGeometry that could be validated now have confidence values.
- Some GeometryParameters may be deemed invalid due to low confidence values.
- Some GeometryParameters may have new calculated values, even if the previous values were valid.
- Some GeometryParameters without a value may have a new value calculated by deriving it from others.
- The BikeGeometry can now be queried for a confidence value (get_confidence_score()).
Parameters: bike_geometry – BikeGeometry object to validate Returns: None
-
datavalidation.validation.validate.validate_geometry_parameter(parameter: datavalidation.core.geometryparameter.GeometryParameter, bike_geometry: datavalidation.core.bikegeometry.BikeGeometry)[source]¶ Validates a GeometryParameter of the BikeGeometry. It modifies the GeometryParameter but not the BikeGeometry.
After calling this function in a GeometryParameter, it will:
- Have a confidence value if we were able to validate it.
- Have a new calculated value if we were able to validate it.
Parameters: - parameter – GeometryParameter inside the BikeGeometry
- bike_geometry – the BikeGeometry
Returns: None