|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | + <head> |
| 4 | + <link |
| 5 | + rel="stylesheet" |
| 6 | + href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" |
| 7 | + /> |
| 8 | + <meta charset="UTF-8" /> |
| 9 | + <meta http-equiv="X-UA-Compatible" content="IE=edge" /> |
| 10 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 11 | + <script |
| 12 | + type="module" |
| 13 | + onload="initHydrolang()" |
| 14 | + src="./hydrolang/hydro.js" |
| 15 | + ></script> |
| 16 | + <title>HydroLang Example Page</title> |
| 17 | + </head> |
| 18 | + <body> |
| 19 | + <h2>HydroLang General Example</h2> |
| 20 | + <button onclick="retrieveDataUSGS()">Retrieve USGS Gauge</button> |
| 21 | + <button onclick="cleaner()">Clean Data</button> |
| 22 | + <button onclick="visualize()">Visualize Data</button> |
| 23 | + <button onclick="Stats()">Basic Stats on Data</button> |
| 24 | + <button onclick="downloadClean()">Download Clean Data</button> |
| 25 | + <button onclick="downloadRaw()">Download Raw Data</button> |
| 26 | + <script> |
| 27 | + var res, clean; |
| 28 | + //Scripts needs to be onloaded by the first click of a function |
| 29 | + function initHydrolang() { |
| 30 | + //hydrolang instance available as a global variable |
| 31 | + window.hydro = new Hydrolang(); |
| 32 | + } |
| 33 | + |
| 34 | + const retrieveDataUSGS = () => { |
| 35 | + res = window.hydro.data.retrieve({ |
| 36 | + params: { |
| 37 | + source: "usgs", |
| 38 | + datatype: "instant-values", |
| 39 | + proxyurl: "local-proxy", |
| 40 | + }, |
| 41 | + args: { |
| 42 | + site: "USGS:05454500", |
| 43 | + startDt: "2008-04-02", |
| 44 | + endDt: "2010-06-30", |
| 45 | + format: "json", |
| 46 | + }, |
| 47 | + }); |
| 48 | + alert("Your data has been retrieved!"); |
| 49 | + console.log(res); |
| 50 | + }; |
| 51 | + |
| 52 | + const cleaner = () => { |
| 53 | + if (res === undefined) { |
| 54 | + alert("Please press the retrieve button first!"); |
| 55 | + return; |
| 56 | + } |
| 57 | + clean = window.hydro.data.transform({ |
| 58 | + params: { |
| 59 | + save: "value", |
| 60 | + }, |
| 61 | + args: { |
| 62 | + type: "ARR", |
| 63 | + keep: '["datetime", "value"]', |
| 64 | + }, |
| 65 | + data: res, |
| 66 | + }); |
| 67 | + alert("If you want to see your data, please run the visualize button!"); |
| 68 | + alert("You can also find it prompted in your console."); |
| 69 | + console.log(clean); |
| 70 | + }; |
| 71 | + |
| 72 | + const visualize = () => { |
| 73 | + if (res === undefined) { |
| 74 | + alert("Please press the retrieve button or clean button first!"); |
| 75 | + return; |
| 76 | + } |
| 77 | + window.hydro.visualize.draw({ |
| 78 | + params: { type: "chart", divID: "USGS_Data" }, |
| 79 | + args: { charttype: "line" }, |
| 80 | + data: clean, |
| 81 | + }); |
| 82 | + }; |
| 83 | + |
| 84 | + const Stats = () => { |
| 85 | + if (res === undefined) { |
| 86 | + alert("Please press the retrieve button or clean button first!"); |
| 87 | + return; |
| 88 | + } |
| 89 | + var basic = window.hydro.analyze.stats.basicstats({ |
| 90 | + data: clean |
| 91 | + }) |
| 92 | + window.hydro.visualize.draw({ |
| 93 | + params: { type: "table", divID: "USGS_Data_Stats" }, |
| 94 | + data: basic, |
| 95 | + }); |
| 96 | + } |
| 97 | + |
| 98 | + const downloadClean = () => { |
| 99 | + if (res === undefined) { |
| 100 | + alert("Please make sure you retrieved and cleaned the data!"); |
| 101 | + return; |
| 102 | + } |
| 103 | + window.hydro.data.download({ |
| 104 | + params: { input: "USGS_Data" }, |
| 105 | + args: { type: "CSV" }, |
| 106 | + data: clean, |
| 107 | + }); |
| 108 | + }; |
| 109 | + |
| 110 | + //Raw data cannto be changde into a CSV format, only the raw datatype it was retrieved in (JSON) |
| 111 | + const downloadRaw = () => { |
| 112 | + if (res === undefined) { |
| 113 | + alert("Please make sure you retrieved and cleaned the data!"); |
| 114 | + return; |
| 115 | + } |
| 116 | + window.hydro.data.download({ |
| 117 | + params: { input: "USGS_Data" }, |
| 118 | + args: { type: "JSON" }, |
| 119 | + data: res, |
| 120 | + }); |
| 121 | + }; |
| 122 | + </script> |
| 123 | + </body> |
| 124 | +</html> |
0 commit comments