Beispiel #1
0
def export_day(day, fetcher):
    day_export_start = datetime.datetime.now()
    simulator = VisitSimulator(fetcher.getVisits(day), day)
    
    if simulator.visit_limit == 0:
        return #nothing to export
    
    VERBOSE("VISIT: Initialize", 2)
    simulator.initialize(fetcher, "ga:latitude,ga:longitude,ga:hour,ga:flashVersion,ga:javaEnabled,ga:language,ga:screenResolution", "ga:visits")

    VERBOSE("VISIT: Fetch 1", 2)
    simulator.update(fetcher, "ga:latitude,ga:longitude,ga:visitLength,ga:hour,ga:visitorType,ga:operatingSystem,ga:operatingSystemVersion","ga:visits")       
    VERBOSE("VISIT: Fetch 2", 2)
    simulator.update(fetcher, "ga:latitude,ga:longitude,ga:hour,ga:browser,ga:browserVersion,ga:country,ga:continent","ga:visits")
    VERBOSE("VISIT: Fetch 3", 2)
    simulator.update(fetcher, "ga:longitude,ga:latitude,ga:hour,ga:browserVersion,ga:keyword,ga:source,ga:operatingSystemVersion","ga:visits")
    
    """
    Getting landing and exit pages
    """
    VERBOSE("VISIT: Fetch landing, exits", 2)
    simulator.update(fetcher, "ga:exitPagePath,ga:landingPagePath,ga:latitude,ga:longitude,ga:hour","ga:entrances")
    VERBOSE("ACTION: Export paths", 2)
    action_manager.export(config.SITE_BASE_URL)
    VERBOSE("ACTION: Completed", 2)
    additional  = {"idsite" : config.ID_SITE, "visit_server_date" : day}
    
    simulator.finalize(additional)
    
    """
    Export views to log_view
    """
    VERBOSE("VISIT: Export vitis", 2)
    for v in simulator.visits:
        v.idvisit = sql.insert_log_visit(v.visit_log)
    VERBOSE("VISIT: Completed", 2)
    
    """
    Simulate actions by taking every page (with pageviews and timeOnPage info) and inserting to log_link_visit_action
    """
    fetcher.FeedFetch("ga:pagePath","ga:pageviews,ga:timeOnPage,ga:bounces", day)
    pageViewDict = fetcher.FeedToDict()
    for action in pageViewDict:
        real_action = action_manager[action["ga:pagePath"]]
        real_action.pageviews = int(action["metric"]["ga:pageviews"])
        real_action.timeleft = float(action["metric"]["ga:timeOnPage"])
        real_action.bounces = int(action["metric"]["ga:bounces"])
        real_action.average = real_action.timeleft / real_action.pageviews
        
        for v in xrange(len(simulator.visits)):
            visit = simulator.visits[v]
            if real_action.bounces == 0: continue
            if visit.google_data.get("ga:landingPagePath") == real_action.path and not visit.bounce:
                real_action.bounces -= 1
                visit.bounce = True
                try:
                    sql.insert_log_visit_action((visit.idvisit, real_action.id_action_url, real_action.id_action_url,\
                                             real_action.id_action_name, real_action.average))
                except Exception, e:
                    print e
Beispiel #2
0
                    print e


    for action in pageViewDict:
        real_action = action_manager[action["ga:pagePath"]]
        real_action.pageviews = int(action["metric"]["ga:pageviews"])
        real_action.timeleft = float(action["metric"]["ga:timeOnPage"])
        real_action.bounces = int(action["metric"]["ga:bounces"])
        real_action.average = real_action.timeleft / real_action.pageviews if real_action.pageviews > 0 else real_action.timeleft

        candicates = filter(lambda v : not v.bounce, simulator.visits)
        for view in xrange(real_action.pageviews - real_action.bounces):
            visit = random.choice(candicates)
            try:
                sql.insert_log_visit_action((visit.idvisit, visit.get_final_value("idcookie"),
                                             visit.get_final_value("visit_server_date"), config.ID_SITE,
                                             real_action.id_action_url, real_action.id_action_url,
                                             real_action.id_action_name, real_action.average))
            except Exception, e:
                print e


    simulated_unique = len(set([visit.visit_log["config_md5config"] for visit in simulator.visits]))
    VERBOSE("Number of simulated unique visits:\t%s" % simulated_unique)

    VERBOSE("Real number of unique visits:\t%s" % fetcher.getUniqueVisitors(day))
    VERBOSE("DAY EXPORT TIME (in seconds): %s" % (datetime.datetime.now() - day_export_start).seconds,2)
    VERBOSE("")

    del simulator

class Visit(object):
Beispiel #3
0
                except Exception, e:
                    print e
                    
                
    for action in pageViewDict:
        real_action = action_manager[action["ga:pagePath"]]
        real_action.pageviews = int(action["metric"]["ga:pageviews"])
        real_action.timeleft = float(action["metric"]["ga:timeOnPage"])
        real_action.bounces = int(action["metric"]["ga:bounces"])
        real_action.average = real_action.timeleft / real_action.pageviews
        
        candicates = filter(lambda v : not v.bounce, simulator.visits)
        for view in xrange(real_action.pageviews - real_action.bounces):
            visit = random.choice(candicates)
            try:
                sql.insert_log_visit_action((visit.idvisit, real_action.id_action_url, real_action.id_action_url,\
                                             real_action.id_action_name, real_action.average))
            except Exception, e:
                print e

    
    simulated_unique = len(set([visit.visit_log["config_md5config"] for visit in simulator.visits]))
    VERBOSE("Number of simulated unique visits:\t%s" % simulated_unique)
        
    VERBOSE("Real number of unique visits:\t%s" % fetcher.getUniqueVisitors(day))
    VERBOSE("DAY EXPORT TIME (in seconds): %s" % (datetime.datetime.now() - day_export_start).seconds,2)
    VERBOSE("")

    del simulator

class Visit(object):
    """