Methods
(static) download(params, args, data) → {Object}
Download files on different formats, depending on the formatted object. It extends the the transform function to automatically transform the data. The default format
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Contains: save (string with name of array to save), output (name of output variable) |
args |
Object | Contains: type ('CSV, JSON, XML') |
data |
Object | type (CSV, JSON, XML, Tab), keep (JS array with column headers to keep) |
- Source:
Returns:
Downloaded data as link from HTML file.
- Type
- Object
Example
hydro.data.transform({params: {save: 'saveVarNamefromObj', output: 'someFinalName'}, args: {keep: [value2keep1, value2keep2]}, data: {someJSObject}})
(static) generateDateString() → {String}
Creates a date a outof a string.
- Source:
Returns:
- generates a string in format YY.MM.DD.HH.MM
- Type
- String
(static) lowercasing(obj) → {Array.<Object>}
Lowercases the keys in an object. Can be nested object with arrays or what not.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object | Object keys to lowercase them. |
- Source:
Returns:
Copy of object with keys in lowercase.
- Type
- Array.<Object>
Example
lowercasing({NaMe: "myname", OtherName: "nextname"})
returns {name: "myname", othername: "nextname"}
(static) recursiveSearch(obj, searchKey, results) → {Array.<Object>}
Searches for an array with data passed as string.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object | Object to find the results from. |
searchKey |
String | Key to find inside the object. |
results |
Array.<Object> | default parameter used to save objects. |
- Source:
Returns:
Saved object from the search.
- Type
- Array.<Object>
Example
recursiveSearch({obj: {key1: "thisiskey", data: ["data1", "data2"]}, searchkey: 'data'})
returns ["data1", "data2"]
(static) retrieve(params, args) → {Object}
Main function to retrieve data.
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Contains: source(USGS, MeteoSTAT, etc.),dataType (streamflow, gauges, etc.), type (CSV, XML, JSON). |
args |
Object | Contains: Arguments from the API. See each API data source to know how to send the requests. |
- Source:
Returns:
Object with retrived data. Usually in JSON format.
- Type
- Object
Example
hydro.data.retrieve({params: {source: 'someSource', dataType: 'someEndpoint', proxy: 'ifProxyReq'}, args: {'someEndpointArgs'}})
(static) transform(params, args, data) → {Object}
Convert data types into others based on the premise of having JS objects as primary input.
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Contains: save (string with name of array to save), output (name of output variable) |
args |
Object | Contains: type (CSV, JSON, XML, Tab), keep (JS array with column headers to keep) |
data |
Object | Contains: data object to be transformed in JS format. |
- Source:
Returns:
Object in different formats with transformed data
- Type
- Object
Example
hydro.data.transform({params: {save: 'saveVarNamefromObj', output: 'someFinalName'}, args: {keep: [value2keep1, value2keep2], type: "typeRequired"}, data: {someJSObject}})
(static) upload(params) → {Object}
Data upload from the user's local storage for analysis.
Parameters:
Name | Type | Description |
---|---|---|
params |
Object | Contains: type(CSV, JSON). |
- Source:
Returns:
JS object, either array or JSON.
- Type
- Object
Example
hydro.data.upload({params: {type: 'someType'}})
(static) xml2json(xml) → {Object}
Recursive function that iteratively converts XML document format to JSON format. Required the XML input to be a JQUERY object parsed from string. Credit: https://stackoverflow.com/a/20861541
Parameters:
Name | Type | Description |
---|---|---|
xml |
Document | parsed XML document from text |
- Source:
Returns:
obj - tagged key-value pair from the XML document.
- Type
- Object
Example
xml2json(<someString attr1:1 attr2:2></someString>)
returns {somestring{ attr1: 1, attr2: 2}}