def exporttoexcel(self, id, page=1, date="", date2=""): assert id and isinstance(id, basestring) vh = _vh.ViewHandle() t = vh.__getConfig__(id) if not t: abort(404) #/view/exporttoexcel/65/1/2011-03-11/2011-03-11 date = vh.__getDate__(date, int(t.labels)) date2 = vh.__getDate__(date2) if t.graphtype == "realtime": c.columns = "N \t datei \t minute \t value" else: c.columns = "N" items = str(t.items).split(',') for x, item in enumerate(items): c.columns += "\t" + item c.pagename = t.graphtype c.template_id = t.typeid c.typename = t.typename rows = vh.getRowsData(t.graphtype, t.typeid, date, date2) if rows == None: abort(404) c.rows = rows return render('/derived/view/exporttoexcel.html')
def webapipost(self, id): assert id and isinstance(id, basestring) vh = _vh.ViewHandle() t = vh.__getConfig__(id) if not t: abort(404) from pyfisheyes.model.utils import WebAPI as _w WebAPI = _w.WebAPI(t, request) if t.graphtype == "day": if WebAPI.SaveDataForGraphsDay(): return WebAPI.message elif t.graphtype == "hour": if WebAPI.SaveDataForGraphsHour(): return WebAPI.message elif t.graphtype == "host": if WebAPI.SaveDataForGraphsHost(): return WebAPI.message elif t.graphtype == "realtime": if WebAPI.SaveDataForGraphsRealtime(): return WebAPI.message else: log.debug("post error") #redirect('/view/data/' + id) return "success"
def index(self, tid, datei, timei): assert tid and isinstance(tid, basestring) assert datei and isinstance(datei, basestring) assert timei and isinstance(timei, basestring) content = "No Content" totalN = 0 vh = _vh.ViewHandle() t = vh.__getConfig__(tid, 0) if not t: abort(404) #typename = t.typename + " ("+datei+" "+timei+")\n\n" typename = datei + " " + timei[0:5] + "\n\n" t = model.Logstuff data = model.meta.Session.query(t).filter_by(tid=tid).filter_by( datei=datei).filter_by(logtime=datei + " " + timei) for i, d in enumerate(data): content = d.stuff response.headers['Content-type'] = 'text/plain' response.charset = 'utf8' p = re.compile('\n') res = p.sub('<br />', typename + content) return res
def webapi(self, id): assert id and isinstance(id, basestring) vh = _vh.ViewHandle() t = vh.__getConfig__(id) if not t: abort(404) c.template_id = t.typeid c.typename = t.typename c.items = t.items.split(",") c.pagename = t.graphtype return render('/derived/view/webapi.html')
def realtimegraph(self, id): assert id and isinstance(id, basestring) vh = _vh.ViewHandle() t = vh.__getConfig__(id, 0) if not t: abort(404) gp = self.rtgrap(t, vh) exp = timedelta(seconds=60) now = datetime.utcnow() response.headers['Cache-Control'] = 'max-age=60' response.headers['Expires'] = ( now + exp).strftime('%a, %d %b %Y %H:%M:%S GMT') response.headers['Content-type'] = 'image/png' return gp
def compare_background_data(self, t, odate, min=4): vh = _vh.ViewHandle() date1 = vh.__getDate__(odate, 1) timerange1 = vh.getSharpDayMinute(date1) rows1 = vh.getRealtimeRowsData(t.typeid, timerange1) sum1 = self.sumValue(rows1) timerange2 = vh.getSharpDayMinute(date1, 7) rows2 = vh.getRealtimeRowsData(t.typeid, timerange2) sum2 = self.sumValue(rows2) dv_ratio = 0 level = "Norml" status = "同比上周同一天上涨:" status_n = "" time_range = "" start_time_point = timerange1['start_time_point'] stop_time_point = timerange1['stop_time_point'] datetime1 = start_time_point.strftime('%Y-%m-%d %H:%M:00') datetime2 = stop_time_point.strftime('%Y-%m-%d %H:%M:00') try: ssum = sum2 - sum1 if ssum: dv_ratio = (sum2 - sum1) * 100 / sum2 else: dv_ratio = 0 if dv_ratio > 0: status = u"同比上周同一天下跌:" else: status = u"同比上周同一天上涨:" except: print "ZeroDivisionError" if abs(dv_ratio) > 10: level = "Warning" if abs(dv_ratio) > 20: level = "Critical" return (level, t.typename, t.typeid, status, datetime1, datetime2, t.r_weight, abs(dv_ratio), sum1)
def data(self, id, page=1, date2="", date=""): #assert id and isinstance(id, basestring) #assert page and isinstance(page, basestring) #assert date and isinstance(date, basestring) #assert date2 and isinstance(date2, basestring) if 'd2' in request.params: date2 = request.params['d2'] if 'pweekday' in request.params: c.pweekday = "1" else: c.pweekday = '0' if 'ck' in request.params: c.ck = "1" else: c.ck = "0" if id and isinstance(id, basestring): pass else: id = 0 if page and isinstance(page, basestring): pass else: page = 1 if date and isinstance(date, basestring): pass else: date = "" if date2 and isinstance(date2, basestring): pass else: date2 = "" if 'd' in request.params: date2 = request.params['d'] vh = _vh.ViewHandle() t = vh.__getConfig__(id) if not t: abort(404) date = vh.__getDate__(date, int(t.labels)) if t.graphtype == "realtime": date2 = vh.__getDate__(date2, 0) else: date2 = vh.__getDate__(date2) #if request.cookies.has_key('set_default_day') and 'd2' not in request.params: if 'set_default_day' in request.cookies and 'd2' not in request.params: date2 = request.cookies['set_default_day'] sw = "" if 's' in request.params: sw = request.params['s'] c.sw = sw c.t = t c.list_alarm_threshold = eval(t.alarm_threshold) c.date = date c.date2 = date2 c.imgpath = config["app_conf"]["img_path"] c.opt = "0" c.topic = t.typename c.template_id = t.typeid c.items = str(t.items).split(',') c.pagesize = t.labels c.yesterday = vh.__getDate__("") #if request.cookies.has_key('set_default_day'): if 'set_default_day' in request.cookies: c.set_default_day = "checked='checked'" else: c.set_default_day = "" if t.graphtype in ['day', 'realtime']: orderby = 0 else: orderby = 1 rows = vh.getRowsData(t.graphtype, t.typeid, date, date2, orderby) if rows == None: abort(404) c.pre_topic = vh.__getTopic__(id, "pre", t.graphtype) c.next_topic = vh.__getTopic__(id, "next", t.graphtype) c.pagename = t.graphtype c.datasupport = t.datasupport c.accessed = t.accessed c.from_date = date c.to_date = date2 if t.graphtype == "realtime": c.sumvalue = vh.sumValue(rows) c.rows = paginate.Page(rows, partial='partial', page=page, date=date, date2=date2, items_per_page=30) events = vh.getEvents(t.typeid, date2) log.info('+++++++++++++++++++++++++++++++++++===') log.info(events) log.info('+++++++++++++++++++++++++++++++++++===') if events: c.events = events if 'partial' in request.params: return render('/derived/view/onlydata.html') else: return render('/derived/view/view.html')
def graph(self, id, opt="0", date="", date2="1970-01-01", big=False): assert id and isinstance(id, basestring) assert opt and isinstance(opt, basestring) assert date and isinstance(date, basestring) assert date2 and isinstance(date2, basestring) ys = request.params.get('ys', '') today = datetime.now().strftime('%Y-%m-%d') vh = _vh.ViewHandle() t = vh.__getConfig__(id, 0) if not t: abort(404) if opt == "": opt = "0" date = vh.__getDate__(date, int(t.labels)) if big == False: date2 = vh.__getDate__(date2) names = t.items.split(',') titles = t.titles.split(',') if t.graphtype == "realtime": hidden = False if 'pweekday' in request.params: hidden = True if big == False: gp = self.rtgrap_big(t, vh, "660x250", titles, date2, hidden, ys) else: #fsize = date2 gp = self.rtgrap_big(t, vh, "7126x350", titles, date, hidden, ys) else: if t.graphtype == "day": rows = vh.getRowsData(t.graphtype, t.typeid, date, date2, 1) else: rows = vh.getRowsData(t.graphtype, t.typeid, date, date2, 0) if t.graphtype == "hour": date3 = vh.__getDateSub__(date2, 7) rows2 = vh.getRowsData(t.graphtype, t.typeid, date, date3) else: date3 = "" rows2 = None if rows == None: abort(404) gp = vh.getGraphData(t.graphtype, rows, rows2, names, titles, opt, date, date2, date3) #if big==False: response.headers['Content-type'] = 'image/png' if date2 == today or date == today: exp = timedelta(seconds=300) now = datetime.utcnow() response.headers['Cache-Control'] = 'max-age=300' response.headers['Expires'] = ( now + exp).strftime('%a, %d %b %Y %H:%M:%S GMT') elif datetime.strptime(date2, '%Y-%m-%d').date() < datetime.strptime( today, '%Y-%m-%d').date() or datetime.strptime( date2, '%Y-%m-%d').date() < datetime.strptime( today, '%Y-%m-%d').date(): exp = timedelta(seconds=315360000) now = datetime.utcnow() response.headers['Cache-Control'] = 'max-age=315360000' response.headers['Expires'] = ( now + exp).strftime('%a, %d %b %Y %H:%M:%S GMT') else: exp = timedelta(seconds=0) now = datetime.utcnow() response.headers['Cache-Control'] = 'max-age=0' response.headers['Expires'] = ( now + exp).strftime('%a, %d %b %Y %H:%M:%S GMT') return gp