Exemplo n.º 1
0
    async def handlePage_(self):
        try:
            await api_req_limit.CheckHTTP(self)
            sid = await CheckRight(self)
            ulang = GetLangCode(self)
            temp = self.get_argument('ids', '')
            sensorids = c_escape.json_decode(c_escape.url_unescape(temp))
            if len(sensorids) < 1:
                raise cyclone_web.HTTPError(404, 'no sensor')

            sql_str = rg_lib.Sqlite.GenInSql(
                """select COALESCE(name,'') name, id
                                                        from rgw_sensor where id in """,
                sensorids)
            sensors = await api_core.BizDB.Query([sql_str, sensorids])
            sensors_tbl = {i['id']: i for i in sensors}
            if len(sensors) > 0:
                self.render(rgw_consts.TPL_NAMES.VIEW_SENSOR_MINS_AVG_DATA,
                            app_js_dir=settings.WEB['js_dir'],
                            app_css_dir=settings.WEB['css_dir'],
                            app_template_dir=settings.WEB['template_dir'],
                            title=self.GetTitle(),
                            sessionid=sid,
                            user_lang=ulang,
                            sensorids=sensorids,
                            sensors_tbl=sensors_tbl,
                            mins_interval_tbls=self.GetMinsInterval())
            else:
                raise cyclone_web.HTTPError(404, 'no sensor')
        except models.AccessOverLimit:
            self.finish(rgw_consts.WebContent.ACCESS_OVER_LIMIT)
        except models.NoRightError:
            self.redirect(rgw_consts.URLs.APP_EM_LOGIN)
Exemplo n.º 2
0
 async def __get(self):
     try:
         self.set_header('Content-Type', 'image/svg+xml')
         temp = self.get_argument('sensorids')
         sensorids = c_escape.json_decode(c_escape.url_unescape(temp))
         para = {
             'width': float(self.get_argument('width')),
             'height': float(self.get_argument('height')),
             'hours': int(self.get_argument('hours')),
             'mins': int(self.get_argument('mins')),
             'tz_offset': int(self.get_argument('tz_offset', 0)),
             'sensorids': sensorids
         }
         res = await plotting_api.SensorRecentHoursLog(para)
         self.finish(res)
     except Exception:
         log.err()
         raise cyclone_web.HTTPError(400)
Exemplo n.º 3
0
 async def handlePage_(self):
     try:
         await api_req_limit.CheckHTTP(self)
         sid = await CheckRight(self)
         ulang = GetLangCode(self)
         temp_str = self.get_argument('sensorids')
         sensorids = c_escape.json_decode(c_escape.url_unescape(temp_str))
         plotting_no = self.get_argument('plotting_no', '1')
         if len(sensorids) < 1:
             raise cyclone_web.HTTPError(404, 'no sensor')
         sql_str = rg_lib.Sqlite.GenInSql(
             """select COALESCE(name,'') name, id from rgw_sensor where id in """,
             sensorids)
         sensors = await api_core.BizDB.Query([sql_str, sensorids])
         if len(sensors) > 0:
             label_tbl = self.GetLabelTbl()[ulang]
             self.render(rgw_consts.TPL_NAMES.VIEW_SENSORS_RECENT_TREND,
                         app_js_dir=settings.WEB['js_dir'],
                         app_css_dir=settings.WEB['css_dir'],
                         app_template_dir=settings.WEB['template_dir'],
                         title=self.GetTitle(),
                         sessionid=sid,
                         user_lang=ulang,
                         sensorids=sensorids,
                         hours_tbls=self.GetHoursTbls(),
                         mins_interval_tbls=self.GetMinsInterval(),
                         label_tbl=label_tbl,
                         plotting_no=plotting_no,
                         sensor_recent_hours_plotting_url=rgw_consts.URLs.
                         VIEW_RECENT_HOURS_SENSOR_DATA_PLOTTING[1:])
         else:
             raise cyclone_web.HTTPError(404, 'no sensor')
     except models.AccessOverLimit:
         self.finish(rgw_consts.WebContent.ACCESS_OVER_LIMIT)
     except models.NoRightError:
         self.redirect(rgw_consts.URLs.APP_EM_LOGIN)
Exemplo n.º 4
0
 def test_url_unescape(self):
     self.assertEqual(url_unescape("a+value", encoding=None), b"a value")
     self.assertEqual(url_unescape("a+value"), "a value")
Exemplo n.º 5
0
 def test_url_unescape(self):
     self.assertEqual(url_unescape("a+value", encoding=None), "a value")
     self.assertEqual(url_unescape("a+value"), "a value")
Exemplo n.º 6
0
 async def __get(self):
     try:
         self.set_header('Content-Type', 'image/svg+xml')
         temp = self.get_argument('sensorids')
         sensorids = c_escape.json_decode(c_escape.url_unescape(temp))
         para = {
             'width': float(self.get_argument('width')),
             'height': float(self.get_argument('height')),
             'hours': int(self.get_argument('hours')),
             'mins': int(self.get_argument('mins')),
             'tz_offset': int(self.get_argument('tz_offset', 0)),
             'sensorids': sensorids
         }
         svg_height = para.get('height')
         svg_width = para.get('width')
         hours = para.get('hours')
         tz_offset = para.get('tz_offset', 0)
         mins = para.get('mins')
         sensorids = para.get('sensorids')
         sql_str = rg_lib.Sqlite.GenInSql(
             """select COALESCE(r1.name,'') name, r1.id, r1.data_no,r1.val_precision, 
                      r1.val_unit from rgw_sensor r1 where r1.id in """,
             sensorids)
         sensors = await api_core.BizDB.Query([sql_str, sensorids])
         sensors_tbl = {s['id']: s for s in sensors}
         curr = rg_lib.DateTime.ts()
         start_ts = curr - hours * 3600
         start_ts = rg_lib.DateTime.dt2ts(
             rg_lib.DateTime.ts2dt(start_ts).replace(minute=0, second=0))
         dt_series = rg_lib.DateTime.GetMinSeries(start_ts, curr, mins,
                                                  'datetime')
         ts_series = [rg_lib.DateTime.dt2ts(i) for i in dt_series]
         rows = await api_sensor_avg_data.QueryMinAvg(
             start_ts, curr, sensorids, mins, 2000)
         rows_tbl = collections.OrderedDict()
         for r in rows:
             if r['cts'] in rows_tbl:
                 rows_tbl[r['cts']].append(r)
             else:
                 rows_tbl[r['cts']] = [r]
         if len(dt_series) > 9:
             steps = 1 + len(dt_series) // 9
         else:
             steps = 1
         chart_obj = pygal.Line(x_labels_major_every=steps,
                                x_label_rotation=20,
                                show_minor_x_labels=False,
                                dots_size=1,
                                height=svg_height,
                                width=svg_width,
                                legend_at_bottom=True,
                                show_y_guides=False,
                                y_labels_major_every=3,
                                show_minor_y_labels=False,
                                allow_interruptions=True,
                                style=pygal_style.CleanStyle)
         chart_obj.x_labels = [
             (rg_lib.DateTime.ts2dt(i) +
              datetime.timedelta(hours=tz_offset)).strftime('%H:%M')
             for i in dt_series
         ]
         for sensorid in sensorids:
             vals = [{'value': None}] * len(chart_obj.x_labels)
             sensor = sensors_tbl[sensorid]
             for _, cts in enumerate(rows_tbl.keys()):
                 for row in rows_tbl[cts]:
                     if row['sensorid'] == sensorid and cts in ts_series:
                         idx = ts_series.index(cts)
                         vals[idx] = {
                             'value':
                             row['avg_val'],
                             'formatter':
                             functools.partial(GetValLabel,
                                               sensor_mdl=sensor)
                         }
             chart_obj.add(sensors_tbl[sensorid]['name'], vals)
         temp = chart_obj.render(True)
         self.finish(temp)
     except Exception:
         log.err()
         raise cyclone_web.HTTPError(400)