def main_campaign_advanced(request, campaign_id=None): # 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 try: campaign = Campaign.objects.get(agency_id=agency, id=campaign_id) except: hitting(request, 1001) # Stats return redirect('/error/1001') ########################### 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)) ########################### Canvas canvas = [] for leyend in leyends_date: canvas.append(App_hit.objects.filter(app__campaign=campaign, hit__webgl=True,\ created__startswith=date(int(leyend.strftime("%Y")),int(leyend.strftime("%m")), int(leyend.strftime("%d")))).count()) ########################### No canvas no_canvas = [] for leyend in leyends_date: no_canvas.append(App_hit.objects.filter(app__campaign=campaign, hit__webgl=False,\ created__startswith=date(int(leyend.strftime("%Y")),int(leyend.strftime("%m")), int(leyend.strftime("%d")))).count()) extra_serie_views = {"tooltip": {"y_start": "Existen ", "y_end": " vistas"}} chartdata_hits = { 'x': leyends, 'name1': 'Soporte 3d', 'y1': canvas, 'extra1': extra_serie_views, 'name2': 'Sin soporte 3d', 'y2': no_canvas, 'extra2': extra_serie_views, } 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('statsExtended/main.html', context, context_instance=RequestContext(request))
def hitting_update(request, hit_id): try: hit = Hit.objects.get(id=hit_id) except: hitting(request, 1003) # Stats return redirect('/error/1003') hit.updated = datetime.utcnow() hit.save() return HttpResponse(hit.id)
def hitting_env(request, hit_id): try: hit = Hit.objects.get(id=hit_id) except: hitting(request, 1003) # Stats return redirect('/error/1003') if (request.POST.get('window_height')): hit.window_height = request.POST.get('window_height') if (request.POST.get('window_width')): hit.window_width = request.POST.get('window_width') if (request.POST.get('screen_height')): hit.screen_height = request.POST.get('screen_height') if (request.POST.get('screen_width')): hit.screen_width = request.POST.get('screen_width') if (request.POST.get('color_depth')): hit.color = request.POST.get('color_depth') if (request.POST.get('flash')): hit.flash = request.POST.get('flash') if (request.POST.get('java_enabled')): hit.java = request.POST.get('java_enabled') if (request.POST.get('silverlight')): hit.silverlight = request.POST.get('silverlight') if (request.POST.get('html5_canvas')): hit.html5_canvas = request.POST.get('html5_canvas') if (request.POST.get('html5_video')): hit.html5_video = request.POST.get('html5_video') if (request.POST.get('html5_audio')): hit.html5_audio = request.POST.get('html5_audio') if (request.POST.get('html5_storage')): hit.html5_storage = request.POST.get('html5_storage') if (request.POST.get('svg')): hit.svg = request.POST.get('svg') if (request.POST.get('webgl')): hit.webgl = request.POST.get('webgl') hit.save() return HttpResponse(hit.id)
def facebook_show(request, app_id): try: fb_Access = Facebook_access.objects.get(facebook_app_id=app_id) except: hitting(request, 1501) # Stats return redirect('/error/1501') if 'signed_request' in request.REQUEST: signed_request = SignedRequest.parse(request.REQUEST.get('signed_request'), str(fb_Access.facebook_app_secret_key)) ################ Get Structure try: app = App.objects.get(facebook_access=fb_Access.id, campaign__facebook_page_id=signed_request['page']['id']) campaign = Campaign.objects.get(id=app.campaign_id) except: hitting(request, 1502) # Stats return redirect('/error/1502') liked = signed_request['page']['liked'] if not liked: if app.like_page == 1 and campaign.membership.like_page: return redirect(reverse('clients:app_show', args=[app.id, 'facebook', -1, -1])) return redirect(reverse('clients:app_show', args=[app.id, 'facebook'])) else: hitting(request, 1504) # Stats return redirect('/error/1504')
def main_campaign(request, campaign_id=None): # 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 try: campaign = Campaign.objects.get(agency_id=agency, id=campaign_id) except: hitting(request, 1001) # Stats return redirect('/error/1001') ########################### 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=campaign,\ 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=campaign,\ 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=campaign,\ 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, app__campaign=campaign,\ 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, } 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))
def main_app_system(request, app_id=None): # 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 try: app = App.objects.get(id=app_id, campaign_id__agency_id=agency) except: hitting(request, 1001) # Stats return redirect('/error/1001') ########################### 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)) touch_array = [] no_touch_array = [] for leyend in leyends_date: touch = 0 user_agent_day = App_hit.objects.filter(app=app,\ created__startswith=date(int(leyend.strftime("%Y")),int(leyend.strftime("%m")), int(leyend.strftime("%d")))).values('hit__user_agent').order_by().annotate(total=Count('id')) count = App_hit.objects.filter(app=app,\ created__startswith=date(int(leyend.strftime("%Y")),int(leyend.strftime("%m")), int(leyend.strftime("%d")))).count() if user_agent_day: for user_agent in user_agent_day: if user_agent['hit__user_agent']: key = parse(user_agent['hit__user_agent']) if key.is_touch_capable: touch = touch + user_agent['total'] touch_array.append(touch) no_touch_array.append(count - touch) extra_serie_views = {"tooltip": {"y_start": "Existen ", "y_end": " vistas"}} chartdata_hits = { 'x': leyends, 'name1': u'Pantalla táctil', 'y1': touch_array, 'extra1': extra_serie_views, 'name2': u'Sin pantalla táctil', 'y2': no_touch_array, 'extra2': extra_serie_views, } 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('statsExtended/main.html', context, context_instance=RequestContext(request))
def main_app_enviroment(request, app_id=None): # 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 try: app = App.objects.get(id=app_id, campaign_id__agency_id=agency) except: hitting(request, 1001) # Stats return redirect('/error/1001') ########################### 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 chrome = [] firefox = [] safari = [] ie = [] other = [] for leyend in leyends_date: day_hits = App_hit.objects.filter(app=app,\ created__startswith=date(int(leyend.strftime("%Y")),int(leyend.strftime("%m")), int(leyend.strftime("%d")))).values('hit__user_agent') chrome_counter = 0 firefox_counter = 0 safari_counter = 0 ie_counter = 0 other_counter = 0 for day_hit in day_hits: if day_hit['hit__user_agent']: key = parse(day_hit['hit__user_agent']) if key.browser.family == "Chrome": chrome_counter = chrome_counter + 1 elif key.browser.family == "Firefox": firefox_counter = firefox_counter + 1 elif key.browser.family == "Safari": safari_counter = safari_counter + 1 elif key.browser.family == "IE": ie_counter = ie_counter + 1 else: other_counter = other_counter + 1 else: other_counter = other_counter + 1 chrome.append(chrome_counter) firefox.append(firefox_counter) safari.append(safari_counter) ie.append(ie_counter) other.append(other_counter) extra_serie_chrome = {"tooltip": {"y_start": "Existen ", "y_end": " vistas desde Chrome"}} extra_serie_firefox = {"tooltip": {"y_start": "Existen ", "y_end": " vistas desde Firefox"}} extra_serie_safari = {"tooltip": {"y_start": "Existen ", "y_end": " vistas desde Safari"}} extra_serie_ie = {"tooltip": {"y_start": "Existen ", "y_end": " vistas desde Internet Explorer"}} extra_serie_other = {"tooltip": {"y_start": "Existen ", "y_end": " vistas desde Otro"}} chartdata_hits = { 'x': leyends, 'name1': 'Chrome', 'y1': chrome, 'extra1': extra_serie_chrome, 'name2': 'Firefox', 'y2': firefox, 'extra2': extra_serie_firefox, 'name3': 'Safari', 'y3': safari, 'extra3': extra_serie_safari, 'name4': 'Internet Explorer', 'y4': ie, 'extra4': extra_serie_ie, 'name5': 'Otro', 'y5': other, 'extra5': extra_serie_other, } ########################### ########################### 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('statsExtended/main.html', context, context_instance=RequestContext(request))
def app_show(request, app_id=None, source='direct', core_app_id=-1, order=0): host = request.META["HTTP_HOST"] if (host.startswith('www.')): host = host[4:] if not host == 'spreadlabs.com' and settings.ONLINE: try: domain = Domain.objects.get(domain=host) except: hitting(request, 1005) # Stats return redirect('/error/1005') if not app_id: app = domain.app campaign = domain.campaign if not app: hitting(request, 1006) # Stats return redirect('/error/1006') else: try: app = App.objects.get(id=app_id, active=True, campaign=domain.campaign) campaign = app.campaign except: hitting(request, 1502) # Stats return redirect('/error/1502') else: if not app_id: hitting(request, 1003) # Stats return redirect('/error/1003') try: app = App.objects.get(id=app_id, active=True) campaign = app.campaign except: hitting(request, 1502) # Stats return redirect('/error/1502') try: if int(core_app_id) >= 0: core = Core_app.objects.get(app=app, id=core_app_id) # go = App_structure.objects.get(app=app.id, core_app=core_app_id) else: core = Core_app.objects.get(app=app, order=order) # go = App_structure.objects.get(app=app.id, order=order) except: hitting(request, 1503) # Stats return redirect('/error/1503') hit_response = hitting(request, 200) # Stats hit = App_hit(app_id=app.id, remote_addr=hit_response.remote_addr, core_app=core, hit=hit_response) try: source_obj = App_source.objects.get(app=app, token=source) except: if source == 'facebook': source_obj = App_source(app=app, name="Facebook", token='facebook') source_obj.save() else: try: source_obj = App_source.objects.get(app=app, token='direct') except: source_obj = App_source(app=app, name="Directo", token='direct') source_obj.save() hit.source = source_obj hit.save() # Stats try: background = Core_object_background.objects.get(core_app=core) except: background = None try: image_links = Core_object_image_links.objects.filter(core_app=core).all() except: image_links = None try: youtube = Core_object_youtube.objects.filter(core_app=core).all() except: youtube = None try: inputs = Core_object_input.objects.filter(core_app=core).order_by('top', 'left').all() except: inputs = None print >>sys.stderr, inputs context = {'app': app, 'hit': hit_response, 'source':source, 'background': background, 'image_links': image_links, 'campaign': campaign, 'youtube': youtube, 'inputs': inputs, 'external': True} return render_to_response('clients/app/render.html', context, context_instance=RequestContext(request))
def export_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_id__agency_id=agency) except: hitting(request, 1001) # Stats return redirect('/error/1001') campaign = app.campaign # for record in records: # Create the HttpResponse object with the appropriate CSV header. now = datetime.now() response = HttpResponse(content_type='text/csv') response[ 'Content-Disposition'] = 'attachment; filename="' + agency.name.encode( 'utf-8') + '_' + campaign.name.encode( 'utf-8') + '_' + app.name.encode('utf-8') + '_' + str( now) + '.csv"' writer = csv.writer(response) writer.writerow([ agency.name.encode('utf-8'), '', '', '', '', '', '', '', '', now.strftime('%d-%m-%Y') ]) writer.writerow([ 'Lista total de registros de ' + campaign.name.encode('utf-8') + ' obtenidos desde la aplicación: ' + app.name.encode('utf-8'), '', '', '', '', '', '', '', '', now.strftime('%X') ]) writer.writerow(['', '', '', '', '', '', '', '', '', '']) writer.writerow([ 'Creación', 'Fuente', 'Cédula', 'Nombre', 'Apellidos', 'Correo', 'Celular', 'Día de nacimiento', 'Mes de nacimiento', 'Año de nacimiento' ]) records = App_record.objects.filter(app=app).all().order_by('-created') for record in records: if record.record.created: created = str(record.record.created) else: created = '' if record.source: source = record.source source = source.encode('utf-8') else: source = '' if record.record.identification: identification = record.record.identification identification = identification.encode('utf-8') else: identification = '' if record.record.name: name = record.record.name name = name.encode('utf-8') else: name = '' if record.record.lastname: lastname = record.record.lastname lastname = lastname.encode('utf-8') else: lastname = '' if record.record.email: email = record.record.email email = email.encode('utf-8') else: email = '' if record.record.cellphone: cellphone = str(record.record.cellphone) else: cellphone = '' if record.record.day_of_birth: day = str(record.record.day_of_birth) else: day = '' if record.record.birth_month: month = str(record.record.birth_month) else: month = '' if record.record.year_of_birth: year = str(record.record.year_of_birth) else: year = '' writer.writerow([ created, source, identification, name, lastname, email, cellphone, day, month, year ]) return response
def 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_id__agency_id=agency) except: hitting(request, 1001) # Stats return redirect('/error/1001') campaign = app.campaign ########################### ########################### Apps Records Graph xdata = [ "Cédula", "Nombre", "Apellidos", "Correo", "Celular", "Día (*)", "Mes (*)", "Año (*)" ] ydata = [] ydata.append( App_record.objects.filter(app=app).exclude( record__identification__isnull=True).count()) ydata.append( App_record.objects.filter(app=app).exclude( record__name__isnull=True).count()) ydata.append( App_record.objects.filter(app=app).exclude( record__lastname__isnull=True).count()) ydata.append( App_record.objects.filter(app=app).exclude( record__email__isnull=True).count()) ydata.append( App_record.objects.filter(app=app).exclude( record__cellphone__isnull=True).count()) ydata.append( App_record.objects.filter(app=app).exclude( record__day_of_birth__isnull=True).count()) ydata.append( App_record.objects.filter(app=app).exclude( record__birth_month__isnull=True).count()) ydata.append( App_record.objects.filter(app=app).exclude( record__year_of_birth__isnull=True).count()) extra_serie1 = {"tooltip": {"y_start": "Existen ", "y_end": " registros"}} chartdata_type = { 'x': xdata, 'name1': 'Registros', 'y1': ydata, 'extra1': extra_serie1, } records_count = App_record.objects.filter(app=app).count() records = App_record.objects.filter(app=app).all().order_by('-created') context = { 'app': app, 'campaign': campaign, 'records': records, 'records_count': records_count, 'chartdata_type': chartdata_type, 'extra': { 'x_is_date': True, 'x_axis_format': '', 'tag_script_js': True, 'jquery_on_ready': True, 'resize': True, 'height': None }, 'extra_discrete': { 'x_is_date': False, 'x_axis_format': '', 'tag_script_js': True, 'jquery_on_ready': True, }, } return render_to_response('records/app.html', context, context_instance=RequestContext(request))