示例#1
0
    def __call__(self, user_name, cache={}):

        first_seen_metric = userstats.user.api.core.FirstSeen()
        first_seen = cache.get(str(first_seen_metric), first_seen_metric(user_name, cache))
        start = get_date(self.start, cache['reference_date'], first_seen, self.strict)
        end = get_date(self.end, cache['reference_date'], first_seen, self.strict)

        if not start or not end:
            return None
        contribs_metric = Contribs()
        contribs = cache.get(str(contribs_metric), contribs_metric(user_name, cache))
       
        if self.rq:
            q = rq.Queue('diffs', connection=redis.Redis(port=self.redis_port))
            results = [q.enqueue(process_contrib_bytes_added, (contrib, start, end, self.ns, user_name, cache)) for contrib in contribs]

            while not all(map(lambda res: res.is_finished or res.is_failed, results)):
                time.sleep(.1)
            bytes_added_results = map(attrgetter('result'), results)
        else:
            bytes_added_results = map(process_contrib_bytes_added, zip(contribs,
                                                                   itertools.repeat(start),
                                                                   itertools.repeat(end),
                                                                   itertools.repeat(self.ns),
                                                                   itertools.repeat(user_name),
                                                                   itertools.repeat(cache)))
        #bytes_added = {}
        for b, contrib in zip(bytes_added_results, contribs):
            #bytes_added[contrib['revid']] = b
            contrib['bytes_added'] = b
        return sum(bytes_added_results)
示例#2
0
文件: core.py 项目: embr/userstats
    def __call__(self, user_name, cache={}):
        contribs_metric = Contribs()
        contribs = cache.get(str(contribs_metric), contribs_metric(user_name, cache))

        first_seen_metric = FirstSeen()
        first_seen = cache.get(str(first_seen_metric), first_seen_metric(user_name, cache))
        start = get_date(self.start, cache['reference_date'], first_seen, self.strict)
        end = get_date(self.end, cache['reference_date'], first_seen, self.strict)

        pages = []
        if not (start and end):
            # this means that this is not a valid date range for this user
            return None
        for contrib in contribs:
            if contrib['timestamp'] < start:
                continue
            if contrib['timestamp'] > end:
                continue
            if contrib['ns'] not in self.ns:
                continue
            pages.append(contrib['pageid'])
        return len(set(pages))
示例#3
0
文件: core.py 项目: embr/userstats
    def __call__(self, user_name, cache={}):

        first_seen_metric = FirstSeen()
        first_seen = cache.get(str(first_seen_metric), first_seen_metric(user_name, cache))
        start = get_date(self.start, cache['reference_date'], first_seen, self.strict)
        end = get_date(self.end, cache['reference_date'], first_seen, self.strict)
        if not (start and end):
            # this means that this is not a valid date range for this user
            logging.debug('metric not applicable')        
            return None

        contribs_metric = Contribs()
        contribs = cache.get(str(contribs_metric), contribs_metric(user_name, cache))
        count = 0
        for contrib in contribs:
            if contrib['timestamp'] < start:
                continue
            if contrib['timestamp'] > end:
                continue
            if contrib['ns'] not in self.ns:
                continue
            count += 1
        return count
示例#4
0
    def __call__(self, user_name, cache={}):


        first_seen_metric = userstats.user.api.core.FirstSeen()
        first_seen = cache.get(str(first_seen_metric), first_seen_metric(user_name, cache))
        start = get_date(self.start, cache['reference_date'], first_seen, self.strict)
        end = get_date(self.end, cache['reference_date'], first_seen, self.strict)
        if not start or not end:
            return None

        contribs_metric = Contribs()
        contribs = cache.get(str(contribs_metric), contribs_metric(user_name, cache))

        diff_metric = Diffs(self.rq)
        diffs = cache.get(str(diff_metric), diff_metric(user_name, cache))
        ordered_diffs = map(diffs.get, map(itemgetter('revid'), contribs))

        if self.rq:
            q = rq.Queue('reverts', connection=redis.Redis(port=self.redis_port))
            results = [q.enqueue(process_contrib, (user_name, cache, i, contrib, diff, start, end, self.ns))
                                 for i, (contrib, diff) in enumerate(zip(contribs, ordered_diffs))]
            while not all(map(lambda res: res.is_finished or res.is_failed, results)):
                pass
            contrib_chars = map(attrgetter('result'), results)
        else:
            pool = multiprocessing.Pool(processes=self.nproc)
            #contrib_chars = map(process_contrib, 
            contrib_chars = pool.map_async(process_contrib, 
                                     zip(itertools.repeat(user_name),
                                         itertools.repeat(cache),
                                         itertools.count(),
                                         contribs,
                                         ordered_diffs,
                                         itertools.repeat(start),
                                         itertools.repeat(end),
                                         itertools.repeat(self.ns))).get(sys.maxint)
        return sum(contrib_chars)