-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from bartekbiz/Fixed-problem-with-flow-calcula…
…tions Fixed problem with flow calculations
- Loading branch information
Showing
7 changed files
with
125 additions
and
57 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 |
---|---|---|
@@ -1,19 +1,16 @@ | ||
|
||
class PlotCalculations: | ||
@staticmethod | ||
def calc_linear_regression(x, y, span=30): | ||
def calc_linear_regression(x, y, span): | ||
result_x = [] | ||
result_dy_dx = [] | ||
|
||
for i in range(len(x) - span): | ||
# Obliczenie przybliżonej pochodnej numerycznej | ||
dx = x[i + span] - x[i] | ||
dy = y[i + span] - y[i] | ||
dy_dx = dy / dx | ||
|
||
result_x.append(x[i]) | ||
result_dy_dx.append(dy_dx) | ||
if dx != 0: | ||
dy_dx = dy / dx | ||
result_x.append(x[i]) | ||
result_dy_dx.append(dy_dx) | ||
|
||
return result_x, result_dy_dx | ||
|
||
|
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 |
---|---|---|
@@ -1,26 +1,26 @@ | ||
from controls.base.TextEntry import TextEntry | ||
from controls.base.TextLabel import TextLabel | ||
|
||
|
||
class VAverageField: | ||
def __init__(self, window, module, row): | ||
self.v_average_field_label = VAverageLabel(window, row) | ||
self.v_average_field_display = VAverageDisplay(window, row) | ||
|
||
def update_display(self, text): | ||
self.v_average_field_display.config(text=text) | ||
self.v_average_label = VAverageLabel(window, row) | ||
self.v_average_entry = VAverageEntry(window, module, row) | ||
|
||
def destroy(self): | ||
self.v_average_field_label.destroy() | ||
self.v_average_field_display.destroy() | ||
self.v_average_label.destroy() | ||
self.v_average_entry.destroy() | ||
|
||
|
||
class VAverageLabel(TextLabel): | ||
def __init__(self, window, row): | ||
super().__init__(window, text="V Average", width=12) | ||
super().__init__(window, text=" VAverage") | ||
self.grid(row=row, column=0, padx=10, sticky="nw") | ||
|
||
|
||
class VAverageDisplay(TextLabel): | ||
def __init__(self, window, row): | ||
super().__init__(window, text="0", width=10) | ||
class VAverageEntry(TextEntry): | ||
def __init__(self, window, module, row): | ||
super().__init__(window, module.v_average_entry) | ||
self.grid(row=row, column=1, padx=10, sticky="ne") | ||
self.bind("<FocusOut>", module.update_flow) | ||
self.bind("<Return>", module.update_flow) |
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
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,28 @@ | ||
from plots.AnimatedPlot import AnimatedPlot | ||
class DisplacementPlot(AnimatedPlot): | ||
def __init__(self, window, app, data, plot_names, plot_units, plot_x_name): | ||
super().__init__(window, app, data, plot_names, plot_units, plot_x_name) | ||
|
||
def update_ax2_ax3_data(self): | ||
v_len = len(self.velocity_y) | ||
v_custom_range_min = v_len - 1 if v_len != 0 else 0 | ||
|
||
a_len = len(self.acceleration_y) | ||
a_custom_range_min = a_len - 1 if a_len != 0 else 0 | ||
|
||
v_x, v_y = self.plot_calculations.calc_linear_regression(self.animated_x, self.animated_y, self.span) | ||
a_x, a_y = self.plot_calculations.calc_linear_regression(v_x, v_y, self.span) | ||
|
||
self.ax2.plot( | ||
v_x[v_custom_range_min:], | ||
v_y[v_custom_range_min:], | ||
self.color | ||
) | ||
|
||
self.ax3.plot( | ||
a_x[a_custom_range_min:], | ||
a_y[a_custom_range_min:], | ||
self.color | ||
) | ||
self.velocity_y.extend(v_y[v_len:]) | ||
self.acceleration_y.extend(a_y[a_len:]) |
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,29 @@ | ||
from plots.AnimatedPlot import AnimatedPlot | ||
class FlowPlot(AnimatedPlot): | ||
def __init__(self, window, app, data, plot_names, plot_units, plot_x_name): | ||
super().__init__(window, app, data, plot_names, plot_units, plot_x_name) | ||
|
||
def update_ax2_ax3_data(self): | ||
v_len = len(self.velocity_y) | ||
v_custom_range_min = v_len - 1 if v_len != 0 else 0 | ||
|
||
a_len = len(self.acceleration_y) | ||
a_custom_range_min = a_len - 1 if a_len != 0 else 0 | ||
|
||
v_x = self.animated_x | ||
v_y = [y * 50 for y in self.animated_y] | ||
a_x, a_y = self.plot_calculations.calc_linear_regression(v_x, v_y, self.span) | ||
|
||
self.ax2.plot( | ||
v_x[v_custom_range_min:], | ||
v_y[v_custom_range_min:], | ||
self.color | ||
) | ||
|
||
self.ax3.plot( | ||
a_x[a_custom_range_min:], | ||
a_y[a_custom_range_min:], | ||
self.color | ||
) | ||
self.velocity_y.extend(v_y[v_len:]) | ||
self.acceleration_y.extend(a_y[a_len:]) |