Skip to content

Commit

Permalink
Remove the period after the comment if not too long.
Browse files Browse the repository at this point in the history
  • Loading branch information
KmolYuan committed Aug 30, 2019
1 parent 1e92634 commit 6a75d16
Show file tree
Hide file tree
Showing 23 changed files with 59 additions and 78 deletions.
7 changes: 2 additions & 5 deletions core/io/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
from core.info import logger
from .overview import OverviewDialog
from .Ui_database import Ui_Form
nan = float('nan')

if TYPE_CHECKING:
from core.widgets import MainWindowBase

Expand All @@ -63,7 +61,7 @@ def _compress(obj: Any) -> bytes:

def _decompress(obj: Union[bytes, BlobField]) -> Any:
"""Use to decode the Python script."""
return eval(decompress(obj).decode())
return eval(decompress(obj).decode(), {'nan': float('nan')})


"""Create a empty Sqlite database object."""
Expand Down Expand Up @@ -447,8 +445,7 @@ def __add_commit(self, commit: CommitModel):
button.loaded.connect(self.__load_commit_id)
self.load_id.connect(button.set_loaded)
self.CommitTable.setCellWidget(row, 0, button)

self.CommitTable.setItem(row, 2, QTableWidgetItem(commit.description))
self.CommitTable.setItem(row, 2, QTableWidgetItem(str(commit.description)))

author_name = commit.author.name
for row in range(self.AuthorList.count()):
Expand Down
1 change: 0 additions & 1 deletion core/io/pyslvs_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
QCoreApplication,
)
from .overview import OverviewDialog

if TYPE_CHECKING:
from core.widgets import MainWindowBase

Expand Down
1 change: 0 additions & 1 deletion core/io/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
QWheelEvent,
)
from .Ui_script import Ui_Dialog

if TYPE_CHECKING:
from core.widgets import MainWindowBase

Expand Down
10 changes: 4 additions & 6 deletions core/main_window/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ def __init__(self):
super(MainWindow, self).__init__()
self.restore_settings()

# Console widget.
# Console widget
self.console_error_option.setChecked(ARGUMENTS.debug_mode)
if not ARGUMENTS.debug_mode:
self.__console_connect()

# Start first solve function calling.
# Start first solve function calling
self.solve()

# Load workbook from argument.
# Load workbook from argument
self.load_from_args()

def closeEvent(self, event: QCloseEvent):
Expand Down Expand Up @@ -128,8 +127,7 @@ def merge_result(self, expr: str, path: Sequence[Sequence[Tuple[float, float]]])
"""Merge result function of dimensional synthesis."""
if not self.ask_add_storage(expr):
return

# Add the path.
# Add the path
i = 0
while f"Algorithm_{i}" in self.inputs_widget.path_data():
i += 1
Expand Down
45 changes: 22 additions & 23 deletions core/main_window/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ def slvs_solve(
x, y = vpoint.c[0]
if vpoint.type in {VJoint.P, VJoint.RP}:
sliders[i] = len(slider_bases)
# Base point (slot) is fixed.
# Base point (slot) is fixed
point = sys.add_point_2d(x, y, wp)
sys.dragged(point, wp)
slider_bases.append(point)
# Slot point (slot) is movable.
# Slot point (slot) is movable
x += cos(vpoint.angle)
y += sin(vpoint.angle)
slider_slots.append(sys.add_point_2d(x, y, wp))
# Pin is movable.
# Pin is movable
x, y = vpoint.c[1]
if vpoint.has_offset() and vpoint.true_offset() <= 0.1:
if vpoint.offset() > 0:
Expand All @@ -109,20 +109,20 @@ def slvs_solve(
point = sys.add_point_2d(x, y, wp)
if vpoint.type in {VJoint.P, VJoint.RP}:
sliders[i] = len(slider_bases)
# Base point (slot) is movable.
# Base point (slot) is movable
slider_bases.append(point)
# Slot point (slot) is movable.
# Slot point (slot) is movable
x += cos(vpoint.angle)
y += sin(vpoint.angle)
slider_slots.append(sys.add_point_2d(x, y, wp))
if vpoint.pin_grounded():
# Pin is fixed.
# Pin is fixed
x, y = vpoint.c[1]
point = sys.add_point_2d(x, y, wp)
sys.dragged(point, wp)
points.append(point)
else:
# Pin is movable.
# Pin is movable
x, y = vpoint.c[1]
if vpoint.has_offset() and vpoint.true_offset() <= 0.1:
if vpoint.offset() > 0:
Expand All @@ -133,8 +133,7 @@ def slvs_solve(
y -= 0.1
points.append(sys.add_point_2d(x, y, wp))
continue

# Point is movable.
# Point is movable
points.append(point)

for vlink in vlinks.values():
Expand Down Expand Up @@ -178,7 +177,7 @@ def slvs_solve(
# Base slot
slider_slot = sys.add_line_2d(slider_bases[b], slider_slots[b], wp)
if vp1.grounded():
# Slot is grounded.
# Slot is grounded
sys.angle(hv, slider_slot, vp1.angle, wp)
sys.coincident(p1, slider_slot, wp)
if vp1.has_offset():
Expand All @@ -188,14 +187,14 @@ def slvs_solve(
else:
sys.coincident(p2, p1, wp)
else:
# Slider between links.
# Slider between links
for name in vp1.links[:1]: # type: str
vlink = vlinks[name]
# A base link friend.
# A base link friend
c = vlink.points[0]
if c == a:
if len(vlink.points) < 2:
# If no any friend.
# If no any friend
continue
c = vlink.points[1]

Expand Down Expand Up @@ -226,11 +225,11 @@ def slvs_solve(

for name in vp1.links[1:]:
vlink = vlinks[name]
# A base link friend.
# A base link friend
c = vlink.points[0]
if c == a:
if len(vlink.points) < 2:
# If no any friend.
# If no any friend
continue
c = vlink.points[1]

Expand All @@ -249,9 +248,9 @@ def slvs_solve(
)

for (b, d), angle in inputs.items():
# The constraints of drive shaft.
# Simulate the input variables to the mechanism.
# The 'base points' are shaft center.
# The constraints of drive shaft
# Simulate the input variables to the mechanism
# The 'base points' are shaft center
if b == d:
continue

Expand Down Expand Up @@ -439,14 +438,14 @@ def preview_path(
else:
raise ValueError("incorrect kernel")
except ValueError:
# Update with error sign.
# Update with error sign
for i in range(vpoint_count):
auto_preview[i].append((nan, nan))
# Back to last feasible solution.
# Back to last feasible solution
angles[dp] -= interval
dp += 1
else:
# Update with result.
# Update with result
for i in range(vpoint_count):
if vpoints[i].type == VJoint.R:
auto_preview[i].append(result[i])
Expand Down Expand Up @@ -483,7 +482,7 @@ def get_graph(self) -> Tuple[
for b, d, _ in self.inputs_widget.input_pairs():
input_pair.update({b, d})

# links name for RP joint.
# links name for RP joint
k = len(self.vlink_list)

graph = Graph([])
Expand All @@ -492,7 +491,7 @@ def get_graph(self) -> Tuple[
same = {}
used_point = set()
mapping = {}
# Link names will change to index number.
# Link names will change to index number
for i, vlink in enumerate(self.vlink_list):
for p in vlink.points:
if p in used_point:
Expand Down
1 change: 0 additions & 1 deletion core/synthesis/collections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from .structure_widget import StructureWidget
from .configure_widget import ConfigureWidget
from .dialogs import CollectionsDialog

if TYPE_CHECKING:
from core.widgets import MainWindowBase

Expand Down
7 changes: 3 additions & 4 deletions core/synthesis/collections/configure_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
list_texts,
)
from .Ui_configure_widget import Ui_Form

if TYPE_CHECKING:
from core.widgets.main_base import MainWindowBase

Expand Down Expand Up @@ -228,7 +227,7 @@ def set_graph(
for link in links:
self.grounded_list.addItem("(" + ", ".join(link) + ")")

# Point name as (P1, P2, P3, ...).
# Point name is (P1, P2, P3, ...)
for node in pos:
self.joint_name.addItem(f'P{node}')

Expand Down Expand Up @@ -434,7 +433,7 @@ def __set_parm_bind(self, _=None):
for row, gs in enumerate(list_texts(self.grounded_list)):
try:
link_expr = []
# Links from grounded list.
# Links from grounded list
for name in gs.replace('(', '').replace(')', '').split(", "):
num = int(name.replace('P', ''))
if num in self.configure_canvas.same:
Expand All @@ -443,7 +442,7 @@ def __set_parm_bind(self, _=None):
except KeyError:
continue
else:
# Customize joints.
# Customize joints
for joint, link in self.configure_canvas.cus.items():
if row == link:
link_expr.append(f"P{joint}")
Expand Down
1 change: 0 additions & 1 deletion core/synthesis/collections/dialogs/customs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from typing import TYPE_CHECKING
from core.QtModules import Slot, Qt, QDialog
from .Ui_customs import Ui_Dialog

if TYPE_CHECKING:
from core.synthesis.collections import ConfigureWidget

Expand Down
3 changes: 1 addition & 2 deletions core/synthesis/collections/structure_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
)
from .dialogs.targets import TargetsDialog
from .Ui_structure_widget import Ui_Form

if TYPE_CHECKING:
from core.widgets import MainWindowBase

Expand Down Expand Up @@ -355,7 +354,7 @@ def __set_selection(self, item: QListWidgetItem):
))
self.selection_window.addItem(item_preview)

# Set attributes.
# Set attributes
self.edges_text.setText(str(list(g.edges)))
self.nl_label.setText(str(len(g.nodes)))
self.nj_label.setText(str(len(g.edges)))
Expand Down
9 changes: 4 additions & 5 deletions core/synthesis/dimensional_synthesis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
ChartDialog,
)
from .Ui_dimension_widget import Ui_Form

if TYPE_CHECKING:
from core.widgets import MainWindowBase

Expand Down Expand Up @@ -264,7 +263,7 @@ def __import_xlsx(self):
wb = load_workbook(file_name)
ws = wb.get_sheet_by_name(wb.get_sheet_names()[0])
data = []
# Keep finding until there is no value.
# Keep finding until there is no value
i = 1
while True:
x = ws.cell(row=i, column=1).value
Expand Down Expand Up @@ -403,14 +402,14 @@ def __synthesis(self):
"The length of target paths should be the same."
)
return
# Get the algorithm type.
# Get the algorithm type
if self.type0.isChecked():
type_num = AlgorithmType.RGA
elif self.type1.isChecked():
type_num = AlgorithmType.Firefly
else:
type_num = AlgorithmType.DE
# Deep copy it so the pointer will not the same.
# Deep copy it so the pointer will not the same
mech_params = deepcopy(self.mech_params)
mech_params['Expression'] = parse_vpoints(mech_params.pop('Expression', []))
mech_params['Target'] = deepcopy(self.path)
Expand All @@ -431,7 +430,7 @@ def name_in_table(target_name: str) -> int:
self.parameter_list.cellWidget(row, 4).value(),
)

# Start progress dialog.
# Start progress dialog
dlg = ProgressDialog(type_num, mech_params, self.alg_options, self)
dlg.show()
if not dlg.exec():
Expand Down
8 changes: 4 additions & 4 deletions core/synthesis/dimensional_synthesis/dialogs/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ def __set_chart(self, tab_name: str, pos_x: int, pos_y: int):
axis_y.setTickCount(11)

if self.__algorithm_data:
# Just copy references from algorithm data.
# Just copy references from algorithm data
plot = [data['time_fitness'] for data in self.__algorithm_data]

# X max.
# X max
max_x = int(max([max([tnf[pos_x] for tnf in data]) for data in plot]) * 100)
axis_x.setMax(max_x)
i10 = int(max_x / 10)
Expand All @@ -84,11 +84,11 @@ def __set_chart(self, tab_name: str, pos_x: int, pos_y: int):
for i in range(0, 1000, 100):
axis_x.append(str(i / 100), i)

# Y max.
# Y max
max_y = max(max([tnf[pos_y] for tnf in data]) for data in plot) + 10
else:
plot = None
# Y max.
# Y max
max_y = 100

max_y -= max_y % 10
Expand Down
2 changes: 1 addition & 1 deletion core/synthesis/dimensional_synthesis/dialogs/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def __set_args(self, settings: Dict[str, Any]):
self.min_fit.setValue(settings['min_fit'])
elif 'max_time' in settings:
self.max_time_option.setChecked(True)
# In second (int).
# In second (int)
max_time = settings['max_time']
self.max_time_h.setValue(max_time // 3600)
self.max_time_m.setValue((max_time % 3600) // 60)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
QMessageBox,
)
from .Ui_path_adjust import Ui_Dialog

if TYPE_CHECKING:
from core.synthesis import DimensionalSynthesis

Expand Down
6 changes: 3 additions & 3 deletions core/synthesis/dimensional_synthesis/dialogs/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(

self.mechanisms: List[Dict[str, Any]] = []

# Batch label.
# Batch label
if 'max_gen' in setting:
self.limit = setting['max_gen']
if self.limit > 0:
Expand All @@ -71,14 +71,14 @@ def __init__(
self.limit_mode = 'max_gen'
self.loopTime.setEnabled(self.limit > 0)

# Timer.
# Timer
self.time = 0
self.timer = QTimer()
self.timer.setInterval(1000)
self.timer.timeout.connect(self.__set_time)
self.time_spend = 0.

# Worker thread.
# Worker thread
self.work = WorkerThread(type_num, mech_params, setting, self)
self.stop_signal.connect(self.work.stop)
if self.work.is_two_kernel():
Expand Down
Loading

0 comments on commit 6a75d16

Please sign in to comment.