blib/lib/oEdtk/Tracking2.pm

filter: Statementstmt 47.8% 11 / 23 Branchbran 16.6% 1 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod n/a totaltotal 42.5% 17 / 40 CC 5 SCAR 22.0
CC
5
Cov
38%
__ANON__
20.0
__ANON__
2.7
BEGIN
1.5
CRAP 9.0
« blib/lib/oEdtk/lib/cob2pm.pl ↑ Summary lib/oEdtk/logger.pm »
1 package oEdtk::Tracking; ## no critic (Modules::RequireFilenameMatchesPackage)
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 our $WARN2LOGGER; # imported from oEdtk::logger below
6  
7 my ( $_TRACK_SIG, $_TRACK_TRK, @_TRACK_JSON );
8  
9 # xxx TO CHANGE : test if SQLite table already exist before creation
10  
11 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=3.9
12 0 ▶ $SIG{'__WARN__'} = sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
13 0 ▶ if ($WARN2LOGGER) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oEdtk::Tracking::WARN2LOGGER) { } 0 0 0
14 0 &logger( 4, $_[0] );
15 }
16 else {
17 0 warn $_[0];
18 }
19  
20 # when Tracking object is defined, $_TRACK_TRK is defined so that events can be catch and sent to tracker
21 0 ▶ if ( defined $_TRACK_TRK && $_TRACK_SIG =~ /warn/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_TRACK_TRK and $_TRACK_SIG =~ /warn/i) 0 0 0
Condition0%0/3
defined $_TRACK_TRK and $_TRACK_SIG =~ /warn/i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_TRACK_TRK and $_TRACK_SIG =~ /warn/i
defined $_TRACK_TRK $_TRACK_SIG =~ /warn/i
Truth table0%0/3
A and B
A= defined $_TRACK_TRKB= $_TRACK_SIG =~ /warn/i
ABresult
0X0
100
111
22  
23 # http://perldoc.perl.org/functions/warn.html
24 0 my $message = $_[0];
25 0 chomp($message);
26 0 $_TRACK_TRK->track( 'Warn', 1, $message );
27 }
28 1 };
29  
30 21 ▶ $SIG{'__DIE__'} = sub {
Subroutine __ANON__: called CC=2 SCAR=10.1
31 21 ▶ if ( defined $_TRACK_TRK ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_TRACK_TRK) 0 21 21
32 0 my $message = $_[0];
33 0 chomp($message);
34 0 $_TRACK_TRK->track( 'Halt', 1, $message );
35 }
36 21 die $_[0];
37 1 };
38 }
39  
40 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 1 ▶use oEdtk::Main;
Subroutine BEGIN: called CC=1 SCAR=2.6
43 use oEdtk::Config qw(config_read);
44 use oEdtk::DBAdmin qw(db_connect create_table_TRACKING);
45 use oEdtk::logger qw(logger $WARN2LOGGER);
46 use oEdtk::Dict;
47 use Config::IniFiles;
48 use Sys::Hostname;
49 use Data::Dumper qw(Dumper);
50 use DBI;
51  
52 #use JSON;
53 use Exporter;
54  
55 our $VERSION = 2.1126;
56 our @ISA = qw(Exporter);
57 our @EXPORT_OK = qw(stats_iddest stats_week stats_month);
58  
59 #my @JSON_TRACE;
60  
61 sub new {
62  
63 # example call
64 # $TRK = oEdtk::Tracking->new($ARGV[1] // "input file",
65 # ED_USER => "utest",
66 # ED_CORP => "Society",
67 # keys => ['T_CALLID', 'T_TYPE', 'O_TT_TYP', 'O_TT_ID', 'T_PARAM', 'O_DESIGN', 'T_STATUT' ]
68 # );
69  
70 my ( $class, $ED_SOURCE, %params ) = @_;
71 $ED_SOURCE = $ED_SOURCE || ( $ARGV[1] || $ARGV[0] );
72 if ( $ED_SOURCE =~ /^\-/ ) {
73 $ED_SOURCE = $ARGV[0];
74 }
75 my $cfg = config_read('EDTK_DB');
76  
77 # Load the dictionary to normalize entity names.
78 my $EDTK_TRACK_DICT = oEdtk::Dict->new( $cfg->{'EDTK_DICO'}, { invert => 1 } );
79  
80 my $EDTK_TRACK_MODE = uc( $cfg->{'EDTK_TRACK_MODE'} );
81 if ( $EDTK_TRACK_MODE eq 'NONE' ) {
82 warn "INFO: Tracking is currently disabled... (see EDTK_TRACK_MODE in config file)\n";
83  
84 # Return a dummy object if tracking is disabled.
85 return bless { EDTK_TRACK_DICT => $EDTK_TRACK_DICT, mode => $EDTK_TRACK_MODE }, $class;
86 }
87  
88 my $table = $cfg->{'EDTK_DBI_TRACKING'};
89 my $dbh = db_connect( $cfg, 'EDTK_DBI_DSN', { AutoCommit => 1 } );
90  
91 # XXX Should we ensure there is at least one key defined?
92 $cfg->{'EDTK_TRACKING_KEYS'} =~ s/\s+//g;
93 $cfg->{'EDTK_TRACKING_KEYS'} =~ s/[()"']+//g;
94  
95 my @userkeys =
96 ( split( /,/, uc( $cfg->{'EDTK_TRACKING_KEYS'} ), $cfg->{'EDTK_MAX_USER_KEY'} ) ) // [];
97  
98 # print Dumper(@userkeys);
99  
100 # my $keys = $params{'keys'} || [];
101  
102 # if (@$keys > $cfg->{'EDTK_MAX_USER_KEY'}) {
103 # die "ERROR: too many tracking keys: got " . @$keys . ", max " .
104 # $cfg->{'EDTK_MAX_USER_KEY'};
105 # }
106  
107 # Check that all the keys are at most 8 characters long, and otherwise
108 # truncate them. Also ensure we don't have the same key several times.
109 my %seen = ();
110 foreach ( my $i = 0 ; $i <= $#userkeys ; $i++ ) {
111 if ( length( $userkeys[$i] ) > 8 ) {
112 $userkeys[$i] =~ s/^(.{8}).*$/$1/;
113 warn "userkeys[$i] = $userkeys[$i]\n";
114 warn "INFO: column \"\U$_\E\" too long, truncated to \"$userkeys[$i])\"\n";
115 }
116 if ( exists( $seen{ $userkeys[$i] } ) ) {
117 die "ERROR: duplicate column \"$userkeys[$i])\"";
118 }
119  
120 # push(@userkeys, $key);
121 $seen{ $userkeys[$i] } = 1;
122 }
123  
124 # my @userkeys = ();
125 # foreach (@$keys) {
126 # my $key = uc($_);
127 # if (length($key) > 8) {
128 # $key =~ s/^(.{8}).*$/$1/;
129 # warn "INFO: column \"\U$_\E\" too long, truncated to \"$key\"\n";
130 # }
131 # if (exists($seen{$key})) {
132 # die "ERROR: duplicate column \"$key\"";
133 # }
134 # push(@userkeys, $key);
135 # $seen{$key} = 1;
136 # }
137  
138 # Extract application name from the script name.
139 my $ED_APP = $0;
140 $ED_APP =~ s/^.*?[\/\\]?([\w-]+[\.plmex]*$)/$1/;
141  
142 # $ED_APP =~ s/^.*?[\/\\]?([A-Z0-9-_]+)\.pl$/$1/;
143 if ( length($ED_APP) > 20 ) {
144 $ED_APP =~ s/\.pl$//i;
145 $ED_APP =~ /(.{20})$/;
146 warn "INFO: application name \"$ED_APP\" too long, truncated to \"$1\"\n";
147 $ED_APP = $1;
148 }
149  
150 # Validate the editing mode.
151 my $ED_MOD_ED = _validate_edmode( $params{'ED_MOD_ED'} );
152  
153 # Limit username length to 10 characters per the table schema.
154 my $ED_USER = $params{'ED_USER'} || 'None';
155 if ( length($ED_USER) > 10 ) {
156 $ED_USER =~ s/^(.{10}).*$/$1/;
157 warn "INFO: username \"$params{'user'}\" too long, truncated to \"$ED_USER\"\n";
158 }
159  
160 # Truncate if necessary, by taking at most 128 characters on the right.
161 if ( length($ED_SOURCE) > 128 ) {
162 $ED_SOURCE = substr( $ED_SOURCE, -128, 128 );
163 }
164  
165 my $self = bless {
166 dbh => $dbh,
167 table => $table,
168 keys => \@userkeys,
169 EDTK_TRACK_DICT => $EDTK_TRACK_DICT,
170 ED_SNGL_ID => oe_ID_LDOC(),
171 ED_SEQ => 1,
172 EDTK_TRACK_MODE => $EDTK_TRACK_MODE,
173 ED_MOD_ED => $ED_MOD_ED,
174 ED_USER => $ED_USER,
175 ED_SOURCE => $ED_SOURCE,
176 ED_APP => $ED_APP
177 }, $class;
178  
179 my $entity = $params{'entity'} || $cfg->{'EDTK_CORP'};
180 $self->set_entity($entity);
181  
182 # Create the table in the SQLite case
183 if ( $dbh->{'Driver'}->{'Name'} eq 'SQLite' ) {
184 eval { create_table_TRACKING( $dbh, $table, $cfg->{'EDTK_MAX_USER_KEY'} ); };
185 if ($@) {
186 warn "INFO: Table already exist : $@\n";
187 }
188 }
189  
190 $self->track( 'Job', 1, join( ' ', @ARGV ) )
191 ; # keep the join to place all the free parameters in the message area
192 if ( defined $cfg->{'EDTK_TRACK_SIG'} && $cfg->{'EDTK_TRACK_SIG'} !~ /no/i ) {
193 $_TRACK_SIG = $cfg->{'EDTK_TRACK_SIG'};
194 warn
195 "INFO: tracking catchs SIG messages = '$_TRACK_SIG' (see EDTK_TRACK_SIG : 'warn' for all, 'halt' for die only)\n";
196 $_TRACK_TRK = $self;
197 }
198  
199 # if (defined $cfg->{'EDTK_TRACK_JSON'} && $cfg->{'EDTK_TRACK_JSON'} !~/no/i ) {
200 # # $_TRACK_TRK_JSON = $cfg->{'EDTK_TRACK_JSON'};
201 # push (@_TRACK_JSON, $cfg->{'EDTK_TRACK_JSON'});
202 # }
203 # } else {
204 # #$_TRACK_TRK_JSON = "no";
205 # $_TRACK_JSON[0] //= "no";
206 # #push (@_TRACK_JSON, "no");
207 # }
208 # warn "INFO: _TRACK_JSON = " . @_TRACK_JSON ." \n";
209  
210 return $self;
211 }
212  
213 sub track {
214  
215 # example call
216 # $TRK->track('Spool', 1, "K0val", "K1val", "K2val", "Knval" );
217 my ( $self, $ED_JOB_EVT, $count, @data ) = @_;
218  
219 return if $self->{'EDTK_TRACK_MODE'} eq 'NONE';
220  
221 $count ||= 1;
222  
223 my @usercols = @{ $self->{'keys'} };
224 if ( @data > ( @usercols + 1 ) ) {
225  
226 # max is @usercols nbcol + 1 for message col
227 warn "INFO: Too much values : got "
228 . @data
229 . ", expected "
230 . ( @usercols + 1 )
231 . " maximum\n";
232 }
233  
234 # Validate the job event.
235 $ED_JOB_EVT = _validate_event($ED_JOB_EVT);
236  
237 # GENERATE SQL REQUEST.
238 my $values = {
239 ED_SNGL_ID => $self->{'ED_SNGL_ID'},
240 ED_SEQ => $self->{'ED_SEQ'}++,
241 ED_TSTAMP => oe_now_time(),
242 ED_USER => $self->{'ED_USER'},
243 ED_APP => $self->{'ED_APP'},
244 ED_CORP => $self->{'entity'},
245 ED_ACCOUNT => $self->{'account'} // "",
246 ED_MOD_ED => $self->{'edmode'},
247 ED_JOB_EVT => $ED_JOB_EVT,
248 ED_OBJ_TYP => $self->{'obj_typ'},
249 ED_OBJ_COUNT => $count,
250 ED_CHILD_TYP => $self->{'child_typ'} // "",
251 ED_CHILD_ID => $self->{'child_id'} // "",
252 ED_PARENT_ID => $self->{'parent_id'} // "",
253  
254 ED_HOST => hostname(),
255 ED_SOURCE => $self->{'ED_SOURCE'}
256 };
257  
258 foreach my $i ( 0 .. $#data ) {
259  
260 # add a message column to handle messages and warnings
261 # to ensure compatibility with what exists, we reverse
262 # the data to put the message first while waiting for job_evt
263 ################## PBM DATA NOT POPULATED, TO REVIEW
264 my $val = $data[$i] // "";
265 $values->{'ED_MESSAGE'} = $val . " " . ( $values->{'ED_MESSAGE'} // "" );
266  
267 # if there is only one data item, make sure not to put it needlessly in a user column
268 if ( $#data > 0 ) {
269 if ( defined( $data[$i] ) && length( $data[$i] ) > 128 ) {
270 warn "INFO: \"$data[$i]\" truncated to 128 characters\n";
271 $data[$i] =~ s/^(.{128}).*$/$1/;
272 }
273 $values->{"ED_K${i}_NAME"} = $usercols[$i];
274 $values->{"ED_K${i}_VAL"} = $val;
275 }
276 }
277  
278 if ( $ED_JOB_EVT eq 'W' || $ED_JOB_EVT eq 'H' ) { # Halt or Warn event
279 # if ED_JOB_EVT is 'Warning' or 'Halt' we handle the messages and the source
280 chomp $values->{'ED_MESSAGE'};
281 $values->{'ED_MESSAGE'} =~ s/\s+/ /g;
282 $values->{'ED_MESSAGE'} =~ s/^(.{256}).*$/$1/;
283 $values->{'ED_SOURCE'} = $self->{'ED_SOURCE'} if ( $ED_JOB_EVT eq 'H' );
284  
285 }
286 elsif ( $ED_JOB_EVT eq 'J' ) { # ED_JOB_EVT event
287 $values->{'ED_SOURCE'} = $self->{'ED_SOURCE'};
288  
289 }
290 else {
291 undef( $values->{'ED_MESSAGE'} );
292 }
293  
294 my @cols = keys(%$values);
295 my $table = $self->{'table'};
296 my $sql =
297 "INSERT INTO $table ("
298 . join( ', ', @cols )
299 . ") VALUES ("
300 . join( ', ', ('?') x @cols ) . ")";
301  
302 #warn "sql = $sql \n";
303 #sql = INSERT INTO EDTK_TRACKING (ED_JOB_EVT, ED_APP, ED_CORP, ED_OBJ_TYP, ED_USER, ED_MESSAGE, ED_TSTAMP, ED_SNGL_ID, ED_OBJ_COUNT, ED_MOD_ED, ED_SOURCE, ED_SEQ, ED_HOST) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
304  
305 my $dbh = $self->{'dbh'};
306 my $sth = $dbh->prepare($sql);
307 $sth->execute( values(%$values) ) or die $sth->errstr;
308  
309 if ( !$dbh->{'AutoCommit'} ) {
310 $dbh->commit or die $dbh->errstr;
311 }
312  
313 #if ($_TRACK_JSON[0] ne "no") { push (@_TRACK_JSON, $values) };
314 }
315  
316 sub set_entity {
317 my ( $self, $entity ) = @_;
318  
319 if ( !defined($entity) || length($entity) == 0 ) {
320 warn "INFO: Tracking::set_entity() called with an undefined entity!\n";
321 return;
322 }
323  
324 # warn "INFO: translate >$entity< \n";
325 $entity = $self->{'EDTK_TRACK_DICT'}->translate($entity);
326 $self->{'entity'} = $entity;
327  
328 # warn $self->{'entity'}. " \$self->{'entity'}\n";
329 }
330  
331 sub end {
332 my $self = shift;
333 $self->track( 'Halt', 1 );
334 }
335  
336 # For each application, for each legal entity, and for each week
337 # the number of documents in the tracking.
338 sub stats_week {
339  
340 # pass the options as hash keys...
341 my ( $dbh, $cfg, $start, $end, $excluded_users ) = @_;
342  
343 my $table = $cfg->{'EDTK_STATS_TRACKING'};
344 my $innersql =
345 "SELECT ED_CORP, ED_APP, "
346 . "'S' || TO_CHAR(TO_DATE(ED_TSTAMP, 'YYYYMMDDHH24MISS'), 'IW') AS ED_WEEK "
347 . "FROM $table "
348 . "WHERE ED_JOB_EVT = 'D' AND ED_TSTAMP >= ? ";
349 my @vals = ($start);
350 if ( defined($end) ) {
351 $innersql .= " AND ED_TSTAMP <= ? ";
352 push( @vals, $end );
353 }
354  
355 if ( defined $excluded_users ) {
356 my @excluded = split( /,\s*/, $excluded_users );
357 for ( my $i = 0 ; $i <= $#excluded ; $i++ ) {
358 $innersql .= " AND ED_USER != ? ";
359 }
360 push( @vals, @excluded );
361 }
362  
363 my $sql = "SELECT i.ED_CORP, i.ED_APP, i.ED_WEEK, COUNT(*) AS ED_COUNT "
364 . "FROM ($innersql) i GROUP BY ED_CORP, ED_APP, ED_WEEK ";
365  
366 # warn "\nINFO: $sql \n";
367 #SELECT i.ED_CORP, i.ED_APP, i.ED_WEEK, COUNT(*) AS ED_COUNT
368 # FROM (
369 # SELECT ED_CORP, ED_APP, 'S' || TO_CHAR(TO_DATE(ED_TSTAMP, 'YYYYMMDDHH24MISS'), 'IW') AS ED_WEEK
370 # FROM EDTK_TRACKING_2010 WHERE ED_JOB_EVT = 'D' AND ED_TSTAMP >= '20101212'
371 # ) i
372 # GROUP BY ED_CORP, ED_APP, ED_WEEK;
373  
374 my $rows = $dbh->selectall_arrayref( $sql, { Slice => {} }, @vals );
375  
376 # use Data::Dumper;
377 # print Dumper($rows);
378 # {
379 # 'ED_COUNT' => '4',
380 # 'ED_APP' => 'FUS-AC007',
381 # 'ED_CORP' => 'CPLTR',
382 # 'ED_WEEK' => 'S51'
383 # },
384  
385 return $rows;
386 }
387  
388 sub stats_iddest {
389  
390 # pass the options as hash keys...
391 my ( $dbh, $cfg, $start, $end, $excluded_users, $ed_app ) = @_;
392  
393 my $table = $cfg->{'EDTK_STATS_TRACKING'};
394 my $innersql =
395 "SELECT ED_CORP, ED_K1_VAL AS ED_EMET, ED_K0_VAL AS ED_IDDEST, ED_APP, "
396 . "'S' || TO_CHAR(TO_DATE(ED_TSTAMP, 'YYYYMMDDHH24MISS'), 'IW') AS ED_WEEK "
397 . "FROM $table "
398 . "WHERE ED_JOB_EVT = 'D' AND ED_TSTAMP >= ? ";
399 my @vals = ($start);
400 if ( defined($end) ) {
401 $innersql .= " AND ED_TSTAMP <= ? ";
402 push( @vals, $end );
403 }
404  
405 if ( defined $excluded_users ) {
406 my @excluded = split( /,\s*/, $excluded_users );
407 for ( my $i = 0 ; $i <= $#excluded ; $i++ ) {
408 $innersql .= " AND ED_USER != ? ";
409 }
410 push( @vals, @excluded );
411 }
412  
413 if ( defined $ed_app ) {
414 $innersql .= " AND ED_APP = ? ";
415 push( @vals, $ed_app );
416 }
417  
418 my $sql = "SELECT i.ED_CORP, i.ED_EMET, i.ED_IDDEST, i.ED_APP, i.ED_WEEK, COUNT(*) AS ED_COUNT "
419 . "FROM ($innersql) i GROUP BY i.ED_CORP, i.ED_EMET, i.ED_IDDEST, i.ED_APP, i.ED_WEEK ";
420  
421 # warn "INFO: $sql \n";
422 # warn "INFO: @vals \n";
423 # SELECT i.ED_CORP, i.ED_SECTION, i.ED_IDDEST, i.ED_APP, i.ED_WEEK, COUNT(*) AS ED_COUNT
424 # FROM (
425 # SELECT ED_CORP, ED_K1_VAL AS ED_SECTION, ED_K0_VAL AS ED_IDDEST, ED_APP,
426 # 'S' || TO_CHAR(TO_DATE(ED_TSTAMP, 'YYYYMMDDHH24MISS'), 'IW') AS ED_WEEK
427 # FROM EDTK_TRACKING_2010 WHERE ED_JOB_EVT = 'D' AND ED_TSTAMP >= ?
428 # AND ED_TSTAMP <= ? AND ED_USER != ? AND ED_APP = ? ) i
429 # GROUP BY i.ED_CORP, i.ED_SECTION, i.ED_IDDEST, i.ED_APP, i.ED_WEEK
430  
431 my $rows = $dbh->selectall_arrayref( $sql, { Slice => {} }, @vals );
432  
433 # use Data::Dumper;
434 # print Dumper($rows);
435 # {
436 # 'ED_COUNT' => '2',
437 # 'ED_APP' => 'CTP-AC001',
438 # 'ED_IDDEST' => '0000428193',
439 # 'ED_CORP' => 'CORP_1',
440 # 'ED_WEEK' => 'S50',
441 # 'ED_EMET' => 'P004'
442 # },
443  
444 return $rows;
445 }
446  
447 # For each application, for each E.R., for each legal entity
448 # and for each month, the number of documents in the tracking.
449 sub stats_month {
450 my ( $dbh, $cfg, $start, $end, $excluded_users ) = @_;
451  
452 my $table = $cfg->{'EDTK_STATS_TRACKING'};
453 my $innersql =
454 "SELECT ED_APP, ED_CORP, ED_K1_VAL AS ED_EMET, "
455 . "'M' || TO_CHAR(TO_DATE(ED_TSTAMP, 'YYYYMMDDHH24MISS'), 'MM') AS ED_MONTH "
456 . "FROM $table WHERE ED_JOB_EVT = 'D' AND ED_TSTAMP >= ? "; # AND ED_K1_NAME = 'SECTION'
457 my @vals = ($start);
458  
459 if ( defined($end) ) {
460 $innersql .= " AND ED_TSTAMP <= ? ";
461 push( @vals, $end );
462 }
463  
464 if ( defined $excluded_users ) {
465 my @excluded = split( /,\s*/, $excluded_users );
466 for ( my $i = 0 ; $i <= $#excluded ; $i++ ) {
467 $innersql .= " AND ED_USER != ? ";
468 }
469 push( @vals, @excluded );
470 }
471  
472 my $sql = "SELECT i.ED_APP, i.ED_CORP, i.ED_EMET, i.ED_MONTH, COUNT(*) AS ED_COUNT "
473 . "FROM ($innersql) i GROUP BY ED_APP, ED_CORP, ED_EMET, ED_MONTH ";
474  
475 my $rows = $dbh->selectall_arrayref( $sql, { Slice => {} }, @vals );
476  
477 # use Data::Dumper;
478 # print Dumper($rows);
479 # 'ED_MONTH' => 'M12',
480 # 'ED_COUNT' => '1',
481 # 'ED_CORP' => 'CORP_1',
482 # 'ED_APP' => 'DEV-CAMELEON',
483 # 'ED_EMET' => '37043'
484  
485 return $rows;
486 }
487  
488 #my $_PRGNAME;
489  
490 sub _validate_event {
491  
492 # Job Event : looking for one of the following :
493 # Job (default), Spool, Document, Line, Warning, Error, Halt (critic), Reject
494 my $job = shift;
495  
496 warn "INFO: Halt event in Tracking = $job\n" if ( $job =~ /^H/ );
497 if ( !defined $job || $job !~ /^([JSDLWEHR])/ ) {
498 die "ERROR: Invalid job event : "
499 . ( defined $job ? $job : '(undef)' ) . "\n"
500 . "\t valid events are : Job / Spool / Document / Line / Warning / Reject / Error / Halt (critic)\n";
501 }
502 return $1;
503 }
504  
505 #{
506 #my $_edmode;
507 #
508 # sub display_edmode {
509 # if (!defined $_edmode) {
510 # $_edmode = _validate_edmode(shift);
511 # }
512 # return $_edmode;
513 # }
514  
515 sub _validate_edmode {
516  
517 # Printing Mode : looking for one of the following :
518 # Undef (default), Batch, Tp, Web, Mail, probinG
519 my $edmode = shift;
520  
521 if ( !defined $edmode || $edmode !~ /^([BTMWG])/ ) {
522 return 'U';
523 }
524 return $1;
525 }
526  
527 #}
528  
529 #END {
530 # #if ($_TRACK_TRK_JSON !~/no/i) {
531 # if ($_TRACK_JSON[0] ne "no") {
532 # my $json = JSON->new;
533 # #print $json->encode(\@_TRACK_JSON);
534 # }
535 #}
536  
537 1;
538  
539 =head1 NAME
540  
541 oEdtk::Tracking2 - legacy warn-based production tracking
542  
543 =head1 SYNOPSIS
544  
545 use oEdtk::Tracking;
546  
547 my $trk = oEdtk::Tracking->new($source, entity => 'Corp');
548 $trk->track('Job', 1, @values);
549 $trk->end;
550  
551 =head1 DESCRIPTION
552  
553 Legacy, warn-based duplicate of L<oEdtk::Tracking>. It declares the same package
554 C<oEdtk::Tracking> and the same public interface, but reports its diagnostics
555 through C<warn> instead of the logger, and reads the user keys from the
556 configuration rather than from the constructor arguments. It is kept for
557 reference; use L<oEdtk::Tracking> for new code.
558  
559 =head1 METHODS
560  
561 =head2 new
562  
563 my $trk = oEdtk::Tracking->new($source, %params);
564  
565 Build a tracker. C<$source> names the input, and C<%params> may carry C<entity>,
566 C<edmode>, C<account>, C<obj_typ>, C<child_typ>, C<child_id> and C<parent_id>.
567 The user keys come from the C<EDTK_TRACKING_KEYS> configuration. When
568 C<EDTK_TRACK_MODE> is C<NONE> an inert object is returned.
569  
570 =head2 track
571  
572 $trk->track($job, $count, @data);
573  
574 Record one event: the job event, the number of objects, and the values of the
575 configured user keys (an optional trailing value is the message).
576  
577 =head2 set_entity
578  
579 $trk->set_entity($entity);
580  
581 Normalise C<$entity> through the dictionary and store it.
582  
583 =head2 end
584  
585 $trk->end;
586  
587 Record the final C<Halt> event.
588  
589 =head1 FUNCTIONS
590  
591 =head2 stats_iddest
592  
593 my $rows = stats_iddest($dbh, $cfg, $start, $end, $excluded_users, $ed_app);
594  
595 Per recipient destination, per week, the number of documents tracked between
596 C<$start> and C<$end>.
597  
598 =head2 stats_week
599  
600 my $rows = stats_week($dbh, $cfg, $start, $end, $excluded_users);
601  
602 Per application, per legal entity and per ISO week, the number of documents
603 tracked during the period.
604  
605 =head2 stats_month
606  
607 my $rows = stats_month($dbh, $cfg, $start, $end, $excluded_users);
608  
609 Per application, per legal entity and per month, the number of documents tracked
610 during the period.
611  
612 The following subs are internal helpers and are not part of the public API:
613 C<_validate_event> and C<_validate_edmode>.
614  
615 =head1 AUTHOR
616  
617 The oEdtk team.
618  
619 =cut
« blib/lib/oEdtk/lib/cob2pm.pl ↑ Summary lib/oEdtk/logger.pm »