X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=ND%2FInclude.pm;h=9a42d97b092f062599c628e7e72e7257bbde2de3;hb=c643b311c8f134a59625192b900aa28b3f12d4f1;hp=421d81ea044e47f3149b0a4d1c24787235cc0113;hpb=33379bf7e2909a0f46ccf771a919121e48f9ab41;p=ndwebbie.git diff --git a/ND/Include.pm b/ND/Include.pm index 421d81e..9a42d97 100644 --- a/ND/Include.pm +++ b/ND/Include.pm @@ -25,7 +25,7 @@ require Exporter; our @ISA = qw/Exporter/; -our @EXPORT = qw/min max parseValue prettyValue log_message intel_log unread_query/; +our @EXPORT = qw/min max parseValue prettyValue log_message intel_log unread_query pa_xp/; sub min { my ($x,$y) = @_; @@ -50,14 +50,21 @@ sub parseValue { } sub prettyValue { - my ($value) = @_; + my ($value,$decimals) = @_; + return sprintf('%.3e',$value) if $value > 1000000000000000; my $unit = ''; my @units = ('k','M','G','T'); - for (my $i = 0; $value >= 1000;$i++){ + for (my $i = 0; $value >= 1000 && $i < 4;$i++){ $value /= 1000; $unit = $units[$i]; } - return sprintf('%.2f%s', $value,$unit); + unless (defined $decimals){ + $decimals = '.0'; + $decimals = '.1' if $value < 100 && $unit; + $decimals = '.2' if $value < 10 && $unit; + } + + return sprintf('%'.$decimals.'f%s', $value,$unit); } @@ -75,6 +82,13 @@ sub intel_log { $log->execute($uid,$message,$planet) or $ND::ERROR .= p($ND::DBH->errstr); } +sub pa_xp { + my ($roids,$ascore,$avalue,$tscore,$tvalue) = @_; + my $bravery = (max(0,min(2,$tscore/$ascore)-0.6)) * (min(2,$tvalue/$avalue)-0.4); + return int(max($roids * 10 * $bravery,0)) + +} + sub unread_query { return $ND::DBH->prepare_cached(q{ SELECT count(*) AS unread, count(NULLIF(fp.time > $2,FALSE)) AS new