2010-07-25 23:13:27 -04:00
|
|
|
from django.shortcuts import get_object_or_404
|
2010-07-26 14:37:17 -04:00
|
|
|
from apps.rss_feeds.models import Feed
|
2010-07-25 23:13:27 -04:00
|
|
|
from utils import json
|
2010-07-28 18:18:01 -04:00
|
|
|
from utils.feed_functions import relative_timeuntil, relative_timesince
|
2010-07-25 23:13:27 -04:00
|
|
|
|
|
|
|
@json.json_view
|
|
|
|
def load_feed_statistics(request):
|
|
|
|
stats = dict()
|
|
|
|
feed_id = request.GET['feed_id']
|
|
|
|
feed = get_object_or_404(Feed, pk=feed_id)
|
|
|
|
|
|
|
|
# Dates of last and next update
|
2010-07-28 18:18:01 -04:00
|
|
|
stats['last_update'] = relative_timesince(feed.last_update)
|
|
|
|
stats['next_update'] = relative_timeuntil(feed.next_scheduled_update)
|
2010-07-25 23:13:27 -04:00
|
|
|
|
|
|
|
# Minutes between updates
|
2010-07-26 22:21:58 -04:00
|
|
|
update_interval_minutes, random_factor = feed.get_next_scheduled_update()
|
|
|
|
stats['update_interval_minutes'] = update_interval_minutes
|
2010-07-25 23:13:27 -04:00
|
|
|
|
|
|
|
# Stories per month - average and month-by-month breakout
|
2010-07-26 14:37:17 -04:00
|
|
|
average_stories_per_month, stories_last_year = feed.average_stories_per_month, feed.stories_last_year
|
|
|
|
stats['average_stories_per_month'] = average_stories_per_month
|
2010-07-25 23:13:27 -04:00
|
|
|
stats['stories_last_year'] = stories_last_year and json.decode(stories_last_year)
|
|
|
|
|
|
|
|
# Subscribers
|
|
|
|
stats['subscriber_count'] = feed.num_subscribers
|
|
|
|
|
2010-08-02 23:09:47 -04:00
|
|
|
print " ---> [%s] Statistics: %s" % (request.user, feed)
|
|
|
|
|
2010-07-25 23:13:27 -04:00
|
|
|
return stats
|