Example #1
0
def stats(request, service_id):
    """Create up some stats.
    """

    service = get_object_or_404(UserService, pk=service_id)
    
    if hasattr(service.auth.access_token, 'username'):
        messages.error(
           request,
           'Please use the settings page to authorise your flickr account.')
        
        return request
         

    if check_is_service_id(service, PACKAGE):
        stats = service.handler.get_stats_items(date.today() - timedelta(days=7))
        if not stats:
            return render(request, {}, 'causal/github/stats.html')
        return render(
            request,
            {
                'events' : stats['events'],
                'commits': stats['commits'],
                'avatar' : stats['avatar'],
                'commit_times' : stats['commit_times'],
                'common_time' : stats['most_common_commit_time'],
                'days_committed' : stats['days_committed'], 
                'max_commits_on_a_day' : stats['max_commits_on_a_day'],
                'repos' : stats['repos']
            },
            'causal/github/stats.html'
        )
    else:
        return redirect('/%s' % (request.user.username,))
Example #2
0
def stats(request, service_id):
    """Create up some stats."""

    service = get_object_or_404(UserService, pk=service_id)

    if check_is_service_id(service, MODULE_NAME):

        bookmarks = get_items(request.user, date.today() - timedelta(days=7), service)

        tags = {}

        for bookmark in bookmarks:
            for tag in bookmark.tags:
                if tags.has_key(tag):
                    tags[tag] = tags[tag] + 1
                else:
                    tags[tag] = 1

        return render(
            request,
            {'bookmarks': bookmarks, 'tags' : tags},
            service.template_name + '/stats.html'
        )
    else:
        return redirect('/%s' %(request.user.username))
Example #3
0
def stats(request, service_id):
    """Create up some stats.
    """

    service = get_object_or_404(UserService, pk=service_id)

    if check_is_service_id(service, PACKAGE_NAME):
        bookmarks = service.handler.get_items(date.today() - timedelta(days=7))

        tags = {}

        for bookmark in bookmarks:
            for tag in bookmark.tags:
                if tags.has_key(tag):
                    tags[tag] = tags[tag] + 1
                else:
                    tags[tag] = 1

        return render(
            request,
            {
                'bookmarks': bookmarks,
                'tags' : tags
            },
            'causal/delicious/stats.html'
        )
    else:
        return redirect('/%s' % (request.user.username,))
Example #4
0
def stats(request, service_id):
    """Display stats based on checkins.
    """

    service = get_object_or_404(UserService, pk=service_id)

    if check_is_service_id(service, PACKAGE):
        template_values = {}
        # get checkins
        checkins, categories, mayorships = service.handler.get_stats_items(date.today() - timedelta(days=7))

        template_values['checkins'] = checkins
        template_values['categories'] = categories
        template_values['mayorships'] = mayorships
        template_values['max_checkins'] = 0
        template_values['total_checkins'] = len(checkins)
        template_values['checkins_per_day'] = round((len(checkins) / 7.0), 1)

        for cat, det in categories.iteritems():
            if det['count'] > template_values['max_checkins']:
                template_values['max_checkins'] = det['count']

        return render(
            request,
            template_values,
            'causal/foursquare/stats.html'
        )
    else:
        return redirect('/%s' % (request.user.username,))
Example #5
0
def stats(request, service_id):
    """Create up some stats.
    """

    service = get_object_or_404(UserService, pk=service_id)

    if check_is_service_id(service, PACKAGE_NAME):
        shares = service.handler.get_items(date.today() - timedelta(days=7))
        sources = {}

        # Count source websites
        for share in shares:
            if sources.has_key(share.source):
                sources[share.source] = sources[share.source] + 1
            else:
                sources[share.source] = 1

        sources = SortedDict(
            sorted(sources.items(), reverse=True, key=lambda x: x[1])
        )

        return render(
            request,
            {
                'shares' : shares,
                'sources' : sources,
            },
            'causal/googlereader/stats.html'
        )
    else:
        return redirect('/%s' % (request.user.username,))
Example #6
0
def stats(request, service_id):
    """Display stats based on checkins.
    """
    service = get_object_or_404(UserService, pk=service_id)

    if check_is_service_id(service, PACKAGE_NAME):
        template_values = {}

        date_offset = date.today() - timedelta(days=7)

        template_values['favourite_artists'] = service.handler.get_artists(date_offset)
        template_values['recent_tracks'] = service.handler.get_items(date_offset)

        gig_index = 0

        for artist in template_values['favourite_artists']:
            artist.gigs = service.handler.get_upcoming_gigs(date_offset, artist.name)
            if artist.gigs:
                if not template_values.has_key('gig_centre') and \
                   artist.gigs[gig_index].location.has_key('lat') and \
                   artist.gigs[gig_index].location.has_key('long') and \
                   artist.gigs[gig_index].location['lat'] and \
                   artist.gigs[gig_index].location['long']:
                    template_values['gig_centre'] = artist.gigs[0]
                else:
                    gig_index = gig_index + 1

        return render(
            request,
            template_values,
            'causal/lastfm/stats.html'
        )
    else:
        return redirect('/%s' % (request.user.username,))
Example #7
0
def stats(request, service_id):
    """Create up some stats."""

    service = get_object_or_404(UserService, pk=service_id)    
    
    if check_is_service_id(service, MODULE_NAME):
        shares = get_items(request.user, date.today() - timedelta(days=7), service)
        sources = {}

        # count source websites
        for share in shares:
            if sources.has_key(share.source):
                sources[share.source] = sources[share.source] + 1
            else:
                sources[share.source] = 1

        sources = SortedDict(sorted(sources.items(),
                                    reverse=True, key=lambda x: x[1]))
        sources_reversed = SortedDict(sorted(sources.items(),
                                    reverse=False, key=lambda x: x[1]))

        return render(
            request,
            {'shares' : shares,
             'sources' : sources,
             'sources_reversed' : sources_reversed},
            service.template_name + '/stats.html'
        )
    else:
        return redirect('/%s' %(request.user.username))
Example #8
0
def stats(request, service_id):
    """Create up some stats."""
    
    service = get_object_or_404(UserService, pk=service_id)

    if check_is_service_id(service, PACKAGE):
        # get tweets
        tweets = service.handler.get_items(date.today() - timedelta(days=7))
        retweets = 0
        template_values = {}

        # retweet ratio
        # who you tweet the most
        ats = {}
        
        template_values['days_tweeted'] = generate_days_dict()
            
        if tweets:
            for tweet in tweets:
                if tweet.has_location():
                    template_values['tweet_centre'] = tweet
                if re.match('RT', tweet.body):
                    retweets = retweets + 1
                else:
                    atteds = re.findall('@[\w]*', tweet.body)
                    for user in atteds:
                        username = user.split('@')[1]
                        if username:
                            if ats.has_key(user):
                                ats[user]['count'] += 1
                            else:
                                ats[user] = {'avatar': 'http://api.twitter.com/1/users/profile_image/%s.json' % (username),
                                          'count' : 1
                                }
    
                if template_values['days_tweeted'].has_key(tweet.created.date()):
                    template_values['days_tweeted'][tweet.created.date()] = \
                               template_values['days_tweeted'][tweet.created.date()] + 1

            template_values['retweets'] = retweets
            template_values['non_retweets'] = len(tweets) - retweets
            template_values['total_tweets'] = len(tweets)
            template_values['tweets'] = tweets

            # order by value and reverse to put most popular at the top
            template_values['atters'] = SortedDict(
                sorted(ats.items(), reverse=True, key=lambda x: x[1]['count']))
            
            template_values['days_tweeted'] = SortedDict(sorted(template_values['days_tweeted'].items(), reverse=False, key=lambda x: x[0]))
            
            max_tweeted_on_a_day = SortedDict(sorted(template_values['days_tweeted'].items(), reverse=True, key=lambda x: x[1]))
            template_values['max_tweeted_on_a_day'] = max_tweeted_on_a_day[max_tweeted_on_a_day.keyOrder[0]] + 1
            
        return render(
            request,
            template_values,
            'causal/twitter/stats.html'
        )
    else:
        return redirect('/%s' %(request.user.username))
Example #9
0
def stats(request, service_id):
    """Create up some stats."""
    service = get_object_or_404(UserService, pk=service_id)
    if check_is_service_id(service, MODULE_NAME):
        # get tweets
        tweets = get_items(request.user, date.today() - timedelta(days=7), service)
        retweets = 0
        template_values = {}

        # retweet ratio
        # who you tweet the most
        ats = {}

        # to store a break down of tweets per day
        days = {}
        if tweets:
            for tweet in tweets:
                if tweet.has_location():
                    template_values['tweet_centre'] = tweet
                if re.match('RT', tweet.body):
                    retweets = retweets + 1
                else:
                    atteds = re.findall('@[\w]*', tweet.body)
                    for i in atteds:
                        if ats.has_key(i):
                            ats[i] = ats[i] + 1
                        else:
                            ats[i] = 1

                if days.has_key(tweet.created.strftime('%d')):
                    days[tweet.created.strftime('%d')] = \
                        days[tweet.created.strftime('%d')] + 1
                else:
                    days[tweet.created.strftime('%d')] = 1

            template_values['retweets'] = retweets
            template_values['non_retweets'] = len(tweets) - retweets
            template_values['total_tweets'] = len(tweets)
            template_values['tweets'] = tweets
            template_values['tweets_per_day'] = \
                           sorted(days.iteritems(), key=lambda (k, v) : (v, k))
            template_values['max_tweets_per_day'] = \
                           template_values['tweets_per_day'][-1][1]

            days = {}

            # tweets per day

            # order by value and reverse to put most popular at the top
            template_values['atters'] = SortedDict(
                sorted(ats.items(), reverse=True, key=lambda x: x[1]))
        return render(
            request,
            template_values,
            service.template_name + '/stats.html'
        )
    else:
        return redirect('/%s' %(request.user.username))
Example #10
0
def stats(request, service_id):
    """Create up some stats."""

    service = get_object_or_404(UserService, pk=service_id)
    
    if check_is_service_id(service, MODULE_NAME):
        pictures = get_stats_items(request.user,
                             date.today() - timedelta(days=7),
                             service)
        template_values = {}
        # most commented
        comments = 0
        template_values['most_commented_picture'] = None
        template_values['number_of_pictures_favorites'] = 0
        template_values['cameras_used'] = {}
        number_of_pictures_favorites = 0
        for pic in pictures:

            if pic.has_location():
                template_values['pic_centre'] = pic

            if pic.favorite:
                template_values['number_of_pictures_favorites'] = \
                               number_of_pictures_favorites + 1
                
            if hasattr(pic, 'number_of_comments'):
                if pic.number_of_comments > comments:
                    comments = pic.number_of_comments
                    template_values['most_commented_picture'] = pic

            # get camera used count
            if template_values['cameras_used'].has_key(hasattr(pic, 'camera_make')):
                template_values['cameras_used'][pic.camera_make] = \
                               template_values['cameras_used'][pic.camera_make] + 1
            else:
                if hasattr(pic, 'camera_make'):
                    template_values['cameras_used'][pic.camera_make] = 1

        template_values['pictures'] = pictures
        template_values['number_of_pictures_uploaded'] = len(pictures)

        if template_values['number_of_pictures_favorites'] == 0:
            template_values['number_of_pictures_favorites'] = "No favourite pictures this week."

        return render(
            request,
            template_values,
            service.template_name + '/stats.html'
        )
    else:
        return redirect('/%s' %(request.user.username))
Example #11
0
def stats(request, service_id):
    """Display stats based on checkins."""

    service = get_object_or_404(UserService, pk=service_id)

    if check_is_service_id(service, PACKAGE):
        items = service.handler.get_stats_items(date.today() - timedelta(days=7))
        return render(
            request,
            {'results' : items},
            'causal/facebook/stats.html'
        )
    
    else:
        return redirect('/%s' %(request.user.username))
Example #12
0
def stats(request, service_id):
    """Create up some stats."""

    service = get_object_or_404(UserService, pk=service_id)

    if check_is_service_id(service, MODULE_NAME):
        commits, avatar, commit_times = get_stats_items(request.user, date.today() - timedelta(days=7), service)

        return render(
            request,
            {'commits': commits,
             'avatar' : avatar,
             'commit_times' : commit_times},
            service.template_name + '/stats.html'
        )
    else:
        return redirect('/%s' %(request.user.username))
Example #13
0
def stats(request, service_id):
    """Display stats based on checkins."""

    service = get_object_or_404(UserService, pk=service_id)

    if check_is_service_id(service, MODULE_NAME):
        links, statuses, details, photos, checkins = get_stats_items(request.user, date.today() - timedelta(days=7), service)
        return render(
            request,
            {'links' : links,
             'statuses' : statuses,
             'details' : details,
             'photos': photos,
             'checkins' : checkins,
             },
            service.template_name + '/stats.html'
        )
    else:
        return redirect('/%s' %(request.user.username))
Example #14
0
def stats(request, service_id):
    """Display stats based on checkins."""
    service = get_object_or_404(UserService, pk=service_id)

    if check_is_service_id(service, MODULE_NAME):
        template_values = {}
        # get checkins
        checkins = get_items(request.user,
                             date.today() - timedelta(days=7), service)

        template_values['checkins'] = checkins

        return render(
            request,
            template_values,
            service.template_name + '/stats.html'
        )
    else:
        return redirect('/%s' %(request.user.username))
Example #15
0
def stats(request, service_id):
    """Create up some stats."""

    service = get_object_or_404(UserService, pk=service_id)

    if check_is_service_id(service, MODULE_NAME):
        try:
            posts = get_items(request.user,
                              date.today() - timedelta(days=7), service)
        except:
            messages.error(request, 'There was an error connnecting to Tumblr.')

        return render(
            request,
            {'posts': posts},
            service.template_name + '/stats.html'
        )
    else:
        return redirect('/%s' %(request.user.username))
Example #16
0
def stats(request, service_id):
    """Display stats based on checkins."""

    service = get_object_or_404(UserService, pk=service_id)

    if check_is_service_id(service, PACKAGE):
        links, statuses, details, photos, checkins, likes = service.handler.get_stats_items(date.today() - timedelta(days=7))
        return render(
            request,
            {'links' : links,
             'statuses' : statuses,
             'details' : details,
             'photos': photos,
             'checkins' : checkins,
             'likes' : likes,
             },
            'causal/facebook/stats.html'
        )
    else:
        return redirect('/%s' %(request.user.username))
Example #17
0
def stats(request, service_id):
    """Create up some stats.
    """

    service = get_object_or_404(UserService, pk=service_id)

    if check_is_service_id(service, PACKAGE):
        commits, avatar, commit_times, common_time, days_committed, max_commits_on_a_day = service.handler.get_stats_items(date.today() - timedelta(days=7))

        return render(
            request,
            {
                'commits': commits,
                'avatar' : avatar,
                'commit_times' : commit_times,
                'common_time' : common_time,
                'days_committed' : days_committed, 
                'max_commits_on_a_day' : max_commits_on_a_day
            },
            'causal/github/stats.html'
        )
    else:
        return redirect('/%s' % (request.user.username,))
Example #18
0
def stats(request, service_id):
    """Create up some stats.
    """

    service = get_object_or_404(UserService, pk=service_id)

    if check_is_service_id(service, PACKAGE_NAME):
        pictures = service.handler.get_stats_items(date.today() - timedelta(days=7))
        template_values = {}
        # Most commented
        comments = 0
        template_values["most_commented_picture"] = None
        template_values["number_of_pictures_favorites"] = 0
        template_values["cameras_used"] = {}
        template_values["days_taken"] = generate_days_dict()

        number_of_pictures_favorites = 0

        for pic in pictures:
            if pic.has_location():
                template_values["pic_centre"] = pic

            if pic.favorite:
                template_values["number_of_pictures_favorites"] = number_of_pictures_favorites + 1

            if hasattr(pic, "number_of_comments"):
                if int(pic.number_of_comments) > comments:
                    comments = pic.number_of_comments
                    template_values["most_commented_picture"] = pic

            # Get camera used count
            if template_values["cameras_used"].has_key(pic.camera_make + " - " + pic.camera_model):
                template_values["cameras_used"][pic.camera_make + " - " + pic.camera_model] = (
                    template_values["cameras_used"][pic.camera_make + " - " + pic.camera_model] + 1
                )
            else:
                if hasattr(pic, "camera_make"):
                    template_values["cameras_used"][pic.camera_make + " - " + pic.camera_model] = 1

            if template_values["days_taken"].has_key(pic.created.date()):
                template_values["days_taken"][pic.created.date()] = (
                    template_values["days_taken"][pic.created.date()] + 1
                )

        template_values["cameras_used"] = SortedDict(
            sorted(template_values["cameras_used"].items(), reverse=True, key=lambda x: x[1])
        )
        template_values["pictures"] = pictures
        template_values["number_of_pictures_uploaded"] = len(pictures)
        template_values["days_taken"] = SortedDict(
            sorted(template_values["days_taken"].items(), reverse=False, key=lambda x: x[0])
        )

        max_taken_on_a_day = SortedDict(sorted(template_values["days_taken"].items(), reverse=True, key=lambda x: x[1]))
        template_values["max_taken_on_a_day"] = max_taken_on_a_day[max_taken_on_a_day.keyOrder[0]] + 1

        if template_values["number_of_pictures_favorites"] == 0:
            template_values["number_of_pictures_favorites"] = "No favourite pictures this week."

        return render(request, template_values, "causal/flickr/stats.html")
    else:
        return redirect("/%s" % (request.user.username,))