Пример #1
0
def _create_statdata(chart_type, stats, terms=None, term_names=None):
    if chart_type == 'bar':
        statdata = DataPool(series=[{
            'options': {
                'source': stats.filter(feature=term)
            },
            'legend_by':
            'feature',
            'terms': [{
                'time_%s' % term: 'time'
            }, {
                term_names[term]: 'value',
                'name': 'feature'
            }]
        } for term in terms])
    elif chart_type == 'pie':
        statdata = DataPool(series=[{
            'options': {
                'source': stats
            },
            'legend_by': 'feature',
            'terms': ['feature', 'value'],
        }])
    else:
        statdata = None

    return statdata
Пример #2
0
Файл: views.py Проект: Whirt/ld
def get_pool(auctions):

    len_sold_auction = len(auctions)
    if len_sold_auction == 0:
        return

    ds = DataPool(series=[{
        'options': {
            'source': auctions
        },
        'terms': ['expire_date', 'current_price']
    }])
    chrt = Chart(datasource=ds,
                 series_options=[{
                     'options': {
                         'type': 'line',
                         'stacking': False
                     },
                     'terms': {
                         'expire_date': ['current_price']
                     }
                 }],
                 chart_options={
                     'title': {
                         'text': ''
                     },
                     'xAxis': {
                         'title': {
                             'text': 'Data'
                         }
                     }
                 })

    return chrt
Пример #3
0
def graphPrediction(request, company_id):
    # Step 1: Create a DataPool with the data we want to retrieve.
    Stockdata = \
        DataPool(
            series=
            [{'options': {
                'source': PredictionList.objects.filter(predictionFK=company_id)},
                'terms': [
                    'dateStock',
                    'estimate']}
            ])
    cht = Chart(datasource=Stockdata,
                series_options=[{
                    'options': {
                        'type': 'line',
                        'stacking': False
                    },
                    'terms': {
                        'dateStock': ['estimate']
                    }
                }],
                chart_options={
                    'title': {
                        'text': 'Predicted Values'
                    },
                    'xAxis': {
                        'title': {
                            'text': 'Month number'
                        }
                    }
                })
    return render_to_response('roboadvisor/graph.html', {'weatherchart': cht})
Пример #4
0
def sales(request):
    salle = 'Nordique'
    Newsalle = request.POST.get('Room')
    if Newsalle != None:
        salle = Newsalle
    drink = 'Champagne'
    Newdrink = request.POST.get('Drinks')
    if Newdrink != None:
        drink = Newdrink

    sales= \
            DataPool(
            series=[{'options':{'source': VenteSum.objects.filter(drink = dk.objects.filter(name = drink)[0].id, room = rooms.objects.filter(name = salle)[0].id)},
                    'terms':['date','quantitySum']}])
    salle_drink = drink + '  ' + salle
    cht = Chart(datasource=sales,
                series_options=[{
                    'options': {
                        'type': 'line'
                    },
                    'terms': {
                        'date': ['quantitySum']
                    }
                }],
                chart_options={
                    'title': {
                        'text': salle_drink
                    },
                    'xAxis': {
                        'title': {
                            'text': drink
                        }
                    }
                })
    return render(request, 'main/sales.html', {'chart_list': [cht]})
Пример #5
0
def chart(request):
    ridershipdata = \
        DataPool(
            series=
            [{'options': {
                'source': PeopleCount.objects.all()}, # PeopleCount.objects.all()},
              'terms': [
                  'Count',
                  'StopID',
                  'LocID']}
            ])
    riderchart = Chart(datasource=ridershipdata,
                       series_options=[{
                           'options': {
                               'type': 'pie',
                               'stacking': False
                           },
                           'terms': {
                               'StopID': ['Count']
                           }
                       }],
                       chart_options={
                           'title': {
                               'text': 'Ridership Data'
                           },
                           'xAxis': {
                               'title': {
                                   'text': 'Rider Count'
                               }
                           }
                       },
                       x_sortf_mapf_mts=(None, stopNames, False))

    return render_to_response('chart.html', {'ridershipChart': riderchart})
Пример #6
0
def weather_chart_view(request):
    #Step 1: Create a DataPool with the data we want to retrieve.
    weatherdata = \
        DataPool(
           series=
            [{'options': {
               'source': Product.objects.all()},
              'terms': [
                'MonthofEntry',
                'OEM': ['123456'],
                'TotalPrice']}
             ])

    #Step 2: Create the Chart object
    cht = Chart(
            datasource = weatherdata,
            series_options =
              [{'options':{
                  'type': 'line',
                  'stacking': False},
                'terms':{
                  'MonthofEntry': [
                    'OEM': ['123456'],
                    'TotalPrice']
                  }}],
            chart_options =
              {'title': {
                   'text': 'Weather Data of Boston and Houston'},
               'xAxis': {
                    'title': {
                       'text': 'Month number'}}})

    #Step 3: Send the chart object to the template.
    return render_to_response({'weatherchart': cht})
Пример #7
0
def simple(request):
    #Step 1: Create a DataPool with the data we want to retrieve.
    weatherdata = \
        DataPool(
           series=
            [{'options': {
               'source': Survey.objects.all()},
              'terms': [
                'date',
                'total_percent_wasted',
                ]}
             ])

    #Step 2: Create the Chart object
    cht = Chart(
            datasource = weatherdata,
            series_options =
              [{'options':{
                  'type': 'line',
                  'stacking': False},
                'terms':{
                  'date': [
                    'total_percent_wasted',
                    ]
                  }}],
            chart_options =
              {'title': {
                   'text': 'TotalPercentWasted'},
               'xAxis': {
                    'title': {
                       'text': 'Date '}}})

    #Step 3: Send the chart object to the template.
    return render(request, '../templates/survey_chart.html',{'weatherchart': cht})
Пример #8
0
def get_all_puzzle_user_day():
    data = DataPool(series=[{
        'options': {
            'source': AllPuzzleUserByDay.objects.filter().order_by('day')
        },
        'terms': ['daystr', 'answer_num', 'phone_num']
    }])
    cht = Chart(datasource=data,
                series_options=[{
                    'options': {
                        'type': 'line',
                        'stacking': False
                    },
                    'terms': {
                        'daystr': ['answer_num', 'phone_num']
                    }
                }],
                chart_options={
                    'title': {
                        'text': u'使用过趣味答题的用户'
                    },
                    'xAxis': {
                        'title': {
                            'text': u'日期'
                        }
                    },
                    'colors': ['#2f7ed8', '#AA4643']
                })
    return cht
Пример #9
0
def inandout(request):
    member = Member.objects.get(user_id=request.user.id)
    family_id = member.fam_id
    all_family_members = Member.objects.filter(fam_id=family_id)
    Earnings = Earning.objects.filter(Member_id__in=all_family_members)
    Spendings = Spending.objects.filter(Member_id__in=all_family_members)
    debt = DataPool(  # what data is being retrieved and where it is being retrieved from
        series=[{
            'options': {
                'source': Earnings
            },
            'terms': [{
                'wage': 'wage',
                'year': 'year'
            }]
        }, {
            'options': {
                'source': Spendings
            },
            'terms': [{
                'neg_amount': 'neg_amount',
                'year2': 'year'
            }]
        }])

    cht = Chart(
        datasource=debt,
        series_options=[{
            'options': {
                'type': 'column',
                'stacking': False
            },
            'terms': {
                'year': ['wage'],
                'year2': ['neg_amount']
            }
        }],
        chart_options={
            'title': {
                'text': 'Income vs Spending over the Last 10 Years'
            },
            'xAxis': {
                'title': {
                    'text': 'Income and Spending'
                }
            },
            'yAxis': {
                'title': {
                    'text': 'Amount'
                }
            },
            'legend': {
                'enabled': True
            },
            'credits': {
                'enabled': True
            }
        },
    )
    return render(request, 'inandout.html', {'chart_list': [cht]})
Пример #10
0
def errorsdetPie(request):
    ds = DataPool(
        series=[
            {
                'options': {
                    'source': datewisedetailknownerrcounts.objects.values('err_name').annotate(
                        sumerrcnts=Sum('err_counts'))},
                'terms': [
                    'err_name', 'sumerrcnts'
                ]
            }
        ]
    )

    cht = Chart(
        datasource=ds,
        series_options=[
            {
                'options': {
                    'type': 'pie', 'stacking': False,
                    'options3d': {'enabled': True, 'alpha': 45, 'beta': 0}
                }, 'terms': {'err_name': ['sumerrcnts']}
            }
        ],
        chart_options={
            'title': {'text': 'DetailErrors Report - Pie Chart'}
        }
    )
    return render(request, 'ErrDetailDatapiechart.html',{
                              'chart_list': cht,
                              'code': "newcode",
                              'title': "Detailed Error Pie Chart",
                              'doc': "This Chart Pie Chart for Detailed Errror Messages sum by Error Counts",
                              'sidebar_items': "SIdeBarItem"})
Пример #11
0
def multi_table_same_x(request, title, code, doc, sidebar_items):
    """
    Data from multiple models on same chart
    ----------------------------------------
    
    This example demonstrates data from two different models 
    ``MonthlyWeatherByCity`` and ``MonthlyWeatherSeattle`` on the same chart
    and on the same x-axis.
    
    Points to note:
    
    - The `month` in ``terms`` for seattle data is written as 
      ``{'month_seattle': 'month'}`` instead of as just ``'month'`` because 
      in the latter case it would overwrite the ``'month'`` term from the 
      other model.
    - Notice that the Seattle weather data in the database does not have any
      data for August (8) and September (9). Chartit gracefully skips them 
      and plots the rest of the data points aligned correctly.
    """
    #start_code
    ds = DataPool(
           series=
            [{'options': {
                'source': MonthlyWeatherByCity.objects.all()},
              'terms': [
                'month',
                'houston_temp', 
                'boston_temp']},
             {'options': {
                'source': MonthlyWeatherSeattle.objects.all()},
              'terms': [
                {'month_seattle': 'month'},
                'seattle_temp']}
             ])

    cht = Chart(
            datasource = ds, 
            series_options = 
              [{'options':{
                  'type': 'line',
                  'stacking': False},
                'terms':{
                  'month': [
                    'boston_temp',
                    'houston_temp'],
                  'month_seattle': [
                    'seattle_temp']
                  }}],
            chart_options = 
              {'title': {
                   'text': 'Weather by Month (from 2 different tables)'},
               'xAxis': {
                    'title': {
                       'text': 'Month number'}}})
    #end_code
    return render_to_response('chart_code.html', {'chart_list': cht,
                                             'code': code,
                                             'title': title,
                                             'doc': doc,
                                             'sidebar_items': sidebar_items})
Пример #12
0
    def test_load_charts_with_single_chart(self):
        chart_data = DataPool(series=[{
            'options': {
                'source': SalesHistory.objects.all()
            },
            'terms': ['price', 'sale_date']
        }])

        chart = Chart(datasource=chart_data,
                      series_options=[{
                          'options': {
                              'type': 'column',
                              'stacking': False
                          },
                          'terms': {
                              'sale_date': ['price']
                          }
                      }])

        html = chartit.load_charts(chart, 'my_chart')

        self.assertIn('<script type="text/javascript">', html)
        self.assertIn('"stacking": false', html)
        self.assertIn('"data": []', html)
        self.assertIn('"type": "column"', html)
        self.assertIn('"name": "price"', html)
        self.assertIn('{"renderTo": "my_chart"}', html)
        self.assertIn('"title": {"text": "Price vs. Sale Date"}', html)
        self.assertIn(
            '<script src="/static/chartit/js/chartloader.js" type="text/javascript">',
            html)
Пример #13
0
    def checkbox_bar_chart(request, question):
        """
		@return Barchart for checkbox results
		"""
        ds = DataPool(series=[{
            'options': {
                'source': CheckboxResults.objects.filter(
                    question__exact=question)
            },
            'terms': ['answer', 'answer_count']
        }])

        chart = Chart(datasource=ds,
                      series_options=[{
                          'options': {
                              'type': 'column',
                              'stacking': True
                          },
                          'terms': {
                              'answer': ['answer_count']
                          }
                      }],
                      chart_options={
                          'title': {
                              'text': question.text
                          },
                          'xAxis': {
                              'title': {
                                  'text': 'Answers'
                              }
                          }
                      })

        return chart
Пример #14
0
    def select_pie_chart(request, question):
        """
		@return Piechart object for select results
		"""

        ds = DataPool(series=[{
            'options': {
                'source': SelectResults.objects.filter(
                    question__exact=question)
            },
            'terms': ['answer', 'answer_count']
        }])

        chart = Chart(datasource=ds,
                      series_options=[{
                          'options': {
                              'type': 'pie',
                              'stacking': False
                          },
                          'terms': {
                              'answer': ['answer_count']
                          }
                      }],
                      chart_options={'title': {
                          'text': question.text
                      }})
        return chart
Пример #15
0
def get_scatter_chart(pts, x_axis, symbol):
    data = \
        DataPool(
           series=
            [{'options': {
               'source': pts},
              'terms': [
                x_axis,
                'percent_correct']}
             ])

    #Step 2: Create the Chart object
    cht = Chart(datasource=data,
                series_options=[{
                    'options': {
                        'type': 'scatter'
                    },
                    'terms': {
                        x_axis: ['percent_correct']
                    }
                }],
                chart_options={
                    'title': {
                        'text':
                        '{} percent correct by {}'.format(symbol, x_axis)
                    },
                    'xAxis': {
                        'title': {
                            'text': x_axis
                        }
                    }
                })
    return cht
Пример #16
0
def citySales(request):
    ds = DataPool(series=[{
        'options': {
            'source':
            SalesHistory.objects.only('bookstore__city', 'sale_qty')[:10],
        },
        'terms': ['bookstore__city__region', 'sale_qty']
    }])
    cht = Chart(datasource=ds,
                series_options=[
                    {
                        'options': {
                            'type': 'bar',
                            'stacking': True,
                            'stack': 0,
                        },
                        'terms': {
                            'bookstore__city__region': ['sale_qty']
                        }
                    },
                ],
                chart_options={
                    'title': {
                        'text': 'Sales reports'
                    },
                    'xAxis': {
                        'title': {
                            'text': 'City'
                        },
                        'legend': {
                            "reversed": True,
                        }
                    }
                })
    return render_to_response('citySales.html', {'citySales': cht})
Пример #17
0
def get_puzzle_user_puzzle():
    data = DataPool(series=[{
        'options': {
            'source': PuzzleUserByPuzzle.objects.filter().order_by('puzzle')
        },
        'terms': ['puzzle', 'new_user', 'old_user']
    }])
    cht = Chart(datasource=data,
                series_options=[{
                    'options': {
                        'type': 'column',
                        'stacking': True
                    },
                    'terms': {
                        'puzzle': ['new_user', 'old_user']
                    }
                }],
                chart_options={
                    'title': {
                        'text': u'答题人数 by 题目'
                    },
                    'xAxis': {
                        'title': {
                            'text': u'题目'
                        }
                    },
                    'colors': ['#2f7ed8', '#AA4643']
                })
    return cht
Пример #18
0
    def setUp(self):
        ds = DataPool(series=[{
            'options': {
                'source':
                SalesHistory.objects.filter(
                    bookstore=BookStore.objects.first())[:10]
            },
            'terms': ['sale_date', 'sale_qty']
        }])

        self.chart = Chart(datasource=ds,
                           series_options=[{
                               'options': {
                                   'type': 'line',
                                   'stacking': False
                               },
                               'terms': {
                                   'sale_date': ['sale_qty']
                               }
                           }],
                           chart_options={
                               'title': {
                                   'text': 'Sales QTY per day'
                               },
                               'xAxis': {
                                   'title': {
                                       'text': 'Sale date'
                                   }
                               }
                           })
Пример #19
0
def get_delta_puzzle_user_day():
    data = DataPool(series=[{
        'options': {
            'source': DeltaPuzzleUserByDay.objects.filter().order_by('day')
        },
        'terms': ['daystr', 'new_user', 'old_user']
    }])
    cht = Chart(datasource=data,
                series_options=[{
                    'options': {
                        'type': 'column',
                        'stacking': True
                    },
                    'terms': {
                        'daystr': ['new_user', 'old_user']
                    }
                }],
                chart_options={
                    'title': {
                        'text': u'答题人数 by 日期'
                    },
                    'xAxis': {
                        'title': {
                            'text': u'日期'
                        }
                    },
                    'colors': ['#2f7ed8', '#AA4643']
                })
    return cht
Пример #20
0
def ping_status_view(request):
	ds = DataPool(
		series = 
			[{'options':{

				'source': PingStatusValue.objects.filter(ip=IP.objects.get(ip='8.8.8.8'))},
			 'terms': [
				('check_time', lambda d: check_time.mktime(d.timetuple())),'ping_value']
			}]
			
		)
	cht = Chart(
		datasource = ds,
		series_options = 
			[{'options':{
				'type': 'line',
				'stacking': False},
			 'terms':{
				'check_time':[
					'ping_value']}	

			}],
		chart_options = 
			{'title':{
				'text':'ping_value status'},
			'xAxis': {

				'title':{
					'text':'check date'}}}
		)
	return render_to_response('highchart2.html',{'pingChart':cht})
Пример #21
0
 def data_chart_cicle(self):
     ds = DataPool(
         series=[{
             'options': {
                 'source': DataSession.objects.values('summary_status',).annotate(count=Count('summary_status')),
             },
             'terms': [
                 'summary_status',
                 'count',
             ]
         }]
     )
     cht = Chart(
         datasource=ds,
         series_options=[{
             'options': {
                 'type': 'pie',
                 'stacking': False
             },
             'terms': {
                 'summary_status': ['count']
             }
         }],
         chart_options={
             'title': {
                 'text': 'Summary status all days'
             }
         },
     )
     return cht
Пример #22
0
def sample(request):
    weatherdata = \
    customerMarital_List = []

    with open(
            "/Users/Rick/Desktop/projectFinalFolder/segments/customerMaritalStatusMoreOverTime.yaml"
    ) as w:
        customerMaritalStatusMoreOverTime = yaml.load(w)
    w.close()

    for row in customerMaritalStatusMoreOverTime.items():
        for value in row:
            customerMarital_List.append(value)

    DataPool(series=[{
        'options': {
            'source': customerMarital_List
        },
        'terms': ['Marital status', 'Household', 'Income']
    }])
    cht = Chart(datasource=weatherdata,
                chart_options={'title': {
                    'text': 'Customer Marital Status'
                }})
    return render_to_response('none.html', {'weatherchart': cht})
Пример #23
0
def weatherByCity(request):
    ds = DataPool(series=[{
        'options': {
            'source': Desktop.objects.all()
        },
        'terms': ['Model_USBheadset', 'Secreen1_Model', 'houston_temp']
    }])

    cht = Chart(datasource=ds,
                series_options=[{
                    'options': {
                        'type': 'line'
                    },
                    'terms': {
                        'month': ['boston_temp']
                    }
                }, {
                    'options': {
                        'type': 'pie',
                        'center': [150, 100],
                        'size': '50%'
                    },
                    'terms': {
                        'month': ['houston_temp']
                    }
                }],
                chart_options={
                    'title': {
                        'text':
                        'Weather Data of Boston (line) and Houston (pie)'
                    }
                },
                x_sortf_mapf_mts=[(None, False), (None, False)])

    return render_to_response('weatherByCity.html', {'weatherByCity': cht})
Пример #24
0
def chart(request):
    hdata =  Humidity.objects.filter(log_date__second__lt=1)
    humiditydata = \
                   DataPool(
                       series =
                       [{'options' : {
                           'source': hdata},
                         'terms': [
                             'humidity',
                             'temp',
                             'log_date']}
                        ])
    cht = Chart(
        datasource = humiditydata,
        series_options =
        [{'options':{
            'type' : 'line',
            'stacking' : False},
          'terms':{
              'log_date':[
                  'humidity',
                  'temp']
              }}],
        chart_options =
        {'title':{
            'text':"Humidity and Temp data for my apartment"},
         'xAxis':{
             'title' :{
                 'text': "Time"}}})
    #return render(request, 'humidity_display/chart.html', cht)

    return render_to_response('humidity_display/chart.html',{'humiditychart':cht})

                  
Пример #25
0
def graficos(request, param):
    if len(Marca.objects.filter(nome=param)) != 0:
        veiculos = VeiculoConsulta.objects.filter(marca=Marca.objects.get(nome=param)).exclude(preco_min__isnull=True)
    if len(Veiculo.objects.filter(categoria=param)) != 0:
        veiculos = VeiculoConsulta.objects.filter(categoria=param).exclude(preco_min__isnull=True)
    if len(VeiculoConsulta.objects.filter(modelo=param)) != 0:
        veiculos = VeiculoConsulta.objects.filter(modelo=param).exclude(preco_min__isnull=True)
    ds = DataPool(
       series=
        [{'options': {
            'source': veiculos},
          'terms': [
            'ano_modelo',
            'preco_min',
            'preco_max']}
         ])
    cht = Chart(
        datasource = ds, 
        series_options = 
          [{'options':{
              'type': 'line',
              'stacking': False},
            'terms':{
              'ano_modelo': [
                'preco_min',
                'preco_max']
              }}],
        chart_options = 
          {'title': {
               'text': param},
           'xAxis': {
                'title': {
                   'text': 'Ano/Modelo'}}})
    return render_to_response('shopcar/veiculos/graficos.html', {'cht': cht})
Пример #26
0
def graph(request):
    graph = \
       DataPool(
           series=
           [{'options':{
               'source':GraphData.objects.all()},
               'terms':[
                 'block_name',
                   'yf',
                   'awc',
               'cc',]}
           ])
    #create the chart object
    cht = Chart(datasource=graph,
                series_options=[{
                    'options': {
                        'type': 'column',
                        'stacking': False
                    },
                    'terms': {
                        'block_name': ['block_name', 'yf', 'awc', 'cc']
                    }
                }],
                chart_options={
                    'title': {
                        'text': 'Total complete work'
                    },
                    'xAxis': {
                        'title': {
                            'text': 'work done'
                        }
                    }
                })
    return render(request, 'Report.html', {'cht': cht})
Пример #27
0
def generalGraph(request, userId):
    # Step 1: Create a DataPool with the data we want to retrieve.
    Stockdata = \
        DataPool(
            series=
            [{'options': {
                'source': UserProjection.objects.filter(userid=userId)
            },
                'terms': [
                    'date',
                    'investment']}
            ])
    cht = Chart(datasource=Stockdata,
                series_options=[{
                    'options': {
                        'type': 'area',
                        'stacking': False
                    },
                    'terms': {
                        'date': ['investment']
                    }
                }],
                chart_options={
                    'title': {
                        'text': 'Estimate return  '
                    },
                    'xAxis': {
                        'title': {
                            'text': 'Day'
                        }
                    }
                })
    return cht
Пример #28
0
def weather_chart_view(request):
    #Step 1: Create a DataPool with the data we want to retrieve.
    weatherdata = \
        DataPool(
           series=
            [{'options': {
               'source': MonthlyWeatherByCity.objects.all()},
              'terms': [
                'month',
                'houston_temp',
                'boston_temp']}
             ])

    #Step 2: Create the Chart object
    cht = Chart(
            datasource = weatherdata,
            series_options =
              [{'options':{
                  'type': 'line',
                  'stacking': False},
                'terms':{
                  'month': [
                    'boston_temp',
                    'houston_temp']
                  }}],
            chart_options =
              {'title': {
                   'text': 'Weather Data of Boston and Houston'},
               'xAxis': {
                    'title': {
                       'text': 'Month number'}}})

    #Step 3: Send the chart object to the template.
    return render_to_response({'weatherchart': cht})
Пример #29
0
def graphHistory(userId):

    Stockdata = \
        DataPool(
            series=
            [{'options': {
                'source': Performance.objects.filter(userid=userId)
            },
                'terms': [
                    'date',
                    'amount']}
            ])
    cht = Chart(datasource=Stockdata,
                series_options=[{
                    'options': {
                        'type': 'area',
                        'stacking': False
                    },
                    'terms': {
                        'date': ['amount']
                    }
                }],
                chart_options={
                    'title': {
                        'text': 'Historical performance  '
                    },
                    'xAxis': {
                        'title': {
                            'text': 'Day'
                        }
                    }
                })
    return cht
Пример #30
0
def weather_view(request):
    #datapool with the data we want to retrieve
    weatherdata = DataPool(series=[{
        'options': {
            'source': MonthlyWeatherByCity.objects.all()
        },
        'terms': ['month', 'boston_temp']
    }])

    #Create chart object
    cht = Chart(
        datasource=weatherdata,
        series_options=[{
            'options': {
                'type': 'pie',
                'stacking': False
            },
            'terms': {
                'month': ['boston_temp']
            }
        }],
        chart_options={'title': {
            'text': 'Monthly Temperature of Boston'
        }},
        x_sortf_mapf_mts=(None, monthname, False))
    #Send the chart object to the template
    return render_to_response('home/weather.html', {'weatherchart': cht})