Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

tags_updateclouts additive, not replacement, peer clouts

Previously, the model for determining peer clout replaced the default
clout value with the determined value.  Now, in the case of the two main
clout types, they are added together, so users can only gain clout from
their (tag_clout, karma, etc.)  determined default clout.  In theory
this should allow active users more (and less-random) say in which tags
appear in top-5 lists, firehose scores, etc.
  • Loading branch information...
commit 05a25ec1ab1a6d762f766df8cb640c5db9895314 1 parent 5f88f66
@jamiemccarthy jamiemccarthy authored
View
79 plugins/Tags/Clout/Describe.pm
@@ -45,7 +45,12 @@ sub getUserClout {
$clout = 0;
}
$clout += 5 if $user_stub->{seclev} > 1;
- $clout *= $user_stub->{tag_clout};
+
+ my $clout_mult = 1;
+ if (defined($user_stub->{tag_clout})) {
+ $clout_mult = $user_stub->{tag_clout};
+ }
+ $clout *= $clout_mult;
# An account created within the past 3 days has low clout.
# Once an account reaches 30 days old, it gets full clout.
@@ -82,15 +87,16 @@ sub get_nextgen {
UNIX_TIMESTAMP(newtag.inactivated)-UNIX_TIMESTAMP(newtag.created_at))
AS duration,
newtag.uid AS newtag_uid,
- users_info.tag_clout AS clout,
- UNIX_TIMESTAMP(users_info.created_at) AS created_at_ut,
- karma, tokens,
+ seclev,
+ users_info.tag_clout,
+ karma, tokens, UNIX_TIMESTAMP(users_info.created_at) AS created_at_ut,
sourcetag.tagnameid,
sourcetag.globjid,
gtid",
"tags AS sourcetag,
tagname_params AS tagparam,
- globjs, tags_peerclout AS sourcetpc, users_info,
+ globjs, tags_peerclout AS sourcetpc,
+ users, users_info,
tags AS newtag LEFT JOIN tags_peerclout AS newtpc USING (uid)",
"sourcetag.inactivated IS NULL
AND sourcetag.globjid=globjs.globjid
@@ -102,6 +108,7 @@ sub get_nextgen {
AND tagparam.name='descriptive'
AND sourcetag.tagid != newtag.tagid
AND newtag.created_at >= DATE_SUB(NOW(), INTERVAL $self->{months_back} MONTH)
+ AND newtag.uid=users.uid
AND newtag.uid=users_info.uid
AND newtpc.uid IS NULL
AND sourcetpc.gen=$g",
@@ -114,34 +121,48 @@ sub process_nextgen {
my %newtag_uid = ( map { $_->{newtag_uid}, 1 } @$hr_ar );
my @newtag_uid = sort { $a <=> $b } keys %newtag_uid;
- my $insert_ar = [ ]; my $i = 0;
+ my $insert_ar = [ ];
+ my $i = 0;
for my $newtag_uid (@newtag_uid) {
+ my $start_time = Time::HiRes::time;
my @match = grep { $_->{newtag_uid} == $newtag_uid } @$hr_ar;
my $match0 = $match[0];
- my($clout, $created_at, $karma, $tokens) =
- ($match0->{clout}, $match0->{created_at_ut}, $match0->{karma}, $match0->{tokens});
+ my($tag_clout, $created_at, $karma, $tokens) =
+ ($match0->{tag_clout}, $match0->{created_at_ut}, $match0->{karma}, $match0->{tokens});
if ($self->{debug_uids}{$newtag_uid}) {
- print STDERR ref($self) . sprintf(" starting uid=%d\n", $newtag_uid);
+ print STDERR sprintf("%s tags_updateclouts %s process_nextgen starting uid=%d\n",
+ scalar(gmtime), ref($self), $newtag_uid);
++$self->{debug};
}
my $uid_mults = $self->get_mults(\@match);
- my $weight = $self->get_total_weight($tags_peerclout, $uid_mults, $clout, $created_at, $karma, $tokens);
+
+ my $peer_weight = $self->get_total_weight($tags_peerclout, $uid_mults, $tag_clout, $created_at, $karma, $tokens);
+
+ my $base_weight = $self->getUserClout($match0);
+
+ my $total_weight = $peer_weight + $base_weight;
+
push @$insert_ar, {
uid => $newtag_uid,
- clout => $weight,
+ clout => $total_weight,
};
+ my $elapsed = Time::HiRes::time - $start_time;
+
if ($self->{debug}) {
use Data::Dumper; my $umd = Dumper($uid_mults); $umd =~ s/\s+/ /g;
- print STDERR ref($self) . " uid=$newtag_uid weight="
- . $self->get_total_weight($tags_peerclout, $uid_mults, $clout, $created_at, $karma, $tokens)
- . " mults: $umd\n";
+ print STDERR sprintf("%s tags_updateclouts %s process_nextgen uid=%d peer_weight=%.6f base_=%.6f total_weight=%.6f in %.6f secs, mults: %s\n",
+ scalar(gmtime), ref($self), $newtag_uid,
+ $peer_weight, $base_weight, $total_weight,
+ $elapsed, $umd);
}
++$i;
- if ($i % 100 == 0) {
- print STDERR ref($self) . " process_nextgen processed $i (uid $newtag_uid, matched " . scalar(@match) . ")\n";
+ if ($i % 100 == 0 || $self->{debug}) {
+ print STDERR sprintf("%s tags_updateclouts %s process_nextgen processed %d uid=%d matched=%d in %.6f secs\n",
+ scalar(gmtime), ref($self), $i, $newtag_uid, scalar(@match), $elapsed);
}
if ($self->{debug_uids}{$newtag_uid}) {
- print STDERR ref($self) . sprintf(" done uid=%d\n", $newtag_uid);
+ print STDERR sprintf("%s tags_updateclouts %s process_nextgen done uid=%d\n",
+ scalar(gmtime), ref($self), $newtag_uid);
--$self->{debug};
}
Time::HiRes::sleep(0.01);
@@ -237,7 +258,11 @@ my @nodef = grep { !defined $tags_peerclout->{$_} } keys %$uid_mults; $#nodef =
push @total_mults, $tags_peerclout->{$uid} * $self->sum_weight_vectors(@balanced);
if ($self->{debug}) {
my @tm2 = map { sprintf("%.5g", $_) } @total_mults;
- print STDERR ref($self) . " source_uid=$uid ($tags_peerclout->{$uid}) total_mults='@tm2'\n";
+ print STDERR sprintf("%s tags_updateclouts %s get_total_weight uid=%d (%d) count=%d pushed %.6f\n",
+ scalar(gmtime), ref($self),
+ $uid, $tags_peerclout->{$uid},
+ scalar(@{$uid_mults->{$uid}}),
+ $total_mults[-1]);
}
}
@@ -246,7 +271,8 @@ my @nodef = grep { !defined $tags_peerclout->{$_} } keys %$uid_mults; $#nodef =
my @balanced = $self->balance_weight_vectors(@total_mults);
my $total = $self->sum_weight_vectors(@balanced);
if ($self->{debug}) {
- print STDERR ref($self) . " total=$total\n";
+ print STDERR sprintf("%s tags_updateclouts %s get_total_weight initial total=%d\n",
+ scalar(gmtime), ref($self), $total);
}
# If this user was created recently, less weight for them.
@@ -279,6 +305,10 @@ my @nodef = grep { !defined $tags_peerclout->{$_} } keys %$uid_mults; $#nodef =
# If the user has low clout, less weight for them.
$total *= $clout;
+ if ($self->{debug}) {
+ print STDERR sprintf("%s tags_updateclouts %s get_total_weight final total=%d\n",
+ scalar(gmtime), ref($self), $total);
+ }
# If the result is _very_ low, just count it as 0 (this may allow
# optimizations later).
@@ -311,8 +341,8 @@ sub balance_weight_vectors {
if ($self->{debug}) {
my @w2 = map { sprintf("%5d", @_) } @w; $#w2 = 4 if $#w2 > 4;
my @r2 = map { sprintf("%5d", @_) } @ret; $#r2 = 4 if $#r2 > 4;
- print STDERR sprintf("%s balance_weight_vectors pos=%.5g neg=%.5g from '%s' to '%s'\n",
- ref($self), $w_pos_mag, $w_neg_mag, join(' ', @w2), join(' ', @r2));
+ print STDERR sprintf("%s tags_updateclouts %s balance_weight_vectors pos=%.5g neg=%.5g from '%s' to '%s'\n",
+ scalar(gmtime), ref($self), $w_pos_mag, $w_neg_mag, join(' ', @w2), join(' ', @r2));
}
return @ret;
}
@@ -327,11 +357,12 @@ sub sum_weight_vectors {
$cur_magnitude *= $self->{cumfrac};
$weight += $cur_magnitude * $w;
}
- $weight = 0 if $weight < 0;
+ my $weight_floored = $weight < 0 ? 0 : $weight;
if ($self->{debug}) {
- print STDERR ref($self) . " sum_weight_vectors weight='$weight' w='@w'\n";
+ print STDERR sprintf("%s tags_updateclouts %s sum_weight_vectors weight=%.6f wf=%.6f w: '%s'\n",
+ scalar(gmtime), ref($self), $weight, $weight_floored, join(' ', @w));
}
- return $weight;
+ return $weight_floored;
}
sub copy_peerclout_sql {
View
132 plugins/Tags/Clout/Vote.pm
@@ -46,7 +46,11 @@ sub getUserClout {
$clout = 0;
}
- $clout *= $user_stub->{tag_clout};
+ my $clout_mult = 1;
+ if (defined($user_stub->{tag_clout})) {
+ $clout_mult = $user_stub->{tag_clout};
+ }
+ $clout *= $clout_mult;
my $created_at_ut;
if (defined($user_stub->{created_at_ut})) {
@@ -111,19 +115,21 @@ sub get_nextgen {
AS duration,
newtag.uid AS newtag_uid,
simil,
- users_info.tag_clout AS clout,
+ users_info.tag_clout,
UNIX_TIMESTAMP(users_info.created_at) AS created_at_ut,
IF(firehose_ogaspt.pubtime IS NULL,
NULL,
UNIX_TIMESTAMP(firehose_ogaspt.pubtime)-UNIX_TIMESTAMP(newtag.created_at))
AS timebeforepub,
- karma, tokens,
+ seclev,
+ karma, tokens, UNIX_TIMESTAMP(users_info.created_at) AS created_at_ut,
sourcetag.tagnameid AS sourcetag_tagnameid,
newtag.tagnameid AS newtag_tagnameid,
sourcetag.globjid,
gtid",
"tags AS sourcetag LEFT JOIN firehose_ogaspt USING (globjid),
- tags_peerclout AS sourcetpc, users_info,
+ tags_peerclout AS sourcetpc,
+ users, users_info,
tagnames_similar, globjs,
tags AS newtag LEFT JOIN tags_peerclout AS newtpc USING (uid)",
"sourcetag.inactivated IS NULL
@@ -136,6 +142,7 @@ sub get_nextgen {
AND simil != 0
AND sourcetag.tagid != newtag.tagid
AND newtag.created_at >= DATE_SUB(NOW(), INTERVAL $self->{months_back} MONTH)
+ AND newtag.uid=users.uid
AND newtag.uid=users_info.uid
AND newtpc.uid IS NULL
AND sourcetpc.gen=$g
@@ -157,7 +164,7 @@ sub process_nextgen {
my $insert_ar = [ ];
my $i = 0;
for my $newtag_uid (@newtag_uid) {
- ++$self->{debug} if $self->{debug_uids}{$newtag_uid};
+ my $start_time = Time::HiRes::time;
my $user_nodnixes_count = ($self->{nodc}{$newtag_uid} || 0) + ($self->{nixc}{$newtag_uid} || 0);
my $user_nodnixes_mult = 0;
if ($user_nodnixes_count >= $user_nodnixes_full) {
@@ -166,40 +173,53 @@ sub process_nextgen {
$user_nodnixes_mult = ($user_nodnixes_count+1-$user_nodnixes_min) /
($user_nodnixes_full+1-$user_nodnixes_min);
}
- my $weight = 0;
- my(@match, $clout, $created_at, $karma, $tokens, $uid_mults);
- if ($self->{debug}) {
- print STDERR ref($self) . sprintf(" starting uid=%d user_nodnixes_mult=%.3f\n",
- $newtag_uid, $user_nodnixes_mult);
+ if ($self->{debug_uids}{$newtag_uid}) {
+ print STDERR sprintf("%s tags_updateclouts %s process_nextgen starting uid=%d user_nodnixes_mult=%.6f\n",
+ scalar(gmtime), ref($self), $newtag_uid, $user_nodnixes_mult);
+ ++$self->{debug};
}
+
+ my $peer_weight = 0;
+ my(@match, $tag_clout, $created_at, $karma, $tokens, $uid_mults);
+ @match = grep { $_->{newtag_uid} == $newtag_uid } @$hr_ar;
+ my $match0 = $match[0];
if ($user_nodnixes_mult > 0) {
- @match = grep { $_->{newtag_uid} == $newtag_uid } @$hr_ar;
- my $match0 = $match[0];
- ($clout, $created_at, $karma, $tokens) =
- ($match0->{clout}, $match0->{created_at_ut}, $match0->{karma}, $match0->{tokens});
+ ($tag_clout, $created_at, $karma, $tokens) =
+ ($match0->{tag_clout}, $match0->{created_at_ut}, $match0->{karma}, $match0->{tokens});
$uid_mults = $self->get_mults(\@match);
$uid_mults->{'-1'} = $self->get_mult_timebeforepub(\@match);
- $weight = $self->get_total_weight($tags_peerclout, $uid_mults,
- $clout, $created_at, $karma, $tokens, $newtag_uid)
+ $peer_weight = $self->get_total_weight($tags_peerclout, $uid_mults,
+ $tag_clout, $created_at, $karma, $tokens, $newtag_uid)
* $user_nodnixes_mult;
}
+
+ my $base_weight = $self->getUserClout($match0);
+
+ my $total_weight = $peer_weight + $base_weight;
+
push @$insert_ar, {
uid => $newtag_uid,
- clout => $weight,
+ clout => $total_weight,
};
+ my $elapsed = Time::HiRes::time - $start_time;
+
if ($self->{debug}) {
- use Data::Dumper;
- print STDERR sprintf("%s uid=%d user_nodnixes_mult=%.3f weight=%.6f mults: %s\n",
- ref($self),
- $newtag_uid, $user_nodnixes_mult,
- $weight,
- Dumper($uid_mults));
+ use Data::Dumper; my $umd = Dumper($uid_mults); $umd =~ s/\s+/ /g;
+ print STDERR sprintf("%s tags_updateclouts %s process_nextgen uid=%d peer_weight=%.6f base_=%.6f total_weight=%.6f in %.6f secs, mults: %s\n",
+ scalar(gmtime), ref($self), $newtag_uid,
+ $peer_weight, $base_weight, $total_weight,
+ $elapsed, $umd);
}
++$i;
- if ($i % 100 == 0) {
- print STDERR scalar(localtime) . " " . ref($self) . " process_nextgen processed $i (uid $newtag_uid, matched " . scalar(@match) . ")\n";
+ if ($i % 100 == 0 || $self->{debug}) {
+ print STDERR sprintf("%s tags_updateclouts %s process_nextgen processed %d uid=%d matched=%d in %.6f secs\n",
+ scalar(gmtime), ref($self), $i, $newtag_uid, scalar(@match), $elapsed);
+ }
+ if ($self->{debug_uids}{$newtag_uid}) {
+ print STDERR sprintf("%s tags_updateclouts %s process_nextgen done uid=%d\n",
+ scalar(gmtime), ref($self), $newtag_uid);
+ --$self->{debug};
}
- --$self->{debug} if $self->{debug_uids}{$newtag_uid};
Time::HiRes::sleep(0.01);
}
@@ -334,10 +354,15 @@ sub get_mult {
my $sfrac = ($stn == $nodid ? $snix : $snod) / ($snod+$snix+1);
my $nfrac = ($ntn == $nodid ? $nnix : $nnod) / ($nnod+$nnix+1);
if ($self->{debug}) {
- print STDERR ref($self) . " get_mult su='$su' nu='$nu' sfrac='$sfrac' nfrac='$nfrac'\n";
+ print STDERR sprintf("%s tags_updateclouts %s get_mult su=%d nu=%d sfrac=%.6f nfrac=%.6f\n",
+ scalar(gmtime), ref($self), $su, $nu, $sfrac, $nfrac);
}
$mult *= $sfrac * $nfrac;
}
+ if ($self->{debug}) {
+ print STDERR sprintf("%s tags_updateclouts %s get_mult returning %.6f\n",
+ scalar(gmtime), ref($self), $mult);
+ }
return $mult;
}
@@ -392,17 +417,24 @@ sub get_total_weight {
# correlations with other users' tags.
if ($uid_mults->{'-1'}) {
if (@{$uid_mults->{'-1'}}) {
- print STDERR "get_total_weight for $new_uid calling balance_weight_vectors -1\n" if $self->{debug};
my @balanced = $self->balance_weight_vectors(@{$uid_mults->{'-1'}});
- push @total_mults, $constants->{tags_tagpeerval_postingbonus}
+ my $m = $constants->{tags_tagpeerval_postingbonus}
* $self->sum_weight_vectors(@balanced);
+ push @total_mults, $m;
$any_weight = 1;
+ if ($self->{debug}) {
+ print STDERR sprintf("%s tags_updateclouts %s get_total_weight uid=%d balance_weight_vectors(-1)=%.6f\n",
+ scalar(gmtime), ref($self), $new_uid, $m);
+ }
}
delete $uid_mults->{'-1'};
}
# Start by sorting source uids by decreasing weight.
- my @nodef = grep { !defined $tags_peerclout->{$_} } keys %$uid_mults; $#nodef = 20 if $#nodef > 20; print STDERR "get_total_weight for $new_uid nodef: '@nodef'\n" if @nodef;
+ my @nodef = grep { !defined $tags_peerclout->{$_} } keys %$uid_mults; $#nodef = 20 if $#nodef > 20;
+ print STDERR sprintf("%s tags_updateclouts %s get_total_weight for uid=%d nodef: '%s'\n",
+ scalar(gmtime), ref($self), $new_uid, join(' ', @nodef))
+ if @nodef;
my @source_uids = sort { $tags_peerclout->{$b} <=> $tags_peerclout->{$a} } keys %$uid_mults;
# If all source uids have weight 0, we know the answer quickly.
@@ -412,25 +444,39 @@ sub get_total_weight {
last;
}
}
+ if ($self->{debug}) {
+ my $src_count = scalar(@source_uids);
+ my @src_abridged = @source_uids;
+ $#src_abridged = 19 if $#src_abridged >= 19;
+ my $src_min = $uid_mults->{ $src_abridged[-1] };
+ my $src_max = $uid_mults->{ $src_abridged[ 0] };
+ my $abridged_str = join(' ', @src_abridged);
+ print STDERR sprintf("%s tags_updateclouts %s get_total_weight uid=%d any_weight=%d count=%d min=%.6f max=%.6f uids: '%d'\n",
+ scalar(gmtime), ref($self), $new_uid, $any_weight,
+ $src_count, $src_min, $src_max, $abridged_str);
+ }
return 0 if !$any_weight;
# Get the mult for each of those
for my $uid (@source_uids) {
- print STDERR "get_total_weight for $new_uid calling balance_weight_vectors $uid\n" if $self->{debug};
my @balanced = $self->balance_weight_vectors(@{$uid_mults->{$uid}});
- push @total_mults, $tags_peerclout->{$uid} * $self->sum_weight_vectors(@balanced);
+ my $m = $tags_peerclout->{$uid} * $self->sum_weight_vectors(@balanced);
+ push @total_mults, $m;
if ($self->{debug}) {
- my @t2 = map { sprintf("%.6g", $_) } @total_mults;
- print STDERR "get_total_weight for $new_uid source_uid=$uid (clout $tags_peerclout->{$uid}), total_mults='@t2' from balanced '@balanced'\n";
+ print STDERR sprintf("%s tags_updateclouts %s get_total_weight uid=%d source_uid=%d (clout %.6f) mult: %.6f for balanced: %s\n",
+ scalar(gmtime), ref($self), $new_uid, $uid, $m,
+ join(' ', map { sprintf("%.6f", $_) } @balanced));
}
}
# Then (using the same decreasing-multipliers algorithm) get the
# total of all those mults.
- print STDERR "get_total_weight for $new_uid calling balance_weight_vectors total\n" if $self->{debug};
my @balanced = $self->balance_weight_vectors(@total_mults);
my $total = $self->sum_weight_vectors(@balanced);
- print STDERR ref($self) . " total=$total for uid $new_uid\n" if $self->{debug};
+ if ($self->{debug}) {
+ print STDERR sprintf("%s tags_updateclouts %s get_total_weight uid=%d initial total=%.6f\n",
+ scalar(gmtime), ref($self), $new_uid, $total);
+ }
# If this user was created recently, less weight for them.
my $daysold = (time - $created_at)/86400;
@@ -462,6 +508,11 @@ sub get_total_weight {
# If the user has low clout, less weight for them.
$total *= $clout;
+
+ if ($self->{debug}) {
+ print STDERR sprintf("%s tags_updateclouts %s get_total_weight uid=%d final total=%.6f\n",
+ scalar(gmtime), ref($self), $new_uid, $total);
+ }
# If the result is _very_ low, just count it as 0 (this may allow
# optimizations later).
@@ -494,8 +545,10 @@ sub balance_weight_vectors {
if ($self->{debug} || $w_pos_mag > 10_000 || $w_neg_mag > 10_000) {
my @w2 = @w; $#w2 = 4 if $#w2 > 4;
my @r2 = @ret; $#r2 = 4 if $#r2 > 4;
- print STDERR sprintf("%s balance_weight_vectors posmag=%0.5g negmag=%0.5g from '%s' to '%s'\n",
- ref($self), $w_pos_mag, $w_neg_mag, join(' ', @w2), join(' ', @r2));
+ print STDERR sprintf("%s tags_updateclouts %s balance_weight_vectors posmag=%0.5g negmag=%0.5g from '%s' to '%s'\n",
+ scalar(gmtime), ref($self), $w_pos_mag, $w_neg_mag,
+ join(' ', map { sprintf("%.6f", $_) } @w2),
+ join(' ', map { sprintf("%.6f", $_) } @r2));
}
return @ret;
}
@@ -512,7 +565,8 @@ sub sum_weight_vectors {
}
$weight = 0 if $weight < 0;
if ($self->{debug}) {
- print STDERR ref($self) . " sum_weight_vectors weight='$weight' w='@w'\n";
+ print STDERR sprintf("%s tags_updateclouts %s sum_weight_vectors weight=%.6f w='%s'\n",
+ scalar(gmtime), ref($self), $weight, join(' ', map { sprintf("%.6f", $_) } @w));
}
return $weight;
}
View
4 plugins/Tags/tags_updateclouts.pl
@@ -46,7 +46,7 @@
'tags_peerclout',
"clid=$clid AND gen = 0");
if ($tags_peerclout && %$tags_peerclout) {
- $slashdb->sqlDelete('tags_peerclout', 'gen > 0');
+ $slashdb->sqlDelete('tags_peerclout', "gen > 0 AND clid=$clid");
sleep 5; # wait for that to replicate
my $g = 0;
while (1) {
@@ -78,7 +78,7 @@ sub insert_nextgen {
my $rows = 0;
for my $hr (@$insert_ar) {
($hr->{clid}, $hr->{gen}) = ($clid, $gen);
-if (!$rows) { use Data::Dumper; my $hd = Dumper($hr); $hd =~ s/\s+/ /g; print STDERR "insert hr: $hd\n"; }
+if (!$rows) { use Data::Dumper; my $hd = Dumper($hr); $hd =~ s/\s+/ /g; slashdLog("insert hr: $hd"); }
$rows += $slashdb->sqlInsert('tags_peerclout', $hr);
$tags_peerclout->{ $hr->{uid} } = $hr->{clout};
}
Please sign in to comment.
Something went wrong with that request. Please try again.