def visits(request): profile = Profile.objects.get(user_id=request.user) agency = profile.agency visits = get_visits_number(App_hit.objects.filter(app_id__campaign_id__agency_id=agency).all()) context = { 'visits_count': visits, } return render_to_response('dashboardExtended/visits.html', context, context_instance=RequestContext(request))
def visits_app(request, app_id=None): profile = Profile.objects.get(user_id=request.user) agency = profile.agency try: app = App.objects.get(id=app_id, campaign__agency=agency) except: return redirect('/error/1001') visits = get_visits_number(App_hit.objects.filter(app=app).all()) context = { 'visits_count': visits, } return render_to_response('dashboardExtended/visits.html', context, context_instance=RequestContext(request))
def main(request): # graph = GraphAPI(request.session['facebook_access_token']) last_month = timezone.now() - timedelta(days=30) profile = Profile.objects.get(user_id=request.user) agency = profile.agency ########################### Main Graph ########################### ########################### Views, Visits, Visitors, Records ########################### ########################### Main Graph Leyends leyends = [] leyends_date = [] leyends_date_str = [] for day in rrule(DAILY, dtstart=last_month, until=timezone.now()): day_zoned = day.astimezone(timezone.get_default_timezone()) leyends_date_str.append(day_zoned.strftime("%Y-%m-%d")) leyends_date.append(day_zoned) leyends.append(int(time.mktime(day_zoned.timetuple()) * 1000)) ########################### Views views = [] for leyend in leyends_date: views.append(App_hit.objects.filter(app__campaign__agency=agency,\ created__startswith=date(int(leyend.strftime("%Y")),int(leyend.strftime("%m")), int(leyend.strftime("%d")))).count()) # print >>sys.stderr, views ########################### Visits visits = [] for leyend in leyends_date: visits.append(get_visits_number(App_hit.objects.filter(app__campaign__agency=agency,\ created__startswith=date(int(leyend.strftime("%Y")),int(leyend.strftime("%m")), int(leyend.strftime("%d")))).all()) ) # print >>sys.stderr, visits ########################### Visitors visitors = [] for leyend in leyends_date: visitors.append(App_hit.objects.filter(app__campaign__agency=agency,\ created__startswith=date(int(leyend.strftime("%Y")),int(leyend.strftime("%m")), int(leyend.strftime("%d")))).values("remote_addr").distinct().count()) # print >>sys.stderr, visitors ########################### Records records = [] for leyend in leyends_date: records.append(App_record.objects.filter(app__campaign__agency=agency,\ created__startswith=date(int(leyend.strftime("%Y")),int(leyend.strftime("%m")), int(leyend.strftime("%d")))).count()) # print >>sys.stderr, records extra_serie_views = {"tooltip": {"y_start": "Existen ", "y_end": " vistas"}} extra_serie_visits = {"tooltip": {"y_start": "Existen ", "y_end": " visitas"}} extra_serie_visitors = {"tooltip": {"y_start": "Existen ", "y_end": " visitantes"}} extra_serie_records = {"tooltip": {"y_start": "Existen ", "y_end": " registros"}} chartdata_hits = { 'x': leyends, 'name1': 'Vistas', 'y1': views, 'extra1': extra_serie_views, 'name2': 'Visitas', 'y2': visits, 'extra2': extra_serie_visits, 'name3': 'Visitantes', 'y3': visitors, 'extra3': extra_serie_visitors, 'name4': 'Registros', 'y4': records, 'extra4': extra_serie_records, } ########################### ########################### Main Graph context = { 'chartdata_hits': chartdata_hits, 'extra': { 'x_is_date': True, 'x_axis_format': '', 'tag_script_js': True, 'jquery_on_ready': True, 'resize': True } } return render_to_response('dashboardExtended/main.html', context, context_instance=RequestContext(request))