mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Retrain classifiers at the end of the trainer.
This commit is contained in:
parent
9b1a873084
commit
b08332e3b6
6 changed files with 62 additions and 22 deletions
|
@ -24,5 +24,6 @@ urlpatterns = patterns('',
|
||||||
url(r'^save_feed_order', views.save_feed_order, name='save-feed-order'),
|
url(r'^save_feed_order', views.save_feed_order, name='save-feed-order'),
|
||||||
url(r'^get_feeds_trainer', views.get_feeds_trainer, name='get-feeds-trainer'),
|
url(r'^get_feeds_trainer', views.get_feeds_trainer, name='get-feeds-trainer'),
|
||||||
url(r'^save_feed_chooser', views.save_feed_chooser, name='save-feed-chooser'),
|
url(r'^save_feed_chooser', views.save_feed_chooser, name='save-feed-chooser'),
|
||||||
|
url(r'^retrain_all_sites', views.retrain_all_sites, name='retrain-all-sites'),
|
||||||
url(r'^buster', views.iframe_buster, name='iframe-buster'),
|
url(r'^buster', views.iframe_buster, name='iframe-buster'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -602,17 +602,6 @@ def get_feeds_trainer(request):
|
||||||
|
|
||||||
return classifiers
|
return classifiers
|
||||||
|
|
||||||
@login_required
|
|
||||||
def login_as(request):
|
|
||||||
if not request.user.is_staff:
|
|
||||||
assert False
|
|
||||||
return HttpResponseForbidden()
|
|
||||||
username = request.GET['user']
|
|
||||||
user = get_object_or_404(User, username=username)
|
|
||||||
user.backend = settings.AUTHENTICATION_BACKENDS[0]
|
|
||||||
login_user(request, user)
|
|
||||||
return HttpResponseRedirect(reverse('index'))
|
|
||||||
|
|
||||||
@ajax_login_required
|
@ajax_login_required
|
||||||
@json.json_view
|
@json.json_view
|
||||||
def save_feed_chooser(request):
|
def save_feed_chooser(request):
|
||||||
|
@ -637,6 +626,14 @@ def save_feed_chooser(request):
|
||||||
usersubs.count()))
|
usersubs.count()))
|
||||||
return {'activated': activated}
|
return {'activated': activated}
|
||||||
|
|
||||||
|
@ajax_login_required
|
||||||
|
def retrain_all_sites(request):
|
||||||
|
for sub in UserSubscription.objects.filter(user=request.user):
|
||||||
|
sub.is_trained = False
|
||||||
|
sub.save()
|
||||||
|
|
||||||
|
return get_feeds_trainer(request)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def activate_premium_account(request):
|
def activate_premium_account(request):
|
||||||
try:
|
try:
|
||||||
|
@ -657,6 +654,18 @@ def activate_premium_account(request):
|
||||||
|
|
||||||
return HttpResponseRedirect(reverse('index'))
|
return HttpResponseRedirect(reverse('index'))
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def login_as(request):
|
||||||
|
if not request.user.is_staff:
|
||||||
|
logging.info(' ---> NON-STAFF LOGGING IN AS ANOTHER USER: %s' % request.user)
|
||||||
|
assert False
|
||||||
|
return HttpResponseForbidden()
|
||||||
|
username = request.GET['user']
|
||||||
|
user = get_object_or_404(User, username=username)
|
||||||
|
user.backend = settings.AUTHENTICATION_BACKENDS[0]
|
||||||
|
login_user(request, user)
|
||||||
|
return HttpResponseRedirect(reverse('index'))
|
||||||
|
|
||||||
def iframe_buster(request):
|
def iframe_buster(request):
|
||||||
logging.info(" ---> [%s] iFrame bust!" % (request.user,))
|
logging.info(" ---> [%s] iFrame bust!" % (request.user,))
|
||||||
return HttpResponse(status=204)
|
return HttpResponse(status=204)
|
|
@ -1821,7 +1821,8 @@ a.NB-splash-link:hover {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.NB-modal-submit .NB-modal-submit-back {
|
.NB-modal-submit .NB-modal-submit-back,
|
||||||
|
.NB-modal-submit .NB-modal-submit-reset {
|
||||||
background-color: #d5d4dB;
|
background-color: #d5d4dB;
|
||||||
color: #909090;
|
color: #909090;
|
||||||
|
|
||||||
|
@ -1964,7 +1965,8 @@ a.NB-splash-link:hover {
|
||||||
/* = Classifier Trainer = */
|
/* = Classifier Trainer = */
|
||||||
/* ====================== */
|
/* ====================== */
|
||||||
|
|
||||||
.NB-modal-trainer .NB-modal-submit .NB-modal-submit-back {
|
.NB-modal-trainer .NB-modal-submit .NB-modal-submit-back,
|
||||||
|
.NB-modal-trainer .NB-modal-submit .NB-modal-submit-reset {
|
||||||
float: left;
|
float: left;
|
||||||
color: #FFF;
|
color: #FFF;
|
||||||
background-color: #b5b4bB;
|
background-color: #b5b4bB;
|
||||||
|
|
|
@ -231,6 +231,18 @@ NEWSBLUR.AssetModel.Reader.prototype = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
retrain_all_sites: function(callback) {
|
||||||
|
var self = this;
|
||||||
|
var params = {};
|
||||||
|
|
||||||
|
if (NEWSBLUR.Globals.is_authenticated) {
|
||||||
|
this.make_request('/reader/retrain_all_sites', params, callback, null);
|
||||||
|
} else {
|
||||||
|
if ($.isFunction(callback)) callback();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
refresh_feeds: function(callback, has_unfetched_feeds) {
|
refresh_feeds: function(callback, has_unfetched_feeds) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
|
|
@ -3284,7 +3284,6 @@
|
||||||
this.$s.$feed_link_loader.fadeOut(250);
|
this.$s.$feed_link_loader.fadeOut(250);
|
||||||
this.setup_feed_refresh();
|
this.setup_feed_refresh();
|
||||||
if (!this.flags['has_unfetched_feeds']) {
|
if (!this.flags['has_unfetched_feeds']) {
|
||||||
NEWSBLUR.log(['has_unfetched_feeds']);
|
|
||||||
this.hide_progress_bar();
|
this.hide_progress_bar();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -63,8 +63,10 @@ NEWSBLUR.ReaderClassifierStory = function(story_id, feed_id, options) {
|
||||||
|
|
||||||
var classifier_prototype = {
|
var classifier_prototype = {
|
||||||
|
|
||||||
runner_trainer: function() {
|
runner_trainer: function(reload) {
|
||||||
|
if (!reload) {
|
||||||
this.user_classifiers = {};
|
this.user_classifiers = {};
|
||||||
|
}
|
||||||
|
|
||||||
this.make_trainer_intro();
|
this.make_trainer_intro();
|
||||||
this.get_feeds_trainer();
|
this.get_feeds_trainer();
|
||||||
|
@ -113,7 +115,7 @@ var classifier_prototype = {
|
||||||
var trainer_data_length = this.trainer_data.length;
|
var trainer_data_length = this.trainer_data.length;
|
||||||
this.trainer_iterator = this.trainer_iterator - 1;
|
this.trainer_iterator = this.trainer_iterator - 1;
|
||||||
var trainer_data = this.trainer_data[this.trainer_iterator];
|
var trainer_data = this.trainer_data[this.trainer_iterator];
|
||||||
NEWSBLUR.log(['load_previous_feed_in_trainer', this.trainer_iterator, trainer_data]);
|
// NEWSBLUR.log(['load_previous_feed_in_trainer', this.trainer_iterator, trainer_data]);
|
||||||
if (!trainer_data || this.trainer_iterator < 0) {
|
if (!trainer_data || this.trainer_iterator < 0) {
|
||||||
this.make_trainer_intro();
|
this.make_trainer_intro();
|
||||||
this.reload_modal();
|
this.reload_modal();
|
||||||
|
@ -123,11 +125,11 @@ var classifier_prototype = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
load_next_feed_in_trainer: function(backwards) {
|
load_next_feed_in_trainer: function() {
|
||||||
var trainer_data_length = this.trainer_data.length;
|
var trainer_data_length = this.trainer_data.length;
|
||||||
this.trainer_iterator = this.trainer_iterator + 1;
|
this.trainer_iterator = this.trainer_iterator + 1;
|
||||||
var trainer_data = this.trainer_data[this.trainer_iterator];
|
var trainer_data = this.trainer_data[this.trainer_iterator];
|
||||||
NEWSBLUR.log(['load_next_feed_in_trainer', this.trainer_iterator, trainer_data]);
|
// NEWSBLUR.log(['load_next_feed_in_trainer', this.trainer_iterator, trainer_data]);
|
||||||
if (!trainer_data || this.trainer_iterator >= trainer_data_length) {
|
if (!trainer_data || this.trainer_iterator >= trainer_data_length) {
|
||||||
this.make_trainer_outro();
|
this.make_trainer_outro();
|
||||||
this.reload_modal();
|
this.reload_modal();
|
||||||
|
@ -157,7 +159,7 @@ var classifier_prototype = {
|
||||||
this.reload_modal();
|
this.reload_modal();
|
||||||
},
|
},
|
||||||
|
|
||||||
reload_modal: function() {
|
reload_modal: function(callback) {
|
||||||
this.flags.modal_loading = setInterval(_.bind(function() {
|
this.flags.modal_loading = setInterval(_.bind(function() {
|
||||||
if (this.flags.modal_loaded) {
|
if (this.flags.modal_loaded) {
|
||||||
clearInterval(this.flags.modal_loading);
|
clearInterval(this.flags.modal_loading);
|
||||||
|
@ -166,6 +168,7 @@ var classifier_prototype = {
|
||||||
$(window).trigger('resize.simplemodal');
|
$(window).trigger('resize.simplemodal');
|
||||||
this.handle_cancel();
|
this.handle_cancel();
|
||||||
this.$modal.parent().scrollTop(0);
|
this.$modal.parent().scrollTop(0);
|
||||||
|
callback && callback();
|
||||||
}
|
}
|
||||||
}, this), 125);
|
}, this), 125);
|
||||||
},
|
},
|
||||||
|
@ -177,7 +180,6 @@ var classifier_prototype = {
|
||||||
load_feeds_trainer: function(e, data) {
|
load_feeds_trainer: function(e, data) {
|
||||||
var $begin = $('.NB-modal-submit-begin', this.$modal);
|
var $begin = $('.NB-modal-submit-begin', this.$modal);
|
||||||
|
|
||||||
NEWSBLUR.log(['data', data]);
|
|
||||||
this.trainer_data = data;
|
this.trainer_data = data;
|
||||||
|
|
||||||
if (!data || !data.length) {
|
if (!data || !data.length) {
|
||||||
|
@ -191,6 +193,15 @@ var classifier_prototype = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
retrain_all_sites: function() {
|
||||||
|
$('.NB-modal-submit-reset', this.$modal).text('Rewinding...').attr('disabled', true).addClass('NB-disabled');
|
||||||
|
|
||||||
|
this.model.retrain_all_sites(_.bind(function(data) {
|
||||||
|
this.load_feeds_trainer(null, data);
|
||||||
|
this.load_next_feed_in_trainer();
|
||||||
|
}, this));
|
||||||
|
},
|
||||||
|
|
||||||
find_story_and_feed: function() {
|
find_story_and_feed: function() {
|
||||||
if (this.story_id) {
|
if (this.story_id) {
|
||||||
this.story = this.model.get_story(this.story_id);
|
this.story = this.model.get_story(this.story_id);
|
||||||
|
@ -300,6 +311,7 @@ var classifier_prototype = {
|
||||||
])
|
])
|
||||||
]),
|
]),
|
||||||
$.make('div', { className: 'NB-modal-submit' }, [
|
$.make('div', { className: 'NB-modal-submit' }, [
|
||||||
|
$.make('a', { href: '#', className: 'NB-modal-submit-button NB-modal-submit-reset' }, $.entity('«') + ' Retrain all sites'),
|
||||||
$.make('a', { href: '#', className: 'NB-modal-submit-end NB-modal-submit-button' }, 'Close Training and Start Reading')
|
$.make('a', { href: '#', className: 'NB-modal-submit-end NB-modal-submit-button' }, 'Close Training and Start Reading')
|
||||||
])
|
])
|
||||||
]);
|
]);
|
||||||
|
@ -747,6 +759,11 @@ var classifier_prototype = {
|
||||||
self.load_previous_feed_in_trainer();
|
self.load_previous_feed_in_trainer();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$.targetIs(e, { tagSelector: '.NB-modal-submit-reset' }, function($t, $p){
|
||||||
|
e.preventDefault();
|
||||||
|
self.retrain_all_sites();
|
||||||
|
});
|
||||||
|
|
||||||
$.targetIs(e, { tagSelector: '.NB-modal-submit-close' }, function($t, $p){
|
$.targetIs(e, { tagSelector: '.NB-modal-submit-close' }, function($t, $p){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
self.save_publisher();
|
self.save_publisher();
|
||||||
|
|
Loading…
Add table
Reference in a new issue