コード例 #1
0
def daily_download(request):
    form = TimeSeriesFilterForm(request.GET)

    if form.is_valid():
        gages = form.cleaned_data["site_list"]
        _logger.info("hourly csv download, gages is %s" % (gages))
        beginDate = form.cleaned_data["timeseries_start"]
        endDate = form.cleaned_data["timeseries_end"]

        station_dict = stage_queries.station_dict(gages)

        beginDate = form.cleaned_data["timeseries_start"]
        endDate = form.cleaned_data["timeseries_end"]

        q, dt = stage_queries.daily_query(*station_dict.values())
        if beginDate:
            q = q.where(dt >= beginDate)
        if endDate:
            q = q.where(dt <= endDate)
        data = q.execute()

        # data_type = 'Hourly Water Level, NAVD88(ft)'  # hard coded for now... maybe this could be in the form where the user's can selected between hourly and daily data
        query_metadata_list = create_metadata_header(
            HEADER_MESSAGE, EDEN_CONTACT, END_OF_HEADER, form.cleaned_data, station_dict.values()
        )

        response = HttpResponse(content_type="text/csv")

        stage_data.write_rdb(data, response, metadata=query_metadata_list)
        return response
    else:
        return HttpResponseBadRequest(",".join(form.errors))
    pass
コード例 #2
0
def param_rdb_download(request):
    form = DataParamForm(request.GET)
    if form.is_valid():
        _logger.info(
            "requested data download for %s with params %s"
            % (form.cleaned_data["site_list"], form.cleaned_data["params"])
        )

        beginDate = form.cleaned_data["timeseries_start"]
        endDate = form.cleaned_data["timeseries_end"]
        gage = form.cleaned_data["site_list"]
        p = form.cleaned_data["params"][0]

        station_list = stage_queries.station_list([gage])
        pt = Plottable(station_list[0], p, beginDate, endDate)
        data_seq = pt.sequence()

        # fifth parameter to create_metadata_header is list of Station objects
        station_list = stage_queries.station_list([gage])
        query_metadata_list = create_metadata_header(
            GENERAL_MESSAGE, EDEN_CONTACT, END_OF_HEADER, form.cleaned_data, station_list, water_level=False
        )

        response = HttpResponse(content_type="text/csv")
        stage_data.write_rdb(data_seq, response, metadata=query_metadata_list)

        return response
    else:
        return HttpResponseBadRequest(",".join(form.errors))
コード例 #3
0
def daily_download(request):
    form = TimeSeriesFilterForm(request.GET)

    if (form.is_valid()):
        gages = form.cleaned_data['site_list']
        _logger.info("hourly csv download, gages is %s" % (gages))
        beginDate = form.cleaned_data["timeseries_start"]
        endDate = form.cleaned_data["timeseries_end"]

        station_dict = stage_queries.station_dict(gages)

        beginDate = form.cleaned_data["timeseries_start"]
        endDate = form.cleaned_data["timeseries_end"]

        q, dt = stage_queries.daily_query(*station_dict.values())
        if beginDate:
            q = q.where(dt >= beginDate)
        if endDate:
            q = q.where(dt <= endDate)
        data = q.execute()

        # data_type = 'Hourly Water Level, NAVD88(ft)'  # hard coded for now... maybe this could be in the form where the user's can selected between hourly and daily data
        query_metadata_list = create_metadata_header(HEADER_MESSAGE, EDEN_CONTACT, END_OF_HEADER, form.cleaned_data, station_dict.values())

        response = HttpResponse(content_type='text/csv')

        stage_data.write_rdb(data, response, metadata=query_metadata_list)
        return response
    else:
        return HttpResponseBadRequest(",".join(form.errors))
    pass
コード例 #4
0
    def test_create_metadata_header(self):
        gages = [
            '2A300',
        ]
        station_qs = Station.objects.filter(station_name_web__in=gages)
        query_info = {"key1": "value1", "key2": "value2"}

        hh = download_header.create_metadata_header("message", "contact",
                                                    "header_end", query_info,
                                                    station_qs)
        self.assertIsInstance(hh, list)
        i = 0
        self.assertEquals("message", hh[i])
        i += 1
        self.assertEquals("contact", hh[i])
        i += 1
        self.assertTrue("Retrieved" in hh[i])
        i += 1
        self.assertTrue("parameters" in hh[i])
        i += 1
        self.assertTrue("2A300" in hh[i])
        i += 1
        self.assertTrue("parameter codes" in hh[i])
        i += 1
        self.assertTrue("Note" in hh[i])
        i += 1
        self.assertTrue("key" in hh[i])
        i += 1
        self.assertTrue("key" in hh[i])
        i += 1
        self.assertEquals("header_end", hh[i])
        i += 1
コード例 #5
0
def timeseries_csv_download(request):
    # TODO Pull gage list up to list of model objects

    form = TimeSeriesFilterForm(request.GET)

    if (form.is_valid()):
        gages = form.cleaned_data['site_list']
        _logger.info("csv download, gages is %s" % (gages))
        beginDate = form.cleaned_data["timeseries_start"]
        endDate = form.cleaned_data["timeseries_end"]

        station_qs = Station.objects.filter(station_name_web__in=gages)

        query_metadata_list = create_metadata_header(HEADER_MESSAGE, EDEN_CONTACT, END_OF_HEADER, form.cleaned_data, station_qs)

        response = HttpResponse(content_type='text/csv')

        results = stage_data.data_for_download(
                        gages,
                        beginDate=beginDate,
                        endDate=endDate
                    )
        stage_data.write_rdb(results, response, metadata=query_metadata_list)
        return response
    else:
        return HttpResponseBadRequest(",".join(form.errors))
コード例 #6
0
    def test_header_crlf(self):
        station_qs = []
        query_info = {"key1": "value1", "key2":"value2"}

        hh = download_header.create_metadata_header(HEADER_MESSAGE, EDEN_CONTACT, END_OF_HEADER, query_info, station_qs)

        self.assertIsInstance(hh, list)
        # let the writer add the line endings
        for h in hh:
            self.assertFalse("\n" in h, "contains newline:" + h)
            self.assertFalse("\r" in h, "contains carriage return:" + h)
コード例 #7
0
    def test_header_crlf(self):
        station_qs = []
        query_info = {"key1": "value1", "key2": "value2"}

        hh = download_header.create_metadata_header(HEADER_MESSAGE,
                                                    EDEN_CONTACT,
                                                    END_OF_HEADER, query_info,
                                                    station_qs)

        self.assertIsInstance(hh, list)
        # let the writer add the line endings
        for h in hh:
            self.assertFalse("\n" in h, "contains newline:" + h)
            self.assertFalse("\r" in h, "contains carriage return:" + h)
コード例 #8
0
    def test_create_metadata_header(self):
        gages = ['2A300', ]
        station_qs = Station.objects.filter(station_name_web__in=gages)
        query_info = {"key1": "value1", "key2":"value2"}

        hh = download_header.create_metadata_header("message", "contact", "header_end", query_info, station_qs)
        self.assertIsInstance(hh, list)
        i = 0
        self.assertEquals("message", hh[i]); i += 1
        self.assertEquals("contact", hh[i]); i += 1
        self.assertTrue("Retrieved" in hh[i]); i += 1
        self.assertTrue("parameters" in hh[i]); i += 1
        self.assertTrue("2A300" in hh[i]); i += 1
        self.assertTrue("parameter codes" in hh[i]); i += 1
        self.assertTrue("Note" in hh[i]); i += 1
        self.assertTrue("key" in hh[i]); i += 1
        self.assertTrue("key" in hh[i]); i += 1
        self.assertEquals("header_end", hh[i]); i += 1
コード例 #9
0
def timeseries_csv_download(request):
    # TODO Pull gage list up to list of model objects

    form = TimeSeriesFilterForm(request.GET)

    if form.is_valid():
        gages = form.cleaned_data["site_list"]
        _logger.info("csv download, gages is %s" % (gages))
        beginDate = form.cleaned_data["timeseries_start"]
        endDate = form.cleaned_data["timeseries_end"]

        station_qs = Station.objects.filter(station_name_web__in=gages)

        query_metadata_list = create_metadata_header(
            HEADER_MESSAGE, EDEN_CONTACT, END_OF_HEADER, form.cleaned_data, station_qs
        )

        response = HttpResponse(content_type="text/csv")

        results = stage_data.data_for_download(gages, beginDate=beginDate, endDate=endDate)
        stage_data.write_rdb(results, response, metadata=query_metadata_list)
        return response
    else:
        return HttpResponseBadRequest(",".join(form.errors))
コード例 #10
0
def param_rdb_download(request):
    form = DataParamForm(request.GET)
    if form.is_valid():
        _logger.info("requested data download for %s with params %s" % (form.cleaned_data['site_list'], form.cleaned_data['params']))

        beginDate = form.cleaned_data["timeseries_start"]
        endDate = form.cleaned_data["timeseries_end"]
        gage = form.cleaned_data['site_list']
        p = form.cleaned_data['params'][0]

        station_list = stage_queries.station_list([gage])
        pt = Plottable(station_list[0], p, beginDate, endDate)
        data_seq = pt.sequence()

        # fifth parameter to create_metadata_header is list of Station objects
        station_list = stage_queries.station_list([gage])
        query_metadata_list = create_metadata_header(GENERAL_MESSAGE, EDEN_CONTACT, END_OF_HEADER, form.cleaned_data, station_list, water_level=False)

        response = HttpResponse(content_type='text/csv')
        stage_data.write_rdb(data_seq, response, metadata=query_metadata_list)

        return response
    else:
        return HttpResponseBadRequest(",".join(form.errors))