User Tools

Site Tools


devel:brewerjsonpythonmodule

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
devel:brewerjsonpythonmodule [2015/09/21 09:39]
ajberjon
devel:brewerjsonpythonmodule [2022/10/20 08:00] (current)
Line 7: Line 7:
 ===== Installation ===== ===== Installation =====
  
-Brewer JSON library can be imported from python code adding the path to brewer.py module to the Python path (list of directories Python goes through to search for modules and files):+Brewer JSON library can be imported from python code adding the path to brewerjson.py module to the Python path (list of directories Python goes through to search for modules and files):
  
   import sys   import sys
   sys.path.append("/​home/​to/​module/"​)   sys.path.append("/​home/​to/​module/"​)
 +
 +By default the sys.path variable includes the current directory, so if brewerjson.py is in the same directory as the Python script, the module can be directly imported.
  
 Alternatively,​ you can download brewer.py file to the standard location for third-party Python modules. This location varies by platform and by how you built/​installed Python itself. Typical locations are shown in the following table: Alternatively,​ you can download brewer.py file to the standard location for third-party Python modules. This location varies by platform and by how you built/​installed Python itself. Typical locations are shown in the following table:
Line 23: Line 25:
  
 ^ Field ^ Description ^ ^ Field ^ Description ^
-^ [[devel:​brewerjsonpythonmodule#​getdata|getdata()]] | Retrieve ​raw data from RBCC-E ​database ​+^ [[devel:​brewerjsonpythonmodule#​getDataList|getDataList()]] | Retrieve ​a list of dictionaries with data from RBCC-E ​between two dates. ​
-^ [[devel:​brewerjsonpythonmodule#​getDataList|getDataList()]] | Retrieve a list of dictionaries ​with data from RBCC-E between two dates ^+^ [[devel:​brewerjsonpythonmodule#​writejson|writejson()]] | Write list of dictionaries ​(measures, config,..) to file. ^ 
 +^ [[devel:​brewerjsonpythonmodule#​readjson|readjson()]] | Read list of dictionaries (measures, config,​..) ​from file. ^
  
-=== getdata() === 
  
-This function retrieve ​brewer data using the interface describing in the [[codes:accessfunctions|access functions Section]]. This function accepts only an argument ​//params// which is a dictionary. Mandatory elements in //params// are the following strings: ​//user//, //password//, //berwerid// and //​function//​. The //​function// ​element refers to the different functions described in the[[codes:accessfunctions|access functions Section]].+=== getDataList() === 
 + 
 +This function retrieve ​a list of [[http://​eubrewnet.aemet.es/​dokuwiki/​doku.php?​id=devel:brewerpythonmodule#​data_structures|dictionaries]] with data of the registered brewers at the RBCC-E databaseArguments are //berwerid////user////password//, //function//, //date1// and //date2//. If //date2// is omitted the function ​returns only data of the day //data1//. 
 + 
 +The returned dictionaries structures depend on the //​function// ​argument value: 
 + 
 +^ //​function//​ ^ Dictionaries ^ 
 +^ '​DS'​ | [[http://​eubrewnet.aemet.es/​dokuwiki/​doku.php?​id=devel:​brewerpythonmodule#​measure|measure]] 
 +^ '​SL'​ | [[http://​eubrewnet.aemet.es/​dokuwiki/​doku.php?​id=devel:​brewerpythonmodule#​measure|measure]] ^ 
 +^ '​ConfigbyDate'​ | [[http://​eubrewnet.aemet.es/​dokuwiki/​doku.php?​id=devel:​brewerpythonmodule#​config|config]] ^
  
 **Example** **Example**
-    ​params['​user'​]='​user'​ +    ​import brewerjson 
-    ​params['​password'​]='​password'​ +    ​import datetime 
-    ​params['​function'​]='​getDS'​ +     
-    ​params['​brewerid'​]='​037'​ +    ​d1=datetime.date(2014,​10,​01) 
-    ​params['​date'​]='​2014-10-01' +    ​d2=datetime.date(2014,10,02) 
-    data=brewerjson.check_hg(params)+    data=brewerjson.getDataList(185,'​user,'​password','​DS',​d1,​d2)
  
-In this example we retrieve data from the url: http://​rbcce.aemet.es/​eubrewnet/​getdata/​getDS?​brewerid=037&​date=2014-10-01 
  
-This function returns different data structures depending on //​function//​ parameter.+=== writejson() ===
  
 +This function save a list of [[http://​eubrewnet.aemet.es/​dokuwiki/​doku.php?​id=devel:​brewerpythonmodule#​data_structures|dictionaries]] to file. The values of '​gmt'​ and '​date'​ are transformed to strings.
  
-=== getDataList() ===+**Example** 
 +    import brewerjson 
 +    import datetime 
 +     
 +    d1=datetime.date(2014,​10,​01) 
 +    d2=datetime.date(2014,​10,​02) 
 +    data=brewerjson.getDataList(185,'​user,'​password','​DS',​d1,​d2) 
 +    brewerjson.getdata(data,'​output.txt'​) 
 + 
 +This function accepts two input parameters: //'​data'//​ and //'​file'//​. 
 + 
 +  * //'​data'//​ is a list of [[http://​eubrewnet.aemet.es/​dokuwiki/​doku.php?​id=devel:​brewerpythonmodule#​data_structures|dictionaries]]. 
 +  * //'​file'//​ output file. 
 + 
 + 
 +=== readjson() === 
 + 
 +This function read a file containing a list of [[http://​eubrewnet.aemet.es/​dokuwiki/​doku.php?​id=devel:​brewerpythonmodule#​data_structures|dictionaries]]. 
 + 
 +**Example** 
 +    import brewerjson 
 +    import datetime 
 +     
 +    brewerjson.getdata('​input.txt'​)
  
  
  
devel/brewerjsonpythonmodule.1442828367.txt.gz · Last modified: 2015/09/21 09:39 by ajberjon