def get_counts(sesh, filters, sdate, edate): stns = [stn[0] for stn in get_stn_list(sesh, filters, cng.station_id)] rv = length_of_return_dataset(sesh, stns, sdate, edate) obs_count = int(rv[0] if rv[0] else 0) rv = length_of_return_climo(sesh, stns) climo_count = int(rv[0] if rv[0] else 0) return {'record_length': obs_count, 'climo_length': climo_count}
def __call__(self, environ, start_response): status = '200 OK' response_headers = [('Content-type', 'application/json; charset=utf-8')] start_response(status, response_headers) filters = validate_vars(environ) with self.session_scope_factory() as sesh: stns = get_stn_list(sesh, filters) return json.dumps({'stations_selected': len(stns)})
def __call__(self, environ, start_response): status = '200 OK' response_headers = [('Content-type', 'application/json; charset=utf-8')] start_response(status, response_headers) filters = validate_vars(environ) sesh = environ.get('sesh', None) @contextmanager def dummy_context(): yield sesh with self.session_scope_factory() if not sesh \ else dummy_context() as sesh: stns = get_stn_list(sesh, filters) return json.dumps({'stations_selected': len(stns)})
def __call__(self, environ, start_response): req = Request(environ) form = req.params filters = validate_vars(environ) sdate, edate = get_clip_dates(environ) with self.session_scope_factory() as sesh: stns = [stn[0] for stn in get_stn_list(sesh, filters, cng.station_id)] rv = length_of_return_dataset(sesh, stns, sdate, edate) obs_count = int(rv[0] if rv[0] else 0) rv = length_of_return_climo(sesh, stns) climo_count = int(rv[0] if rv[0] else 0) status = '200 OK' response_headers = [('Content-type', 'application/json; charset=utf-8')] start_response(status, response_headers) return json.dumps({'record_length': obs_count, 'climo_length': climo_count})
def __call__(self, environ, start_response): '''Fire off pydap requests and return an iterable (from :func:`ziperator`)''' req = Request(environ) form = req.params climo = True if 'download-climatology' in form else False filters = validate_vars(environ) stns = get_stn_list(self.session, filters) ext = get_extension(environ) if not ext: return HTTPBadRequest("Requested extension not supported")(environ, start_response) status = '200 OK' response_headers = [('Content-type','application/zip'), ('Content-Disposition', 'filename="pcds_data.zip"')] start_response(status, response_headers) environ['pydap.handlers.pcic.dsn'] = self.dsn responders = chain(get_all_metadata_index_responders(self.session, stns, climo), get_pcds_responders(self.dsn, stns, ext, get_clip_dates(environ), environ) ) return ziperator(responders)
def test_get_stn_list(test_session): stns = get_stn_list(test_session, []) assert len(stns) == 50
def test_single_column_select(test_session): stns = get_stn_list(test_session, [], cng.station_id) assert isinstance(stns[0][0], int)
def test_get_stn_list_with_filter(test_session, constraints, to_select, expected): stns = get_stn_list(test_session, constraints, to_select) assert set(expected) == set([x[0] for x in stns])