def index(): chart1 = Chart().pie("饼图", data={ u"衬衫": 100, u"羊毛衫": 360, u"雪纺衫": 120, u"裤子": 500, u"高跟鞋": 300 }) chart2 = Chart() \ .legend(data=[u"最高气温", u"最低气温"]) \ .x_axis(data=[u"周一", u"周二", u"周三", u"周四", u"周五", u"周六", u"周日"]) \ .y_axis(formatter="{value} C") \ .line(u"最高气温", [10, 20, 30, 40, 30, 20, 10], mark_max_point=True, show_item_label=True) \ .bar(u"最低气温", [5, 10, 5, 10, 5, 6, 7]) \ .pie(name="测试", data={"Java": 50, "PHP": 50, "Python": 100}, center=["20%", "30%"], radius="15%") print json.dumps(chart2, indent=2) render = { "title": u"测试的标题", "templates": [{ "type": "radio" }, { "type": "table" }, { "type": "chart", "option": json.dumps(chart1, indent=2) }, { "type": "chart", "option": json.dumps(chart2, indent=2) }] } return render_template("main.html", **render)
def index(): presto=Presto_Query() age_price_tuples=presto.query_age_price() age_dict=presto.getAgeDict(age_price_tuples) chart1 = Chart().pie("饼图", data=age_dict ) tuples=presto.query_brand_price() keys=presto.getKeys(tuples) values=presto.getValues(tuples) chart2 = Chart() \ .x_axis(data=keys) \ .y_axis(formatter="{value}") \ .bar(u"Brand Price", values, show_item_label=True) redis=Redis_Query() province_price=redis.query_province() china_province_price=redis.get_province_price(province_price) print china_province_price chart3= Chart()\ .map(china_province_price) render = { "title": u"电商双十一大数据日志分析系统", "templates": [ {"type": "chart", "title":u"不同年龄消费的情况", "option": json.dumps(chart1, indent=2)}, {"type": "chart", "title":u"消费商品的情况", "option": json.dumps(chart2, indent=2)}, {"type": "chart", "title":u"各省购买情况", "option": json.dumps(chart3, indent=2)} ] } return render_template("main.html", **render)
def api_create_chart(request, *, type, description, project_id, option): Option = json.dumps(option, ensure_ascii=False).encode('utf-8') chart = Chart(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, project_id=project_id.strip(), type=type.strip(), description=description.strip(), status=False, option=Option) yield from chart.save() chart.option = markdown2.markdown(chart.option) return chart
def api_get_project(*, id): project = yield from Project.find(id) charts = yield from Chart.findAll('project_id=?', [id], orderBy='created_at desc') for chart in charts: chart.option = json.loads(chart.option) return dict(project=project, charts=charts)
def setUp(self): self.group, created = Group.objects.get_or_create(name='test') self.user, created = DjangoUser.objects.get_or_create(username=self.username) self.user.set_password(self.password) self.user.save() perspective, created = Perspective.objects.get_or_create(name='default') perspective.set_default_user() perspective.save() ModuleSetting.set('default_perspective', perspective.id) self.report = Report(name='test') self.report.set_default_user() self.report.save() self.chart = Chart(name='test_chart', report=self.report) self.chart.set_default_user() self.chart.save()
def api_save_chart(request , *, type, description, id, option): chart = yield from Chart.find(id) chart.status = True chart.option = json.dumps(option, ensure_ascii=False).encode('utf-8') chart.description = description yield from chart.update() chart.option = markdown2.markdown(chart.option) return chart
def api_save_chart(request, *, type, description, id, option): chart = yield from Chart.find(id) chart.status = True chart.option = json.dumps(option, ensure_ascii=False).encode('utf-8') chart.description = description yield from chart.update() chart.option = markdown2.markdown(chart.option) return chart
def piechart_add(request, layer_id): if request.method == 'POST': layer = Layer.objects.get(id=int(layer_id)) title = request.POST.get('title') description = request.POST.get('description') chart_conf = request.POST.get('chart_conf') chart = Chart(layer=layer, type='piechart', title=title, description=description, conf=chart_conf) chart.save() return HttpResponse(json.dumps({'success': True}, indent=4), content_type='application/json') else: layer = Layer.objects.get(id=int(layer_id)) layer = Layer.objects.get(id=int(layer_id)) datastore = Datastore.objects.get(id=layer.datastore_id) workspace = Workspace.objects.get(id=datastore.workspace_id) gs = geographic_servers.get_instance().get_server_by_id( workspace.server.id) (ds_type, resource) = gs.getResourceInfo(workspace.name, datastore, layer.name, "json") fields = utils.get_fields(resource) numeric_fields = utils.get_numeric_fields(fields) alpha_numeric_fields = utils.get_alphanumeric_fields(fields) geom_fields = utils.get_geometry_fields(fields) conf = { 'layer_id': layer_id, 'fields': json.dumps(fields), 'numeric_fields': json.dumps(numeric_fields), 'alpha_numeric_fields': json.dumps(alpha_numeric_fields), 'geom_fields': json.dumps(geom_fields) } return render(request, 'piechart_add.html', conf)
def presto(): query = Presto_Query() # 各年龄段消费者每日购买商品总价值 xdata, series = query.total_price_perday() multiLineChart = Chart().multiLine("年龄日期统计", xdata, "日期", series) # 男女消费者每日、每周和每月总借贷金额 xdata_day, series_day = query.gender_loan_query() multiBarChart_day = Chart().multiBar("性别借款统计(每日)", xdata_day, "日期", series_day) xdata_week, series_week = query.gender_loan_query("week") multiBarChart_week = Chart().multiBar("性别借款统计(每周)", xdata_week, "日期", series_week) xdata_month, series_month = query.gender_loan_query("month") multiBarChart_month = Chart().multiBar("性别借款统计(每月)", xdata_month, "日期", series_month) render = { "title": "京东金融信贷需求预分析", "templates": [{ "type": "chart", "title": u"年龄日期统计", "index": 1, "option": json.dumps(multiLineChart, indent=2) }, { "type": "chart", "title": u"性别借款统计(每日)", "index": 2, "option": json.dumps(multiBarChart_day, indent=2) }, { "type": "chart", "title": u"性别借款统计(每周)", "index": 3, "option": json.dumps(multiBarChart_week, indent=2) }, { "type": "chart", "title": u"性别借款统计(每月)", "index": 4, "option": json.dumps(multiBarChart_month, indent=2) }] } return render_template("main.html", **render)
def index(): presto=Presto_Query() # 以城市为单位,统计每个城市总体消费金额 city_price_total_tuples=presto.query_city_price_total() city_data=presto.getData(city_price_total_tuples) chart1=Chart().pie("饼图", data=city_data) # 以天为单位,统计所有商家交易发生次数 transaction_count_tuples=presto.query_transaction_count() xAxisData=presto.getPayXData(transaction_count_tuples) yAxisData=presto.getPayYData(transaction_count_tuples) chart2= Chart().line("折线图",data=yAxisData, date = xAxisData) # 以天为单位,统计所有商家被用户浏览次数 view_count_tuples=presto.query_view_count() xAxisData=presto.getPayXData(view_count_tuples) yAxisData=presto.getPayYData(view_count_tuples) chart3= Chart().line("折线图",data = yAxisData, date = xAxisData) #平均日交易额最大的前 10 个商家 top_10_shop_tuples=presto.query_top_10_shop() keys=presto.getKeys(top_10_shop_tuples) values=presto.getValues(top_10_shop_tuples) chart4=Chart() \ .x_axis(data=keys,name="商家编号") \ .y_axis(formatter="{value}",name="日均交易额") \ .bar(u"shop Average daily turnover", values, show_item_label=True) render = { "title": u"阿里巴巴口碑商家流量分析", "templates": [ {"type": "chart", "title":u"每个城市总体消费金额", "option": json.dumps(chart1, indent=2)}, {"type": "chart", "title":u"所有商家交易发生次数", "option": json.dumps(chart2, indent=2)}, {"type": "chart", "title":u"所有商家被用户浏览次数", "option": json.dumps(chart3, indent=2)}, {"type": "chart", "title":u"平均日交易额最大的前 10 个商家", "option": json.dumps(chart4, indent=2)} ] } return render_template("main.html", **render)
def stream(): query = Redis_Query() # 每个页面累计点击次数 tuples_click = query.click_query() keys_click = query.get_keys(tuples_click) values_click = query.get_values(tuples_click) bar_click = Chart() \ .x_axis(data=keys_click) \ .y_axis(formatter="{value}") \ .line(u"点击次数", values_click) # 不同年龄段消费总金额 tuples_order = query.order_query() keys_order = query.get_keys(tuples_order) values_order = query.get_values(tuples_order) bar_order = Chart() \ .x_axis(data=keys_order) \ .y_axis(formatter="{value}") \ .line(u"人数", values_order) render = { "title": "京东金融信贷需求预分析", "templates": [ { "type": "chart", "title": u"每个页面累计点击次数", "index": 1, "option": json.dumps(bar_click, indent=2) }, { "type": "chart", "title": u"不同年龄段消费总金额", "index": 2, "option": json.dumps(bar_order, indent=2) }, ] } return render_template("stream.html", **render)
def chartEstatisticas(estatisticas): labels = [] values = [] colors = [] if estatisticas: tipo_estatistica = estatisticas[0].tipo_estatistica.nome else: tipo_estatistica = '' for e in estatisticas: labels.append(e.jogador.nome) values.append(e.quantidade) c = lambda: random.randint(0, 255) colors.append('#%02X%02X%02X' % (c(), c(), c())) return Chart(labels, values, colors, tipo_estatistica)
def test_model_chart(self): "Test Chart Model" report = Report(name='test') report.save() obj = Chart(name='test', report=report) obj.save() self.assertEquals('test', obj.name) self.assertNotEquals(obj.id, None) obj.delete()
def charts(request): """Lists the charts and also displays a form to add a new one.""" if request.method == 'POST': chart = Chart(user=request.user) form = CreateChartForm(request.POST, instance=chart, usr_=request.user) if form.is_valid(): form.save() return HttpResponseRedirect('/charts/%s/' % chart.id) else: form = CreateChartForm(usr_=request.user) charts = Chart.objects.filter(user=request.user) return render(request, 'chartchemy/charts.html', { 'form': form, 'charts': charts, })
def save(self): if hasattr(self, 'chart_id'): chart = get_object_or_404(Chart, pk=self.chart_id) else: chart = Chart() report = get_object_or_404(Report, pk=self.report_id) chart.report = report chart.name = self.data['title'] chart.options = dumps(self.data) chart.save() return chart
def api_delete_chart(request, *, id): check_admin(request) chart = yield from Chart.find(id) yield from chart.remove() return dict(id=id)
def api_get_chart(*, id): chart = yield from Chart.find(id) chart.option = json.loads(chart.option) return chart
def api_create_chart(request , *, type, description, project_id, option): Option = json.dumps(option, ensure_ascii=False).encode('utf-8') chart = Chart(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, project_id=project_id.strip(), type=type.strip(), description=description.strip(), status=False, option = Option) yield from chart.save() chart.option = markdown2.markdown(chart.option) return chart
def api_get_chart(*,id): chart = yield from Chart.find(id) chart.option = json.loads(chart.option) return chart
def mysql(): query = Mysql_Query() # 分析借款金额、年龄、性别的数据分布(平均借款) xdata1, series1 = query.age_sex_loan_query() multiLineChart_avg = Chart().multiLine("分析借款金额、年龄、性别的数据分布(平均借款)", xdata1, "年龄", series1) # 分析借款金额、年龄、性别的数据分布(最大借款) xdata2, series2 = query.age_sex_loan_query(value_type="max") multiLineChart_max = Chart().multiLine("分析借款金额、年龄、性别的数据分布(最大借款)", xdata2, "年龄", series2) # 分析借款金额、年龄、性别的数据分布(最小借款) xdata3, series3 = query.age_sex_loan_query(value_type="min") multiLineChart_min = Chart().multiLine("分析借款金额、年龄、性别的数据分布(最小借款)", xdata3, "年龄", series3) # 分别统计用户账号激活后3 天、7 天、一个月和三个月内会借款的用户的数量 tuples = query.active_after_query() keys = query.get_keys(tuples) values = query.get_values(tuples) bar1 = Chart() \ .x_axis(data=keys) \ .y_axis(formatter="{value}") \ .bar(u"人数", values, show_item_label=True) # 从不买打折产品且不借款的用户 xdata4, series4 = query.no_discount_loan_query() multiBarChart_no = Chart().multiBar("从不买打折产品且不借款的用户", xdata4, "日期", series4) render = { "title": "京东金融信贷需求预分析", "templates": [ { "type": "chart", "title": u"分析借款金额、年龄、性别的数据分布(平均借款)", "index": 1, "option": json.dumps(multiLineChart_avg, indent=2) }, { "type": "chart", "title": u"分析借款金额、年龄、性别的数据分布(最大借款)", "index": 2, "option": json.dumps(multiLineChart_max, indent=2) }, { "type": "chart", "title": u"分析借款金额、年龄、性别的数据分布(最小借款)", "index": 3, "option": json.dumps(multiLineChart_min, indent=2) }, { "type": "chart", "title": u"分别统计用户账号激活后3 天、7 天、一个月和三个月内会借款的用户的数量", "index": 4, "option": json.dumps(bar1, indent=2) }, { "type": "chart", "title": u"从不买打折产品且不借款的用户", "index": 5, "option": json.dumps(multiBarChart_no, indent=2) }, ] } return render_template("main.html", **render)
def index(): """ presto=Presto_Query() age_price_tuples20=presto.query_age_price20() age_price_keys20=presto.getKeys(age_price_tuples20) age_price_values20=presto.getValues(age_price_tuples20) age_price_tuples25=presto.query_age_price25() age_price_keys25=presto.getKeys(age_price_tuples25) age_price_values25=presto.getValues(age_price_tuples25) age_price_tuples30=presto.query_age_price30() age_price_keys30=presto.getKeys(age_price_tuples30) age_price_values30=presto.getValues(age_price_tuples30) age_price_tuples35=presto.query_age_price35() age_price_keys35=presto.getKeys(age_price_tuples35) age_price_values35=presto.getValues(age_price_tuples35) age_price_tuples40=presto.query_age_price40() age_price_keys40=presto.getKeys(age_price_tuples40) age_price_values40=presto.getValues(age_price_tuples40) age_price_tuples45=presto.query_age_price45() age_price_keys45=presto.getKeys(age_price_tuples45) age_price_values45=presto.getValues(age_price_tuples45) age_price_tuples50=presto.query_age_price50() age_price_keys50=presto.getKeys(age_price_tuples50) age_price_values50=presto.getValues(age_price_tuples50) chart1 = Chart() \ .x_axis(data=age_price_keys20) \ .y_axis(formatter="{value}") \ .line(u"20", age_price_values20) \ .line(u"25", age_price_values25) \ .line(u"30", age_price_values30) \ .line(u"35", age_price_values35) \ .line(u"40", age_price_values40) \ .line(u"45", age_price_values45) \ .line(u"50", age_price_values50) sex_loan_tuples0=presto.query_sex_loan0() sex_loan_keys0=presto.getKeys(sex_loan_tuples0) sex_loan_values0=presto.getValues(sex_loan_tuples0) sex_loan_tuples1=presto.query_sex_loan1() sex_loan_keys1=presto.getKeys(sex_loan_tuples1) sex_loan_values1=presto.getValues(sex_loan_tuples1) chart2 = Chart() \ .x_axis(data=sex_loan_keys0) \ .y_axis(formatter="{value}") \ .bar(u"M", sex_loan_values0, show_item_label=True) \ .bar(u"F", sex_loan_values1, show_item_label=True) """ redis = Redis_Query() click_dict = redis.query_click() chart3 = Chart().pie("饼图", data=click_dict) render = { "title": u"京东金融信贷需求分析系统", "templates": [ # {"type": "chart", "title":u"各年龄段消费者每日购买商品总价值", "option": json.dumps(chart1, indent=2)}, # {"type": "chart", "title":u"男女消费者每日借贷金额 ", "option": json.dumps(chart2, indent=2)}, { "type": "chart", "title": u"每个页面累计点击次数", "option": json.dumps(chart3, indent=2) } # {"type": "chart", "title":u"不同年龄段消费总金额", "option": json.dumps(chart3, indent=2)} ] } return render_template("main.html", **render)
class ReportsViewsTest(TestCase): username = "******" password = "******" def setUp(self): self.group, created = Group.objects.get_or_create(name='test') self.user, created = DjangoUser.objects.get_or_create(username=self.username) self.user.set_password(self.password) self.user.save() perspective, created = Perspective.objects.get_or_create(name='default') perspective.set_default_user() perspective.save() ModuleSetting.set('default_perspective', perspective.id) self.report = Report(name='test') self.report.set_default_user() self.report.save() self.chart = Chart(name='test_chart', report=self.report) self.chart.set_default_user() self.chart.save() ###################################### # Testing views when user is logged in ###################################### def test_reports_login(self): """Testing /reports/""" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('reports')) self.assertEquals(response.status_code, 200) def test_index_login(self): "Testing /reports/index/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('reports_index')) self.assertEquals(response.status_code, 200) def test_index_owned(self): "Testing /reports/owned/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('reports_index')) self.assertEquals(response.status_code, 200) # Charts def test_chart_add(self): "Testing /reports/chart/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('reports_chart_add')) self.assertEquals(response.status_code, 200) def test_chart_delete_login(self): "Testing /reports/chart/delete/<chart_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('reports_chart_delete', args=[self.chart.id])) self.assertEquals(response.status_code, 200) # Reports def test_report_add(self): "Testing /reports/report/add/" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get(reverse('reports_report_add')) self.assertEquals(response.status_code, 200) def test_report_delete_login(self): "Testing /reports/report/delete/<report_id>" response = self.client.post('/accounts/login', {'username': self.username, 'password': self.password}) self.assertRedirects(response, '/') response = self.client.get( reverse('reports_report_delete', args=[self.report.id])) self.assertEquals(response.status_code, 200) ###################################### # Testing views when user is not logged in ###################################### def test_reports_out(self): "Testing /reports/" response = self.client.get(reverse('reports')) self.assertRedirects(response, reverse('user_login')) def test_index_out(self): "Testing /reports/index/" response = self.client.get(reverse('reports_index')) self.assertRedirects(response, reverse('user_login')) def test_index_owned_out(self): "Testing /reports/owned/" response = self.client.get(reverse('reports_index')) self.assertRedirects(response, reverse('user_login')) # Charts def test_chart_add_out(self): "Testing /reports/chart/add/" response = self.client.get(reverse('reports_chart_add')) self.assertRedirects(response, reverse('user_login')) def test_chart_add_typed_out(self): "Testing /reports/chart/add/<report_id>" response = self.client.get( reverse('reports_chart_add', args=[self.report.id])) self.assertRedirects(response, reverse('user_login')) def test_chart_edit_out(self): "Testing /reports/chart/edit/<chart_id>" response = self.client.get( reverse('reports_chart_edit', args=[self.chart.id])) self.assertRedirects(response, reverse('user_login')) def test_chart_delete_out(self): "Testing /reports/chart/delete/<chart_id>" response = self.client.get( reverse('reports_chart_delete', args=[self.chart.id])) self.assertRedirects(response, reverse('user_login')) # Reports def test_report_add_out(self): "Testing /reports/report/add/" response = self.client.get(reverse('reports_report_add')) self.assertRedirects(response, reverse('user_login')) def test_report_view_out(self): "Testing /reports/report/view/<report_id>" response = self.client.get( reverse('reports_report_view', args=[self.report.id])) self.assertRedirects(response, reverse('user_login')) def test_report_edit_out(self): "Testing /reports/report/edit/<report_id>" response = self.client.get( reverse('reports_report_edit', args=[self.report.id])) self.assertRedirects(response, reverse('user_login')) def test_report_delete_out(self): "Testing /reports/report/delete/<report_id>" response = self.client.get( reverse('reports_report_delete', args=[self.report.id])) self.assertRedirects(response, reverse('user_login'))