Adding feed update interval for non-premium users in Statistics.

This commit is contained in:
Samuel Clay 2012-01-13 17:54:17 -08:00
parent 5ac3c39da0
commit edb76d8c83
5 changed files with 82 additions and 50 deletions

View file

@ -83,8 +83,16 @@ def load_feed_statistics(request, feed_id):
stats['next_update'] = relative_timeuntil(feed.next_scheduled_update)
# Minutes between updates
update_interval_minutes, random_factor = feed.get_next_scheduled_update(force=True)
update_interval_minutes, _ = feed.get_next_scheduled_update(force=True)
stats['update_interval_minutes'] = update_interval_minutes
original_active_premium_subscribers = feed.active_premium_subscribers
original_premium_subscribers = feed.premium_subscribers
feed.active_premium_subscribers = max(feed.active_premium_subscribers+1, 1)
feed.premium_subscribers += 1
premium_update_interval_minutes, _ = feed.get_next_scheduled_update(force=True)
feed.active_premium_subscribers = original_active_premium_subscribers
feed.premium_subscribers = original_premium_subscribers
stats['premium_update_interval_minutes'] = premium_update_interval_minutes
# Stories per month - average and month-by-month breakout
average_stories_per_month, story_count_history = feed.average_stories_per_month, feed.data.story_count_history

1
fabfile.py vendored
View file

@ -148,7 +148,6 @@ def kill_celery():
run('ps aux | grep celeryd | egrep -v grep | awk \'{print $2}\' | sudo xargs kill -9')
def compress_assets():
local('rm -fr static/*')
local('jammit -c assets.yml --base-url http://www.newsblur.com --output static')
local('tar -czf static.tar static/*')

View file

@ -4480,6 +4480,21 @@ background: transparent;
float: left;
width: 33%;
text-align: center;
overflow: hidden;
margin: 0 0 12px 0;
}
.NB-modal-statistics .NB-statistics-premium-stats {
border-top: 1px solid #E0E0E0;
padding: 12px 0 0;
margin: 0 12px;
clear: both;
text-align: center;
}
.NB-modal-statistics .NB-statistics-premium-stats .NB-statistics-update {
width: auto;
margin: 0;
padding: 0;
float: none;
}
.NB-modal-statistics .NB-statistics-stat .NB-statistics-fetches-half {

View file

@ -24,6 +24,7 @@ _.extend(NEWSBLUR.ReaderStatistics.prototype, {
self.get_stats();
}, 50);
this.$modal.bind('click', $.rescope(this.handle_click, this));
this.$modal.bind('change', $.rescope(this.handle_change, this));
},
@ -48,40 +49,11 @@ _.extend(NEWSBLUR.ReaderStatistics.prototype, {
var $stats = this.make_stats({
'last_update': '',
'next_update': ''
'next_update': '',
'premium_interval': ''
});
$('.NB-modal-statistics-info', this.$modal).replaceWith($stats);
},
open_modal: function() {
var self = this;
this.$modal.modal({
'minWidth': 600,
'maxWidth': 600,
'minHeight': 425,
'overlayClose': true,
'autoResize': true,
'onOpen': function (dialog) {
dialog.overlay.fadeIn(200, function () {
dialog.container.fadeIn(200);
dialog.data.fadeIn(200);
});
},
'onShow': function(dialog) {
$('#simplemodal-container').corner('6px');
},
'onClose': function(dialog) {
dialog.data.hide().empty().remove();
dialog.container.hide().empty().remove();
dialog.overlay.fadeOut(200, function() {
dialog.overlay.empty().remove();
$.modal.close();
});
$('.NB-modal-holder').empty().remove();
}
});
},
get_stats: function() {
var $loading = $('.NB-modal-loading', this.$modal);
@ -98,20 +70,7 @@ _.extend(NEWSBLUR.ReaderStatistics.prototype, {
var $loading = $('.NB-modal-loading', this.$modal);
$loading.removeClass('NB-active');
var interval_start = data['update_interval_minutes'];
var interval_end = data['update_interval_minutes'] * 1.25;
var interval = '';
if (interval_start < 60) {
interval = interval_start + ' to ' + interval_end + ' minutes';
} else {
var interval_start_hours = parseInt(interval_start / 60, 10);
var interval_end_hours = parseInt(interval_end / 60, 10);
var dec_start = interval_start % 60;
var dec_end = interval_end % 60;
interval = interval_start_hours + (dec_start >= 30 ? '.5' : '') + ' to ' + interval_end_hours + (dec_end >= 30 || interval_start_hours == interval_end_hours ? '.5' : '') + ' hours';
}
var $stats = this.make_stats(data, interval);
var $stats = this.make_stats(data);
$('.NB-modal-statistics-info', this.$modal).replaceWith($stats);
setTimeout(function() {
@ -124,6 +83,9 @@ _.extend(NEWSBLUR.ReaderStatistics.prototype, {
},
make_stats: function(data, interval) {
var update_interval = this.calculate_update_interval(data['update_interval_minutes']);
var premium_update_interval = this.calculate_update_interval(data['premium_update_interval_minutes']);
var $stats = $.make('div', { className: 'NB-modal-statistics-info' }, [
$.make('div', { className: 'NB-statistics-stat NB-statistics-updates'}, [
$.make('div', { className: 'NB-statistics-update'}, [
@ -132,12 +94,24 @@ _.extend(NEWSBLUR.ReaderStatistics.prototype, {
]),
$.make('div', { className: 'NB-statistics-update'}, [
$.make('div', { className: 'NB-statistics-label' }, 'Every'),
$.make('div', { className: 'NB-statistics-count' }, interval)
$.make('div', { className: 'NB-statistics-count' }, update_interval)
]),
$.make('div', { className: 'NB-statistics-update'}, [
$.make('div', { className: 'NB-statistics-label' }, 'Next Update'),
$.make('div', { className: 'NB-statistics-count' }, '&nbsp;' + (data['next_update'] && ('in ' + data['next_update'])))
])
]),
(!NEWSBLUR.Globals.is_premium && $.make('div', { className: 'NB-statistics-premium-stats' }, [
$.make('div', { className: 'NB-statistics-update'}, [
$.make('div', { className: 'NB-statistics-label' }, [
'If you went ',
$.make('a', { href: '#', className: 'NB-premium-link NB-splash-link' }, 'premium'),
', ',
$.make('br'),
'this site would update every'
]),
$.make('div', { className: 'NB-statistics-count' }, premium_update_interval)
])
]))
]),
$.make('div', { className: 'NB-statistics-stat NB-statistics-history'}, [
$.make('div', { className: 'NB-statistics-history-stat' }, [
@ -166,6 +140,23 @@ _.extend(NEWSBLUR.ReaderStatistics.prototype, {
return $stats;
},
calculate_update_interval: function(update_interval_minutes) {
var interval_start = update_interval_minutes;
var interval_end = update_interval_minutes * 1.25;
var interval = '';
if (interval_start < 60) {
interval = interval_start + ' to ' + interval_end + ' minutes';
} else {
var interval_start_hours = parseInt(interval_start / 60, 10);
var interval_end_hours = parseInt(interval_end / 60, 10);
var dec_start = interval_start % 60;
var dec_end = interval_end % 60;
interval = interval_start_hours + (dec_start >= 30 ? '.5' : '') + ' to ' + interval_end_hours + (dec_end >= 30 || interval_start_hours == interval_end_hours ? '.5' : '') + ' hours';
}
return interval;
},
make_classifier_count: function(facet, data) {
var self = this;
if (!data) return;
@ -256,6 +247,16 @@ _.extend(NEWSBLUR.ReaderStatistics.prototype, {
});
},
close_and_load_premium: function() {
this.close(function() {
NEWSBLUR.reader.open_feedchooser_modal();
});
},
// ===========
// = Actions =
// ===========
handle_change: function(elem, e) {
var self = this;
@ -265,6 +266,15 @@ _.extend(NEWSBLUR.ReaderStatistics.prototype, {
self.initialize_feed(feed_id);
self.get_stats();
});
},
handle_click: function(elem, e) {
var self = this;
$.targetIs(e, { tagSelector: '.NB-premium-link' }, function($t, $p) {
e.preventDefault();
self.close_and_load_premium();
});
}
});

View file

@ -136,7 +136,7 @@ def json_view(func):
'text': unicode(e)}
code = 500
else:
raise
print '\n'.join(traceback.format_exception(*exc_info))
if isinstance(response, HttpResponseForbidden):
return response