Skip to content

Commit

Permalink
Updates to FHPopularity (and -2) tagboxes, and to FireHose to take ad…
Browse files Browse the repository at this point in the history
…vantage

of them.
  • Loading branch information
jamiemccarthy committed Apr 25, 2007
1 parent 89927a6 commit e90682b
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 50 deletions.
91 changes: 55 additions & 36 deletions plugins/FireHose/FireHose.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ sub createUpdateItemFromJournal {
if ($journal) {
my $globjid = $self->getGlobjidCreate("journals", $journal->{id});
my $globjid_q = $self->sqlQuote($globjid);
# XXX does this next line depend on the primary key being the
# first column returned by "SELECT *"? If I read that right,
# that's non-intuitive; we should select id by name instead. -Jamie
my($itemid) = $self->sqlSelect("*", "firehose", "globjid=$globjid_q");
if ($itemid) {
my $introtext = balanceTags(strip_mode($journal->{article}, $journal->{posttype}), { deep_nesting => 1 });
Expand Down Expand Up @@ -113,8 +116,8 @@ sub createItemFromJournal {
if ($journal) {
my $globjid = $self->getGlobjidCreate("journals", $journal->{id});
my $popularity = $journal->{promotetype} eq "publicize"
? $self->getMidPopularityForColorLevel(5)
: $self->getMidPopularityForColorLevel(6);
? $self->getEntryPopularityForColorLevel(5)
: $self->getEntryPopularityForColorLevel(6);
my $type = $user->{acl}{vendor} ? "vendor" : "journal";
my $data = {
title => $journal->{description},
Expand All @@ -124,6 +127,7 @@ sub createItemFromJournal {
public => "yes",
introtext => $introtext,
popularity => $popularity,
popularity2 => $popularity,
editorpop => $popularity,
tid => $journal->{tid},
srcid => $id,
Expand All @@ -146,8 +150,8 @@ sub createUpdateItemFromBookmark {
my $popularity = defined $options->{popularity}
? $options->{popularity}
: $type eq "feed"
? $self->getMidPopularityForColorLevel(6)
: $self->getMidPopularityForColorLevel(7);
? $self->getEntryPopularityForColorLevel(6)
: $self->getEntryPopularityForColorLevel(7);
my $activity = defined $options->{activity} ? $options->{activity} : 1;

if ($count) {
Expand All @@ -161,6 +165,7 @@ sub createUpdateItemFromBookmark {
url_id => $bookmark->{url_id},
uid => $bookmark->{uid},
popularity => $popularity,
popularity2 => $popularity,
editorpop => $popularity,
activity => $activity,
public => "yes",
Expand All @@ -178,13 +183,14 @@ sub createItemFromSubmission {
my $submission = $self->getSubmission($id);
if ($submission) {
my $globjid = $self->getGlobjidCreate("submissions", $submission->{subid});
my $midpop = $self->getMinPopularityForColorLevel(5);
my $midpop = $self->getEntryPopularityForColorLevel(5);
my $data = {
title => $submission->{subj},
globjid => $globjid,
uid => $submission->{uid},
introtext => $submission->{story},
popularity => $midpop,
popularity2 => $midpop,
editorpop => $midpop,
public => "yes",
attention_needed => "yes",
Expand Down Expand Up @@ -241,9 +247,9 @@ sub createItemFromStory {
my %ignore_skids = map {$_ => 1 } @{$constants->{firehose_story_ignore_skids}};
my $story = $self->getStory($id, '', 1);

my $popularity = $self->getMidPopularityForColorLevel(2);
my $popularity = $self->getEntryPopularityForColorLevel(2);
if ($story->{story_topics_rendered}{$constants->{mainpage_nexus_tid}}) {
$popularity = $self->getMidPopularityForColorLevel(1);
$popularity = $self->getEntryPopularityForColorLevel(1);
}

if ($story && !$ignore_skids{$story->{primaryskid}}) {
Expand All @@ -257,6 +263,7 @@ sub createItemFromStory {
introtext => parseSlashizedLinks($story->{introtext}),
bodytext => parseSlashizedLinks($story->{bodytext}),
popularity => $popularity,
popularity2 => $popularity,
editorpop => $popularity,
primaryskid => $story->{primaryskid},
tid => $story->{tid},
Expand All @@ -272,7 +279,7 @@ sub createItemFromStory {

sub getFireHoseCount {
my($self) = @_;
my $pop = $self->getMidPopularityForColorLevel(6);
my $pop = $self->getEntryPopularityForColorLevel(6);
my $user = getCurrentUser();
my $pop_q = $self->sqlQuote($pop);
my $signoff_label = "sign$user->{uid}\ed";
Expand Down Expand Up @@ -348,6 +355,8 @@ sub getFireHoseEssentials {
$options->{orderdir} = uc($options->{orderdir}) eq "ASC" ? "ASC" : "DESC";
#($user->{is_admin} && $options->{orderby} eq "createtime" ? "ASC" :"DESC");

my $popularitycol = $constants->{firehose_userpop_col} || 'popularity';

my @where;
my $tables = "firehose";
if ($options->{tagged_by_uid}) {
Expand All @@ -363,7 +372,7 @@ sub getFireHoseEssentials {
push @where, "tags.tagnameid != $nix_id";
}
}
my $columns = "firehose.*";
my $columns = "firehose.*, firehose.$popularitycol AS userpop";

if ($options->{createtime_no_future} && !$doublecheck) {
push @where, "createtime <= NOW()";
Expand Down Expand Up @@ -410,7 +419,7 @@ sub getFireHoseEssentials {
if ($options->{filter}) {
# sanitize $options->{filter};
$options->{filter} =~ s/[^a-zA-Z0-9_]+//g;
push @where, "firehose_text.title like '%" . $options->{filter} . "%'";
push @where, "firehose_text.title LIKE '%" . $options->{filter} . "%'";
}

if ($options->{fetch_text}) {
Expand Down Expand Up @@ -451,7 +460,7 @@ sub getFireHoseEssentials {
if ($user->{is_admin} && !$user->{firehose_usermode}) {
push @where, "editorpop >= $pop_q";
} else {
push @where, "popularity >= $pop_q";
push @where, "$popularitycol >= $pop_q";
}
}
if ($user->{is_admin}) {
Expand Down Expand Up @@ -560,8 +569,10 @@ sub getFireHose {
}

# XXX cache this eventually
my $constants = getCurrentStatic();
my $popularitycol = $constants->{firehose_userpop_col} || 'popularity';
my $id_q = $self->sqlQuote($id);
my $answer = $self->sqlSelectHashref("*", "firehose", "id=$id_q");
my $answer = $self->sqlSelectHashref("*, firehose.$popularitycol AS userpop", "firehose", "id=$id_q");
my $append = $self->sqlSelectHashref("*", "firehose_text", "id=$id_q");

for my $key (keys %$append) {
Expand Down Expand Up @@ -886,11 +897,12 @@ sub ajaxFireHoseGetUpdates {
my $mode = $opts->{mode};
my $curmode = $opts->{mode};
my $mixed_abbrev_pop = $firehose->getMinPopularityForColorLevel(1);
my $popularitycol = $constants->{firehose_userpop_col} || 'popularity';

foreach (@$items) {
if ($mode eq "mixed") {
$curmode = "full";
$curmode = "fulltitle" if $_->{popularity} < $mixed_abbrev_pop;
$curmode = "fulltitle" if $_->{$popularitycol} < $mixed_abbrev_pop;

}
my $item = {};
Expand Down Expand Up @@ -1325,12 +1337,13 @@ sub getAndSetOptions {
}
$options->{color} ||= $user->{firehose_color};

my $popularitycol = $constants->{firehose_userpop_col} || 'popularity';
if ($form->{orderby}) {
if ($form->{orderby} eq "popularity") {
if ($user->{is_admin} && !$user->{firehose_usermode}) {
$options->{orderby} = "editorpop";
} else {
$options->{orderby} = "popularity";
$options->{orderby} = $popularitycol;
}
} else {
$options->{orderby} = "createtime";
Expand Down Expand Up @@ -1629,34 +1642,38 @@ sub getFireHoseTagsTop {

sub getMinPopularityForColorLevel {
my($self, $level) = @_;
my $slashdb = getCurrentDB();
my $levels = $slashdb->getVar('firehose_slice_points', 'value', 1);
my @levels = split(/\|/, $levels);
return $levels[$level - 1 ];
my $constants = getCurrentStatic();
my $slicepoints = $constants->{firehose_slice_points};
my @levels = split / /, $slicepoints;
my $entry_min = $levels[$level-1];
my($entry, $min) = split /,/, $entry_min;
return $min;
}

sub getMidPopularityForColorLevel {
sub getEntryPopularityForColorLevel {
my($self, $level) = @_;
my $slashdb = getCurrentDB();
my $levels = $slashdb->getVar('firehose_slice_points', 'value', 1);
my @levels = split(/\|/, $levels);
my $min = $levels[$level - 1 ];

my $maxindex = $level - 2;
my $max = $maxindex >= 0 && defined $levels[$maxindex] ? $levels[$maxindex] : $levels[$level - 1] + 5;
return (($min + $max) / 2);
my $constants = getCurrentStatic();
my $slicepoints = $constants->{firehose_slice_points};
my @levels = split / /, $slicepoints;
my $entry_min = $levels[$level-1];
my($entry, $min) = split /,/, $entry_min;
return $entry;
}

sub getPopLevelForPopularity {
my($self, $pop) = @_;
my $slashdb = getCurrentDB();
my $levels = $slashdb->getVar('firehose_slice_points', 'value', 1);
my @levels = split(/\|/, $levels);
my $i = 0;
for ($i=0; $i< $#levels; $i++) {
return $i+1 if $pop >= $levels[$i];
}
return $i + 1;
my $constants = getCurrentStatic();
my $slicepoints = $constants->{firehose_slice_points};
my @levels = split / /, $slicepoints;
for my $i (0..$#levels) {
my $entry_min = $levels[$i];
my($entry, $min) = split /,/, $entry_min;
return $i+1 if $pop >= $min;
}
# This should not happen, since the min value for the last slice
# is supposed to be very large negative. If a score goes below
# it, though, return the next slice number.
return $#levels + 1;
}

sub listView {
Expand Down Expand Up @@ -1696,11 +1713,13 @@ sub listView {
my $mode = $options->{mode};
my $curmode = $options->{mode};
my $mixed_abbrev_pop = $self->getMinPopularityForColorLevel(1);
my $constants = getCurrentStatic();
my $popularitycol = $constants->{firehose_userpop_col} || 'popularity';

foreach (@$items) {
if ($mode eq "mixed") {
$curmode = "full";
$curmode = "fulltitle" if $_->{popularity} < $mixed_abbrev_pop;
$curmode = "fulltitle" if $_->{$popularitycol} < $mixed_abbrev_pop;

}
$maxtime = $_->{createtime} if $_->{createtime} gt $maxtime && $_->{createtime} lt $now;
Expand Down
1 change: 0 additions & 1 deletion plugins/FireHose/PLUGIN
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ htdoc=firehose.pl
mysql_dump=mysql_dump.sql
mysql_schema=mysql_schema.sql
requiresplugin=Tags
task=set_color_ranges.pl
template=templates/adv_pref_firehose;misc;default
template=templates/list;firehose;default
template=templates/view;firehose;default
Expand Down
5 changes: 3 additions & 2 deletions plugins/FireHose/mysql_dump.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ INSERT INTO ajax_ops VALUES (NULL, 'firehose_get_updates', 'Slash::FireHose', 'a
INSERT INTO ajax_ops VALUES (NULL, 'firehose_set_options', 'Slash::FireHose', 'ajaxFireHoseSetOptions', 'ajax_user_static', 'use');
INSERT INTO vars (name, value, description) VALUES ('firehose_story_ignore_skids', '', 'list of skids that you want to not want created or shown as firehose entries. Delimit skids with |');
INSERT INTO vars (name, value, description) VALUES ('firehose_color_slices', '30|30|0.2|0.2|0.2|0.2|0.2|0.0', 'Number or percent of remaining stories at each color level separated by | 30|0.5|0.5 would mean 30 stories at the level of highest popularity and 50% at each of remainining stories at the next 2 levels');
INSERT INTO vars (name, value, description) VALUES ('firehose_slice_points', '20|15|12|7|5|3|1', 'Minimum popularity value to reach a particular color level');
INSERT INTO vars (name, value, description) VALUES ('firehose_color_labels', 'red|orange|yellow|green|blue|purple|violet', 'Firehose color labels');
INSERT INTO vars (name, value, description) VALUES ('firehose_slice_points', '290,240 220,200 185,175 155,138 102,93 30,25 0,-20 -60,-999999', 'Seven pairs of numbers: the entry score and minimum score for each color slice (last min should be large negative)');
INSERT INTO vars (name, value, description) VALUES ('firehose_color_labels', 'red|orange|yellow|green|blue|purple|violet|black', 'Firehose color labels');
INSERT INTO vars (name, value, description) VALUES ('firehose_anonval_param', '', 'String needed to be passed in anonval form param to validate requests, set to a string to enforce this validation');
INSERT INTO vars (name, value, description) VALUES ('firehose_userpop_col', 'popularity', 'Column name in firehose table storing popularity as seen by users');

INSERT INTO firehose_tab VALUES (1,0,'Firehose','','createtime','DESC','indigo','fulltitle');
INSERT INTO firehose_tab VALUES (2,0,'Slashdot','story','createtime','DESC','black','full');
Expand Down
3 changes: 3 additions & 0 deletions plugins/FireHose/set_color_ranges.pl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
$task{$me}{fork} = SLASHD_NOWAIT;
$task{$me}{code} = sub {
my($virtual_user, $constants, $slashdb, $user, $info, $gSkin) = @_;

return 'task is no longer used';

my @slices = split(/\|/,$constants->{firehose_color_slices});
my $pops = $slashdb->sqlSelectColArrayref("popularity", "firehose", "createtime > DATE_SUB(NOW(),INTERVAL 1 DAY) and popularity > 0", "order by popularity desc");

Expand Down
4 changes: 2 additions & 2 deletions plugins/FireHose/templates/formatHoseTitle;misc;default
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ END;
title = title _ "'>" _ item.name _ "</span>";

firehose = Slash.getObject("Slash::FireHose");
pop_val = firehose.getPopLevelForPopularity(item.popularity);
pop_val = firehose.getPopLevelForPopularity(item.userpop);
pop_val_offset = pop_val - 1;
pop_disp = item.popularity.int;
pop_disp = item.userpop.int;
colors = firehose.getFireHoseColors(1);
color = colors.$pop_val_offset;
pop_str = "";
Expand Down
12 changes: 6 additions & 6 deletions tagboxes/FHEditorPop/FHEditorPop.pm
Original file line number Diff line number Diff line change
Expand Up @@ -148,26 +148,26 @@ sub run {
my($type, $target_id) = $tagsdb->getGlobjTarget($affected_id);
my $target_id_q = $self->sqlQuote($target_id);
if ($type eq "submissions") {
$popularity = $firehose->getMidPopularityForColorLevel(5);
$popularity = $firehose->getEntryPopularityForColorLevel(5);
} elsif ($type eq "journals") {
my $journal = getObject("Slash::Journal");
my $j = $journal->get($target_id);
$popularity = $firehose->getMidPopularityForColorLevel(6);
$popularity = $firehose->getMidPopularityForColorLevel(5) if $j->{promotetype} eq "publicize";
$popularity = $firehose->getEntryPopularityForColorLevel(6);
$popularity = $firehose->getEntryPopularityForColorLevel(5) if $j->{promotetype} eq "publicize";

} elsif ($type eq 'urls') {
my $bookmark_count = $self->sqlCount('bookmarks', "url_id=$target_id_q");
my $pop_level = 7;
$pop_level = 6 if $self->sqlCount("firehose", "type='feed' AND url_id=$target_id");
$popularity = $firehose->getMidPopularityForColorLevel($pop_level) + $bookmark_count;
$popularity = $firehose->getEntryPopularityForColorLevel($pop_level) + $bookmark_count;
} elsif ($type eq "stories") {
my $story = $self->getStory($target_id);
if($story->{story_topics_rendered}{$constants->{mainpage_nexus_tid}}) {
# Mainpage
$popularity = $firehose->getMidPopularityForColorLevel(1);
$popularity = $firehose->getEntryPopularityForColorLevel(1);
} else {
# Sectional
$popularity = $firehose->getMidPopularityForColorLevel(2);
$popularity = $firehose->getEntryPopularityForColorLevel(2);
}
}
# There's also 'feed' which doesn't get extra points (starts at 1).
Expand Down
2 changes: 1 addition & 1 deletion tagboxes/FHPopularity/FHPopularity.pm
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ sub run {
? 1 # mainpage
: 2; # sectional
}
$popularity = $firehose->getMidPopularityForColorLevel($color_level) + $extra_pop;
$popularity = $firehose->getEntryPopularityForColorLevel($color_level) + $extra_pop;

# Add up nods and nixes.
my $upvoteid = $tagsdb->getTagnameidCreate($constants->{tags_upvote_tagname} || 'nod');
Expand Down
4 changes: 2 additions & 2 deletions tagboxes/FHPopularity2/FHPopularity2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ sub run {
? 1 # mainpage
: 2; # sectional
}
$popularity = $firehose->getMidPopularityForColorLevel($color_level) + $extra_pop;
$popularity = $firehose->getEntryPopularityForColorLevel($color_level) + $extra_pop;

# Add up nods and nixes.
my $upvoteid = $tagsdb->getTagnameidCreate($constants->{tags_upvote_tagname} || 'nod');
Expand Down Expand Up @@ -192,7 +192,7 @@ print STDERR "extra_pop for $tag_hr->{tagid}: $extra_pop * $udc_mult\n";

sub get_udc_mult {
my($time, $cache) = @_;
my $prevhour = ($time/3600)*3600 - 1;
my $prevhour = int($time/3600-1)*3600;
my $curhour = $prevhour+3600;
my $nexthour = $prevhour+3600;
my $tagsdb = getObject('Slash::Tags');
Expand Down

0 comments on commit e90682b

Please sign in to comment.