Data Handling Classes

Unfortunately some parts of the source code are a bit unorganized as the project grew over several years and, alongside the project, the php programming skills got better and better.

City Handler

class wetterturnier_cityObject

A class to handle city information. Loads and stores information from the *_wetterturnier_cities database table. Whenever possible objects of this type will be called cityObj within the php code.

@param $init (mixed)
If numeric it will be interpreted as station ID, if the input is of type string the city `HASH and name of the city will be checked.

Please also check the two classes wetterturnier_stationObject and wetterturnier_paramObject.

get($key)

Main method to extract information from the class. Information should be stored on $this->data which is a private stdClass object or NULL if there was a problem initializing this object (default). The method checks whether a property on $this->data exists and returns the content. If not found, boolean false will be returned.

@param $key (str)
name of the property you would like to get, e.g., ID or name.
@return Returns false if the value does not exist or the value of
the corresponding element if existing.
show()

Helper class for development. Print on standard out.

stations()

Returns the station information of this cityObject. Information loaded by _load_stations during the initialization of this object.

@return An array of wetterturnier_stationObject objects.

getParams()

Return parameter object array from first station, they are the same (except the ‘active’ flag which is killed in here) for all stations.

@return Returns an array of wetterturnier_paramObject.

Station Handler

class wetterturnier_stationObject

A class to handle station information. Each city (see wetterturnier_cityObject) can have one or more stations attached to it. Should be called $stnObj whenever possible in the php code!

@param $init (numeric)
depending on the input argument by this is either the station ID or station wmo identification number.
@param $by (str)
default is ID, can also be set to wmo to initialize a new object via WMO station number.

Please also check the two classes wetterturnier_cityObject and wetterturnier_paramObject.

showActiveParams($active = true)

Helper function, returns a string with all active parameters.

@param $active (bool)
Boolean, default true for showActiveParams. showInactiveParams (which is only a wrapper) uses $active=false to return inactive parameters, showInactiveParams.

@return Character string with active parameters.

showInactiveParams()

Helper function, returns a string with all inactive parameters. See also showActiveParams.

@return Character string with inactive parameters.

getParams()

Returns the parameter array containing paramObjects.

@return Array of @see wetterturnier_paramObjects.

showParamCheckboxes()

Helper function for the admin interface. Showas checkboxes for the parameters.

@return Html code for the checkboxes. Each parameter gets a box which
is either checked if active or not checked if inactive.
get($key)

This is the main method to extract information from the class. Information should be stored on $this->data which is a private stdClass object or NULL if there was a problem initializing this object (default). The method checks whether a property on $this->data exists and returns the content. If not found, boolean false will be returned.

@param $key (str)
ame of the property you would like to get, e.g., ID or name.

@return Returns false or the value of the element with the corresponding key.

show()

Helper class for development. Shows loaded key/value. Prints on stdout.

Parameter Handler

class wetterturnier_paramObject

A class to handle parameter information.

@param $init (numeric)
depending on input parameter $by this is either the parameter ID (numeric) r parameter shortname of the parameter (str).
@param $by (str)
default is ‘ID’. Allowed are ‘ID’ or ‘paramName’.
@param $tdate (int)
tournament date (days since 1970-01-01), default is NULL. if NULL the current date/time is used. If given the system is checking whether the parameter was active for $tdate or not. This changes the outcome of the isParameterActive method of this class.

Please also check the two classes wetterturnier_cityObject and wetterturnier_stationObject.

isParameterActive($stationID)

Checks if the parameter is active for a specific station.

@param $stationID (numeric)
station identifier ID.
@return Boolean True if parameter is active for station
$stationID and false else.
setActive($to)

Allows to overrule the ‘active’ flag in the object.

get($key)

This is the main method to extract information from the class. Information should be stored on $this->data which is a private stdClass object or NULL if there was a problem initializing this object (default). The method checks whether a property on $this->data exists and returns the content. If not found, boolean false will be returned.

@param $key (str)
name of the property you would like to get, e.g., ID or name.

@return Returns false or the value of the element with the corresponding key.

show()

Helper class for development. Shows loaded key/value. Print on stdout.

Webcam Handler

class wetterturnier_webcamObject

A class to handle webcam information. Loads and stores information from the *_wetterturnier_webcams database table. Whenever possible objects of this type will be called $webcamObj within the php code.

@param $ID (int)
ID (as in the database) of the webcam to be loaded/prepared.
get($key)

This is the main method to extract information from the class. Information should be stored on $this->data which is a private stdClass object or NULL if there was a problem initializing this object (default). The method checks whether a property on $this->data exists and returns the content. If not found, boolean false will be returned.

@param $key (string)
name of the property you would like to get, e.g., ID or uri.

@return Returns false or the value of the element with the corresponding key.

display_webcam()

Prints html to display the webcam image.

show()

Helper class for development purposes. Print on stdout.

Group Handler

class wetterturnier_groupsObject
This is a small class for group handling.
During initialization all groups will be loaded. The class contains some methods to load users (active/inactive) among the groups which is used to display e.g., the group tables.
iteritems()

Returns all groups as array, often used in foreach loops to iterate over all available groups. Thus, this method is called iteritems.

@return Returns an array with all groups.

get_members($groupID)

For a given groupID the members will be returned.

@param $groupID (int)
ID (as in the database) of the group.
@return Returns boolean False if the group cannot be found.
Else a list of stdClass objects will be returned containing the required information about the user/users in the group.
show_frontend_tables()

Shows the frontend tables. No inputs, uses the object information loaded in the __construct method. Information on active/inactive status: active = 0: is inactive; active = 1: is active; active = 8: is active, but the user has an open ‘remove me from group’ request; active = 9: not yet in the group but a ‘add me to the group’ request open.

Latest Observations

class wetterturnier_latestobsObject

A small class to load latest observations from the obs database. Loading data and description from the obs database table. Requires read access on the obs.* tables!

@param $stnObj (wetterturnier_stationObject)
object containing the station information for which the observation data should be loaded.
@param $from (Null or int)
Either Null (default) or a unix time stamp. Has to be numeric! Details see _load_latest_obs_from_db_.
@param $to (Null or int)
Either Null (default) or a unix time stamp. If set in combination with $from has to be larger than $from! Details _load_latest_obs_from_db_.
@param $limit (Null or int)
Either Null or a positiv numeric integer value. If set $limit rows will be loaded.
_load_description_from_db()

Loading the bufrdescription information from the database. This contains the parameter description and it’s scaling/descaling values.

get_desc($param, $value = Null)

Returns parameter description for a given parameter $param. If parameter cannot be found or value is not available a None will be returned.

@param $param (str)
name of the observed parameter.
@param $value (misc)
Default Null, if Null the whole object for the $param will be returned. If set only this specific value will be returned if existing.
@return Returns parameter $value for $parmater if both inputs
are set or the object for $param if $value = Null. If not existing a Null will be returned.
get_value($param, $offset = Null, $format = Null)

Returns a value from the data set loaded. If offset is not given the first (newest) value will be returned.

@param $param (str)
String, name of the observed parameter.
@param $offset (Null or int)
Either Null or a positive integer. If e.g., set to $offset=1 the second last value will be returned if available.
@param $format (Null or str)
Default Null, if set the value will be converted and returned as string.

@return Returns observed value or Null if not available.

has_data()

Helper function, returns true if the object contains data and false if not.

@return Boolean true or false whether the object contains data or not.

nobs()

Helper function, returns number of loaded data sets.

@return Returns number (int) of loaded observations.

get_json($encode = true)

Create and return json array.

@param $encode (bool)
Default true, can be set to false, only for development purposes, du not use it in your code.
@return If $encode is set to false
the array will be returned which will be converted to a json array with the default input $encode = true.
get_json_d3($encode = true)

Create and return json array.

@param $encode. Default true, can be set to false, only for development purposes, du not use it in your code.

@return If $encode is set to false
the array will be returned which will be converted to a json array with the default input $encode = true.
show()

Helper function to show/print the content of this object. Mainly designed for development purposes. Prints output on stdout.

Ranking Class

A php class which computes and returns the data for all kinds of ranking tables (e.g., weekend ranking, season ranking, rankings for multiple cities, …).

This class is only used by ranking_ajax, the ajax call handling ranking requests and should not be used/loaded in-line.

Note

How the integration in wordpress is done: The wetterturnier_userclass registers an action called ranking_ajax which makes use of the wetterturnier_rankingObject.

How it works:

  • js/wetterturnier.rankingtable_init.js is looking for html objects via div.wt-ranking-container selector. Thise div’s have an args attribute containing the necessary parameters to create the ranking (a JSON array which defines for which city and which date the ranking should be computed).
  • For each div.wt-ranking-container object the jQuery function show_ranking(...) is called (js/wetterturnier.rankingtabe.js) which makes performs the data request. show_ranking(...) triggers the ranking_ajax function via ajax request.
  • ranking_ajax creates a new instance of the wetterturnier_rankingObject class, performs the calculation of the ranks (or loads the cached file if caching is enabled) and returns a JSON object to show_ranking(...) which is then used to create the html output on the website.

What the ranking will display is controlled via a set of arguments. Most important is the definition of the city/cities, and a set of parameters to control the date periods. For some cases we also want to have a trend, thus two different time periods are needed. If set, the rank for the previous period is calculated, the rank for the current period is calculated, and the difference between these two is the trend.

This is controlled via from, to, from_prev, and to_prev. Each of these elements is an integer tournament date (days since 1970-01-01).

  • from and to define the period for which the current rank should be computed. For one specific weekend both arguments are the same.
  • from_prev and to_prev define the previous period. If one of them is Null the previous round is not defined and no rank for this period is calculated (and thus, no tend is shown). If set these two arguments also specify the beginning and end of the period (tournament dates, days since 1970-01-01). For the weekend ranking both arguments are the same, and both contain the tournament date for the tournament just one weekend before from and to. For the yearly ranking table from is typically identical to from_prev, and to_prev defines the one tournament one week before to.
class wetterturnier_rankingObject

Class which calculates (and caches) the rankings for different views, e.g., weekend rankings, yearly rankings, alpine ranking, and so far and so on.

@param deadman (str)
login name of the user which provides the points for players not having participated. On wetterturnier this user is known as “Sleepy” (default).
@param points_max (int):
maximum number of points per weekend. Used to compute the ‘relative points’ gained of the players given the ranking settings. Default is 200 as on wetterturnier.de.
@param cache (bool)
whether file cache is active or not. If true (default) the rankings will be stored (serialized) in the cache folder and will be re-used if another user makes the same request. Files will be kept for 10 minutes. Can be disabled if set to false. Note: requires write access to the cache folder within the wp-wetterturnier plugin directory!
print_r($data = false)

Prints the content of $this->ranking (or $this->ranking->data), just a development helper function!

@param $data (bool)
if false the whole object will be printed, if set to true only the data is printed.
return_obj()

Public function which simply returns the internal object.

@return Returns the structured object containing the data.

return_json()

Returns the ranking prepared by prepare_ranking as JSON string. This is what will be returned for the ajax requests.

@return Returns JSON string containing data and meta information
which is used by the js/wetterturnier.ranking.js function

show_ranking(..) to display the ranking table on the frontend.