def widget_layout(request,widget,user_widget,style): import cjson,urllib from pywik import prep_date from forms import WidgetSettingsForm if user_widget.custom_date_range != None: calc_date = user_widget.custom_date_range elif (request.GET.has_key('start_date')) & (request.GET.has_key('end_date')): calc_date = str(request.GET['start_date'])+","+str(request.GET['end_date']) elif (request.POST.has_key('start_date')) & (request.POST.has_key('end_date')): calc_date = str(request.POST['start_date'])+","+str(request.POST['end_date']) else: calc_date = prep_date(user_widget.widget.widget_date_range) d = { } if user_widget.custom_group != None: d['group_data_by'] = user_widget.custom_group if user_widget.custom_columns != None: x,y = user_widget.custom_columns.split(",") d['variable1'] = x d['variable2'] = y if calc_date != "" and calc_date.find(","): d['start_date'] = calc_date.split(",")[0] d['end_date'] = calc_date.split(",")[1] else: d['start_date'] = "" d['end_date'] = "" my_widget = {} my_widget['form'] = WidgetSettingsForm(initial=d).as_p() if style == 'None': style = widget.widget_style if style == "table": if widget.widget_type == 2: my_widget['html'] = widget.getDataTable(auth=request.organization.pywik_token_auth_key, idSite=request.organization.pywik_siteId,group_by = request.GET.get('group_by',0), period='day', date=calc_date, headers = widget.headers.split(','), data_columns = widget.data_columns.split(",")) else: my_widget['html'] = widget.getAqDataTable(request=request, chart_style=style, date=calc_date, group_by = user_widget.custom_group, widget_id=widget.id, user_widget_id = user_widget.id) my_widget['header'] = widget.widget_name user_widget.custom_style = style if request.GET.get('preview',None) == None: user_widget.save() else: if user_widget.widget.widget_type == 2: my_widget['html'] = openFlashChart.flashHTML('100%', '300', '/api/'+str(user_widget.widget.id)+'/'+str(style)+'/?data=idSite='+str(request.organization.pywik_siteId)+'|date='+str(calc_date)+'|period=day', '/ofc/') else: if user_widget.custom_columns != None: custom_columns = "|custom_columns="+str(user_widget.custom_columns) else: custom_columns = "" my_widget['html'] = openFlashChart.flashHTML('100%', '300', '/api/'+str(user_widget.widget.id)+'/'+str(style)+'/?data=date='+str(calc_date)+'|group_by='+str(user_widget.custom_group)+str(custom_columns), '/ofc/') my_widget['header'] = user_widget.widget.widget_name user_widget.custom_style = style if request.GET.get('preview',None) == None: user_widget.save() my_widget['widget_id'] = user_widget.id return HttpResponse(str(cjson.encode(my_widget)))
def index(self): graphs = [] #self.ifile = ifile # Bar Charts graphs.append(openFlashChart.flashHTML('100%', '800', '/my_bar_stack', '/flashes/')) graphs.append(openFlashChart.flashHTML('100%', '800', '/ilp_filtered_bar_stack_0', '/flashes/')) graphs.append(openFlashChart.flashHTML('100%', '800', '/ilp_filtered_bar_stack_1', '/flashes/')) graphs.append(openFlashChart.flashHTML('100%', '800', '/ilp_filtered_bar_stack_2', '/flashes/')) graphs.append(openFlashChart.flashHTML('100%', '800', '/ilp_filtered_bar_stack_3', '/flashes/')) #graphs.append(openFlashChart.flashHTML('100%', '800', '/ilp_filtered_bar_stack_vrac', '/flashes/')) graphs.append(self.source("html_snippet.html")) return self.source("OFC.htm") %({"chart": "<br/><br/><br/><br/>".join(graphs)})
def index(request): chartList = [] xenHostList = XenHost.objects.all(); print "Total de ", len(xenHostList), " hosts" for xenHost in xenHostList: xenHost.chart = openFlashChart.flashHTML('100%', '400', '/monitor/data/' + str(xenHost.id), "http://localhost/") chartList.append(xenHost) return render_to_response('Base/monitor.xhtml', {'chartList': chartList})
def widget_layout(request, widget, user_widget, style): import cjson, urllib from pywik import prep_date from forms import WidgetSettingsForm if user_widget.custom_date_range != None: calc_date = user_widget.custom_date_range elif (request.GET.has_key('start_date')) & ( request.GET.has_key('end_date')): calc_date = str(request.GET['start_date']) + "," + str( request.GET['end_date']) elif (request.POST.has_key('start_date')) & ( request.POST.has_key('end_date')): calc_date = str(request.POST['start_date']) + "," + str( request.POST['end_date']) else: calc_date = prep_date(user_widget.widget.widget_date_range) d = {} if user_widget.custom_group != None: d['group_data_by'] = user_widget.custom_group if user_widget.custom_columns != None: x, y = user_widget.custom_columns.split(",") d['variable1'] = x d['variable2'] = y if calc_date != "" and calc_date.find(","): d['start_date'] = calc_date.split(",")[0] d['end_date'] = calc_date.split(",")[1] else: d['start_date'] = "" d['end_date'] = "" my_widget = {} my_widget['form'] = WidgetSettingsForm(initial=d).as_p() if style == 'None': style = widget.widget_style if style == "table": if widget.widget_type == 2: my_widget['html'] = widget.getDataTable( auth=request.organization.pywik_token_auth_key, idSite=request.organization.pywik_siteId, group_by=request.GET.get('group_by', 0), period='day', date=calc_date, headers=widget.headers.split(','), data_columns=widget.data_columns.split(",")) else: my_widget['html'] = widget.getAqDataTable( request=request, chart_style=style, date=calc_date, group_by=user_widget.custom_group, widget_id=widget.id, user_widget_id=user_widget.id) my_widget['header'] = widget.widget_name user_widget.custom_style = style if request.GET.get('preview', None) == None: user_widget.save() else: if user_widget.widget.widget_type == 2: my_widget['html'] = openFlashChart.flashHTML( '100%', '300', '/api/' + str(user_widget.widget.id) + '/' + str(style) + '/?data=idSite=' + str(request.organization.pywik_siteId) + '|date=' + str(calc_date) + '|period=day', '/ofc/') else: if user_widget.custom_columns != None: custom_columns = "|custom_columns=" + str( user_widget.custom_columns) else: custom_columns = "" my_widget['html'] = openFlashChart.flashHTML( '100%', '300', '/api/' + str(user_widget.widget.id) + '/' + str(style) + '/?data=date=' + str(calc_date) + '|group_by=' + str(user_widget.custom_group) + str(custom_columns), '/ofc/') my_widget['header'] = user_widget.widget.widget_name user_widget.custom_style = style if request.GET.get('preview', None) == None: user_widget.save() my_widget['widget_id'] = user_widget.id return HttpResponse(str(cjson.encode(my_widget)))
def dashboard(request, org): pids, aids = request.organization.get_dashboard_filtered_orgs() var1 = request.organization.dashboard_variable1 var1_name = request.organization.get_dashboard_variable1_display() today_range = compute_date_range(REPORTTIMEFRAME_TODAY, True) yesterday_range = compute_date_range(REPORTTIMEFRAME_YESTERDAY, True) mtd_range = compute_date_range(REPORTTIMEFRAME_MONTHTODATE, True) ytd_range = compute_date_range(REPORTTIMEFRAME_YEARTODATE, True) number_of_var1 = request.organization.get_metric(var1, today_range, aids, pids) yesterday = request.organization.get_metric(var1, yesterday_range, aids, pids) monthly_var1 = request.organization.get_chart_vars(var1, mtd_range, 0, aids, pids) yearly_var1 = request.organization.get_chart_vars(var1, ytd_range, 0, aids, pids) try: month_high = int(max([monthly_var1[1][1]])) month_low = int(min([monthly_var1[1][1]])) except: month_high = 0 month_low = 0 try: ytd_high = int(max([yearly_var1[1][1]])) ytd_low = int(min([yearly_var1[1][1]])) except: ytd_high = 0 ytd_low = 0 total_mtd = request.organization.get_metric(var1, mtd_range, aids, pids) total_ytd = request.organization.get_metric(var1, ytd_range, aids, pids) daily_avg = request.organization.get_metric( var1, ytd_range, aids, pids) / (ytd_range[1] - ytd_range[0]).days orders = request.organization.get_metric(METRIC_ORDERS, ytd_range, aids, pids) clicks = request.organization.get_metric(METRIC_CLICKS, ytd_range, aids, pids) amount = request.organization.get_metric(METRIC_AMOUNT, ytd_range, aids, pids) impressions = request.organization.get_metric(METRIC_IMPRESSIONS, ytd_range, aids, pids) if orders == 0: aov = 0 else: aov = float(amount) / float(orders) aov = currency_formatter(aov, request.organization) if clicks == 0: epc = 0 else: epc = float(amount) / float(clicks) epc = currency_formatter(epc, request.organization) if clicks == 0: cpc = 0 else: cpc = float(amount) / float(clicks) cpc = currency_formatter(cpc, request.organization) if impressions == 0: cpm = 0 else: cpm = float(amount) / float(impressions) cpm = currency_formatter(cpm, request.organization) custom_date_range_start = request.GET.get('custom_date_range_start', None) custom_date_range_end = request.GET.get('custom_date_range_end', None) if request.session.has_key("date_range") == False: date_range = REPORTTIMEFRAME_PAST30DAYS else: date_range = request.session["date_range"] if (custom_date_range_start != None) & (custom_date_range_end != None): try: date_start = datetime.date(int(custom_date_range_start[6:10]), int(custom_date_range_start[:2]), int(custom_date_range_start[3:5])) date_end = datetime.date(int(custom_date_range_end[6:10]), int(custom_date_range_end[:2]), int(custom_date_range_end[3:5])) except: date_start, date_end = compute_date_range(date_range, True) else: date_start, date_end = compute_date_range(date_range, True) date_range_name = "Custom" for rtf_v, rtf_n in REPORTTIMEFRAME_CHOICES: if rtf_v == date_range: date_range_name = rtf_n link_report = CreativeReport(date_start, date_end, request.organization, spec=specs['advertiser'][REPORTTYPE_CREATIVE], publisher_set=pids) if request.organization.org_type == 1: publisher_report = AdvertiserReport( date_start, date_end, request.organization, spec=specs['publisher'][REPORTTYPE_REVENUE_BY_ADVERTISER], advertiser_set=aids) sales_report = DateReport(request.organization.dashboard_group_data_by, date_start, date_end, request.organization, spec=specs['publisher'][REPORTTYPE_SALES], advertiser_set=aids) else: publisher_report = PublisherReport( date_start, date_end, request.organization, spec=specs['advertiser'][REPORTTYPE_REVENUE_BY_PUBLISHER], publisher_set=pids) sales_report = DateReport(request.organization.dashboard_group_data_by, date_start, date_end, request.organization, spec=specs['advertiser'][REPORTTYPE_SALES], publisher_set=pids) pending_applications = Organization.objects.filter( advertiser_relationships__status=RELATIONSHIP_APPLIED, status=ORGSTATUS_LIVE, advertiser_relationships__advertiser=request.organization).extra( select={ "advertiser_id": "select advertiser_id from base_or ganization where id=" + str(request.organization.id) }).count() inquiries = PublisherInquiry.objects.filter( status=INQUIRYSTATUS_UNRESOLVED, advertiser=request.organization) from datetime import date today = date.today() month_span = date(today.year, today.month, 1) chart_links = { 'main_graph': openFlashChart.flashHTML( '100%', '200', '/advertiser/get_chart/columns/' + str(month_span) + '/' + str(today) + '/?onevar=1', '/ofc/'), 'lines': openFlashChart.flashHTML( '100%', '400', '/advertiser/get_chart/lines/' + str(date_start) + '/' + str(date_end) + '/', '/ofc/'), 'pie': openFlashChart.flashHTML( '100%', '400', '/advertiser/get_chart/pie/' + str(date_start) + '/' + str(date_end) + '/', '/ofc/'), 'columns': openFlashChart.flashHTML( '100%', '400', '/advertiser/get_chart/columns/' + str(date_start) + '/' + str(date_end) + '/', '/ofc/'), 'bars': openFlashChart.flashHTML( '100%', '400', '/advertiser/get_chart/bars/' + str(date_start) + '/' + str(date_end) + '/', '/ofc/') } return AQ_render_to_response( request, 'commons/dashboard.html', { 'number_of_var1': number_of_var1, 'date_start': date_start.strftime("%m-%d-%Y"), 'date_end': date_end.strftime("%m-%d-%Y"), 'date_range_name': date_range_name, 'var1_name': var1_name, 'yesterday': yesterday, 'month_high': month_high, 'month_low': month_low, 'ytd_high': ytd_high, 'ytd_low': ytd_low, 'total_mtd': total_mtd, 'total_ytd': total_ytd, 'daily_avg': daily_avg, 'aov': aov, 'epc': epc, 'cpm': cpm, 'cpc': cpc, 'org': org, 'sales_report': sales_report, 'link_report': link_report, 'publisher_report': publisher_report, 'pending_applications': pending_applications, 'inquiries': inquiries, 'chart_links': chart_links, }, context_instance=RequestContext(request))
def index(self): graphs = [] # Line Charts graphs.append( openFlashChart.flashHTML('100%', '400', '/line', '/flashes/')) graphs.append( openFlashChart.flashHTML('100%', '400', '/line_dot', '/flashes/')) graphs.append( openFlashChart.flashHTML('100%', '400', '/line_hollow', '/flashes/')) # Bar Charts graphs.append( openFlashChart.flashHTML('100%', '400', '/bar', '/flashes/')) graphs.append( openFlashChart.flashHTML('100%', '400', '/bar_filled', '/flashes/')) graphs.append( openFlashChart.flashHTML('100%', '400', '/bar_glass', '/flashes/')) graphs.append( openFlashChart.flashHTML('100%', '400', '/bar_3d', '/flashes/')) graphs.append( openFlashChart.flashHTML('100%', '400', '/bar_sketch', '/flashes/')) graphs.append( openFlashChart.flashHTML('100%', '400', '/hbar', '/flashes/')) graphs.append( openFlashChart.flashHTML('100%', '400', '/bar_stack', '/flashes/')) # Area Charts graphs.append( openFlashChart.flashHTML('100%', '400', '/area_line', '/flashes/')) graphs.append( openFlashChart.flashHTML('100%', '400', '/area_hollow', '/flashes/')) # Pie Chart graphs.append( openFlashChart.flashHTML('100%', '400', '/pie', '/flashes/')) # Scatter Charts graphs.append( openFlashChart.flashHTML('100%', '400', '/scatter', '/flashes/')) graphs.append( openFlashChart.flashHTML('100%', '400', '/scatter_line', '/flashes/')) # Radar Charts graphs.append( openFlashChart.flashHTML('100%', '400', '/radar', '/flashes/')) # Testing Chart graphs.append( openFlashChart.flashHTML('100%', '400', '/test', '/flashes/')) graphs.append(self.source("html_snippet.html")) return self.source("OFC.htm") % ({ "chart": "<br/><br/><br/><br/>".join(graphs) })
def index(self): graphs = [] # Line Charts graphs.append(openFlashChart.flashHTML('100%', '400', '/line', '/flashes/')) graphs.append(openFlashChart.flashHTML('100%', '400', '/line_dot', '/flashes/')) graphs.append(openFlashChart.flashHTML('100%', '400', '/line_hollow', '/flashes/')) # Bar Charts graphs.append(openFlashChart.flashHTML('100%', '400', '/bar', '/flashes/')) graphs.append(openFlashChart.flashHTML('100%', '400', '/bar_filled', '/flashes/')) graphs.append(openFlashChart.flashHTML('100%', '400', '/bar_glass', '/flashes/')) graphs.append(openFlashChart.flashHTML('100%', '400', '/bar_3d', '/flashes/')) graphs.append(openFlashChart.flashHTML('100%', '400', '/bar_sketch', '/flashes/')) graphs.append(openFlashChart.flashHTML('100%', '400', '/hbar', '/flashes/')) graphs.append(openFlashChart.flashHTML('100%', '400', '/bar_stack', '/flashes/')) # Area Charts graphs.append(openFlashChart.flashHTML('100%', '400', '/area_line', '/flashes/')) graphs.append(openFlashChart.flashHTML('100%', '400', '/area_hollow', '/flashes/')) # Pie Chart graphs.append(openFlashChart.flashHTML('100%', '400', '/pie', '/flashes/')) # Scatter Charts graphs.append(openFlashChart.flashHTML('100%', '400', '/scatter', '/flashes/')) graphs.append(openFlashChart.flashHTML('100%', '400', '/scatter_line', '/flashes/')) # Radar Charts graphs.append(openFlashChart.flashHTML('100%', '400', '/radar', '/flashes/')) # Testing Chart graphs.append(openFlashChart.flashHTML('100%', '400', '/test', '/flashes/')) graphs.append(self.source("html_snippet.html")) return self.source("OFC.htm") %({"chart": "<br/><br/><br/><br/>".join(graphs)})
def dashboard(request, org): pids,aids = request.organization.get_dashboard_filtered_orgs() var1 = request.organization.dashboard_variable1 var1_name = request.organization.get_dashboard_variable1_display() today_range = compute_date_range(REPORTTIMEFRAME_TODAY,True) yesterday_range = compute_date_range(REPORTTIMEFRAME_YESTERDAY,True) mtd_range = compute_date_range(REPORTTIMEFRAME_MONTHTODATE,True) ytd_range = compute_date_range(REPORTTIMEFRAME_YEARTODATE,True) number_of_var1 = request.organization.get_metric(var1,today_range,aids,pids) yesterday = request.organization.get_metric(var1,yesterday_range,aids,pids) monthly_var1 = request.organization.get_chart_vars(var1,mtd_range,0,aids,pids) yearly_var1 = request.organization.get_chart_vars(var1,ytd_range,0,aids,pids) try: month_high = int(max([monthly_var1[1][1]])) month_low = int(min([monthly_var1[1][1]])) except: month_high = 0 month_low = 0 try: ytd_high = int(max([yearly_var1[1][1]])) ytd_low = int(min([yearly_var1[1][1]])) except: ytd_high = 0 ytd_low = 0 total_mtd = request.organization.get_metric(var1,mtd_range,aids,pids) total_ytd = request.organization.get_metric(var1,ytd_range,aids,pids) daily_avg = request.organization.get_metric(var1,ytd_range,aids,pids)/(ytd_range[1]-ytd_range[0]).days orders = request.organization.get_metric(METRIC_ORDERS,ytd_range,aids,pids) clicks = request.organization.get_metric(METRIC_CLICKS,ytd_range,aids,pids) amount = request.organization.get_metric(METRIC_AMOUNT,ytd_range,aids,pids) impressions = request.organization.get_metric(METRIC_IMPRESSIONS,ytd_range,aids,pids) if orders == 0: aov = 0 else: aov = float(amount) / float(orders) aov = currency_formatter(aov,request.organization) if clicks == 0: epc = 0 else: epc = float(amount) / float(clicks) epc = currency_formatter(epc,request.organization) if clicks == 0: cpc = 0 else: cpc = float(amount) / float(clicks) cpc = currency_formatter(cpc,request.organization) if impressions == 0: cpm = 0 else: cpm = float(amount) / float(impressions) cpm = currency_formatter(cpm,request.organization) custom_date_range_start = request.GET.get('custom_date_range_start', None) custom_date_range_end = request.GET.get('custom_date_range_end',None) if request.session.has_key("date_range") == False: date_range = REPORTTIMEFRAME_PAST30DAYS else: date_range = request.session["date_range"] if (custom_date_range_start != None) & (custom_date_range_end != None): try: date_start = datetime.date(int(custom_date_range_start[6:10]),int(custom_date_range_start[:2]),int(custom_date_range_start[3:5])) date_end = datetime.date(int(custom_date_range_end[6:10]),int(custom_date_range_end[:2]),int(custom_date_range_end[3:5])) except: date_start,date_end = compute_date_range(date_range,True) else: date_start,date_end = compute_date_range(date_range,True) date_range_name = "Custom" for rtf_v,rtf_n in REPORTTIMEFRAME_CHOICES: if rtf_v == date_range: date_range_name = rtf_n link_report = CreativeReport(date_start,date_end,request.organization,spec=specs['advertiser'][REPORTTYPE_CREATIVE],publisher_set=pids) if request.organization.org_type == 1: publisher_report = AdvertiserReport(date_start,date_end,request.organization,spec=specs['publisher'][REPORTTYPE_REVENUE_BY_ADVERTISER],advertiser_set=aids) sales_report = DateReport(request.organization.dashboard_group_data_by,date_start,date_end,request.organization,spec=specs['publisher'][REPORTTYPE_SALES],advertiser_set=aids) else: publisher_report = PublisherReport(date_start,date_end,request.organization,spec=specs['advertiser'][REPORTTYPE_REVENUE_BY_PUBLISHER],publisher_set=pids) sales_report = DateReport(request.organization.dashboard_group_data_by,date_start,date_end,request.organization,spec=specs['advertiser'][REPORTTYPE_SALES],publisher_set=pids) pending_applications = Organization.objects.filter(advertiser_relationships__status=RELATIONSHIP_APPLIED, status=ORGSTATUS_LIVE,advertiser_relationships__advertiser=request.organization).extra(select={"advertiser_id":"select advertiser_id from base_or ganization where id="+str(request.organization.id)}).count() inquiries = PublisherInquiry.objects.filter(status=INQUIRYSTATUS_UNRESOLVED,advertiser=request.organization) from datetime import date today = date.today() month_span = date(today.year, today.month, 1) chart_links = { 'main_graph':openFlashChart.flashHTML('100%', '200', '/advertiser/get_chart/columns/'+str(month_span)+'/'+str(today)+'/?onevar=1', '/ofc/'), 'lines':openFlashChart.flashHTML('100%', '400', '/advertiser/get_chart/lines/'+str(date_start)+'/'+str(date_end)+'/', '/ofc/'), 'pie':openFlashChart.flashHTML('100%', '400', '/advertiser/get_chart/pie/'+str(date_start)+'/'+str(date_end)+'/', '/ofc/'), 'columns':openFlashChart.flashHTML('100%', '400', '/advertiser/get_chart/columns/'+str(date_start)+'/'+str(date_end)+'/', '/ofc/'), 'bars':openFlashChart.flashHTML('100%', '400', '/advertiser/get_chart/bars/'+str(date_start)+'/'+str(date_end)+'/', '/ofc/') } return AQ_render_to_response(request, 'commons/dashboard.html', { 'number_of_var1' : number_of_var1, 'date_start':date_start.strftime("%m-%d-%Y"), 'date_end':date_end.strftime("%m-%d-%Y"), 'date_range_name':date_range_name, 'var1_name' : var1_name, 'yesterday' : yesterday, 'month_high' : month_high, 'month_low' : month_low, 'ytd_high' : ytd_high, 'ytd_low' : ytd_low, 'total_mtd' : total_mtd, 'total_ytd' : total_ytd, 'daily_avg' : daily_avg, 'aov' : aov, 'epc' : epc, 'cpm' : cpm, 'cpc' : cpc, 'org': org, 'sales_report': sales_report, 'link_report': link_report, 'publisher_report': publisher_report, 'pending_applications': pending_applications, 'inquiries':inquiries, 'chart_links':chart_links, }, context_instance=RequestContext(request))