-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathRTGap.pm
More file actions
executable file
·269 lines (219 loc) · 6.78 KB
/
Copy pathRTGap.pm
File metadata and controls
executable file
·269 lines (219 loc) · 6.78 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#!/usr/bin/perl -I/home/geoff/bin
#
# Determines how much of a task (and time) is completed
# given a particular competition / task
#
# Geoff Wong 2007
#
package RTGap;
require Gap;
@ISA = ( "Gap" );
#require DBD::mysql;
#use POSIX qw(ceil floor);
#use Math::Trig;
#use Data::Dumper;
#use TrackLib qw(:all);
sub points_weight
{
my ($self, $task, $taskt, $formula) = @_;
my $Fversion;
my $quality;
my $distweight;
my ($Adistance, $Aspeed, $Astart, $Aarrival);
my $x;
$quality = $taskt->{'quality'};
#print "distweight=$distweight($Ngoal/$Nfly)\n";
$x = $taskt->{'goal'} / $taskt->{'launched'};
$distweight = 1-0.8*sqrt($x);
$Adistance = 1000 * $quality * $distweight;
$Aspeed = 1000 * $quality * (1-$distweight);
$Fversion = $formula->{'version'};
print "points_weight (1): ($Fversion) Quality=$quality Adist=$Adistance, Aspeed=$Aspeed, Astart=$Astart, Aarrival=$Aarrival\n";
return ($Adistance, $Aspeed, $Astart, $Aarrival);
}
#
# Calculate Task Validity - GAP
#
# Distance Validity - is the ratio between the area under the ActDistrib and
# the area under the NomDistrib. Only the areas above MinDist considered.
#
sub day_quality
{
my ($self, $taskt, $formula) = @_;
my $launch = 0;
my $distance = 0;
my $time = 0;
my $topspeed;
my $x;
if ($taskt->{'pilots'} == 0)
{
$launch = 0;
$distance = 0;
$time = 0.1;
return ($distance,$time,$launch);
}
$launch = 1;
$time = 1;
$distance = 2*($taskt->{'distance'}-$taskt->{'launched'}*$formula->{'mindist'}) /
($taskt->{'launched'}*(1+$formula->{'nomgoal'}/100)*($formula->{'nomdist'}-$formula->{'mindist'}));
print "distance quality=$distance\n";
if ($distance > 1)
{
$distance = 1;
}
if ($distance < 0)
{
$distance = 0;
}
return ($distance,$time,$launch,1);
}
# POINTS ALLOCATION
# Points Allocation:
# x=Ngoal/Nfly
# distweight = 1-0.8*x^0.5
#
# Pilot Distance Score:
# half of the available distance points is assigned linearly with the
# distance flown; the other half is assigned considering the relative
# difficulty of each km flown.
# DistancePoints =
# Available DistancePoints *(PilotDistance/(2*MaxDistance) + KmDiff)
#
# Pilot speed score:
# P.speed = 1-((PilotTime-Tmin)/radq(Tmin))^(2/3)
#
sub points_allocation
{
my ($self, $dbh, $task, $taskt, $formula) = @_;
my $tasPk;
my $quality;
my $Ngoal;
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;
# Find fastest pilot into goal and calculate leading coefficients
# for each track .. (GAP2002 only?)
$tasPk = $task->{'tasPk'};
$quality = $taskt->{'quality'};
$Ngoal = $taskt->{'goal'};
$Tmin = $taskt->{'fastest'};
$Tfarr = $taskt->{'firstarrival'};
$Cmin = $taskt->{'mincoeff'};
print "Nfly=$Nfly Nlo=$Nlo\n";
# Some GAP basics
($Adistance, $Aspeed, $Astart, $Aarrival) = $self->points_weight($task, $taskt, $formula);
# 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->execute();
while ($ref = $sth->fetchrow_hashref())
{
my %taskres;
%taskres = ();
$taskres{'tarPk'} = $ref->{'tarPk'};
$taskres{'penalty'} = $ref->{'tarPenalty'};
$taskres{'distance'} = $ref->{'tarDistance'};
# set pilot to min distance if they're below that ..
if ($taskres{'distance'} < $formula->{'mindist'})
{
$taskres{'distance'} = $formula->{'mindist'};
}
$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'};
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;
my $Parrival;
my $Pdepart;
my $Pscore;
my $tarPk;
my $penalty;
my $pilrdist;
$tarPk = $pil->{'tarPk'};
$penalty = $pil->{'penalty'};
# Pilot distance score
# FIX: should round $pil->distance properly?
# $pilrdist = round($pil->{'distance'}/100.0) * 100;
$Pdist = $Adistance * ($pil->{'distance'}/$taskt->{'maxdist'});
# Pilot speed score
print "$tarPk speed: ", $pil->{'time'}, ", $Tmin\n";
if ($pil->{'time'} > 0)
{
$Pspeed = $Aspeed * (1-(($pil->{'time'}-$Tmin)/3600/sqrt($Tmin/3600))**(2/3));
}
else
{
$Pspeed = 0;
}
if ($Pspeed < 0)
{
$Pspeed = 0;
}
if (0+$Pspeed != $Pspeed)
{
print "Pdepart is nan for $tarPk, pil->{'time'}=", $pil->{'time'}, "\n";
$Pspeed = 0;
}
# Pilot departure score
print "$tarPk pil->startSS=", $pil->{'startSS'}, "\n";
print "$tarPk pil->endSS=", $pil->{'endSS'}, "\n";
print "$tarPk tast->first=", $taskt->{'firstdepart'}, "\n";
# No arrival/departure
$Pdepart = 0;
$Parrival = 0;
# Penalty for not making goal ..
if ($pil->{'goal'} == 0)
{
$Pspeed = $Pspeed - $Pspeed * $formula->{'sspenalty'};
}
if (($pil->{'result'} eq 'dnf') or ($pil->{'result'} eq 'abs'))
{
$Pdist = 0;
$Pspeed = 0;
$Parrival = 0;
$Pdepart = 0;
}
$Pscore = $Pdist + $Pspeed + $Parrival + $Pdepart - $penalty;
# Store back into tblTaskResult ...
if (defined($tarPk))
{
print "update $tarPk: d:$Pdist, s:$Pspeed, p: $penalty, a:$Parrival, g:$Pdepart\n";
$sth = $dbh->prepare("update tblTaskResult set
tarDistanceScore=$Pdist, tarSpeedScore=$Pspeed,
tarArrival=$Parrival, tarDeparture=$Pdepart, tarScore=$Pscore
where tarPk=$tarPk");
$sth->execute();
}
}
}
1;
1;