Page 1 of 1
Plug-in design discussion
Posted: Mon Aug 13, 2007 11:07 am
by krambriw
Hi Bitmonster,
I have thought about creating a python version of my application NexaSunRise and I would like to discuss some design ideas, which would be best etc....
See picture below
Create two eg plug-ins (or one big)???
A brief description of the function would be;
The first plug-in execution is started by an eg.timer every 30 seconds and calculates the sunset/rise for your location and sends the result to the second plug-in.
The second plug-in takes this result, checks actual day type, time offset settings and time of day, compares this with data in tables to find if its time to switch one or more "things" on/off
If so, it sends the appropriate events to eg
For plug-in configuration purposes I would need to read eg configurations for events and to link them in a table with time and offset settings for each daytype
Other configurations of the plug-ins would be setting geographical position, the holidays, the time trigger settings, the offset time settings etc
Would this be feasible?
Best regards, Walter
Re: Plug-in design discussion
Posted: Mon Aug 13, 2007 11:33 am
by Bitmonster
Building plugins that depend on each other is always a bad idea. I also see no need to poll the time. Once the plugin is started, it would know when the next event should happen and can therefore schedule its next execution. You can also consider to make all configurations through actions, that can be added to the autostart macro for example. So the user can create one action to schedule a sunset event and another action to schedule a sunrise event (each having its own location and time offset). The "Timer" plugin of Bartman works this way (and it is also quite similar in its functionality, so it might be worth considering to enhance the Timer plugin with a new action type, instead of writing a new plugin).
If Bartman is reading this:
@Bartman
Looking at the Timer code, you run a small thread to handle the time scheduling. It might be a not so bad idea, if EG would have a small scheduler in its core code, so other code can simply add callbacks to given times. But this would need some rewrite of your plugin (making it callback based and not loop based).
Re: Plug-in design discussion
Posted: Mon Aug 13, 2007 4:59 pm
by Bartman
Bitmonster wrote:Looking at the Timer code, you run a small thread to handle the time scheduling. It might be a not so bad idea, if EG would have a small scheduler in its core code, so other code can simply add callbacks to given times. But this would need some rewrite of your plugin (making it callback based and not loop based).
I'm not to happy with the waiting thread either. The threads may be referenced a long time and therefore not removed from memory and the waiting does not consider DST or timezone changes, nor pauses caused by standby.
I could probably change this. Most time went off with creating the GUI.
Re: Plug-in design discussion
Posted: Mon Aug 13, 2007 5:34 pm
by krambriw
Regarding the sunset/sunrise calculation, I was lucky and found this:
http://kortis.to/radix/python/code/Sun.py
Could this be re-used in the plug-in somehow (it has infact more functions than needed)
Best regards, Walter
Re: Plug-in design discussion
Posted: Tue Aug 14, 2007 1:18 pm
by Bitmonster
Of course this could be used in a plugin. But actually most work for such kind of plugin is the GUI, because you have many values the user must be able to edit.
So it is also an alternative to handle this task by a script instead of a plugin. If the script is prepared in a way to easily edit the needed geographical locations and so on and has some documentation (in the wiki for example) it might be nearly as handy as a plugin and will not take much coding time.
I have written a small scheduler now for EG, that will be included in one of the next versions. Once I have completed testing it, I will show you how you can schedule events with it.
Re: Plug-in design discussion
Posted: Tue Aug 14, 2007 3:40 pm
by krambriw
Thanks a lot, will be great to see. I guess for me, samples where you can guide me a bit to start with is very kind of you since I'm new to python .
BTW, once upon a time I worked in a team where we used ST (SmallTalk). I think there are many similarities with Python...or is it not?
Best regards, Walter
Re: Plug-in design discussion
Posted: Tue Aug 14, 2007 7:11 pm
by Bitmonster
Yes, some concepts of Python are borrowed from Smalltalk.
Re: Plug-in design discussion
Posted: Wed Aug 15, 2007 4:01 pm
by Bitmonster
Ok, I've included the scheduler code in the latest beta and updated the API docs. You find a description of it here:
http://www.eventghost.org/apidocs/eg.Sc ... class.html
Re: Plug-in design discussion
Posted: Wed Aug 15, 2007 6:07 pm
by krambriw
Thanks m8, this will be very interesting!!!
Walter
Re: Plug-in design discussion
Posted: Fri Aug 17, 2007 3:58 pm
by krambriw
@Bitmonster
Thanks for the scheduler, I have played with it and I understand how it works.
I'm diving into python scripting to update myself...and I have started the walk to migrate my code to a python script. I expect I will run into situations when I would need your help & advice. For the moment everything is working as expected...
All the best, Walter