Editing Python Scheduling Application

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 8: Line 8:
 
= Features =
 
= Features =
  
* Schedules events either running code internal to itself ( and anything you can write in Python ) or external applications.
 
* Events can be run at fixed times or any other schedule you would like, from one time to an infinite time.
 
 
* Python 3.6.
 
* Python 3.6.
 
* Extensible.
 
* Extensible.
Line 30: Line 28:
  
 
Reading the section on design as well may help understand this section.
 
Reading the section on design as well may help understand this section.
=== Parameters ===
 
The general parameter setup is explained in [[Configuration Files For Python]]  and another example of its uses is discussed in [[Smart Terminal Parameter Examples]]  There are additional features of the parameter setup here:
 
  
* The additional use of a global dict is different in this application.
+
The general parameter setup is explained in [[Configuration Files For Python]]  and another example of its uses is discussed in [[Smart Terminal Parameter Examples]]  The additional use of a global dict is different in this application.
* Most of the parameters are set up almost as soon as the application starts, but a second set of parameters is run from the processing_helper ( if any ) to set up additional parameters.  This setup is delayed so that it can reference objects that have not be created until near the end of the application initialization. It is in the method:  init_from_helper( ).
 
 
 
=== A Dictionary ===
 
  
 
Each scheduling activity may have its own ( but sharable ) set of parameters for that activity.  These are stored in a dictionary, which is in turn stored in a master dictionary of all activity parameters.  It is set up in parameters.py and is called: AppGlobal.parameter_dicts.  When an event related function is called it is passed the name of the dictionary ( a string ) in AppGlobal.parameter_dicts and it gets out the correct dictionary it needs as in:
 
Each scheduling activity may have its own ( but sharable ) set of parameters for that activity.  These are stored in a dictionary, which is in turn stored in a master dictionary of all activity parameters.  It is set up in parameters.py and is called: AppGlobal.parameter_dicts.  When an event related function is called it is passed the name of the dictionary ( a string ) in AppGlobal.parameter_dicts and it gets out the correct dictionary it needs as in:
Line 45: Line 38:
  
 
   my_count  = a_dict["failed_connect_count"]
 
   my_count  = a_dict["failed_connect_count"]
 
To keep the creation of a dictionary in one controllable spot I typically do it in its own method
 
 
<pre>
 
 
    #  ------------------------------------
 
    def create_parm_dict_greenhouse( self, ):
 
            dict_name                      = "greenhouse"
 
            a_dict                          = {}
 
 
            a_dict["db_host"]              = '192.168.0.189'  #
 
            a_dict["db_port"]              = 3306
 
            a_dict["db_db"]                = 'pi_db'
 
 
            a_dict["db_user"]              = 'pi_user'
 
            a_dict["db_passwd"]            = 'db_passwrd here'
 
 
            a_dict["sql_select"]            = "SELECT ev_time, temp_1, humid_1 FROM ev_data          WHERE ( ev_time > %s ) order by temp_1 asc"
 
            a_dict["select_timedelat"]      = datetime.timedelta( days= 0, hours = 0, minutes = 30  )
 
 
            a_dict["alarm_min_temp"]        = 50        # farenheight
 
            a_dict["alarm_max_temp"]        = 75
 
 
            a_dict["failed_connect_count"]  = 0
 
            a_dict["max_connect_count"]    = 4          # at 4 trigges an email
 
            a_dict["min_repeat_email_time"] = datetime.timedelta( days= 1, hours = 0, minutes = 0  )
 
            a_dict["time_last_email"]      = None
 
 
            AppGlobal.parameter_dicts[dict_name] = a_dict
 
 
</pre>
 
  
 
= Install =
 
= Install =
Line 82: Line 44:
  
 
= Design =
 
= Design =
 
Events are packaged up basically as 2 functions that run at some time.  The first function carries out the action you wish to schedule.  The second function is more introspective:  it typically looks at the event that has just been run and adjust the time of the event for its next run.
 
 
This means if you have an event that sends an email at 12:00 every day for 5 days, then at any time in the system it will exists only one event with a time in the future when it should be run.  After the next time it is run it will count down the number of times it has been run ( stopping at 0 ) and reschedule itself for the next run.
 
  
 
== Some Big Ideas ==
 
== Some Big Ideas ==
Line 99: Line 57:
 
* A function that is run after the event is run that is intended to reschedule the event in some way.
 
* A function that is run after the event is run that is intended to reschedule the event in some way.
 
* Most of the design is similar to [[Python Smart Terminal Technical]] except for the plug in processing modules.
 
* Most of the design is similar to [[Python Smart Terminal Technical]] except for the plug in processing modules.
 
== Lets Look At Code ==
 
 
I will need to add code for a better example, for now I will use the example I have built.
 
 
=== Does What ===
 
 
This code is intended to connect to a remoter computer, make sure its database is alive and email me if it is not.  Several attempts in a row must fail before the email is sent, and while the event keeps running, further email is blocked for some period of time.
 
 
=== Does How ===
 
  
 
== The GUI ==
 
== The GUI ==
Line 125: Line 73:
  
  
[[Category:Python Projects]] [[Category:Arduino/RaspberryPi]] [[Category:Python]][[Category:Python Scheduling Application]]
+
[[Category:Arduino/RaspberryPi]] [[Category:Python]]

Please note that all contributions to OpenCircuits may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see OpenCircuits:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)