My favorites | Sign in
Project Logo
                
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
#!/usr/bin/perl

#
# Reads in a zip file full of .igc files
# should be named as such: FAINO.igc or LASTNAME_FIRSTNAME.igc
#
# Geoff Wong 2007
#

require DBD::mysql;
use Data::Dumper;

use TrackLib qw(:all);

local * DIR;

#
# Extract files and read them all into the database
#
sub extract_igcs
{
my ($f) = @_;

my @fields;
my @names;
my %tracks;
my $row;
my $tmpdir = '/tmp/igcimport/';
my $pilPk;
my $sth;

# clean up and extract files ..
system("/usr/bin/rm -rf $tmpdir");
mkdir($tmpdir, 0755);
system("/usr/bin/unzip $f -d $tmpdir");

opendir(DIR, $tmpdir) or die "can't opendir $f: $!";

while (defined($file = readdir(DIR)))
{
# find the pilot ..
#print "got: $file\n";
if ($file eq "." or $file eq "..")
{
next;
}

@fields = split /\./, $file;

# check size = 2
@names = split /_/, $fields[0];

if (scalar @names < 1)
{
my $pilPk;

$pilPk = $fields[0] + 0;

#print "found: $pilPk\n";
$sth = $dbh->prepare("select pilPk from tblPilot where pilHGFA=$pilPk" );
}
else
{
#print "two found: ", $names[0], " ", $names[1], "\n";
$pilPk = $fields[0] + 0;

if ($pilPk != 0)
{
$sth = $dbh->prepare("select pilPk from tblPilot where pilHGFA=$pilPk" );
}
else
{
$sth = $dbh->prepare("select pilPk from tblPilot where pilLastName='$names[1]' and pilFirstName='$names[0]'");
}
}
$sth->execute();

# add the pilot if they're not found?
$pilPk = $sth->fetchrow_array() + 0;

if ($pilPk == 0)
{
print "Can't find pilot $file in database\n";
}
else
{
print "Found: $file with pilPk=$pilPk\n";
$tracks{$pilPk} = $tmpdir . $file;
}
}

closedir(DIR);

return \%tracks;
}

sub read_all_tracks
{
my ($comPk,$tasPk,$tracks) = @_;
my $file;
my $traPk;
my @fields;
my $out;
my $outo;
my $gliPk;
my $sth;

#print Dumper($tracks);
for my $pilPk ( keys %$tracks )
{
$file = $tracks->{$pilPk};
#print "igcreader.pl $pilPk $file\n";
print "Track read ($file) for pilot=$pilPk\n";
$out = `igcreader.pl "$file" $pilPk`;
$outo = `optimise_flight.pl $traPk`;
@fields = split /traPk=/, $out;
if (scalar @fields < 1)
{
print "Track read ($pilPk:$file) may have failed\n";
next;
}
$traPk=$fields[1] + 0;

# Link track to task/comp.
if ($traPk != 0)
{
$sth = $dbh->prepare("select max(traPk) from tblTrack where pilPk=$pilPk and traGlider <> 'unknown' and traGlider <> ''");
$sth->execute();
$gliPk = $sth->fetchrow_array() + 0;
if ($gliPk > 0)
{
$dbh->do("update tblTrack T, tblTrack P set T.traGlider=P.traGlider and T.traDHV=P.traGlider where T.traPk=$traPk and P.traPk=$gliPk");
}
$dbh->do("insert into tblComTaskTrack (comPk,tasPk,traPk) values (?,?,?)", undef, $comPk, $tasPk, $traPk);

# Verify against the task
print "track_verify_sr.pl $traPk\n";
system("track_verify_sr.pl $traPk");
}
else
{
print "Track read ($pilPk:$file) may have failed: $out\n";
}
}
}

#
# Main program here ..
#

my $tracks;
my $tasPk;
my $comPk;
my $sth;

if (scalar @ARGV < 2)
{
print "bulk_igc_read.pl tasPk zipfile\n";
exit 0;
}

$dbh = db_connect();

# Check the task stuff
$tasPk = $ARGV[0] + 0;

$sth = $dbh->prepare("select comPk from tblTask where tasPk=$tasPk");
$sth->execute();
$comPk = $sth->fetchrow_array() + 0;

if ($comPk == 0)
{
print "Can't find task $tasPk\n";
exit 1;
}

# Find all the tracks
$tracks = extract_igcs($ARGV[1]);

# Read each of the tracks
read_all_tracks($comPk,$tasPk,$tracks);

# Score the round ..
#system("task_score.pl $tasPk");

Show details Hide details

Change log

r82 by geoff.wong on Oct 30, 2009   Diff
Bunch of updates. Smoothed scoring
algorithm for scalps.
Go to: 
Project members, sign in to write a code review

Older revisions

r11 by geoff.wong on Feb 18, 2008   Diff
More OLC handling stuff. Code re-
arranged for track submission /
verification.
r10 by geoff.wong on Feb 17, 2008   Diff
Various updates to separate out OLC
optimisation.

r2 by geoff.wong on Jan 22, 2008   Diff
Initial check-in of the code under new
name :-)
All revisions of this file

File info

Size: 4197 bytes, 185 lines

File properties

svn:executable
*
Hosted by Google Code