Exemplo n.º 1
0
def graph_climate(request):
    # DataSource object
    queryset = Climate.objects.raw("SELECT * FROM store_climate \
                                   where year>1000 \
                                   and year<9999  \
                                   group by season,region \
                                   order by season,region")

    #    data_source = ModelDataSource(queryset, fields= ['season', 'tmax', 'tmin', ] )
    data_source_tmin = ModelDataSource(queryset, fields=['season', 'tmin'])
    data_source_tmax = ModelDataSource(queryset, fields=['season', 'tmax'])
    data_source_tmean = ModelDataSource(queryset, fields=['season', 'tmean'])
    data_source_rainfall = ModelDataSource(queryset,
                                           fields=['season', 'rainfall'])
    data_source_sunshine = ModelDataSource(queryset,
                                           fields=['season', 'sunshine'])

    # Chart object

    chart_tmin = ColumnChart(
        data_source_tmin,
        options={
            'title': 'Min. Temperature (England,Scotland,UK,Wales - 1911-2017)'
        })
    chart_tmax = ColumnChart(
        data_source_tmax,
        options={
            'title': 'Max. Temperature (England,Scotland,UK,Wales - 1911-2017)'
        })
    chart_tmean = ColumnChart(
        data_source_tmean,
        options={
            'title': 'Mean Temperature (England,Scotland,UK,Wales - 1911-2017)'
        })
    chart_rainfall = ColumnChart(
        data_source_rainfall,
        options={'title': 'Rainfall (England,Scotland,UK,Wales - 1911-2017)'})
    chart_sunshine = ColumnChart(
        data_source_sunshine,
        options={'title': 'Sunshine (England,Scotland,UK,Wales - 1911-2017)'})

    context = {
        'chart_tmin': chart_tmin,
        'chart_tmax': chart_tmax,
        'chart_tmean': chart_tmean,
        'chart_rainfall': chart_rainfall,
        'chart_sunshine': chart_sunshine
    }

    template = loader.get_template('metoffice/graphs_climate.html')

    return HttpResponse(template.render(context, request))
Exemplo n.º 2
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
        })
Exemplo n.º 3
0
def role_report(request):
    print("ROLE")
    queryset = Employee.objects.all().values('role__name').annotate(
        total=Count('role')).order_by('total')
    data_source = ModelDataSource(queryset, fields=['role__name', 'total'])
    chart = gchart.PieChart(data_source)
    return render_to_response('account/graph.html', {"chart": chart})
Exemplo n.º 4
0
 def Humidity_Gauge(self):
     queryset = Humidity.objects.filter(
         reading_time__date=now).order_by('-id')[:1]
     data_source = ModelDataSource(queryset, fields=['Humidity_Percent'])
     humidity_gauge = gchart.GaugeChart(data_source,
                                        options={
                                            "greenFrom":
                                            90,
                                            "greenTo":
                                            100,
                                            "yellowFrom":
                                            75,
                                            "yellowTo":
                                            90,
                                            "redFrom":
                                            65,
                                            "redTo":
                                            75,
                                            "max":
                                            100,
                                            "majorTicks":
                                            [0, 20, 40, 60, 80, 100],
                                            "minorTicks":
                                            10
                                        })
     return humidity_gauge
Exemplo n.º 5
0
def monthly(request):

    queryset = Temperature.objects.filter(reading_time__month=month)
    data_source = ModelDataSource(queryset, fields=['reading_time', 'Temp_F'])
    temp_monthly_line_chart = gchart.LineChart(data_source, options={'title': "Monthly Redings"})

    return render(request, 'tempsensor/monthly.html', {'temp_monthly_line_chart': temp_monthly_line_chart})
Exemplo n.º 6
0
    def get_context_data(self, **kwargs):
        super_context = super(Demo, self).get_context_data(**kwargs)
        create_demo_accounts()
        queryset = Account.objects.all()
        data_source = ModelDataSource(queryset,
                                      fields=['year', 'sales'])
        simple_data_source = SimpleDataSource(data=data)
        line_chart = self.renderer.LineChart(data_source,
                                      options={'title': "Sales Growth"})
        column_chart = self.renderer.ColumnChart(SimpleDataSource(data=data),
                                          options={'title': "Sales/ Expense"})
        bar_chart = self.renderer.BarChart(data_source,
                                    options={'title': "Expense Growth"})
        pie_chart = self.renderer.PieChart(data_source)

        context = {
                "data_source": data_source,
                "simple_data_source": simple_data_source,
                "line_chart": line_chart,
                "column_chart": column_chart,
                'bar_chart': bar_chart,
                'pie_chart': pie_chart,
                }
        context.update(super_context)
        return context
Exemplo n.º 7
0
 def get_context_data(self, **kwargs):
     context = super(GChartDemo, self).get_context_data(**kwargs)
     data_source = context['data_source']
     candlestick_chart = self.renderer.CandlestickChart(
         SimpleDataSource(data=candlestick_data))
     treemap_chart = self.renderer.TreeMapChart(
         SimpleDataSource(data=treemap_data))
     area_chart = self.renderer.AreaChart(data_source)
     queryset = Account.objects.all()
     data_source = ModelDataSource(queryset, fields=['year', 'sales'])
     gauge_chart = self.renderer.GaugeChart(data_source,
                                            options={
                                                'redFrom': 0,
                                                'redTo': 800,
                                                'yellowFrom': 800,
                                                'yellowTo': 1500,
                                                'greenFrom': 1500,
                                                'greenTo': 3000,
                                                'max': 3000,
                                            })
     context.update({
         'candlestick_chart': candlestick_chart,
         'treemap_chart': treemap_chart,
         'gauge_chart': gauge_chart,
         'area_chart': area_chart
     })
     return context
Exemplo n.º 8
0
def monthly(request):

    queryset = Humidity.objects.filter(reading_time__month=month)
    data_source = ModelDataSource(queryset, fields=['reading_time', 'Humidity_Percent'])
    humidity_monthly_line_chart = gchart.LineChart(data_source, options={'title': "Monthly Readings"})

    return render(request, 'humidity/monthly.html', {'humidity_monthly_line_chart': humidity_monthly_line_chart})
Exemplo n.º 9
0
 def get_context_data(self, **kwargs):
     context = super(GChartDemoView, self).get_context_data(**kwargs)
     queryset = RestaurantLocation.objects.all()
     data_source = ModelDataSource(queryset, fields=['updated', 'vanzari'])
     #data_source = SimpleDataSource(data=data)chart = gchart.LineChart(data_source)
     context.update({'line_chart': chart})
     print context
     return context
Exemplo n.º 10
0
def line_chart_maker_model(queryset, fields):
    # call specific > stats
    # get data source need to use models
    # DataSource object creation
    data_source = ModelDataSource(queryset, fields=[fields])
    # Chart object
    linechart = LineChart(data_source)
    return {'line_chart': linechart}
 def get_context_data(self):
     create_demo_accounts()
     Account.objects.create(week="10", count=2130, area=1940, farmer="Cook")
     queryset = Account.objects.all()
     data_source = ModelDataSource(queryset, fields=['week', 'count'])
     line_chart = gchart.LineChart(data_source)
     context = {"chart": line_chart}
     return context
Exemplo n.º 12
0
def graphoo(request):

    queryset = Price.objects.all()
    data_source = ModelDataSource(queryset, fields=['entry', 'xbt'])
    # Chart object
    chart = LineChart(data_source)
    context = {'chart': chart}
    return render(request, 'graph/price_list.html', context)
Exemplo n.º 13
0
def morris_demo(request):

    create_demo_accounts()
    queryset = Account.objects.all()
    data_source = ModelDataSource(queryset, fields=['year', 'sales'])
    line_chart = morris.LineChart(SimpleDataSource(data=data))
    data_source = ModelDataSource(queryset, fields=['year', 'sales'])
    line_chart = morris.LineChart(data_source,
                                  options={'title': "Sales Growth"})
    bar_chart = morris.BarChart(SimpleDataSource(data=data),
                                options={'title': "Sales vs Expense"})
    donut_chart = morris.DonutChart(data_source)
    context = {
        "line_chart": line_chart,
        'bar_chart': bar_chart,
        'donut_chart': donut_chart
    }
    return render(request, 'demo/morris.html', context)
Exemplo n.º 14
0
 def get_context_data(self):
     create_demo_accounts()
     Account.objects.create(year="2010", sales=2130,
                            expenses=1940, ceo="Cook")
     queryset = Account.objects.all()
     data_source = ModelDataSource(queryset,
                                   fields=['year', 'sales'])
     line_chart = gchart.LineChart(data_source)
     context = {"chart": line_chart}
     return context
Exemplo n.º 15
0
def weatherchart(request):
    queryset = Weatherdata.objects.filter(month_or_season="JAN",
                                          weather_country="UK ",
                                          weather_type=" Rainfall")
    data_source = ModelDataSource(queryset,
                                  fields=['weather_year', 'weather_reading'])
    chart = BarChart(data_source)
    return render(request,
                  template_name='kisanhub/weatherchart.html',
                  context={'chart': chart})
Exemplo n.º 16
0
 def get_context_data(self, **kwargs):
     super_context = super(MorrisDemo, self).get_context_data(**kwargs)
     queryset = Choice.objects.all() 
     data_source = ModelDataSource(queryset,
                                   fields=['choice_text', 'votes'])
     line_chart = self.renderer.LineChart(data_source,
                                   options={'choice_text': "votes"})
     bar_chart = self.renderer.BarChart(data_source,
                                 options={'choice_text': "votes"})
     context = {"line_chart": line_chart,
                'bar_chart': bar_chart}
     context.update(super_context)
     return context
Exemplo n.º 17
0
def entry(request, entry_id):
    """Show an entry"""
    entry = get_object_or_404(Entry, id=entry_id)
    # Make sure the entry belongs to the current user.
    if entry.owner != request.user:
        raise Http404

    prices = entry.price_set.order_by('date')
    data_source = ModelDataSource(prices, fields=['date', 'price'])
    chart = LineChart(data_source)

    context = {'entry': entry, 'prices': prices, 'chart': chart}
    return render(request, "pt/entry.html", context)
Exemplo n.º 18
0
 def temp_daily_line(self):
     queryset = Temperature.objects.filter(reading_time__date=now)
     data_source = ModelDataSource(queryset,
                                   fields=['reading_time', 'Temp_F'])
     temp_daily_line_chart = gchart.LineChart(data_source,
                                              options={
                                                  'title': "Daily Readings",
                                                  'vAxis': {
                                                      'minValue': 60,
                                                      'maxValue': 80
                                                  }
                                              })
     return temp_daily_line_chart
Exemplo n.º 19
0
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)
Exemplo n.º 20
0
def summary(request):
    allsurveys = Survey.objects.all()
    graphs = []
    for survey in allsurveys:
        allquestions = Question.objects.all().filter(survey_id=survey.id)
        for question in allquestions:
            choices = Choice.objects.filter(question = question.id)
            data_source = ModelDataSource(choices, fields=['choice_text', 'votes'])
            chart = gchart.PieChart(data_source,
                    options={'is3D': True,
                    'pieSliceText': 'value',
                    'title': question.question_text})
            graphs.append((chart, survey.survey_name))
    return render(request, 'app/summary.html', {'graphs': graphs})
Exemplo n.º 21
0
 def humidity_monthly_line(self):
     queryset = Humidity.objects.filter(reading_time__month=month)
     data_source = ModelDataSource(
         queryset, fields=['reading_time', 'Humidity_Percent'])
     humidity_monthly_line_chart = gchart.LineChart(data_source,
                                                    options={
                                                        "title":
                                                        "Monthly Reading",
                                                        'vAxis': {
                                                            'minValue': 70,
                                                            'maxValue': 100
                                                        }
                                                    })
     return humidity_monthly_line_chart
Exemplo n.º 22
0
def monthly_chart(user, month_num):
    sql = 'SELECT 1 id,YEAR(added_at) year,MONTH(added_at) month,SUM(total) total FROM `bazar_entry` e JOIN bazar_product p on(e.id=p.entry_id) where user_id=%s GROUP by YEAR(added_at),MONTH(added_at) order by year desc,month desc limit %s' % (
        user.id, month_num)
    print(sql)
    queryset = Entry.objects.raw(sql)
    data_source = ModelDataSource(
        queryset,
        fields=[
            'month',
            'total',
        ],
    )
    chart = BarChart(data_source)
    print(queryset.columns)
    return {'chart': chart, 'month_num': month_num}
Exemplo n.º 23
0
def index(request):


    queryset = Humidity.objects.all().order_by('-id')[:1]
    data_source = ModelDataSource(queryset, fields=['Humidity_Percent'])
    humidity_chart = gchart.GaugeChart(data_source,
            options = {
               "greenFrom": 90, "greenTo": 100,
                "yellowFrom": 75, "yellowTo": 90,
                "redFrom": 65, "redTo": 75,
                "max": 100, "majorTicks": [0,20,40,60,80,100], "minorTicks": 10,
            }
    )

    return render(request, 'humidity/index.html', {'humidity_chart': humidity_chart})
Exemplo n.º 24
0
 def get_context_data(self):
     create_demo_accounts()
     queryset = Account.objects.all()
     data_source = ModelDataSource(queryset,
                                   fields=['year', 'sales'])
     simple_data_source = SimpleDataSource(data=data)
     line_chart = self.renderer.LineChart(data_source,
                                   options={'title': "Sales Growth"})
     bar_chart = self.renderer.BarChart(data_source,
                                 options={'title': "Expense Growth"})
     donut_chart = self.renderer.DonutChart(data_source)
     context = {"line_chart": line_chart,
            'bar_chart': bar_chart,
            'donut_chart': donut_chart}
     return context
Exemplo n.º 25
0
def index(request):


    queryset = Temperature.objects.all().order_by('-id')[:1]
    data_source = ModelDataSource(queryset, fields=['Temp_F'])
    temp_chart = gchart.GaugeChart(data_source,
            options = {
                "greenFrom": 73, "greenTo": 76,
                "yellowFrom": 76, "yellowTo": 82,
                "redFrom": 82, "redTo": 100,
                "max": 100, "majorTicks": [0,20,40,60,80,100], "minorTicks": 10,
            }
    )

    return render(request, 'tempsensor/index.html', {'temp_chart': temp_chart})
Exemplo n.º 26
0
 def get_context_data(self, **kwargs):
     super_context = super(MorrisDemo, self).get_context_data(**kwargs)
     create_demo_accounts()
     queryset = Account.objects.all()
     data_source = ModelDataSource(queryset,
                                   fields=['year', 'sales'])
     line_chart = self.renderer.LineChart(data_source,
                                   options={'title': "Sales Growth"})
     bar_chart = self.renderer.BarChart(data_source,
                                 options={'title': "Expense Growth"})
     donut_chart = self.renderer.DonutChart(data_source)
     context = {"line_chart": line_chart,
            'bar_chart': bar_chart,
            'donut_chart': donut_chart}
     context.update(super_context)
     return context
Exemplo n.º 27
0
def yui_demo(request):
    create_demo_accounts()
    queryset = Account.objects.all()
    line_chart = yui.LineChart(SimpleDataSource(data=data))
    data_source = ModelDataSource(queryset, fields=['year', 'sales'])
    line_chart = yui.LineChart(data_source, options={'title': "Sales Growth"})
    column_chart = yui.ColumnChart(SimpleDataSource(data=data),
                                   options={'title': "Sales vs Expense"})
    bar_chart = yui.BarChart(data_source, options={'title': "Expense Growth"})
    pie_chart = yui.PieChart(data_source)
    context = {
        "line_chart": line_chart,
        "column_chart": column_chart,
        'bar_chart': bar_chart,
        'pie_chart': pie_chart
    }
    return render(request, 'demo/yui.html', context)
Exemplo n.º 28
0
def draw(request):

    queryset = Location.objects.filter(user__pk=request.user.id)
    data_source = ModelDataSource(queryset, fields=['place', 'population'])

    if request.method == 'GET' and not 'charts' in request.GET:
        chart = BarChart(data_source)
    elif request.GET['charts'] == "BarChart":
        chart = BarChart(data_source)
    elif request.GET['charts'] == "LineChart":
        chart = LineChart(data_source)
    elif request.GET['charts'] == "PieChart":
        chart = PieChart(data_source)
    elif request.GET['charts'] == "ColumnChart":
        chart = ColumnChart(data_source)

    context = {'chart': chart}
    return render(request, 'my_charts/draw.html', context)
Exemplo n.º 29
0
 def temp_monthly_line(self):
     queryset = Temperature.objects.filter(reading_time__month=month)
     data_source = ModelDataSource(queryset,
                                   fields=['reading_time', 'Temp_F'])
     temp_monthly_line_chart = gchart.LineChart(data_source,
                                                options={
                                                    "title":
                                                    "Monthly Reading",
                                                    'vAxis': {
                                                        'minValue':
                                                        60,
                                                        'maxValue':
                                                        80,
                                                        'viewWindowMode':
                                                        'maximized'
                                                    }
                                                })
     return temp_monthly_line_chart
Exemplo n.º 30
0
 def Temperature_Gauge(self):
     queryset = Temperature.objects.filter(
         reading_time__date=now).order_by('-id')[:1]
     data_source = ModelDataSource(queryset, fields=['Temp_F'])
     temp_gauge = gchart.GaugeChart(data_source,
                                    options={
                                        "greenFrom": 73,
                                        "greenTo": 76,
                                        "yellowFrom": 76,
                                        "yellowTo": 84,
                                        "redFrom": 84,
                                        "redTo": 100,
                                        "max": 100,
                                        "majorTicks":
                                        [0, 20, 40, 60, 80, 100],
                                        "minorTicks": 10,
                                    })
     return temp_gauge