Skip to content

Commit

Permalink
Merge pull request #1187 from mrbeam/develop
Browse files Browse the repository at this point in the history
v0.9.0
  • Loading branch information
khaledsherkawi authored Mar 1, 2021
2 parents a6d0c98 + a810161 commit af34515
Show file tree
Hide file tree
Showing 135 changed files with 9,424 additions and 3,078 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ octoprint_mrbeam/gcodegenerator/simplestyle.pyc
octoprint_mrbeam/gcodegenerator/simpletransform.pyc
octoprint_mrbeam/printer.pyc
octoprint_mrbeam/profile.pyc
octoprint_mrbeam/.jshintrc
octoprint_mrbeam/static/messages/test_messages.json
*.pyc
*.swp
.idea
Expand Down
290 changes: 87 additions & 203 deletions octoprint_mrbeam/__init__.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion octoprint_mrbeam/__version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.8.0"
__version__ = "0.9.0"
5 changes: 4 additions & 1 deletion octoprint_mrbeam/analytics/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def update_progress(self, progress):
self._progress = progress

def _add_cpu_temp_value(self, cpu_temp):
rounded = str(self._round_temp_down_to(cpu_temp))
if cpu_temp == None:
rounded = "None"
else:
rounded = str(self._round_temp_down_to(cpu_temp))
if rounded in self._temp:
self._temp[rounded] += 1
else:
Expand Down
58 changes: 53 additions & 5 deletions octoprint_mrbeam/analytics/review_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def __init__(self, plugin):
self._plugin = plugin
self._event_bus = plugin._event_bus
self._settings = plugin._settings
self._usage_handler = plugin.usage_handler
self._device_info = plugin._device_info

self.review_folder = os.path.join(
self._settings.getBaseFolder("base"),
Expand All @@ -40,19 +42,65 @@ def __init__(self, plugin):

self._current_job_time_estimation = -1

# sync given value from settings to usage_handler
self._sync_given_val_to_usage_handler()

self._event_bus.subscribe(
MrBeamEvents.MRB_PLUGIN_INITIALIZED, self._on_mrbeam_plugin_initialized
)

def _on_mrbeam_plugin_initialized(self, event, payload):
ReviewFileUploader.upload_now(self._plugin, self._review_lock)

def save_review_data(self, data):
self._write_review_to_file(data)
self._settings.set_boolean(["review", "given"], data["dontShowAgain"])
self._settings.save() # This is necessary because without it the value is not saved
def is_review_already_given(self):
return bool(
self._usage_handler.get_review_given()
# deprecated
or self._settings.get(["review", "given"])
)

ReviewFileUploader.upload_now(self._plugin, self._review_lock)
def save_review_data(self, data):
if not self.is_review_already_given() or data.get("debug", False):
data = self._add_review_data(data)
self._write_review_to_file(data)
if data["dontShowAgain"]:
if data["rating"] > 0:
# write here only if we really go a review
# if user clicked don't show again, we ask after a reset or rescue stick
self._usage_handler.set_review_given(migrated=False)
# deprecated but needed while this version is in beta and users could go back
self._settings.set_boolean(["review", "given"], True)
else:
self._settings.set_boolean(["review", "doNotAskAgain"], True)
self._settings.save() # This is necessary because without it the value is not saved

ReviewFileUploader.upload_now(self._plugin, self._review_lock)
else:
self._logger.warn("Not accepting user review since it was already given.")

def _sync_given_val_to_usage_handler(self):
"""
_settings.get(["review", "given"]) is deprecated
"""
if not self._usage_handler.get_review_given() and self._settings.get(
["review", "given"]
):
self._logger.info("Syncing review state 'given' to _usage_handler...")
self._usage_handler.set_review_given(migrated=True)

def _add_review_data(self, data):
try:
data["env"] = self._plugin.get_env()
data["snr"] = self._device_info.get_serial()
data["sw_version"] = self._plugin._plugin_version
data["sw_tier"] = self._settings.get(["dev", "software_tier"])
data["model"] = self._device_info.get_model()
data["production_date"] = self._device_info.get_production_date()
data["total_usage"] = self._usage_handler.get_total_usage()
data["total_jobs"] = self._usage_handler.get_total_jobs()
except:
self._logger.exception("Unable to fill system data to user review.")
return data

def _write_review_to_file(self, review):
try:
Expand Down
19 changes: 19 additions & 0 deletions octoprint_mrbeam/analytics/usage_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,19 @@ def reset_gantry_usage(self):
self._write_usage_data()
self.write_usage_analytics(action="reset_gantry")

def get_review_given(self):
return self._usage_data.get("review", {}).get("given", False)

def set_review_given(self, migrated=False):
if not self.get_review_given():
self._usage_data["review"] = {
"given": True,
"ts": time.time(),
"v": self._plugin_version,
"migrated": migrated,
}
self._write_usage_data()

def _log_usage_data(self, usage_data):
self._logger.info(
"USAGE DATA: prefilter={pre}, carbon_filter={carbon}, laser_head={lh}, gantry={gantry}, compressor={compressor}".format(
Expand Down Expand Up @@ -315,6 +328,12 @@ def get_total_usage(self):
else:
return 0

def get_total_jobs(self):
if "succ_jobs" in self._usage_data:
return self._usage_data["succ_jobs"]["count"]
else:
return 0

def _load_usage_data(self):
success = False
recovery_try = False
Expand Down
10 changes: 6 additions & 4 deletions octoprint_mrbeam/camera/corners.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
from numpy.linalg import norm
import cv2
from octoprint_mrbeam.camera import lens
from octoprint_mrbeam.mrb_logger import mrb_logger

# Set this after merging the logging overhaul.
_logger = logging.getLogger(__name__)
_logger = mrb_logger("octoprint.plugins.mrbeam.camera.corners")

# @logtime()
def warpImgByCorners(image, corners, zoomed_out=False):
Expand Down Expand Up @@ -83,7 +83,7 @@ def f(qd):


def save_corner_calibration(
path, newCorners, newMarkers, hostname=None, from_factory=False
path, newCorners, newMarkers, hostname=None, plugin_version=None, from_factory=False
):
"""Save the settings onto a calibration file"""

Expand Down Expand Up @@ -113,7 +113,9 @@ def save_corner_calibration(
pic_settings[__CORNERS_KEY] = newCorners
pic_settings[__MARKERS_KEY] = newMarkers
if hostname:
pic_settings["hostname_KEY"] = hostname
pic_settings["hostname"] = hostname
if plugin_version:
pic_settings["version"] = plugin_version
write_corner_calibration(pic_settings, path)


Expand Down
15 changes: 15 additions & 0 deletions octoprint_mrbeam/camera/lens.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from os import path
import numpy as np
from copy import copy
import re

from octoprint_mrbeam.camera.definitions import (
LEGACY_STILL_RES,
Expand All @@ -33,6 +34,7 @@
TMP_PATH,
TMP_RAW_FNAME,
TMP_RAW_FNAME_RE,
TMP_RAW_FNAME_RE_NPZ,
)
from octoprint_mrbeam.mrbeam_events import MrBeamEvents
from octoprint_mrbeam.util import makedirs, get_thread
Expand Down Expand Up @@ -104,6 +106,19 @@ def undist_dict(dict_pts, *a, **kw):
return {keys[i]: np.array(pos) for i, pos in enumerate(res_iter)}


def clean_unexpected_files(tmp_path):
"""
Removes unexpected files in the directory path
- .npz files that do not have the corresponding image anymore
"""
files = os.listdir(tmp_path)
for f in files:
_logger.info("File: {} - file[:-4] - {}".format(f, f[:-4]))
if re.match(TMP_RAW_FNAME_RE_NPZ, f) and not f[:-4] in files:
_logger.info("Match !")
os.remove(path.join(tmp_path, f))


### CAMERA LENS CALIBRATION


Expand Down
Loading

0 comments on commit af34515

Please sign in to comment.