6 <& /util/import_javascript.mas, classes => [ ] &>
8 <& /page/page_title.mas, title=>"Analyze NOAA NCDC Weather Data" &>
10 <div class="form-horizontal">
11 <div class="form-group">
12 <label class="col-sm-4 control-label">Select Location: </label>
13 <div class="col-sm-8" >
14 <div id="noaa_ncdc_analysis_location_select"></div>
19 <div id="noaa_ncdc_analysis_input_div" style="display:none">
20 <div class="form-horizontal">
21 <div class="form-group">
22 <label class="col-sm-4 control-label">Start Date (YYYY-MM-DD): </label>
23 <div class="col-sm-8" >
24 <input class="form-control" id="noaa_ncdc_analysis_start_date" name="noaa_ncdc_analysis_start_date" type="text" />
28 <div class="form-horizontal">
29 <div class="form-group">
30 <label class="col-sm-4 control-label">End Date (YYYY-MM-DD): </label>
31 <div class="col-sm-8" >
32 <input class="form-control" id="noaa_ncdc_analysis_end_date" name="noaa_ncdc_analysis_end_date" type="text" />
36 <div class="form-horizontal">
37 <div class="form-group">
38 <label class="col-sm-4 control-label">Results: </label>
39 <div class="col-sm-8" >
40 <select class="form-control" id="noaa_ncdc_analysis_type">
41 <option value="daily_temp_prec">Daily Temperature and Precipitation Chart</option>
46 <div class="form-horizontal">
47 <div class="form-group">
48 <label class="col-sm-4 control-label">Cumulative Values by Year: </label>
49 <div class="col-sm-8" >
50 <select class="form-control" id="noaa_ncdc_analysis_cumulative_year">
51 <option value="no">No</option>
52 <option value="yes">Yes</option>
57 <div class="form-horizontal">
58 <div class="form-group">
59 <label class="col-sm-4 control-label">Window Start (YYYY-MM-DD) (Optional): </label>
60 <div class="col-sm-8" >
61 <input class="form-control" id="noaa_ncdc_analysis_window_start_date" name="noaa_ncdc_analysis_window_start_date" type="text" />
65 <div class="form-horizontal">
66 <div class="form-group">
67 <label class="col-sm-4 control-label">Window End (YYYY-MM-DD) (Optional): </label>
68 <div class="col-sm-8" >
69 <input class="form-control" id="noaa_ncdc_analysis_window_end_date" name="noaa_ncdc_analysis_window_end_date" type="text" />
75 <button class="btn btn-primary" type="button" id="noaa_ncdc_analysis_submit" name="noaa_ncdc_analysis_submit">Submit</button>
79 <div id="noaa_ndcd_analysis_result">
84 jQuery(document).ready(function() {
86 get_select_box('locations', 'noaa_ncdc_analysis_location_select', {'id':'noaa_ncdc_analysis_location_id', 'name':'noaa_ncdc_analysis_location_id', 'empty':'1'});
88 var noaa_ncdc_analysis_location_id = '';
89 var noaa_ncdc_analysis_location_station_id = '';
90 var noaa_ncdc_analysis_start_date = '';
91 var noaa_ncdc_analysis_end_date = '';
92 var noaa_ncdc_analysis_type = '';
93 var noaa_ncdc_analysis_cumulative_year = '';
94 var noaa_ncdc_token = '<% $c->config->{noaa_ncdc_access_token} %>';
96 if (noaa_ncdc_token == 'NULL') {
97 alert(`Configuration variable 'noaa_ncdc_access_token' is undefined. Data from station `+noaa_station_id+` can't be accessed without a token.\r\nPlease visit https://www.ncdc.noaa.gov/cdo-web/token to generate a valid access token, then include the token in sgn_local.conf`);
100 jQuery(document).on('change', '#noaa_ncdc_analysis_location_id', function(){
101 noaa_ncdc_analysis_location_id = jQuery(this).val();
103 url : '/ajax/location/get_noaa_station_id/'+noaa_ncdc_analysis_location_id,
104 success: function(response){
105 console.log(response);
106 if (response.noaa_station_id) {
107 noaa_ncdc_analysis_location_station_id = response.noaa_station_id;
110 url:'https://www.ncdc.noaa.gov/cdo-web/api/v2/stations/'+noaa_ncdc_analysis_location_station_id,
111 headers:{ token: noaa_ncdc_token },
112 success: function(response) {
113 console.log(response);
115 alert('Found a valid NOAA Station for this location: '+response.name);
116 jQuery('#noaa_ncdc_analysis_input_div').show();
119 alert('Could not verify the NOAA StationID you provided. Go to Manage->Locations and make sure your location has a valid NOAA station id!');
120 jQuery('#noaa_ncdc_analysis_input_div').hide();
124 alert('The NOAA NCDC authorization token may not be valid! We could not verify your NOAA StationID. Please contact us!');
125 jQuery('#noaa_ncdc_analysis_input_div').hide();
130 alert('No NOAA NCDC station id for this location. Go to Manage->Locations and edit your location to add a valid NOAA station id!');
131 jQuery('#noaa_ncdc_analysis_input_div').hide();
134 error: function(response){
135 alert('Error getting NOAA NCDC ID for location!');
136 jQuery('#noaa_ncdc_analysis_input_div').hide();
141 jQuery('#noaa_ncdc_analysis_submit').click(function(){
142 noaa_ncdc_analysis_start_date = jQuery('#noaa_ncdc_analysis_start_date').val();
143 noaa_ncdc_analysis_end_date = jQuery('#noaa_ncdc_analysis_end_date').val();
144 noaa_ncdc_analysis_type = jQuery('#noaa_ncdc_analysis_type').val();
145 noaa_ncdc_analysis_window_start_date = jQuery('#noaa_ncdc_analysis_window_start_date').val();
146 noaa_ncdc_analysis_window_end_date = jQuery('#noaa_ncdc_analysis_window_end_date').val();
147 noaa_ncdc_analysis_cumulative_year = jQuery('#noaa_ncdc_analysis_cumulative_year').val();
148 if (noaa_ncdc_analysis_start_date == '') {
149 alert('Please give a start date!');
152 if (noaa_ncdc_analysis_end_date == '') {
153 alert('Please give a end date!');
158 url : '/ajax/location/noaa_ncdc_analysis?location_id='+noaa_ncdc_analysis_location_id+'&station_id='+noaa_ncdc_analysis_location_station_id+'&start_date='+noaa_ncdc_analysis_start_date+'&end_date='+noaa_ncdc_analysis_end_date+'&analysis_type='+noaa_ncdc_analysis_type+'&w_start='+noaa_ncdc_analysis_window_start_date+'&w_end='+noaa_ncdc_analysis_window_end_date+'&cumul_year='+noaa_ncdc_analysis_cumulative_year,
159 success: function(response){
160 console.log(response);
161 if (response.error) {
162 alert(response.error);
164 else if (response.noaa_station_id) {
165 var html = '<img src="'+response.plot+'"><hr><img src="'+response.plot2+'">';
166 jQuery('#noaa_ndcd_analysis_result').html(html);
169 alert('There was an error getting NOAA analysis!');
172 error: function(response){
173 alert('Error getting NOAA NCDC analysis!');