Skip to content

Commit

Permalink
enh: remove unnecessary integer conversions
Browse files Browse the repository at this point in the history
round() produces an integer already, if no explicit number of decimal places passed as 2nd parameter. Wrapping it into another int() is hence unnecessary.

Arithmetic operations with non-numeric/invalid values produce meaningful error messages. Wrapping input values into int() before dividing or multiplying them, is hence unnecessary. Manually entered floats in UI input and config file are then mathematically correctly rounded, which however cannot cause a value drift in save/read cycles, since on both ends, the float is converted into an integer directly.

Signed-off-by: MichaIng <[email protected]>
  • Loading branch information
MichaIng committed Dec 8, 2024
1 parent 1518046 commit b1c0fb6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions motioneye/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ def motion_camera_ui_to_dict(ui, prev_config=None):
'threshold_maximum': ui['max_frame_change_threshold'],
'threshold_tune': ui['auto_threshold_tuning'],
'noise_tune': ui['auto_noise_detect'],
'noise_level': max(1, int(round(int(ui['noise_level']) * 2.55))),
'noise_level': max(1, round(ui['noise_level'] * 2.55)),
'lightswitch_percent': ui['light_switch_detect'],
'event_gap': int(ui['event_gap']),
'pre_capture': int(ui['pre_capture']),
Expand Down Expand Up @@ -1384,7 +1384,7 @@ def motion_camera_dict_to_ui(data):
'auto_noise_detect': data['noise_tune'],
'max_frame_change_threshold': data['threshold_maximum'],
'auto_threshold_tuning': data['threshold_tune'],
'noise_level': round(int(data['noise_level']) / 2.55),
'noise_level': round(data['noise_level'] / 2.55),
'light_switch_detect': data['lightswitch_percent'],
'despeckle_filter': data['despeckle_filter'],
'event_gap': int(data['event_gap']),
Expand Down

0 comments on commit b1c0fb6

Please sign in to comment.