]> iEval git - gruntmaster-data.git/blame - lib/Gruntmaster/Opener.pm
Ignore pending and running jobs when building standings
[gruntmaster-data.git] / lib / Gruntmaster / Opener.pm
CommitLineData
a832cd59
MG
1package Gruntmaster::Opener;
2use 5.014;
3use warnings;
4
5use parent qw/Exporter/;
6use re '/s';
7
8our @EXPORT = qw/handle_line/;
9our @EXPORT_OK = @EXPORT;
b35cbc0d 10our $VERSION = '5999.000_016';
a832cd59
MG
11
12use Date::Parse qw/str2time/;
13use Gruntmaster::Data;
14
15sub _analyze_request {
16 s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg for @_; # From URI::Escape POD
17 my ($req, $parms) = @_;
18 return unless $parms =~ /contest=(\w+)/;
19 my $ct = $1;
20 return $req =~ m,/pb/(\w+), ? ($1, $ct) : ();
21}
22
23sub handle_line {
24 my ($owner, $datetime, $request, $parms) = $_[0] =~
25 /(\w+)\s # user
26 \[([^]]+)\]\s # date
27 "\w+\s # request method
28 ([^" ?]+) # URL (without query string)
29 [?]
30 ([^" ]+)\s # query string
31 [^"]+"\s # HTTP version
32 2 # response code starts with 2
33 /x or return;
34 my ($pb, $ct) = _analyze_request $request, $parms or return;
35 my $time = str2time $datetime;
36 open_problem $ct, $pb, $owner, $time;
37}
38
391;
40__END__
41
42=encoding utf-8
43
44=head1 NAME
45
46Gruntmaster::Opener - Populate opens table from NCSA access logs
47
48=head1 SYNOPSIS
49
50 use Gruntmaster::Opener;
51
52 open my $fh, '<', '/var/log/apache2/access.log';
53 handle_line $_ while <$fh>;
54
55=head1 DESCRIPTION
56
57Gruntmaster::Opener is the backend of the L<gruntmaster-opener> script
58that reads NCSA-style access logs, finds lines that represent
59successful requests to problems during contests, extracts data from
60them and inserts it into the database.
61
62B<handle_line>($line)
63
64The only function in this module. Exported by default. Takes a single
65parameter, a line from a logfile in NCSA common/combined format.
66
67If the request described in the given line:
68
69=over
70
71=item *
72
73Is successful (response code is 2xx)
74
75=item *
76
77Targets a problem (C</pb/something>)
78
79=item *
80
81Has a query parameter named C<contest>
82
83=item *
84
85Happened during the contest named in the C<contest> query parameter
86(this restriction is enforced by the B<open_problem> function).
87
88=back
89
90an entry is added to the C<opens> table, using the B<open_problem>
91function from L<Gruntmaster::Data>.
92
93=head1 SEE ALSO
94
95L<gruntmaster-opener>
96
97=head1 AUTHOR
98
99Marius Gavrilescu E<lt>marius@ieval.roE<gt>
100
101=head1 COPYRIGHT AND LICENSE
102
b35cbc0d 103Copyright (C) 2014-2016 by Marius Gavrilescu
a832cd59
MG
104
105This library is free software; you can redistribute it and/or modify
e1b9f3dd 106it under the same terms as Perl itself, either Perl version 5.20.1 or,
a832cd59
MG
107at your option, any later version of Perl 5 you may have available.
108
109
110=cut
This page took 0.034028 seconds and 4 git commands to generate.