Ejemplo n.º 1
0
    def get(self, dataName):
        """
        ref: web_api.yaml
        :param dataName:
        :return:
        """
        # parse params in request
        data_name = utils.encode_if_unicode(dataName)
        data_service = DataService(data_name)
        if not data_service.exists():
            return self.render(msg='%s not found' % data_name, status=404)
        if not data_service.auth_read():
            return self.render(msg='%s: data access forbidden' % data_name,
                               status=403)
        plugin = Plugin(data_service)
        start_time = g.args['startTime'] / 1000
        end_time = g.args['endTime'] / 1000
        # get raw
        line = data_service.get_line(start_time, end_time)
        # get base line
        base_line = self._get_raw(plugin, line)
        # get label line
        label_line = self._get_label(line, base_line['data'])
        # get ref
        ref_lines = self._get_refs(data_service, plugin, start_time, end_time)
        # get band
        bands, band_lines = self._get_bands(data_service, base_line['data'],
                                            start_time, end_time)

        trends = [base_line, label_line] + ref_lines + band_lines
        return self.render(data={
            'trends': trends,
            'bands': bands,
            'yAxis': data_service.get_y_axis()
        })
Ejemplo n.º 2
0
    def get(self, dataName):
        """
        ref: web_api.yaml
        :param dataName:
        :return:
        """
        data_name = utils.encode_if_unicode(dataName)
        data_service = DataService(data_name)
        if not data_service.exists():
            return self.render(msg='%s not found' % data_name, status=404)
        if not data_service.auth_read():
            return self.render(msg='%s: data access forbidden' % data_name, status=403)
        data_abstract = data_service.get_abstract()
        data_raw = data_service.get_raw()
        time_format = getattr(utils, data_abstract.time_formatter)
        data_raw = [raw.view(time_format) for raw in data_raw]
        string_io = StringIO()
        writer = csv.writer(string_io)
        writer.writerow(self.csv_header)
        writer.writerows(data_raw)

        return self.render_file('%s.csv' % data_name, string_io.getvalue())