-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.pl
64 lines (45 loc) · 1.21 KB
/
calc.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/perl
use Data::Dumper;
use DBD::mysql;
use XML::XPath;
use setup;
our $dbh;
my ($race_id, $class) = @ARGV;
print "*** Calc points for $class in $race_id\n";
my $sth = $dbh->prepare("select id, person_id,time,status, time_sec from result where race_id=? and class=? order by class,time");
$sth->execute($race_id, $class);
my $h;
my @rows;
my @times;
while ($h = $sth->fetchrow_arrayref) {
my $r = {"id"=>$h->[0], "pid"=>$h->[1], "time"=>$h->[2], "status"=>$h->[3],
"time_sec"=>$h->[4] };
if ($r->{"status"}=~ /OK/i) {
push (@rows, $r);
push (@times, $r->{"time_sec"} );
}
}
my @ordered = (sort {$a<=>$b} @times)[0..2];
print join(";", @ordered)."\n";
my $sum = 0.0; my $n = 0;
foreach (@ordered) {
if ($_>0) {
$sum+=$_;
$n++;
}
}
die "No results?! / $class / $race_id " if ($n==0);
my $avg = $sum/$n;
print "Avg: $avg seconds\n";
my $stu = $dbh->prepare("update result set points=? where id=?");
foreach my $r (@rows) {
my $t = $r->{"time_sec"};
my $points = 1600/0.6 + ((-1000)/(0.6*$avg))*$t;
if ($points>0) {
$r->{"points"} = $points;
} else {
$r->{"points"} = 0;
}
$stu->execute($r->{"points"}, $r->{"id"});
}
# =MAX(0;(1600/0.6)+((-1000)/(0.6*avg))*t)