-
Notifications
You must be signed in to change notification settings - Fork 3
/
NoGap.pm
executable file
·154 lines (128 loc) · 4.13 KB
/
NoGap.pm
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/perl -I/home/geoff/bin
#
# "NoGap"
# Pilot score is the distance flown
#
# Geoff Wong 2013
#
package NoGap;
use Data::Dumper;
require Gap;
@ISA = ( "Gap" );
#require DBD::mysql;
#use POSIX qw(ceil floor);
#use Math::Trig;
#use TrackLib qw(:all);
sub day_quality
{
return (1,1,1,1);
}
#
#
# Points Allocation:
#
# Directly allocate the distance points (+pen).
#
sub points_allocation
{
my ($self, $dbh, $task, $taskt, $formula) = @_;
my $comPk;
my $tasPk;
my $quality;
my ($Ngoal,$Nfly,$Nlo);
my ($Tmin);
my $Tfarr;
my $Cmin;
my $x;
my $distweight;
my $Adistance;
my $Aspeed;
my $Astart;
my $Arival;
my $penspeed;
my $pendist;
my $difdist;
my $debc;
my @pilots;
my $kmdiff = [];
# Find fastest pilot into goal and calculate leading coefficients
# for each track .. (GAP2002 only?)
$comPk = $task->{'comPk'};
$tasPk = $task->{'tasPk'};
$quality = $taskt->{'quality'};
$Ngoal = $taskt->{'goal'};
$Nfly = $taskt->{'launched'};
$Nlo = $Nfly - $Ngoal;
$Tmin = $taskt->{'fastest'};
$Tfarr = $taskt->{'firstarrival'};
$Cmin = $taskt->{'mincoeff'};
#print Dumper($taskt);
# Get all pilots and process each of them
# pity it can't be done as a single update ...
$dbh->do('set @x=0;');
#$sth = $dbh->prepare("select \@x:=\@x+1 as Place, tarPk, tarDistance, tarSS, tarES, tarPenalty, tarResultType, tarLeadingCoeff, tarGoal from tblTaskResult where tasPk=$tasPk and tarResultType <> 'abs' order by tarDistance desc, tarES");
$sth = $dbh->prepare("select \@x:=\@x+1 as Place, TR.tarPk, TR.tarDistance, TR.tarSS, TR.tarES, TR.tarPenalty, TR.tarResultType, TR.tarLeadingCoeff, TR.tarGoal, H.hanHandicap from tblTaskResult TR join tblTrack T on TR.traPk=T.traPk left outer join tblHandicap H on H.pilPk=T.pilPk and H.comPk=$comPk where tasPk=$tasPk and tarResultType <> 'abs' order by tarDistance desc, tarES");
$sth->execute();
while ($ref = $sth->fetchrow_hashref())
{
my %taskres;
%taskres = ();
$taskres{'tarPk'} = $ref->{'tarPk'};
$taskres{'penalty'} = $ref->{'tarPenalty'};
$taskres{'distance'} = $ref->{'tarDistance'} / 1000;
# set pilot to min distance if they're below that ..
$taskres{'result'} = $ref->{'tarResultType'};
$taskres{'startSS'} = $ref->{'tarSS'};
$taskres{'endSS'} = $ref->{'tarES'};
# OZGAP2005
$taskres{'timeafter'} = $ref->{'tarES'} - $Tfarr;
$taskres{'place'} = $ref->{'Place'};
$taskres{'time'} = $taskres{'endSS'} - $taskres{'startSS'};
$taskres{'goal'} = $ref->{'tarGoal'};
$taskres{'handicap'} = 0 + $ref->{'hanHandicap'};
if ($taskres{'handicap'} == 0)
{
$taskres{'handicap'} = 1;
}
if ($taskres{'time'} < 0)
{
$taskres{'time'} = 0;
}
# Leadout Points
$taskres{'coeff'} = $ref->{'tarLeadingCoeff'};
# FIX: adjust against fastest ..
push @pilots, \%taskres;
}
# Score each pilot now
for my $pil ( @pilots )
{
my $Pdist;
my $Pspeed = 0;
my $Parrival = 0;
my $Pdepart = 0;
my $Pscore;
my $tarPk;
my $penalty;
$tarPk = $pil->{'tarPk'};
$penalty = $pil->{'penalty'};
# Pilot distance score
$Pdist = $pil->{'distance'} * $pil->{'handicap'};
if (($pil->{'result'} eq 'dnf') or ($pil->{'result'} eq 'abs'))
{
$Pdist = 0;
$Pspeed = 0;
$Parrival = 0;
$Pdepart = 0;
}
$Pscore = $Pdist - $penalty;
# Store back into tblTaskResult ...
if (defined($tarPk))
{
print "update $tarPk: d:$Pdist, s:$Pspeed, p: $penalty, a:$Parrival, g:$Pdepart\n";
print "update tblTaskResult set tarDistanceScore=$Pdist, tarSpeedScore=$Pspeed, tarScore=$Pscore where tarPk=$tarPk\n";
$sth = $dbh->prepare("update tblTaskResult set tarDistanceScore=$Pdist, tarSpeedScore=$Pspeed, tarScore=$Pscore where tarPk=$tarPk");
$sth->execute();
}
}
}
1;