-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIdentifyGameEvents.pl
76 lines (61 loc) · 2.89 KB
/
IdentifyGameEvents.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
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl
# Imago <[email protected]>
## Relates AGC Events with Games (EventResuts!)
## This will allow for faster (indexed) scans when post-processing for TrueSkill (balance database updates/inserts)
use strict;
use DBI;
use DateTime::Format::SQLite;
use Data::Dumper;
my ($context,$date,$eid) = @ARGV;
die "Usage: IdentifyGameResults.pl <GameContext> <GameOverEventLocalTime> <GameOverEventID>\n" if (!$context || !$date || !$eid);
#setup the databases
my $dbefile = "C:/Inetpub/wwwroot/build/AllegSkill/events.db";
our $dbeh = DBI->connect("dbi:SQLite:dbname=$dbefile","","") or die $!;
my $dbsfile = "C:/Inetpub/wwwroot/build/AllegSkill/stats.db";
our $dbsh = DBI->connect("dbi:SQLite:dbname=$dbsfile","","") or die $!;
#and queries
our $seledt = $dbeh->prepare(q{SELECT timeEnter, ComputerName FROM EventResults WHERE eid = ?}) or die $!;
our $sele = $dbeh->prepare(q{SELECT eid FROM EventResults WHERE Context = ? AND ComputerName = ? AND (DateTime <= ? AND DateTime >= ?)}) or die $!;
our $sels = $dbsh->prepare(q{SELECT gid,timeEnter, nDuration FROM GameResults WHERE szGameID = ? AND (timeEnter <= ? AND timeEnter >= ?)}) or die $!;
#obtain the database timestamp for the AGC 2031 event
$seledt->execute($eid) or die $!;
my $te; my $comp;
$seledt->bind_columns(\$te,\$comp) or die $!;
$seledt->fetch;
die $! if (!$te);
my $dt = DateTime::Format::SQLite->parse_datetime($te);
#create a 10 second window arount it used for sanity checking
my $dtahead = DateTime::Format::SQLite->parse_datetime($te);
$dtahead->add(seconds => 10);
my $dtbehind = DateTime::Format::SQLite->parse_datetime($te);
$dtbehind->subtract(seconds => 10);
#find the game that matches it
$sels->execute($context,DateTime::Format::SQLite->format_datetime($dtahead),DateTime::Format::SQLite->format_datetime($dtbehind)) or die $!;
my $gid; my $duration; my $teactual;
$sels->bind_columns(\$gid,\$teactual,\$duration) or die $!;
$sels->fetch or die $!;
die $! if (!$duration);
#determine the lag-time from game end post to agc event log post
my $dtactual = DateTime::Format::SQLite->parse_datetime($teactual);
my $dur = $dt->subtract_datetime_absolute($dtactual);
#create the event log window for the game's duration
my $dtback = DateTime::Format::SQLite->parse_datetime($date);
$dtback->subtract(seconds => $duration+15+$dur->seconds()); # game duration + countdown + proceesing / lag
#make a list of eventids
$sele->execute($context,$comp,$date,DateTime::Format::SQLite->format_datetime($dtback)) or die $!;
my $id; my @eids = ();
$sele->bind_columns(\$id) or die $!;
push(@eids,$id) while $sele->fetch;
die $! if (!scalar @eids);
#update the events with the game id
my $sql = sprintf 'UPDATE EventResults SET gid = ? WHERE eid IN ( %s )', join( ',', map { $dbeh->quote( $_ ) } @eids );
my $upd = $dbeh->prepare($sql);
$upd->execute($gid);
#tada
$upd->finish;
$sels->finish;
$sele->finish;
$seledt->finish;
$dbeh->disconnect;
$dbsh->disconnect;
exit 0;