-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add unixtime pseudo-variable to jinja2 context #6010
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
base: master
Are you sure you want to change the base?
Conversation
|
Thanks, but I'm not sure this is a good fit for the Klipper master branch. As high-level feedback, it seems a bit "esoteric" and I'm not sure it is worth the additional code and documentation complexity. Separately, the existing (undocumented) -Kevin |
Do you mean the general concept of having a Regarding "code and documentation complexity" the implementation is pretty much as minimal and straightforward as it can get ... the documentation might be suboptimal. I just threw it together quickly, so feel free to cut it down/edit it if you find it confusing. I didn't know about |
|
@KevinOConnor using air filtration gets more and more common at least in the Voron world. Followed by the question, how to monitor the used time and also the service life. B) could be solved with printer.toolhead.estimated_print_time but a) is still not possible. |
|
Would such a functionality not better fit into the Moonraker / Web-IF realm? |
|
@Sineos no as you would spend much more effort to do it there and you would need a specific solution for every component. Why off load everything to moonraker where you then need to develop a component for every single piece, instead using the power of macros and give the user the freedom to solve his/her needs? And to be clear for his case you would need also a methode in klipper to push an ON and OFF event of "something" e.g. the Nevermore filter from klipper to moonraker. And also a feedback path from moonraker to klipper to send a notification if a target is reached. The feedback path does not exist at all currently. So you need a much bigger development than in both. So lets talk about the Nevermore Mini and how I do it currently as I lack a timestamp system: So I monitore the printing time and store with SAVE_VARIABLE at every print end. I check the 50h also at the end of print and at klipper start and throw a message if reached. I do the following, when I change the material:
If I do not use the printer for a few days I open the calendar app first to check if the 30 days are reached |
|
@Sineos and it should be clear that it could never be done in the WEB-IF as they are only active while open in your browser. |
|
You can do the monitoring of the time using air filtration method via a
macro with saved variables to disk, or you could call a shell command
running a unix script to get the time from there.
I have an example I can share with you.
I will later today get home and share it with you.
…On Thu, Jan 26, 2023, 6:52 AM Alex Zellner ***@***.***> wrote:
@KevinOConnor <https://github.com/KevinOConnor> using air filtration gets
more on more common at least in the Voron world. Followed by the question,
how to monitor the used time and also the service life.
Regardless how it will solved but a possibility to monitor
a) time since a last stored event
b) on time while printing
would be much appreciated.
B) could be solved with printer.toolhead.estimated_print_time but a) is
still not possible.
—
Reply to this email directly, view it on GitHub
<#6010 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAWT4RFY2MBG2HZSROFU65DWUH7HHANCNFSM6AAAAAAUFWD35Q>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
|
Running a unix script doesn't sound like a good solution because instead of maintaining a macro only, users will be forced to maintain both a macro and a unix script. It will also make sharing macros a headache. |
|
@manu7irl sure we can add another client to do all that, but why not do it where it belongs to? The filter is part of a klipper controlled printer. So why not monitor it in there? As said the whole PR adds only the possibility to readout a timestamp that than can be used later on as the user needs it |
klippy/extras/gcode_macro.py
Outdated
| kwparams.update(self.template.create_template_context()) | ||
| kwparams['params'] = gcmd.get_command_parameters() | ||
| kwparams['rawparams'] = gcmd.get_raw_command_parameters() | ||
| kwparams['unixtime'] = calendar.timegm(time.gmtime()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python is not my forte, but can't this just be:
| kwparams['unixtime'] = calendar.timegm(time.gmtime()) | |
| kwparams['unixtime'] = time.time() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should actually be fine, yes. I was reading through this and there were some comments that stated that time.time() is not timezone aware and results different results in different timezones, but that seems to have been wrong information.
(Don't forget to also get remove the calendar import.)
|
I tend to agree with @zellneralex, there are scenarios where something like this would help to solve with just plain Klipper macros. Having said that, I do wonder if this would be better as a function (set on The advantage being that we could then have |
For me this sounds very much like Arksine/moonraker#124 And it should be clear that I still do not consider this as part of Klipper's core competency Edit or for the same principle: |
|
@Sineos and your opinion counts as much as mine … yes there are feature requests for that everywhere. If you search for it you might also found similar request at Mainsail, Fluidd and Klipperscreen. That does not change the fact that nothing exists anywhere. For me a function to add a time stamp is something I consider as a core function that Klipper should provide. |
klippy/extras/gcode_macro.py
Outdated
| # | ||
| # This file may be distributed under the terms of the GNU GPLv3 license. | ||
| import traceback, logging, ast, copy | ||
| import traceback, logging, ast, copy, time, calendar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import traceback, logging, ast, copy, time, calendar | |
| import traceback, logging, ast, copy, time |
Remove calendar import, because using time.time() is sufficient.
Even if it's not, what's the problem with having it exactly? |
I actually implemented it as a function first, but a) the variable definitions implementation was smaller, b) from how I understand it, what you get in your macro is the same eitherways. Even if it's a function, it'll still be evaluated when the macro will be evaluated thus resulting in the same timestamp throughout your whole macro. So there's nothing really more "dynamic" about a function from what I can tell. The other possible consideration would be """performance""", because with the variable implementation The variable implementation is the way to go, imo. |
|
A possible alternative would be a self caching function I guess. |
|
FWIW, there is already a timestamp available ( -Kevin |
|
Got to say, I would have never guessed what @KevinOConnor that sure sounds like a good compromise to me! |
That's why it is undocumented - it's a terrible name. Although undocumented, it is used in a few places for display_templates (for animations). It is probably worth renaming it, but I'm not sure what a good naming convention should be. -Kevin |
|
In *nix land, |
|
That'd atleast allow for the functionality to be implemented at all, I think I'd still prefer a direct timestamp without the unnecessary calculations, but yeah. Regarding naming |
|
I think it would make most sense to report |
|
It's possible to add these fields to the toolhead object, but the toolhead.py code is already very complex. I'm a little leery of adding unrelated complexity to it. Another option is to add these fields to the We could add new fields such as -Kevin |
|
In that case |
|
Just initialize -Kevin |
|
In the suggested Because if that is the case, in my opinion, the name doesn't seem to be very clear. |
|
What about changing |
|
I reimplemented the functionality with the discussed changes. |
|
Can someone please review the new implementation? |
|
Just gave this a try on my simulated docker container, works as designed and seems like a nice feature! |
|
Thanks a lot for reviewing! |
|
Any chance someone could take a look at this again? |
|
Sorry, for the delay. I do plan to look at this further. Alas, my slow response is due to lack of time. -Kevin |
|
pr#4694 offers timestamp functionality...without digging into other parts of Klipper |
|
What's the purpose of this bot? |
|
This PR was inadvertently closed due to a regression introduced by #6293. -Kevin |
|
why not just expose everything as a new module called [time] |
|
Any updates on this? I've been running this for over 1.5 years now, just manually patched over in my (It hasn't been causing any issue this whole time btw.) |
|
It's been almost another year and I've still been using this without any problems. Because of conflicts with the base repository, my inexperience at that time (committing the changes directly to master) and a generally pretty cluttered git history, I decided to move this to a new PR (#7124), as I would still like this to get merged. For anyone subscribed to this, feel free to follow the discussions there too. |
Improved version of #5881 (Extend system stats with unixtime), originally proposed by @denis-efimov:
As described this funcionality would be very useful, especially in combination with
[save_variables]to for example track how long you've been using your air filters, without adelayed_gcodescript that's continuously running. Here's a more complex example for a set of nevermore/air filter timer macros I've thrown together and used for the past couple of days.This PR directly adds
unixtimeto the jinja2 context, instead of adding it to theprinterstatus pseudo-variable, as recommended by @pedrolamas and @Arksine.Patch has been tested on
v0.11.0-86-g6026a99a. I've also added documentation, including an example for using the variable.