• Antelope Release 5.5 Linux 2.6.32-220.el6.x86_64 2015-04-21

 

NAME

sta2json.rpy - deliver station metadata in JSON format

SYNOPSIS

**** NO BRTT SUPPORT ****
Author: "Juan Reyes"<reyes@ucsd.edu>

This tool is a module to extend the rtwebserver program. It is design to read a Datascope database containing station information and produce a memory cached object for fast delivery to web clients. This object will be converted to a JSON formatted string easy to interpret by JavaScript and, unlike XML, readable by people. There is also a segment in the configuration object to specify orbservers to track and query for "sources" and "clients" status. If the SNET STA entry between the db cached object and the orb cached object then the orb status is included on the return JSON blob. You can also query orbserver status only. Multiple databases/orbs can be tracked by the tool. All configuration is set on the rtwebserver paramter file.

SUPPORT


Contributed code: NO BRTT support.
THIS PIECE OF SOFTWARE WAS CONTRIBUTED BY THE ANTELOPE USER COMMUNITY. BRTT DISCLAIMS ALL OWNERSHIP, LIABILITY, AND SUPPORT FOR THIS PIECE OF SOFTWARE.

FOR HELP WITH THIS PIECE OF SOFTWARE, PLEASE CONTACT THE CONTRIBUTING AUTHOR.

DESCRIPTION

The rtwebserver will declare an instance of an Station() class that will handle all database interactions and web requests. This class will read multiple tables and join them to get the most information possible from them.

The tool will track the checksum of every table and determine if there is a change from the last time the cache was updated. If the checksum is different then the Station() class will attempt to read the database and update the cached object. The data will be converted from a dictionary structure to a JSON string at the time of delivery.

A successful response from the server will have Content-Type and Expires fields set. The field "Expires" will be set by the server to be the time of the query in addition to the refresh time specified on the parameter file. Example of headers set in this way:

Content-Type    application/json
Date    Fri, 24 Oct 2014 04:21:56 GMT
Expires Fri, 24 Oct 2014 04:22:56 GMT
Server  TwistedWeb/13.1.0

Valid flag on the API

    orb=orbname
    clients=True/False
    sources=True/False
    snet=network name
    sta=station name

    db=dbname
    active=True/False
    decom=True/False
    decom=True/False
    snet=network name
    sta=station name

JSON FORMAT

{

    "strendtime": "12/13/01 (347) 20:45:-2147483648 UTC",
    "lon": -156.6175,
    "vnet": "_US-TA",
    "time": 1403434673.525,
    "lat": 71.3221,
    "endtime": 9999999999.999,
    "strtime": " 6/22/14 (173) 10:57:53 UTC"

}

PARAMETER FILE

All is configured on the [rtwebserver.pf] file. You need to specify the tool in the [site][pages] area of the parameter file. The configuration used here will be the same values you will use on the URL when you try to query the tool. http://localhost:8000/stations?db=usarray&snet=TA&sta=A21K http://localhost:8000/stations?db=usarray&active=True Example:

   sta2jsonconfig &Arr{
        debug           True
        verbose         True
        #sta_subset      sta =~ /^.*$/    # Seconds in the past to track
        readableJSON    None               # None, 0(just newline), number
        readableJSON    None               # None, 0(just newline), 4(int number)
        refresh         60              # seconds for next refresh of cached data
        timezone        UTC             # Timezone for time string
        timeformat      %D (%j) %H:%M:%S %z
        databases &Arr{
            #demo   /opt/antelope/data/db/demo/demo
            usarray ~/TA/dbs/usarray
        }
        orbnames &Arr{  #use same key names than 'databases'
            usarray anfexport:usarrayTA
        }
   }
   pages &Arr{
        index        pf:demoindex     text/html     index
        stations     rpy:/opt/antelope/5.4/data/python/rtwebserver/sta2json.rpy
   }
The timezone and timeformat will specify a pre-formatted time string included on the JSON object. The epoch time will be there too in case you want to use that on your client code. The databases segment are a list of tuples. The first value is an arbitrarily name that we select for the instance. This is important because that is used on the URL to request data from that database. The second is the path to the descriptor file for that database.

SEE ALSO

rtwebserver(1), rtwebserver_rpy(3y)

BUGS AND CAVEATS

**** NO BRTT SUPPORT **** You DON'T need to copy the code to the folder structure running the rtwebserver instance. Just make sure that you "make install;" the code and then set the absolute path on the rtwebserver.pf file for the rpy file.

AUTHOR

Juan Reyes <reyes@ucsd.edu>
Antelope User Group Contributed Software
Printer icon