Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sending regular progress messages #16

Merged
merged 3 commits into from
Jul 12, 2017
Merged

Conversation

tsh-xx
Copy link
Contributor

@tsh-xx tsh-xx commented Jun 2, 2017

Add interval setting to configuration screen
Incremented revision

Resolves #15

I was unsure about using the devel branch or master - seems they've diverged. I started working with master, and currently haven't managed to demonstrate devel working (without my changes).

Coding style isn't great, it was more of a challenge than I expected to get this to work - so given some pointers I can make updates if necessary. At least anyone who needs it can try my version and give feedback.

Default interval is 30 min (can be changes in the configuration page)
First and last messages should be suppressed (based on estimated print time)
Incremented revision
@prahjister
Copy link

I'm sorry I'm a git noob. How can I test this?

@foosel
Copy link
Member

foosel commented Jun 2, 2017

Awesome! 😄

I'll take a proper look ASAP - hopefully early next week, if no unforeseen OctoPrint emergencies get in the way!

Copy link
Member

@foosel foosel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are sadly some huge TODOs left. I have to admit I didn't understand at all what is going on in the progress handler, there's so much back and forth of variables and calculations with seemingly arbitrary values that it's unclear what is happening for what reason and when. All in all it looks to be way too complicated for what it is supposed to achieve, so I think some clarification is required. There are also some typos in there that would cause stuff not to work as expected at all, and I think a parameter you added to the connection handler probably made connection to pushbullet stop entirely.


def _connect_bullet(self, apikey, channel_name=""):
self._bullet, self._sender = self._create_sender(apikey, channel_name)

#~~ progress message helpers
def _sanitize_current_data(self, currentData):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's dangerous to just use arbitrary values (1000, 0, ...) instead of the actual values. If they are None they are None for a reason - they are unknown or not stable and shouldn't be displayed to the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I borrowed this from the detailed progress plugin, I've simplified it now.

if (currentData["progress"]["printTimeLeft"] == None):
currentData["progress"]["printTimeLeft"] = currentData["job"]["estimatedPrintTime"]
if (currentData["progress"]["printTimeLeft"] == None):
self._logger.info("Messasge: Still got no print time {}".format(currentData["progress"]["printTimeLeft"]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and most of the other info logging lines should be self._logger.debug and you also had a consistent typo there: "Messasge" instead of "Message" (but why the prefix at all, that it's a log message is fairly visible if it lands in the log anyhow, no need to explicitly state this?).


return currentData

def _get_time_from_seconds(self, seconds):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less lines:

days, seconds = divmod(seconds, 86400)
hours, seconds = divmod(seconds, 3600)
minutes, seconds = divmod(seconds, 60)
return self._etl_format.format(**locals())

minutes = 0
if seconds >= 86400:
days = int(seconds / 86400)
secionds = seconds % 86400
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, "secionds" instead of "seconds", this will produce wrong results.

access_token=None,
push_channel=None,
printDone=dict(
title="Print job finished",
body="{file} finished printing in {elapsed_time}"
),
printPartial=dict(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think printProgress would be more fitting, or what do you think?

return self._etl_format.format(**locals())

#~~ PrintProgressPlugin
def on_print_progress(self, storage, path, progress):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to admit I don't fully understand the calculations going on in this method, but I have the feeling it is way too complicated for what it's supposed to achieve (regularly send an update to the user).

From what I understand your calculations are supposed to limit the amount of messages sent out due to the API limitations of the Pushbullet API, however, it's completely intransparent to me HOW it's supposed to do that and also it appears to do it in a very convulted way. Since in the end I'll be responsible of maintaining this, some explanation would be great :)

What I'd prefer here is splitting this method up to make operation a bit clearer. First of all determine if according to rate limiting you want to send a message in the first place. If not, abort and return. Once you've figured out you want to send a message, fetch the data you need for that, format it and go for it. Replace values you don't know yet with a placeholder ("unknown"?) instead of arbitrarily determined values. Also just fetch what you need from the data structure provided by the backend once instead of multiple times and create your own data structure. Makes things also way more readable due to less [][][] noise.

@@ -29,10 +33,106 @@ def __init__(self):
self._bullet = None
self._channel = None
self._sender = None
self._pc_interval = 5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very cryptic identifier, what does pc stand for here?

@@ -26,6 +26,17 @@
<input type="text" class="input-block-level" data-bind="value: settings.settings.plugins.octobullet.push_channel">
</div>
</div>
{% trans %}<p>
You can define a time interval (in minutes) here for regular update messages as the print progresses. Set to 0 to prevent updates. First and last messages will usually not be sent. Be aware of the monthly message limit applied to free PushBullet accounts.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting quiet time to 0 turns stuff off? I find this unintuitive. At least UI wise it should maybe rather be displayed as a toggle switch (which internally sets that value to 0 to signal it's disabled) which when toggled on allows setting the quiet time (> 1).

Also, I can't help myself, but I think "quiet_time" for something that is actually a "regular progress report interval" is a very unintuitive name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New config added.

@@ -45,7 +145,7 @@ def on_settings_load(self):
data = octoprint.plugin.SettingsPlugin.on_settings_load(self)

# only return our restricted settings to admin users - this is only needed for OctoPrint <= 1.2.16
restricted = ("access_token", "push_channel")
restricted = ("quiet_minutes", "access_token", "push_channel")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to restrict access to "quiet_minutes", it's not really sensitive information, right?

)
)

def get_settings_restricted_paths(self):
# only used in OctoPrint versions > 1.2.16
return dict(admin=[["access_token"], ["push_channel"]])
return dict(admin=[["quiet_minutes"], ["access_token"], ["push_channel"]])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to restrict access to "quiet_minutes", it's not really sensitive information, right?

@tsh-xx
Copy link
Contributor Author

tsh-xx commented Jun 7, 2017

Thanks for the review - should be easy enough to fix with those pointers...

@foosel
Copy link
Member

foosel commented Jun 23, 2017

Sorry, somehow Github didn't notify me about the fact that you pushed changes. I'll take a look ASAP (probably early next week though).

@tsh-xx
Copy link
Contributor Author

tsh-xx commented Jun 23, 2017

I still have to update the more functional parts, may find time this weekend.

@foosel
Copy link
Member

foosel commented Jun 23, 2017

Ah, ok. In that case, could you drop me a quick comment here when you have done that? :)

Regular messages now generated based on time, not percent done.
Config flag to disable regular messages
Simplified generation of data to display
@tsh-xx
Copy link
Contributor Author

tsh-xx commented Jun 26, 2017

OK, it should be worth another look now - it's all a lot simpler. I'm in two minds about if it's necessary to update the README to describe this feature, given that the config page is more visible to the end user.

@foosel foosel merged commit adbc739 into OctoPrint:master Jul 12, 2017
@foosel
Copy link
Member

foosel commented Jul 12, 2017

Merged, slightly refactored and pushed as part of 0.1.9 together with some other things. Thanks :)

@warbeerocks1
Copy link

warbeerocks1 commented Jul 13, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants