コード例 #1
0
ファイル: views.py プロジェクト: epkugelmass/django-graphos
def home(request):
    chart = flot.LineChart(SimpleDataSource(data=data), html_id="line_chart")
    g_chart = gchart.LineChart(SimpleDataSource(data=data))
    cursor = get_mongo_cursor("graphos_mongo", "zips", max_docs=100)
    m_data = MongoDBDataSource(cursor=cursor, fields=['_id', 'pop'])
    m_chart = flot.LineChart(m_data)

    context = {'chart': chart, 'g_chart': g_chart, 'm_chart': m_chart}
    return render(request, 'demo/home.html', context)
コード例 #2
0
ファイル: views.py プロジェクト: epkugelmass/django-graphos
def tutorial(request):
    chart = flot.LineChart(SimpleDataSource(data=data), html_id="line_chart")
    url = "https://raw.github.com/agiliq/django-graphos/master/README.md"
    str = urllib2.urlopen(url).read()
    readme = markdown.markdown(str)
    context = {'chart': chart, "readme": readme}
    return render(request, 'demo/tutorial.html', context)
コード例 #3
0
ファイル: views.py プロジェクト: leotop/django-graphos
def other(request):
    cursor = get_mongo_cursor("graphos_mongo", "zips", max_docs=100)
    m_data = MongoDBDataSource(cursor=cursor, fields=['_id', 'pop'])
    m_chart = flot.LineChart(m_data)
    context = {}
    context['m_chart'] = m_chart
    return render(request, 'demo/other.html', context)
コード例 #4
0
ファイル: views.py プロジェクト: mahmoudhossam/django-graphos
 def get_context_data(self, *args, **kwargs):
     accounts_cursor = get_db("accounts").docs.find()
     field_names = self.request.REQUEST.getlist("fields[]") or ['Year', 'Net Profit']
     data_source = MongoDBDataSource(accounts_cursor,
                                   fields=field_names)
     chart = flot.LineChart(data_source)
     return {"chart": chart}
コード例 #5
0
def estadis(request, materia):
    """
    Esta funcion devuelve las estadisticas generales de la materia seleccionada.
    :param request: HttpRequest
    :param materia: String
    :type: POST
    :return:html
    """
    lista_examenes = Exam.objects.filter(nombre_materia=materia)
    cant_preguntas = lista_examenes.aggregate(Sum('cantidad_preg'))
    preg_correctas = lista_examenes.aggregate(Sum('preguntas_correctas'))
    preg_incorrectas = lista_examenes.aggregate(Sum('preguntas_incorrectas'))
    materia = get_object_or_404(Materia, nombre_materia=materia)
    promedio = materia.promedio
    data_source = ModelDataSource(queryset=lista_examenes,
                                  fields=['pk', 'porcentaje'])
    chart = flot.LineChart(data_source, height=300, width=500)
    return render(
        request, 'estadisticas/general.html', {
            'lista_examenes': lista_examenes,
            'cant_preguntas': cant_preguntas,
            'preg_correctas': preg_correctas,
            'preg_incorrectas': preg_incorrectas,
            'materia': materia,
            'promedio': promedio,
            'chart': chart
        })
コード例 #6
0
ファイル: views.py プロジェクト: daemon13/django-graphos
def flot_demo(request):
    create_demo_accounts()
    queryset = Account.objects.all()
    data_source = ModelDataSource(queryset, fields=['year', 'sales'])
    line_chart = flot.LineChart(data_source, options={'title': "Sales Growth"})
    bar_chart = flot.BarChart(data_source, options={'title': "Sales Growth"})
    point_chart = flot.PointChart(data_source,
                                  options={'title': "Sales Growth"})
    context = {
        'line_chart': line_chart,
        'bar_chart': bar_chart,
        'point_chart': point_chart
    }
    return render(request, 'demo/flot.html', context)
コード例 #7
0
ファイル: views.py プロジェクト: epkugelmass/django-graphos
def time_series_demo(request):
    create_demo_mongo()
    db = get_db('charts')

    query = get_query('year_ago', None,
                      'employee=/example/employee/500ff1b8e147f74f7000000c/')
    coll_name = "mapreduce_daily__sumof__time_record__hours"
    cursor = db[coll_name].find(query)
    data_source_2 = DemoMongoDBDataSource(cursor, fields=["_id", "value"])
    chart_2 = flot.LineChart(data_source_2)

    accounts_cursor = get_db("accounts").docs.find()
    data_source_3 = MongoDBDataSource(accounts_cursor,
                                      fields=['Year', 'Sales', 'Expenses'])

    chart_3 = gchart.LineChart(data_source_3)
    data_source_4 = MongoDBDataSource(accounts_cursor,
                                      fields=['Year', 'Sales'])
    chart_4 = CustomFlot2(data_source_4)
    period = 'weekly'
    start = 'year_ago'
    end = None
    series = [{
        'resource': 'time_record',
        'field': 'hours',
        'filter': 'employee=/example/employee/500ff1b8e147f74f7000000c/',
        'mapreduce_function': 'sumof'
    }, {
        'resource': 'other_time_record',
        'field': 'hours',
        'filter': 'employee=/example/employee/500ff1b8e147f74f7000000c/',
        'mapreduce_function': 'sumof'
    }]

    datasets = build_timeseries_chart(period=period,
                                      series=series,
                                      start=start,
                                      end=end)

    context = {
        'datasets': json.dumps(datasets),
        'chart_2': chart_2,
        "chart_3": chart_3,
        "chart_4": chart_4,
    }
    return render(request, 'demo/mongodb_source.html', context)
コード例 #8
0
def results(request):
    #region GET
    if request.method == 'GET':
        queryset = ResultModel.objects.all()

        if not queryset.exists():
            request.session.update(
                dict(error_message='No Results Available Yet'))
            return redirect('home')
    #endregion
    #region POST
    if request.method == 'POST':
        query = request.POST.get('search')

        queryset = ResultModel.objects.filter(winning_address=query) | ResultModel.objects.filter(winning_deposit=query)\
                  | ResultModel.objects.filter(losing_address=query) | ResultModel.objects.filter(losing_deposit=query)\
                  | ResultModel.objects.filter(txid=query)
    #endregion
    #region RETURN
    if queryset.exists():
        queryset = queryset.order_by('-id')
        data_source = ModelDataSource(
            queryset[:100], fields=['id', 'winning_deposit', 'losing_deposit'])
        chart = flot.LineChart(data_source)

        form = ResultsSearchForm()
        table = ResultsTable(queryset)
        RequestConfig(request, paginate=dict(per_page=100)).configure(table)

        html_dtc = dict(table=table, form=form, chart=chart)

        error_message = request.session.get('error_message', False)
        if error_message:
            html_dtc.update(dict(error_message=error_message))
            del request.session['error_message']

        html_dtc.update(csrf(request))

        return render(request, 'chikun/results.html', html_dtc)

    request.session.update(dict(error_message='No Result Found'))
    return redirect('results')
コード例 #9
0
ファイル: views.py プロジェクト: Edmene/Open-Game-Benchmarks
def fps_line_chart(benchmark):

    if not benchmark: return None

    data = [['Second', 'FPS', 'Median', '1st Quartile', '3rd Quartile']]

    for s, f in enumerate(benchmark.fps_data.split(",")):
        data += [[
            int(s),
            int(f),
            int(benchmark.fps_median),
            int(benchmark.fps_1st_quartile),
            int(benchmark.fps_3rd_quartile)
        ]]

    data_source = SimpleDataSource(data=data)

    chart = flot.LineChart(data_source, options={'title': "Frames per second"})

    return chart
コード例 #10
0
ファイル: views.py プロジェクト: pawneshg/cloud_ems
def graphview(request, difftime, contid):
    ldatetime = datetime.now() - timedelta(minutes=int(difftime))
    indexint = calendar.timegm(ldatetime.timetuple())
    mk_id = indexint * 10**9
    evndata = []

    start_evn_id = indexint / (10**5)
    start_data_id = indexint / (10**5)

    try:
        tzu = TZUser.objects.get(user=request.user)
        tzobj = tzu.usertimezone
    except ObjectDoesNotExist:
        tzobj = 'UTC'

    if contid == "":
        cont = ControllerInfo.objects.all()[0:1].get()
        return redirect('receivedata.views.graphview',
                        difftime=difftime,
                        contid=cont.controllerid)

    disLevel = dict(Event.LEVEL_CHOICES)
    for evn in Event.objects.filter(controllerid=contid,
                                    id__gt=mk_id).order_by('-id')[0:10]:
        list = {
            'id':
            evn.id,
            'measureddate':
            evn.measureddate.astimezone(
                pytz.timezone(tzobj)).strftime('%Y-%m-%d %H:%M:%S'),
            'level':
            disLevel[evn.level],
            'code':
            evn.code,
            'message':
            evn.message,
        }
        evndata.append(list)

    if len(evndata) > 0:
        start_evn_id = evndata[0]['id'] / (10**5)

    data = [[
        "measured data", "Battery-Power", "DEG-Power", "Grid-Power",
        "Load-Power", "PV-Power"
    ]]
    data2 = [[
        "measured data",
        "Battery-SoC",
        "Battery-Voltage",
    ]]
    data3 = [[
        "measured data",
        "Battery-Cell",
        "Inner",
        "Outer",
    ]]

    idlist = []

    for obj in MeasuredBattery.objects.filter(controllerid=contid,
                                              id__gt=mk_id).order_by('id'):
        try:
            mdeg = MeasuredDEG.objects.filter(
                controllerid=obj.controllerid,
                uniquekey=obj.uniquekey)[0:1].get()
        except ObjectDoesNotExist:
            mdeg = MeasuredDEG()
            mdeg.status = 0
            mdeg.power = 0
        try:
            mgrid = MeasuredGrid.objects.filter(
                controllerid=obj.controllerid,
                uniquekey=obj.uniquekey)[0:1].get()
        except ObjectDoesNotExist:
            mgrid = MeasuredGrid()
            mgrid.status = 0
            mgrid.power = 0
        try:
            mload = MeasuredLoad.objects.filter(
                controllerid=obj.controllerid,
                uniquekey=obj.uniquekey)[0:1].get()
        except ObjectDoesNotExist:
            mload = MeasuredLoad()
            mload.power = 0
        try:
            mpv = MeasuredPV.objects.filter(
                controllerid=obj.controllerid,
                uniquekey=obj.uniquekey)[0:1].get()
        except ObjectDoesNotExist:
            mpv = MeasuredPV()
            mpv.power = 0
        try:
            mt1 = MeasuredTemperature.objects.filter(
                controllerid=obj.controllerid,
                deviceindex=0,
                uniquekey=obj.uniquekey)[0:1].get()
        except ObjectDoesNotExist:
            mt1 = MeasuredTemperature()
            mt1.temperature = 0
        try:
            mt2 = MeasuredTemperature.objects.filter(
                controllerid=obj.controllerid,
                deviceindex=1,
                uniquekey=obj.uniquekey)[0:1].get()
        except ObjectDoesNotExist:
            mt2 = MeasuredTemperature()
            mt2.temperature = 0

        settime = calendar.timegm(
            obj.measureddate.astimezone(
                pytz.timezone(tzobj)).timetuple()) * 1000,
        list = [
            settime,
            smart_str(obj.power),
            smart_str(mdeg.power),
            smart_str(mgrid.power),
            smart_str(mload.power),
            smart_str(mpv.power),
        ]
        data.append(list)
        list2 = [
            settime,
            smart_str(obj.soc),
            smart_str(obj.voltage),
        ]
        data2.append(list2)

        list3 = [
            settime,
            smart_str(obj.celltem),
            smart_str(mt1.temperature),
            smart_str(mt2.temperature),
        ]
        data3.append(list3)

        start_data_id = obj.id / (10**5)
        if len(data) > 50:
            del data[1]
            del data2[1]
            del data3[1]

    chart = flot.LineChart(
        SimpleDataSource(data=data),
        html_id="line_chart1",
        options={'xaxis': {
            'mode': 'time',
            'timeformat': '%H:%M'
        }})
    chart2 = flot.LineChart(SimpleDataSource(data=data2),
                            html_id="line_chart2",
                            options={
                                'xaxis': {
                                    'mode': 'time',
                                    'timeformat': '%H:%M'
                                },
                                'yaxes': [{
                                    'position': 'left',
                                    'min': 0,
                                    'max': 100
                                }, {
                                    'position': 'right',
                                    'min': 0,
                                    'max': 65
                                }]
                            })
    chart3 = flot.LineChart(
        SimpleDataSource(data=data3),
        html_id="line_chart3",
        options={'xaxis': {
            'mode': 'time',
            'timeformat': '%H:%M'
        }})

    cdata2 = chart2.get_series_objects()

    cdata2[1]['yaxis'] = 2

    arealist = AreaInfo.objects.values('areaid', 'areanm')
    continfo = ControllerInfo.objects.get(pk=contid)
    placeid = continfo.placeid
    placeinfo = PlaceInfo.objects.get(pk=placeid.placeid)
    areaid = placeinfo.areaid
    placelist = PlaceInfo.objects.filter(
        areaid_id__exact=areaid.areaid).values('placeid', 'placenm')
    contlist = ControllerInfo.objects.filter(
        placeid_id__exact=placeid.placeid).values('controllerid',
                                                  'controllernm')

    #jarealist=json.dumps(list(arealist))
    #jplacelist=json.dumps(placelist)
    #jcontlist=json.dumps(contlist)

    my_context = {
        'evnlist': evndata,
        'cdata1': chart.get_series_objects_json(),
        'cdata2': json.dumps(cdata2),
        'cdata3': chart3.get_series_objects_json(),
        'contid': contid,
        'difftime': difftime,
        'startevnid': start_evn_id,
        'startdataid': start_data_id,
        'areaid': areaid.areaid,
        'placeid': placeid.placeid,
        'arealist': arealist,
        'placelist': placelist,
        'contlist': contlist,
    }

    return render_to_response(["graphview.html"],
                              my_context,
                              context_instance=RequestContext(request))
コード例 #11
0
ファイル: views.py プロジェクト: pawneshg/cloud_ems
def getdatapower(request, dataid, contid):

    mk_id = int(dataid) * 10**5 + 99999

    data = [[
        "measured data", "Battery-Power", "DEG-Power", "Grid-Power",
        "Load-Power", "PV-Power"
    ]]
    data2 = [[
        "measured data",
        "Battery-SoC",
        "Battery-Voltage",
    ]]
    data3 = [[
        "measured data",
        "Battery-Cell",
        "Inner",
        "Outer",
    ]]

    try:
        tzu = TZUser.objects.get(user=request.user)
        tzobj = tzu.usertimezone
    except ObjectDoesNotExist:
        tzobj = 'UTC'

    for obj in MeasuredBattery.objects.filter(controllerid=contid,
                                              id__gt=mk_id).order_by('id'):
        try:
            mdeg = MeasuredDEG.objects.filter(
                controllerid=obj.controllerid,
                uniquekey=obj.uniquekey)[0:1].get()
        except ObjectDoesNotExist:
            mdeg = MeasuredDEG()
            mdeg.status = 0
            mdeg.power = 0
        try:
            mgrid = MeasuredGrid.objects.filter(
                controllerid=obj.controllerid,
                uniquekey=obj.uniquekey)[0:1].get()
        except ObjectDoesNotExist:
            mgrid = MeasuredGrid()
            mgrid.status = 0
            mgrid.power = 0
        try:
            mload = MeasuredLoad.objects.filter(
                controllerid=obj.controllerid,
                uniquekey=obj.uniquekey)[0:1].get()
        except ObjectDoesNotExist:
            mload = MeasuredLoad()
            mload.power = 0
        try:
            mpv = MeasuredPV.objects.filter(
                controllerid=obj.controllerid,
                uniquekey=obj.uniquekey)[0:1].get()
        except ObjectDoesNotExist:
            mpv = MeasuredPV()
            mpv.power = 0
        try:
            mt1 = MeasuredTemperature.objects.filter(
                controllerid=obj.controllerid,
                deviceindex=0,
                uniquekey=obj.uniquekey)[0:1].get()
        except ObjectDoesNotExist:
            mt1 = MeasuredTemperature()
            mt1.temperature = 0
        try:
            mt2 = MeasuredTemperature.objects.filter(
                controllerid=obj.controllerid,
                deviceindex=1,
                uniquekey=obj.uniquekey)[0:1].get()
        except ObjectDoesNotExist:
            mt2 = MeasuredTemperature()
            mt2.temperature = 0

        settime = calendar.timegm(
            obj.measureddate.astimezone(
                pytz.timezone(tzobj)).timetuple()) * 1000,
        list = [
            settime,
            smart_str(obj.power),
            smart_str(mdeg.power),
            smart_str(mgrid.power),
            smart_str(mload.power),
            smart_str(mpv.power),
        ]
        data.append(list)
        list2 = [
            settime,
            smart_str(obj.soc),
            smart_str(obj.voltage),
        ]
        data2.append(list2)

        list3 = [
            settime,
            smart_str(obj.celltem),
            smart_str(mt1.temperature),
            smart_str(mt2.temperature),
        ]
        data3.append(list3)

        dataid = obj.id / (10**5)

        if len(data) > 50:
            break

    chart = flot.LineChart(
        SimpleDataSource(data=data),
        html_id="line_chart1",
        options={'xaxis': {
            'mode': 'time',
            'timeformat': '%H:%M'
        }})
    chart2 = flot.LineChart(SimpleDataSource(data=data2),
                            html_id="line_chart2",
                            options={
                                'xaxis': {
                                    'mode': 'time',
                                    'timeformat': '%H:%M'
                                },
                                'yaxes': [{
                                    'position': 'left',
                                    'min': 0,
                                    'max': 100
                                }, {
                                    'position': 'right',
                                    'min': 0,
                                    'max': 65
                                }]
                            })
    cdata2 = chart2.get_series_objects()
    cdata2[1]['yaxis'] = 2
    chart3 = flot.LineChart(
        SimpleDataSource(data=data3),
        html_id="line_chart3",
        options={'xaxis': {
            'mode': 'time',
            'timeformat': '%H:%M'
        }})
    alldata = {
        'data1': chart.get_series_objects(),
        'data2': cdata2,
        'data3': chart3.get_series_objects(),
        'startdataid': dataid
    }

    return HttpResponse(json.dumps(alldata))
コード例 #12
0
ファイル: views.py プロジェクト: epkugelmass/django-graphos
 def get_context_data(self, *args, **kwargs):
     accounts_cursor = get_db("accounts").docs.find()
     data_source = MongoDBDataSource(accounts_cursor,
                                     fields=['Year', 'Net Profit'])
     chart = flot.LineChart(data_source)
     return {"chart": chart}
コード例 #13
0
ファイル: views.py プロジェクト: leotop/django-graphos
def home(request):
    chart = flot.LineChart(SimpleDataSource(data=data), html_id="line_chart")
    g_chart = gchart.LineChart(SimpleDataSource(data=data))
    context = {'chart': chart, 'g_chart': g_chart}
    return render(request, 'demo/home.html', context)
コード例 #14
0
def monitor(request):
    if request.method == 'GET':
        form = DateForm()
    else:
        form = DateForm(request.POST)

    end = sensors.objects.latest('time')
    end_time = datetime.fromtimestamp(int(end.time)).strftime('%Y-%m-%d %H:%M')
    start = sensors.objects.earliest('time')
    start_time = datetime.fromtimestamp(int(
        start.time)).strftime('%Y-%m-%d %H:%M')
    query = sensors.objects.latest('time')
    query.time = time.ctime(int(query.time))

    yesterday = datetime.now() - timedelta(days=1)
    yesterday_time = yesterday.strftime("%Y-%m-%d %H:%M")

    dates = request.POST
    start_date = dates.get('start_date', yesterday_time)
    end_date = dates.get('end_date', end_time)

    start_stamp = time.mktime(time.strptime(start_date, "%Y-%m-%d %H:%M"))
    end_stamp = time.mktime(time.strptime(end_date, "%Y-%m-%d %H:%M"))

    queryset = sensors.objects.filter(time__gte=start_stamp,
                                      time__lt=end_stamp).order_by('time')

    queryset1 = water_amount.objects.filter(
        time__gte=start_stamp, time__lt=end_stamp).order_by('time')

    data_source1 = ModelDataSource(queryset, fields=['java_time', 'temp'])
    data_source2 = ModelDataSource(queryset, fields=['java_time', 'hum'])
    data_source3 = ModelDataSource(queryset, fields=['java_time', 'light'])
    data_source4 = ModelDataSource(queryset, fields=['java_time', 'lux'])

    data_source5 = ModelDataSource(queryset1,
                                   fields=[
                                       'java_time', 'liters_total_r1',
                                       'liters_total_r2', 'liters_total_r3'
                                   ])

    line_chart1 = flot.LineChart(data_source1,
                                 options={
                                     'series': {
                                         'lines': {
                                             'fill': 'true'
                                         },
                                         'color': 'blue'
                                     },
                                     'xaxis': {
                                         'mode': 'time',
                                         'timeformat': '%m/%e %I:%M %P',
                                         "timezone": "browser"
                                     }
                                 })
    line_chart2 = flot.LineChart(data_source2,
                                 options={
                                     'series': {
                                         'lines': {
                                             'fill': 'true'
                                         },
                                         'color': 'red'
                                     },
                                     'xaxis': {
                                         'mode': 'time',
                                         'timeformat': '%m/%e %I:%M %P',
                                         'timezone': 'browser'
                                     }
                                 })
    line_chart3 = flot.LineChart(data_source3,
                                 options={
                                     'series': {
                                         'lines': {
                                             'fill': 'true'
                                         },
                                         'color': 'green'
                                     },
                                     'xaxis': {
                                         'mode': 'time',
                                         'timeformat': '%m/%e %I:%M %P',
                                         'timezone': 'browser'
                                     }
                                 })
    line_chart4 = flot.LineChart(data_source4,
                                 options={
                                     'series': {
                                         'lines': {
                                             'fill': 'true'
                                         },
                                         'color': 'purple'
                                     },
                                     'xaxis': {
                                         'mode': 'time',
                                         'timeformat': '%m/%e %I:%M %P',
                                         'timezone': 'browser'
                                     }
                                 })

    line_chart5 = flot.BarChart(data_source5,
                                options={
                                    'series': {
                                        'lines': {
                                            'steps': 'boolean'
                                        }
                                    },
                                    'xaxis': {
                                        'mode': 'time',
                                        'timeformat': '%m/%e %I:%M %P',
                                        "timezone": "browser"
                                    }
                                })

    context = {
        "line_chart1": line_chart1,
        "line_chart2": line_chart2,
        "line_chart3": line_chart3,
        "line_chart4": line_chart4,
        "line_chart5": line_chart5,
        "form": form,
        "dates": dates,
        "start_stamp": start_stamp,
    }

    return render(request, 'base/monitor.html', context)