Hydro Data Source Data Source Bin | R Documentation |
RomDataSource is an object that contains tables and methods of model data objects. It serves as a global object store that references to all objects of a given domain and pointers to remote data source if applicable. It offers the flexibility of synching (via POST or INSERT/UPDATE) to a remote data source OR allows users to update local data bases or sources. It does not permit a mix of these data streams, keeping the RomDataSource object consistent.
Provides integrated, queryable universe of features, observations and meta data
reference class of type openmi.om.base.
site
URL of some RESTful repository
json_obj_url
URL for retrieving full objects
connection_type
rest or odbc
connection
rest or odbc
rest_uname
username to connect to RESTful repository
dbname
DATABASE TO USE IN odbC CONNECTION
debug
show debug info for queries
timeline
for default time series data
tsvalues
table of time series data
propvalues
table of object properties (can be contained by objects)
features
table of physical features
var_defs
table of variable definitions
admin_features
table of adminreg features
prop_json_cache
list of json objects retrieved, keyed by ID
ts_cache
list of ts objects instantiated
feature_cache
list of feature objects instantiated
prop_cache
list of prop objects instantiated
var_cache
list of var objects instantiated
new()
Initialize a RomDataSource, returning a RomDataSource R6 object that is
now populated with site, username, connection type, database name, and
any connection string details if using ODBC. This object will also have numerous methods that are
described in ?RomDataSource
RomDataSource$new( site, rest_uname = NULL, connection_type = "rest", dbname = NULL )
site
URL of some RESTful repository or the host of the target database. At DEQ, this is defined in the default config files.
rest_uname
username to connect to RESTful repository or database. At DEQ, this should be defined within local config files
connection_type
String, either 'rest' or 'odbc' depending on target database
dbname
Used only when connection_type = 'odbc'. This is the database name of the database that supports the ODBC connection. At DEQ, this should generally target the active dbase, not alpha, although both are supported
Instance of RomDataSource, now with populated site, rest_uname, connection_type, and dbname data
reset()
Clear entries and reset tables stored in RomDataSource. Used to clean out features, properties, tsvalues, or variable definitions
RomDataSource$reset(table)
table
Which table(s) should be cleared? . Defaults to 'all', but will
also accept a vector that contains any or all of: c('props', 'features', 'tsvalues', 'var_defs')
nothing, but will clear requested data tables stored on this object #'@description Set the connection to either the database via ODBC or to a REST service (through the act of obtaining a token). OFten done in DEQ config.R files.
get_token()
RomDataSource$get_token(rest_pw = NULL, odbc_port = 5431)
rest_pw
Password to REST/odbc service requested. Will prompt user for entry if not provided
odbc_port
If using odbc, which port should be used? Will prompt user for entry if not provided. Defaults to DEQ port approved by OIS
Nothing, but sets internal private token. Private fields are not
visible via RomDataSource$token
notation and are hidden for
security
get_vardef()
Queries first local variable definitions and if necessary dh_variabledefinition for a varkey, setting the varid within RomDataSource instance
RomDataSource$get_vardef(varkey, force_refresh = FALSE, debug = FALSE)
varkey
Variable key as defined in dh_variabledefinition as varkey. See Hydrotools readme for more information, but represents an abbreviated variable name to define a property or timeseries.
force_refresh
Should the remote database be checked for new info?
debug
Show relevant debugging info
Nothing, but sets variable definitions on RomDataSource Queries first local properties and if needed or requested dh_property for the properties specified in the user config file. This method creates a WHERE clause from the config file for an SQL query of the user input for entity_type provided by user. Will only return the first found property.
get_prop()
RomDataSource$get_prop( config, return_type = "data.frame", force_refresh = FALSE, obj = FALSE )
config
A list of values that includes query constructors. Each entry in this list and its corresponding value will be added to the WHERE clause of a query that queries the table specified in entity_type with the exception of "limit", which will only be used to generate the LIMIT clause for the query. May include a primary key ID, in which case it will be all that is used in the WHERE clause. Relevant data for list may include propname, propvalue, hydrocode, or other fields shown in the Hydrotools Readme e.g. list(entity_type, featureid, pid, varid, tstime, tsendtime). See Readme for more options
return_type
'data.frame' or 'list'
force_refresh
Should the remote data source be queried (TRUE) or just local properties stored on the RomDataSource instance
obj
(optional) object class calling this routine, can supply a base query via sql_select_from field as would otherwise be returned via hydrotools:::fn_guess_sql()
Data frame of the first property returned from query of properties based on data provided in config
get_ts()
RomDataSource$get_ts( config, return_type = "data.frame", force_refresh = FALSE, obj = FALSE )
config
A list of values that includes query constructors. Each entry in this list and its corresponding value will be added to the WHERE clause of a query that queries the table specified in entity_type with the exception of "limit", which will only be used to generate the LIMIT clause for the query. May include a primary key ID, in which case it will be all that is used in the WHERE clause. Relevant data for list may include propname, propvalue, hydrocode, or other fields shown in the Hydrotools Readme e.g. list(entity_type, featureid, tid = NULL, varid = NULL, tstime = NULL, tsendtime = NULL, tscode = NULL, tlid = NULL) timeline ID (not yet used). See Readme for more options
return_type
'data.frame' or 'list', but will default to data.frame
force_refresh
Should the remote data source be queried (TRUE) or just local properties stored on the RomDataSource instance
obj
(optional) object class calling this routine, can supply a base query via sql_select_from field as would otherwise be returned via hydrotools:::fn_guess_sql()
Data frame of the first TS returned from query of dh_timeseries based on data provided in config
auth_read()
Used to read views from a REST service.
RomDataSource$auth_read( uri, content_type = "text/csv", delim = ",", enc = "xml" )
uri
remote address to retrieve data
content_type
http content-type
delim
delimiter
enc
encoding
result of web request
set_ts()
RomDataSource$set_ts(ts)
ts
= list(entity_type, featureid, tid = NULL, varid = NULL, tstime = NULL, tsendtime = NULL, tscode = NULL, tlid = NULL) timeline ID (not yet used)
nothing sets internal private token
set_prop()
RomDataSource$set_prop(prop)
prop
= list(entity_type, featureid, pid = NULL, varid = NULL, tstime = NULL, tsendtime = NULL, tscode = NULL, tlid = NULL) timeline ID (not yet used)
nothing seprop internal private token
insure_cols()
RomDataSource$insure_cols(src_df, dest_df)
src_df
= df to verify/insure
dest_df
= df template to supply valid names
local df index?
set_vardef()
RomDataSource$set_vardef(vardef)
vardef
= list(varid, varkey, varname, varunits, varcode,...)
local df index?
store_features()
RomDataSource$store_features(features)
features
= list(entity_type, featureid, pid = NULL, varid = NULL, tstime = NULL, tsendtime = NULL, tscode = NULL, tlid = NULL) timeline ID (not yet used)
nothing seprop internal private token
set_feature()
RomDataSource$set_feature(feature)
feature
= list(entity_type, featureid, pid = NULL, varid = NULL, tstime = NULL, tsendtime = NULL, tscode = NULL, tlid = NULL) timeline ID (not yet used)
nothing seprop internal private token
get()
RomDataSource$get(entity_type, pk, config, obj = FALSE)
entity_type
Most often dh_feature or dh_properties. Indicates which table to retrieve data from. This will be the target table for the query constructed from user inputs input list
pk
Primary key column name, often hydroid or pid. See Readme for additional information or contact OWSPA Data Coordinatory if you do not know the appropriate primary key for the table of interest. If referenced in config, will be the only item in the WHERE clause of the user query
config
A list of potential values to be added to an SQL query that targets entity_type. This list will be iterated through and added to a WHERE clause to ensure user query operates. If a primary key id is provided named the same as the user input pk, the WHERE clause will only contain a statement on this key id. "limit" may also be in this list to limit query results
obj
(optional) object class calling this routine, can supply a base query via sql_select_from field as would otherwise be returned via hydrotools:::fn_guess_sql()
Results of the query of entity_type constructed from the config supplied by user. Typically a data frame.
post()
RomDataSource$post(entity_type, pk, config)
entity_type
= dh_feature, dh_properties, ...
pk
= primary key column name, e.g. hydroid, pid, ...
config
= contents of record to post in list(pid, propname, propvalue, ...)
local df index?
delete()
RomDataSource$delete(entity_type, pk, config, obj = FALSE)
entity_type
= dh_feature, dh_properties, ...
pk
= primary key column name, e.g. hydroid, pid, ...
config
= contents of record to post in list(pid, propname, propvalue, ...)
obj
= (optional) object class calling this routine, can supply extra info
local df index?
get_json_prop()
RomDataSource$get_json_prop(pid)
pid
= object pid
unserialized json as list, with object stored in ds$prop_json_cache
get_nested_export()
RomDataSource$get_nested_export(ds, featureid, props, depth = 0)
ds
= satasource object, kept for posterity, as this may not always live here
featureid
= object pid
props
= container for stashing
depth
= depth limit for nesting (rarely used)
unserialized json as list, with object stored in ds$prop_json_cache
clone()
The objects of this class are cloneable with this method.
RomDataSource$clone(deep = FALSE)
deep
Whether to make a deep clone.
NA
##Get new datasource via odbc
#ds <- RomDataSource$new(site,
# rest_uname = odbc_uname,
# connection_type = 'odbc',
# dbname = databaseName)
# ds$get_token(rest_pw = odbc_pw)
##Pointer to external db
# ds$connection
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.