def appdb(request): from agila.analytics import user_consumption_total as uct from agila.analytics import user_percentile as upercentile user_consumption = uct(request.user) user_consumption_today = uct(user=request.user, days_=1) user_percentile = upercentile(request.user) if request.method == "GET": appdb = AppDB.objects.all() for app in appdb: app.typestring = "Smart Device" if app.type is "SMART" else "Non-Smart Appliance" return render(request, "appdb.html", { "flash": getFlash(request), "appdb": appdb, "user_consumption": user_consumption, "user_consumption_today": user_consumption_today, "user_percentile": user_percentile }) else: for x in ["name", "wattage"]: if x not in request.POST: storeFlash(request, "Unable to submit device, you need to fill in all the details.", "danger") return redirect('/appdb/') try: new_device = AppDB( name = request.POST.get('name'), wattage = int(request.POST.get('wattage')), type = "SMART" if request.POST.get('is_smart') else "DUMB") new_device.save() except Exception, e: print e storeFlash(request, "Unable to submit device, something went wrong!", "danger") return redirect('/appdb/')
def analytics(request): from agila.analytics import user_consumption_total as uct from agila.analytics import user_percentile as upercentile user_consumption = uct(request.user) user_consumption_today = uct(user=request.user, days_=1) user_percentile = upercentile(request.user) groups = request.user.usergroup_set.all() return render(request, "dashboard-analytics.html", { "groups": groups, "user_consumption": user_consumption, "user_consumption_today": user_consumption_today, "user_percentile": user_percentile })
def analytics(request): from agila.analytics import user_consumption_total as uct from agila.analytics import user_percentile as upercentile user_consumption = uct(request.user) user_consumption_today = uct(user=request.user, days_=1) user_percentile = upercentile(request.user) groups = request.user.usergroup_set.all() return render( request, "dashboard-analytics.html", { "groups": groups, "user_consumption": user_consumption, "user_consumption_today": user_consumption_today, "user_percentile": user_percentile })
def appdb(request): from agila.analytics import user_consumption_total as uct from agila.analytics import user_percentile as upercentile user_consumption = uct(request.user) user_consumption_today = uct(user=request.user, days_=1) user_percentile = upercentile(request.user) if request.method == "GET": appdb = AppDB.objects.all() for app in appdb: app.typestring = "Smart Device" if app.type is "SMART" else "Non-Smart Appliance" return render( request, "appdb.html", { "flash": getFlash(request), "appdb": appdb, "user_consumption": user_consumption, "user_consumption_today": user_consumption_today, "user_percentile": user_percentile }) else: for x in ["name", "wattage"]: if x not in request.POST: storeFlash( request, "Unable to submit device, you need to fill in all the details.", "danger") return redirect('/appdb/') try: new_device = AppDB( name=request.POST.get('name'), wattage=int(request.POST.get('wattage')), type="SMART" if request.POST.get('is_smart') else "DUMB") new_device.save() except Exception, e: print e storeFlash(request, "Unable to submit device, something went wrong!", "danger") return redirect('/appdb/')
def dashboard(request): devices = request.user.device_set.filter(linked=True) groups = request.user.usergroup_set.all() appdb = AppDB.objects.filter(type='DUMB') dumbapps = request.user.dumbdevice_set.filter(linked=True) hours = [ {"value": 0, "text": "12am"}, {"value": 1, "text": "1am"}, {"value": 2, "text": "2am"}, {"value": 3, "text": "3am"}, {"value": 4, "text": "4am"}, {"value": 5, "text": "5am"}, {"value": 6, "text": "6am"}, {"value": 7, "text": "7am"}, {"value": 8, "text": "8am"}, {"value": 9, "text": "9am"}, {"value": 10, "text": "10am"}, {"value": 11, "text": "11am"}, {"value": 12, "text": "12pm"}, {"value": 13, "text": "1pm"}, {"value": 14, "text": "2pm"}, {"value": 15, "text": "3pm"}, {"value": 16, "text": "4pm"}, {"value": 17, "text": "5pm"}, {"value": 18, "text": "6pm"}, {"value": 19, "text": "7pm"}, {"value": 20, "text": "8pm"}, {"value": 21, "text": "9pm"}, {"value": 22, "text": "10pm"}, {"value": 23, "text": "1pm"} ] from agila.analytics import user_consumption_total as uct from agila.analytics import user_percentile as upercentile user_consumption = uct(request.user) user_consumption_today = uct(user=request.user, days_=1) user_percentile = upercentile(request.user) consumption_not_set = 0 # Put string data for device in devices: if not device.consumption: device.status = "Set Wattage" device.statusclass = "label-warning" consumption_not_set += 1 else: buffertime = datetime.now() - timedelta(hours=1) usageinbuffer = device.usage_set.filter(datetime__gt=buffertime) device.status = "Tracking" if (usageinbuffer.count() > 0) else "Offline" device.statusclass = "label-success" if (usageinbuffer.count() > 0) else "label-danger" for group_ in groups: group_.members = group_.group.members if group_.group.members else 0 groups_json = json.dumps([group.name for group in CustomGroup.objects.all()]) return render(request, "dashboard-main.html", { "user_consumption": user_consumption, "user_consumption_today": user_consumption_today, "user_percentile": user_percentile, "devices": devices, "groups": groups, "flash": getFlash(request), "groups_json": groups_json, "appdb": appdb, "dumbapps": dumbapps, "days": ['Su', 'M', 'T', 'W', 'Th', 'Fr', 'Sa'], "hours": hours, "setconsumption": True if consumption_not_set > 0 else False })
def dashboard(request): devices = request.user.device_set.filter(linked=True) groups = request.user.usergroup_set.all() appdb = AppDB.objects.filter(type='DUMB') dumbapps = request.user.dumbdevice_set.filter(linked=True) hours = [{ "value": 0, "text": "12am" }, { "value": 1, "text": "1am" }, { "value": 2, "text": "2am" }, { "value": 3, "text": "3am" }, { "value": 4, "text": "4am" }, { "value": 5, "text": "5am" }, { "value": 6, "text": "6am" }, { "value": 7, "text": "7am" }, { "value": 8, "text": "8am" }, { "value": 9, "text": "9am" }, { "value": 10, "text": "10am" }, { "value": 11, "text": "11am" }, { "value": 12, "text": "12pm" }, { "value": 13, "text": "1pm" }, { "value": 14, "text": "2pm" }, { "value": 15, "text": "3pm" }, { "value": 16, "text": "4pm" }, { "value": 17, "text": "5pm" }, { "value": 18, "text": "6pm" }, { "value": 19, "text": "7pm" }, { "value": 20, "text": "8pm" }, { "value": 21, "text": "9pm" }, { "value": 22, "text": "10pm" }, { "value": 23, "text": "1pm" }] from agila.analytics import user_consumption_total as uct from agila.analytics import user_percentile as upercentile user_consumption = uct(request.user) user_consumption_today = uct(user=request.user, days_=1) user_percentile = upercentile(request.user) consumption_not_set = 0 # Put string data for device in devices: if not device.consumption: device.status = "Set Wattage" device.statusclass = "label-warning" consumption_not_set += 1 else: buffertime = datetime.now() - timedelta(hours=1) usageinbuffer = device.usage_set.filter(datetime__gt=buffertime) device.status = "Tracking" if ( usageinbuffer.count() > 0) else "Offline" device.statusclass = "label-success" if ( usageinbuffer.count() > 0) else "label-danger" for group_ in groups: group_.members = group_.group.members if group_.group.members else 0 groups_json = json.dumps( [group.name for group in CustomGroup.objects.all()]) return render( request, "dashboard-main.html", { "user_consumption": user_consumption, "user_consumption_today": user_consumption_today, "user_percentile": user_percentile, "devices": devices, "groups": groups, "flash": getFlash(request), "groups_json": groups_json, "appdb": appdb, "dumbapps": dumbapps, "days": ['Su', 'M', 'T', 'W', 'Th', 'Fr', 'Sa'], "hours": hours, "setconsumption": True if consumption_not_set > 0 else False })