def global_statistics(): hoods = stattools.hoods() return render_template("statistics.html", stats = db.stats.find({}, {"_id": 0}), clients = stattools.total_clients(), router_status = stattools.router_status(), router_models = stattools.router_models(), router_firmwares = stattools.router_firmwares(), hoods = hoods, hoods_sum = stattools.hoods_sum(), newest_routers = db.routers.find({"hardware.name": {"$ne": "Legacy"}}, {"hostname": 1, "hood": 1, "created": 1}).sort("created", pymongo.DESCENDING).limit(len(hoods)+1) )
def global_hoodstatistics(selecthood): mysql = FreifunkMySQL() hoods = stattools.hoods(mysql) stats = mysql.fetchall("SELECT * FROM stats_hood WHERE hood = %s",(selecthood,)) stats = mysql.utcawaretuple(stats,"time") numnew = len(hoods)-18 if numnew < 1: numnew = 1 newest_routers = mysql.fetchall(""" SELECT id, hostname, hood, created FROM router WHERE hardware <> 'Legacy' AND hood = %s ORDER BY created DESC LIMIT %s """,(selecthood,numnew,)) newest_routers = mysql.utcawaretuple(newest_routers,"created") clients = stattools.total_clients(mysql) router_status = stattools.router_status(mysql) router_models = stattools.router_models(mysql,selecthood) router_firmwares = stattools.router_firmwares(mysql,selecthood) hoods_sum = stattools.hoods_sum(mysql) mysql.close() return render_template("statistics.html", selecthood = selecthood, stats = stats, clients = clients, router_status = router_status, router_models = router_models, router_firmwares = router_firmwares, hoods = hoods, hoods_sum = hoods_sum, newest_routers = newest_routers )
def helper_statistics(mysql,stats,selecthood,selectgw): try: hoods = stattools.hoods(mysql,selectgw) gws = stattools.gws_ifs(mysql,selecthood) if selecthood: selecthoodname = mysql.findone("SELECT name FROM hoods WHERE id = %s",(selecthood,),'name') else: selecthoodname = None if selectgw: selectgwint = mac2int(selectgw) else: selectgwint = None if selecthood and not selecthoodname: mysql.close() return "Hood not found" if selectgw and not selectgwint in gws: mysql.close() return "Gateway not found" stats = mysql.utcawaretupleint(stats,"time") numnew = len(hoods)-27 if numnew < 1: numnew = 1 if selectgw: newest_routers = mysql.fetchall(""" SELECT router.id, hostname, hoods.id AS hoodid, hoods.name AS hood, created FROM router INNER JOIN hoods ON router.hood = hoods.id INNER JOIN router_gw ON router.id = router_gw.router WHERE hardware <> 'Legacy' AND mac = %s ORDER BY created DESC LIMIT %s """,(mac2int(selectgw),numnew,)) else: if selecthood: where = " AND hoods.id = %s" tup = (selecthood,numnew,) else: where = "" tup = (numnew,) newest_routers = mysql.fetchall(""" SELECT router.id, hostname, hoods.id AS hoodid, hoods.name AS hood, created FROM router INNER JOIN hoods ON router.hood = hoods.id WHERE hardware <> 'Legacy' {} ORDER BY created DESC LIMIT %s """.format(where),tup) newest_routers = mysql.utcawaretuple(newest_routers,"created") clients = stattools.total_clients(mysql) router_status = stattools.router_status(mysql) router_models = stattools.router_models(mysql,selecthood,selectgw) router_firmwares = stattools.router_firmwares(mysql,selecthood,selectgw) hoods_sum = stattools.hoods_sum(mysql,selectgw) hoods_gws = stattools.hoods_gws(mysql) gws_sum = stattools.gws_sum(mysql,selecthood) gws_info = stattools.gws_info(mysql,selecthood) gws_admin = stattools.gws_admin(mysql,selectgw) mysql.close() return render_template("statistics.html", selecthood = selecthood, selecthoodname = selecthoodname, selectgw = selectgw, selectgwint = selectgwint, stats = stats, clients = clients, router_status = router_status, router_models = router_models, router_firmwares = router_firmwares, hoods = hoods, hoods_sum = hoods_sum, hoods_gws = hoods_gws, newest_routers = newest_routers, gws = gws, gws_sum = gws_sum, gws_info = gws_info, gws_admin = gws_admin ) except Exception as e: writelog(CONFIG["debug_dir"] + "/fail_stats.txt", str(e)) import traceback writefulllog("Warning: Failed to display stats page: %s\n__%s" % (e, traceback.format_exc().replace("\n", "\n__")))