Updating read counts and story intelligence status on training.

This commit is contained in:
Samuel Clay 2012-05-25 22:13:50 -07:00
parent 14755d5e88
commit 15943bb2b9
10 changed files with 68 additions and 55 deletions

View file

@ -126,6 +126,8 @@ def get_classifiers_for_user(user, feed_id=None, social_user_id=None, classifier
params['feed_id__in'] = feed_id
if social_user_id:
params['social_user_id'] = int(social_user_id.replace('social:', ''))
elif feed_id:
params['social_user_id'] = 0
if classifier_feeds is None:
classifier_feeds = list(MClassifierFeed.objects(**params))

View file

@ -78,9 +78,9 @@ def save_classifier(request):
if content_type == 'feed':
if not post_content.startswith('social:'):
classifier_dict['feed_id'] = post_content
print classifier_dict
# try:
classifier, created = ClassifierCls.objects.get_or_create(**classifier_dict)
print classifier_dict, classifier, created
# except OperationError:
# continue
if score == 0:

View file

@ -301,7 +301,7 @@ class UserSubscription(models.Model):
# if not silent:
# logging.info(' ---> [%s] Format stories: %s' % (self.user, datetime.datetime.now() - now))
classifier_feeds = list(MClassifierFeed.objects(user_id=self.user_id, feed_id=self.feed_id))
classifier_feeds = list(MClassifierFeed.objects(user_id=self.user_id, feed_id=self.feed_id, social_user_id=0))
classifier_authors = list(MClassifierAuthor.objects(user_id=self.user_id, feed_id=self.feed_id))
classifier_titles = list(MClassifierTitle.objects(user_id=self.user_id, feed_id=self.feed_id))
classifier_tags = list(MClassifierTag.objects(user_id=self.user_id, feed_id=self.feed_id))

View file

@ -388,7 +388,7 @@ def load_single_feed(request, feed_id):
logging.user(request, "~BR~FK~SBRedis is unavailable for shared stories.")
# Get intelligence classifier for user
classifier_feeds = list(MClassifierFeed.objects(user_id=user.pk, feed_id=feed_id))
classifier_feeds = list(MClassifierFeed.objects(user_id=user.pk, feed_id=feed_id, social_user_id=0))
classifier_authors = list(MClassifierAuthor.objects(user_id=user.pk, feed_id=feed_id))
classifier_titles = list(MClassifierTitle.objects(user_id=user.pk, feed_id=feed_id))
classifier_tags = list(MClassifierTag.objects(user_id=user.pk, feed_id=feed_id))
@ -900,7 +900,6 @@ def add_url(request):
code = 0
url = request.POST['url']
auto_active = is_true(request.POST.get('auto_active', True))
print auto_active
if not url:
code = -1

View file

@ -1132,7 +1132,12 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
recalculate_story_scores: function(feed_id) {
this.stories.each(_.bind(function(story, i) {
if (story.get('story_feed_id') != feed_id) return;
var intelligence = _.extend({}, this.defaults.classifiers);
var intelligence = {
author: 0,
feed: 0,
tags: 0,
title: 0
};
_.each(this.classifiers[feed_id].titles, _.bind(function(classifier_score, classifier_title) {
if (story.get('story_title', '').indexOf(classifier_title) != -1) {

View file

@ -83,7 +83,7 @@ NEWSBLUR.Collections.Stories = Backbone.Collection.extend({
mark_unread: function(story, options) {
options = options || {};
NEWSBLUR.assets.mark_story_as_unread(story.id, story.get('story_feed_id'), function(read) {
NEWSBLUR.reader.update_read_count(story.id, story.get('story_feed_id'));
NEWSBLUR.reader.update_read_count(story.id, story.get('story_feed_id'), {unread: true});
});
story.set('read_status', 0);
},
@ -150,6 +150,7 @@ NEWSBLUR.Collections.Stories = Backbone.Collection.extend({
if (selected_story.get('selected')) {
this.deselect(selected_story);
this.active_story = selected_story;
NEWSBLUR.reader.active_story = selected_story;
if (!selected_story.get('read_status')) {
this.mark_read(selected_story);
}

View file

@ -1368,6 +1368,8 @@
this.active_feed = null;
this.active_story = null;
NEWSBLUR.assets.stories.reset();
},
open_feed: function(feed_id, options) {
@ -1397,6 +1399,8 @@
if (NEWSBLUR.app.story_unread_counter) {
NEWSBLUR.app.story_unread_counter.remove();
}
NEWSBLUR.app.story_titles.show_loading();
// this.show_stories_progress_bar();
this.iframe_scroll = null;
this.set_correct_story_view_for_feed(feed.id);
@ -2598,41 +2602,41 @@
feed_id = feed_id || this.active_feed;
this.model.recalculate_story_scores(feed_id);
var replace_stories = _.bind(function($story, story_id) {
var story = this.model.get_story(story_id);
if (story.get('story_feed_id') != feed_id) return;
var score = this.compute_story_score(story);
$story.removeClass('NB-story-positive')
.removeClass('NB-story-neutral')
.removeClass('NB-story-negative');
if (score > 0) {
$story.addClass('NB-story-positive');
} else if (score == 0) {
$story.addClass('NB-story-neutral');
} else if (score < 0) {
$story.addClass('NB-story-negative');
}
NEWSBLUR.log(['story recalculation', story, story.get('read_status'), $story]);
// $story.toggleClass('read', !story.get('read_status'));
$('.NB-feed-story-tags', $story).replaceWith(this.make_story_feed_tags(story));
$('.NB-feed-story-author', $story).replaceWith(this.make_story_feed_author(story));
$('.NB-feed-story-title', $story).replaceWith(this.make_story_feed_title(story));
if (this.model.preference('new_window') == 1) {
$('a', $story).attr('target', '_blank');
}
}, this);
_.each(this.cache.feed_view_stories, _.bind(function($story, story_id) {
replace_stories($story, story_id);
}));
$('.story', this.$s.$story_titles).each(function() {
var $story = $(this);
var story_id = $story.data('story_id');
replace_stories($story, story_id);
});
//
// var replace_stories = _.bind(function($story, story_id) {
// var story = this.model.get_story(story_id);
// if (story.get('story_feed_id') != feed_id) return;
// var score = this.compute_story_score(story);
// $story.removeClass('NB-story-positive')
// .removeClass('NB-story-neutral')
// .removeClass('NB-story-negative');
// if (score > 0) {
// $story.addClass('NB-story-positive');
// } else if (score == 0) {
// $story.addClass('NB-story-neutral');
// } else if (score < 0) {
// $story.addClass('NB-story-negative');
// }
// NEWSBLUR.log(['story recalculation', story, story.get('read_status'), $story]);
// // $story.toggleClass('read', !story.get('read_status'));
// $('.NB-feed-story-tags', $story).replaceWith(this.make_story_feed_tags(story));
// $('.NB-feed-story-author', $story).replaceWith(this.make_story_feed_author(story));
// $('.NB-feed-story-title', $story).replaceWith(this.make_story_feed_title(story));
//
// if (this.model.preference('new_window') == 1) {
// $('a', $story).attr('target', '_blank');
// }
// }, this);
//
// _.each(this.cache.feed_view_stories, _.bind(function($story, story_id) {
// replace_stories($story, story_id);
// }));
//
// $('.story', this.$s.$story_titles).each(function() {
// var $story = $(this);
// var story_id = $story.data('story_id');
// replace_stories($story, story_id);
// });
},
// =================================
@ -3173,9 +3177,9 @@
this.model.classifiers[feed_id][type+'s'][value] = score;
this.model.save_classifier(data, _.bind(function(resp) {
this.model.recalculate_story_scores(feed_id);
this.force_feeds_refresh(callback, true, feed_id);
}, this));
this.recalculate_story_scores(feed_id);
},
show_correct_feed_in_feed_title_floater: function(story) {

View file

@ -424,32 +424,32 @@ var classifier_prototype = {
// NEWSBLUR.log(['Make Story', story, feed]);
// HTML entities decoding.
story.story_title = $('<div/>').html(story.story_title).text();
story_title = _.string.trim($('<div/>').html(story.get('story_title')).text());
this.$modal = $.make('div', { className: 'NB-modal-classifiers NB-modal' }, [
$.make('h2', { className: 'NB-modal-title' }),
(this.options['feed_loaded'] &&
$.make('form', { method: 'post' }, [
(story.story_title && $.make('div', { className: 'NB-modal-field NB-fieldset' }, [
(story_title && $.make('div', { className: 'NB-modal-field NB-fieldset' }, [
$.make('h5', 'Story Title'),
$.make('div', { className: 'NB-fieldset-fields NB-classifiers' }, [
$.make('input', { type: 'text', value: story.story_title, className: 'NB-classifier-title-highlight' }),
$.make('input', { type: 'text', value: story_title, className: 'NB-classifier-title-highlight' }),
this.make_classifier('<span class="NB-classifier-title-placeholder">Highlight phrases to look for in future stories</span>', '', 'title'),
$.make('span',
this.make_user_titles(story.story_title)
this.make_user_titles(story_title)
)
])
])),
(story.story_authors && $.make('div', { className: 'NB-modal-field NB-fieldset' }, [
(story.get('story_authors') && $.make('div', { className: 'NB-modal-field NB-fieldset' }, [
$.make('h5', 'Story Author'),
$.make('div', { className: 'NB-fieldset-fields NB-classifiers' },
this.make_authors([story.story_authors])
this.make_authors([story.get('story_authors')])
)
])),
(story.story_tags.length && $.make('div', { className: 'NB-modal-field NB-fieldset' }, [
(story.get('story_tags').length && $.make('div', { className: 'NB-modal-field NB-fieldset' }, [
$.make('h5', 'Story Categories &amp; Tags'),
$.make('div', { className: 'NB-classifier-tags NB-fieldset-fields NB-classifiers' },
this.make_tags(story.story_tags)
this.make_tags(story.get('story_tags'))
)
])),
$.make('div', { className: 'NB-modal-field NB-fieldset' }, [
@ -851,7 +851,7 @@ var classifier_prototype = {
serialize_classifier: function() {
var data = {};
$('.NB-classifier', this.$modal).each(function() {
var value = $('.NB-classifier-input-like', this).val();
var value = _.string.trim($('.NB-classifier-input-like', this).val());
if ($('.NB-classifier-input-like, .NB-classifier-input-dislike', this).is(':checked')) {
var name = $('input:checked', this).attr('name');
if (!data[name]) data[name] = [];
@ -886,9 +886,9 @@ var classifier_prototype = {
$save.addClass('NB-disabled').attr('disabled', true);
this.update_opinions();
NEWSBLUR.assets.recalculate_story_scores(feed_id);
this.model.save_classifier(data, function() {
if (!keep_modal_open) {
NEWSBLUR.reader.recalculate_story_scores(feed_id);
NEWSBLUR.reader.force_feeds_refresh(null, true);
// NEWSBLUR.reader.force_feed_refresh();
// NEWSBLUR.reader.open_feed(self.feed_id, true);

View file

@ -15,6 +15,7 @@ NEWSBLUR.Views.StoryTitleView = Backbone.View.extend({
this.model.bind('change:read_status', this.toggle_read_status, this);
this.model.bind('change:selected', this.toggle_selected, this);
this.model.bind('change:starred', this.toggle_starred, this);
this.model.bind('change:intelligence', this.render, this);
this.model.story_title_view = this;
},

View file

@ -25,6 +25,7 @@ NEWSBLUR.Views.StoryView = Backbone.View.extend({
this.model.bind('change:read_status', this.toggle_read_status, this);
this.model.bind('change:selected', this.toggle_selected, this);
this.model.bind('change:starred', this.toggle_starred, this);
this.model.bind('change:intelligence', this.render, this);
// Binding directly instead of using event delegation. Need for speed.
this.$el.bind('mouseenter', this.mouseenter);
@ -215,7 +216,7 @@ NEWSBLUR.Views.StoryView = Backbone.View.extend({
preserve_classifier_color: function(classifier_type, value, score) {
var $tag;
this.$('.NB-feed-story-'+classifier_type).each(function() {
if ($(this).text() == value) {
if (_.string.trim($(this).text()) == value) {
$tag = $(this);
return false;
}
@ -330,9 +331,9 @@ NEWSBLUR.Views.StoryView = Backbone.View.extend({
save_classifier: function(e) {
var $tag = $(e.currentTarget);
var classifier_type = $tag.hasClass('NB-feed-story-author') ? 'author' : 'tag';
var tag = $tag.text();
var tag = _.string.trim($tag.text());
var score = $tag.hasClass('NB-score-1') ? -1 : $tag.hasClass('NB-score--1') ? 0 : 1;
NEWSBLUR.reader.save_classifier(classifier_type, tag, score, feed_id);
NEWSBLUR.reader.save_classifier(classifier_type, tag, score, this.model.get('story_feed_id'));
this.preserve_classifier_color(classifier_type, tag, score);
},