Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Implemented a function to calculate the monotonicity of a curve file …
…in a specific format. Fixed the logger creating a handler every time it is called.
- Loading branch information
Showing
6 changed files
with
1,423 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env python | ||
""" | ||
@author Peter Zaffetti 2018 | ||
""" | ||
from stick_knot import StickKnot | ||
|
||
|
||
class MonotonicallyFormattedCurve: | ||
|
||
def __init__(self, knot_name, stick_knot): | ||
self.knot_name = knot_name | ||
self.stick_knot = stick_knot | ||
|
||
def get_name(self): | ||
return self.knot_name | ||
|
||
def get_stick_knot(self): | ||
return self.stick_knot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from monotonically_formatted_curve import MonotonicallyFormattedCurve | ||
from logger import get_logger | ||
|
||
|
||
# TODO: Refactor the hardcoded coordinate location: 0 should be a variable x, 1 should be y, and 2 should be z | ||
def calculate_monotonicity(monotonically_formatted_curve): | ||
curve_name = monotonically_formatted_curve.get_name() | ||
stick_knot_points = monotonically_formatted_curve.get_stick_knot().get_points() | ||
|
||
# PDZ- This will hold the monotonic status for all the coordinates. 0 means no monotonicity, 1 mean monotonically increasing, and -1 mean monotonically decreasing | ||
coordinate_monotonic_status = [0, 0, 0] | ||
for i in range(1, len(stick_knot_points) - 1): | ||
if i == 1: | ||
coordinate_monotonic_status[0] = calculate_coordinate_monotonicity(0, stick_knot_points[i - 1], stick_knot_points[i]) | ||
coordinate_monotonic_status[1] = calculate_coordinate_monotonicity(1, stick_knot_points[i - 1], | ||
stick_knot_points[i]) | ||
coordinate_monotonic_status[2] = calculate_coordinate_monotonicity(2, stick_knot_points[i - 1], | ||
stick_knot_points[i]) | ||
|
||
else: | ||
# PDZ- Check each monotonicity status: if it differs then just set the coordinate to 0. Otherwise, leave it alone. At the end, any that are 0 aren't monotonic | ||
if calculate_coordinate_monotonicity(0, stick_knot_points[i - 1], stick_knot_points[i]) != coordinate_monotonic_status[0]: | ||
coordinate_monotonic_status[0] = 0 # PDZ- X coordinate was checked | ||
|
||
if calculate_coordinate_monotonicity(1, stick_knot_points[i - 1], stick_knot_points[i]) != coordinate_monotonic_status[1]: | ||
coordinate_monotonic_status[1] = 0 # PDZ- Y coordinate was checked | ||
|
||
if calculate_coordinate_monotonicity(2, stick_knot_points[i - 1], stick_knot_points[i]) != coordinate_monotonic_status[2]: | ||
coordinate_monotonic_status[2] = 0 # PDZ- Z coordinate was checked | ||
|
||
logger = get_logger(calculate_monotonicity.__name__) | ||
|
||
logger.info("%s, x: %s" % (curve_name, convert_int_to_monotonicity_str(coordinate_monotonic_status[0]))) | ||
logger.info("%s, y: %s" % (curve_name, convert_int_to_monotonicity_str(coordinate_monotonic_status[1]))) | ||
logger.info("%s, z: %s" % (curve_name, convert_int_to_monotonicity_str(coordinate_monotonic_status[2]))) | ||
logger.info("End of curve\n") | ||
|
||
|
||
def convert_int_to_monotonicity_str(value): | ||
if value == 0: | ||
return "no" | ||
if value == 1: | ||
return "Strictly Mono Increasing" | ||
if value == -1: | ||
return "Strictly Mono Decreasing" | ||
|
||
return "Something wasn't quite right" | ||
|
||
|
||
def calculate_coordinate_monotonicity(index, stick_knot_point_behind, stick_knot_point_current): | ||
prev_coord_val = 0 | ||
current_coord_val = 0 | ||
|
||
if index == 0: | ||
prev_coord_val = stick_knot_point_behind.get_x() | ||
current_coord_val = stick_knot_point_current.get_x() | ||
elif index == 1: | ||
prev_coord_val = stick_knot_point_behind.get_y() | ||
current_coord_val = stick_knot_point_current.get_y() | ||
elif index == 2: | ||
prev_coord_val = stick_knot_point_behind.get_z() | ||
current_coord_val = stick_knot_point_current.get_z() | ||
|
||
if prev_coord_val < current_coord_val: # PDZ- Increasing since the point is bigger | ||
return 1 | ||
elif prev_coord_val > current_coord_val: # PDZ- Decreasing | ||
return -1 | ||
else: # PDZ- Same point | ||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.