Exemplo n.º 1
0
def fix_counts():
    """Fix the global totals of points. Do a bunch of count querys."""
    
    ranges = _get_date_ranges()
    
    for start, end in ranges:
        count = Commit.query().filter(Commit.timestamp >= start, Commit.timestamp < end).count(1000)
        Accumulator.add_count('global', start, count, reset=True)
Exemplo n.º 2
0
def fix_player_counts(auth_id):
    """Fix a single user counts."""
    user = User.get_by_auth_id(auth_id)
    
    ranges = _get_date_ranges()
    
    for start, end in ranges:
        count = Commit.query(ancestor=user.key).filter(Commit.timestamp >= start, Commit.timestamp < end).count(1000)
        Accumulator.add_count('own:%s' % user.username, start, count, reset=True)
Exemplo n.º 3
0
def fix_counts():
    """Fix the global totals of points. Do a bunch of count querys."""

    ranges = _get_date_ranges()

    for start, end in ranges:
        count = Commit.query().filter(Commit.timestamp >= start,
                                      Commit.timestamp < end).count(1000)
        Accumulator.add_count('global', start, count, reset=True)
Exemplo n.º 4
0
 def test_get_histogram(self):
     acc1 = Accumulator.get_or_insert('test:7')
     acc2 = Accumulator.get_or_insert('test:8')
     acc1.count = 4
     acc2.count = 6
     ndb.put_multi([acc1, acc2])
     counts = Accumulator.get_histogram('test')
     self.assertListEqual(counts, 
         [0,0,0,0,0,0,4,6,0,0,
          0,0,0,0,0,0,0,0,0,0,
          0,0,0,0,0,0,0,0,0,0,0])
Exemplo n.º 5
0
def fix_player_counts(auth_id):
    """Fix a single user counts."""
    user = User.get_by_auth_id(auth_id)

    ranges = _get_date_ranges()

    for start, end in ranges:
        count = Commit.query(ancestor=user.key).filter(
            Commit.timestamp >= start, Commit.timestamp < end).count(1000)
        Accumulator.add_count('own:%s' % user.username,
                              start,
                              count,
                              reset=True)
Exemplo n.º 6
0
 def get(self, metric):
     from july.people.models import Accumulator
     stats = Accumulator.get_histogram(metric)
     
     self.respond_json({
         'metric': metric,
         'stats': stats,
         'total': sum(stats),
     })
Exemplo n.º 7
0
    def get(self, metric):
        from july.people.models import Accumulator
        stats = Accumulator.get_histogram(metric)

        self.respond_json({
            'metric': metric,
            'stats': stats,
            'total': sum(stats),
        })
Exemplo n.º 8
0
 def test_add_count(self):
     t = datetime.datetime(year=2012, month=7, day=2, hour=0, minute=5)
     Accumulator.add_count('test', t, 5)
     Accumulator.add_count('test', t + datetime.timedelta(days=2), 7)
     Accumulator.add_count('test', t + datetime.timedelta(days=9))
     
     counts = Accumulator.get_histogram('test')
     self.assertListEqual(counts, 
         [0,5,0,7,0,0,0,0,0,0,
          1,0,0,0,0,0,0,0,0,0,
          0,0,0,0,0,0,0,0,0,0,0])
Exemplo n.º 9
0
    def test_post_adds_points_to_global(self):
        self.policy.SetProbability(1)
        user = self.make_user('marcus', location='Austin TX')
        user.add_auth_id('email:[email protected]')
        self.app.post('/api/v1/bitbucket', self.POST)
        tasks = self.taskqueue_stub.GetTasks('default')
        self.assertEqual(3, len(tasks))

        # Run the task
        for task in tasks:
            deferred.run(base64.b64decode(task['body']))

        stats = Accumulator.get_histogram('global')
        self.assertListEqual(stats, [
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            1,
            0,
        ])
Exemplo n.º 10
0
    def test_post_adds_points_to_global(self):
        self.policy.SetProbability(1)
        user = self.make_user('marcus', location='Austin TX')
        user.add_auth_id('email:[email protected]')
        self.app.post('/api/v1/bitbucket', self.POST)
        tasks = self.taskqueue_stub.GetTasks('default')
        self.assertEqual(3, len(tasks))

        # Run the task
        for task in tasks:
            deferred.run(base64.b64decode(task['body']))
    
        stats = Accumulator.get_histogram('global')
        self.assertListEqual(stats, [
            0,0,0,0,0,0,0,0,0,0,
            0,0,0,0,0,0,0,0,0,0,
            0,0,0,0,0,0,0,0,0,1,0,
        ])
Exemplo n.º 11
0
def live(request):
    stats = Accumulator.get_histogram('global')
    total = sum(stats)
    message_future = Message.query().order(-Message.timestamp).fetch_async(30)
        
    # Julython live stuffs
    token_key = 'live_token:%s' % request.user.username
    token = memcache.get(token_key)
    if token is None:
        token = channel.create_channel(request.user.username)
        memcache.set(token_key, token, time=7000)

    message_models = message_future.get_result()
    
    m_list = [to_dict(m) for m in message_models]
    m_list.reverse()
    messages = json.dumps(m_list)
    
    return render_to_response('live/index.html', {
        'token': token, 'messages': messages, 'total': total},
        context_instance=RequestContext(request))
Exemplo n.º 12
0
def live(request):
    stats = Accumulator.get_histogram('global')
    total = sum(stats)
    message_future = Message.query().order(-Message.timestamp).fetch_async(30)

    # Julython live stuffs
    token_key = 'live_token:%s' % request.user.username
    token = memcache.get(token_key)
    if token is None:
        token = channel.create_channel(request.user.username)
        memcache.set(token_key, token, time=7000)

    message_models = message_future.get_result()

    m_list = [to_dict(m) for m in message_models]
    m_list.reverse()
    messages = json.dumps(m_list)

    return render_to_response('live/index.html', {
        'token': token,
        'messages': messages,
        'total': total
    },
                              context_instance=RequestContext(request))
Exemplo n.º 13
0
def index(request):
    """Render the home page"""

    # For now we are just using hard coded sections
    #sections = cache.get('front_page')
    #if sections is None:
    #    sections = Section.all().order('order').fetch(10)
    #    cache.set('front_page', sections, 120)

    stats = []
    total = 0
    people = []
    locations = []
    projects = []
    teams = []
    messages = []
    token = ''

    # this is only shown on authenticated page loads
    # to save on the overhead.
    if True:
        stats = Accumulator.get_histogram('global')
        total = sum(stats)
        location_future = Location.query().order(-Location.total).fetch_async(
            15)
        people_future = User.query().order(
            -ndb.GenericProperty('total')).fetch_async(10)
        project_future = Project.query().order(-Project.total).fetch_async(10)
        team_future = Team.query().order(-Team.total).fetch_async(15)
        message_future = Message.query().order(-Message.timestamp).fetch_async(
            30)

        # Julython live stuffs
        #token_key = 'live_token:%s' % request.user.username
        #token = memcache.get(token_key)
        #if token is None:
        #token = channel.create_channel(request.user.username)
        #memcache.set(token_key, token, time=7000)

        locations = location_future.get_result()
        people = people_future.get_result()
        projects = project_future.get_result()
        teams = team_future.get_result()
        message_models = message_future.get_result()

        m_list = [to_dict(m) for m in message_models]
        m_list.reverse()
        messages = json.dumps(m_list)

    ctx = Context({
        'sections': [],
        'people': people,
        'projects': projects,
        'locations': locations,
        'teams': teams,
        'stats': json.dumps(stats),
        'total': total,
        'token': token,
        'messages': messages,
        'user': request.user,
        'MEDIA_URL': settings.MEDIA_URL,
        'STATIC_URL': settings.STATIC_URL
    })

    return render_to_response('index.html', context_instance=ctx)
Exemplo n.º 14
0
 def test_make_key(self):
     key = Accumulator.make_key('test', 7)
     self.assertEqual(key.id(), 'test:7')
Exemplo n.º 15
0
def index(request):
    """Render the home page"""
    
    # For now we are just using hard coded sections
    #sections = cache.get('front_page')
    #if sections is None:
    #    sections = Section.all().order('order').fetch(10)
    #    cache.set('front_page', sections, 120)
    
    stats = []
    total = 0
    people = []
    locations = []
    projects = []
    teams = []
    messages = []
    token = ''
    
    # this is only shown on authenticated page loads
    # to save on the overhead. 
    if True:
        stats = Accumulator.get_histogram('global')
        total = sum(stats)
        location_future = Location.query().order(-Location.total).fetch_async(15)
        people_future = User.query().order(-ndb.GenericProperty('total')).fetch_async(10)
        project_future = Project.query().order(-Project.total).fetch_async(10)
        team_future = Team.query().order(-Team.total).fetch_async(15)
        message_future = Message.query().order(-Message.timestamp).fetch_async(30)
        
        # Julython live stuffs
        #token_key = 'live_token:%s' % request.user.username
        #token = memcache.get(token_key)
        #if token is None:
            #token = channel.create_channel(request.user.username)
            #memcache.set(token_key, token, time=7000)

        
        locations = location_future.get_result()
        people = people_future.get_result()
        projects = project_future.get_result()
        teams = team_future.get_result()
        message_models = message_future.get_result()
        
        m_list = [to_dict(m) for m in message_models]
        m_list.reverse()
        messages = json.dumps(m_list)
    
    ctx = Context({
        'sections': [],
        'people': people,
        'projects': projects,
        'locations': locations,
        'teams': teams,
        'stats': json.dumps(stats),
        'total': total,
        'token': token,
        'messages': messages,
        'user': request.user,
        'MEDIA_URL': settings.MEDIA_URL,
        'STATIC_URL': settings.STATIC_URL})
    
    return render_to_response('index.html', context_instance=ctx)