forked from dginev/deprecated-CorTeX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cortex-frontend
671 lines (614 loc) · 26.3 KB
/
cortex-frontend
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
#!/usr/bin/perl
# /=====================================================================\ #
# | CorTeX Framework | #
# | Frontend - Mojo web server & interface | #
# |=====================================================================| #
# | Part of the LaMaPUn project: https://trac.kwarc.info/lamapun/ | #
# | Research software, produced as part of work done by: | #
# | the KWARC group at Jacobs University | #
# | Copyright (c) 2012 | #
# | Released under the GNU Public License | #
# |---------------------------------------------------------------------| #
# | Deyan Ginev <[email protected]> #_# | #
# | http://kwarc.info/people/dginev (o o) | #
# \=========================================================ooo==U==ooo=/ #
use strict;
use warnings;
use Encode;
use HTML::Entities;
use File::Basename 'dirname';
use File::Spec::Functions 'catdir';
my ($libdir, $cortexgears);
my $FILE_BASE;
BEGIN {
$FILE_BASE = dirname(__FILE__);
$cortexgears = $FILE_BASE.'/cortex-gears';
$libdir = catdir($FILE_BASE,"lib");
}
if (-d $libdir) {
use lib $libdir;
}
use feature qw(switch);
use Data::Dumper;
use CorTeX::Util::DB_File_Utils qw(db_file_connect db_file_disconnect);
# TODO: Make this customizable from the interface (if that makes sense?)
our $MAIN_REPOS = 'buildsys';
our $META_GRAPH = 'meta';
our $BUILD_SYSTEM_URL = 'http://buildsys.mathweb.org';
our $gears_workhorse_pid;
# TODO: Rethink where the Cron Builder / Gears Client belongs
# 1. First Fork a CorTeX Gears Builder
$SIG{CHLD} = 'IGNORE'; # Let them die!
$SIG{'INT'} = \&stop_cron; # Interrupt handler
$SIG{'HUP'} = \&stop_cron; # Apache Hangup handler
$SIG{'KILL'} = \&stop_cron; # Just good-old KILL handler
my $dbhandle = db_file_connect;
my $saved_pid = $dbhandle->{gears_workhorse_pid};
db_file_disconnect($dbhandle);
my $gears_alive = ($saved_pid && (kill 0, $saved_pid));
if (!$gears_alive) { # Non booted, start a new one:
$gears_workhorse_pid = fork();
if ($gears_workhorse_pid == 0) {
exec($cortexgears);
}
$dbhandle = db_file_connect;
$dbhandle->{gears_workhorse_pid} = $gears_workhorse_pid;
db_file_disconnect($dbhandle);
}
sub stop_cron {
if ($gears_workhorse_pid) {
kill 2, $gears_workhorse_pid;
waitpid($gears_workhorse_pid,0);
}
exit 0;
}
# 2. Now start the web server
use Mojolicious::Lite;
use CorTeX::Import;
use CorTeX::Backend;
our $version = '0.1';
push @{app->renderer->paths}, catdir($FILE_BASE, 'templates');
push @{app->static->paths}, catdir($FILE_BASE, 'public');
$ENV{MOJO_HOME} = $FILE_BASE;
$ENV{MOJO_MAX_MESSAGE_SIZE} = 10485760; # 10 MB file upload limit
$ENV{MOJO_REQUEST_TIMEOUT} = 60;# 1 minute;
$ENV{MOJO_CONNECT_TIMEOUT} = 60; # 1 minute
$ENV{MOJO_INACTIVITY_TIMEOUT} = 60; # 1 minutes;
# Make signed cookies secure
app->secret('TiX TeX');
get '/' => sub {
my $self = shift;
return $self->redirect_to('login') unless $self->session('name');
$self->redirect_to('overview');
};
get '/overview' => sub {
my ($self) = @_;
return $self->redirect_to('login') unless $self->session('name');
$self->render;
} => 'cortex-overview';
get '/admin' => sub {
my $self = shift;
my $dbfile = db_file_connect;
$self->stash(current_exist_url=>$dbfile->{exist_url});
$self->stash(current_sesame_url=>$dbfile->{sesame_url});
$self->stash(current_proxy_url=>$dbfile->{proxy_url});
# TODO: MySQL URL?
$self->stash(current_gearman_urls=>
$dbfile->{gearman_urls} ? [split("\n",$dbfile->{gearman_urls})] : []);
db_file_disconnect($dbfile);
$self->render;
} => 'cortex-admin';
get '/dev' => sub {
my $self = shift;
return $self->redirect_to('login') unless $self->session('name');
my $taskdb = $self->backend->taskdb;
my $current_corpora = $taskdb->current_corpora;
my $current_services = $taskdb->current_services;
# NOTE: Beware the switch of perspective here:
# -- the Task DB has a number of out formats on record
# -- which are exactly the available INPUT formats for a new service
# that will be positioned further down the pipeline
my $current_outputformats = $taskdb->current_outputformats;
$self->stash(current_corpora=>$current_corpora);
$self->stash(current_services=>$current_services);
$self->stash(current_input_formats=>$current_outputformats);
$self->render;
} => 'cortex-dev';
# use AnyEvent::Gearman;
# my $client = gearman_client '127.0.0.1';
# get '/gearman' => sub {
# my ($self)=@_;
# $client->add_task(
# test => "Hello, World!",
# on_complete => sub {
# my $result = $_[1];
# $self->render(text=>$result);
# },
# on_fail => sub {$self->render(text=>'failure');},
# );
# };
get '/corpus-report' => sub {
my $self = shift;
return $self->redirect_to('login') unless $self->session('name');
my $current_corpora = $self->backend->taskdb->current_corpora;
$self->stash(current_corpora=>$current_corpora);
$self->render;
} => 'cortex-corpus-report';
get '/service-report' => sub {
my $self = shift;
return $self->redirect_to('login') unless $self->session('name');
my $current_services = $self->backend->taskdb->current_services;
$self->stash(current_services=>$current_services);
$self->render;
} => 'cortex-service-report';
get '/report' => sub {
my $self=shift;
return $self->redirect_to('login') unless $self->session('name');
$self->render;
} => 'cortex-report';
helper verify_user => sub {
my ($self,$name,$pass)=@_;
# TODO: Stub, admin:admin is the hardcoded test
return 'admin' if (($name eq $pass) && ($name eq 'admin'));
};
get '/login' => sub {
my $self = shift;
my $name = $self->param('name') || '';
my $pass = $self->param('pass') || '';
return $self->render
unless ($self->verify_user($name, $pass) eq 'admin');
$self->session(name => $name);
$self->flash(message => "Thanks for logging in $name!");
$self->redirect_to('overview');
} => 'cortex-login';
get '/logout' => sub {
my $self = shift;
$self->session(expires => 1);
$self->flash(message => "Successfully logged out!");
$self->redirect_to('login');
};
post '/ajax' => sub {
my $self=shift;
return $self->redirect_to('login') unless $self->session('name');
my $action = $self->param('action');
given ($action) {
when ('add-corpus') { $self->add_corpus; }
when ('delete-corpus') {} #TODO
when ('add-service') { $self->add_service; }
when ('update-service') { $self->update_service; }
#when ('delete-service') { $self->delete_service; }
when ('service-description') {$self->service_description;}
when ('register-proxy') { $self->register_proxy; }
when ('register-databases') { $self->register_databases; }
when ('register-workers') { $self->register_workers; }
when ('corpus-report') { $self->corpus_report; }
when ('service-report') { $self->service_report; }
when ('classic-report') {$self->classic_report; }
when ('queue-rerun') { $self->queue_rerun; }
default {$self->render(json=>{message=>"Unrecognized action \"$action\"!"});}
}
};
get '/retval_detail' => sub {
my $self = shift;
my $dbfile = db_file_connect();
my $backend = CorTeX::Backend->new(sesame_url=>$dbfile->{sesame_url}||'',exist_url=>$dbfile->{exist_url}||'');
db_file_disconnect($dbfile);
my $corpus_name = $self->param("corpus");
my $service_name = $self->param("service");
my $countby = $self->param("countby");
my $component = [ split(/:/, $self->param('component')) ];
# 3 items max, slurp anything that follows:
$component->[3] = join(":",@$component[3..scalar(@$component)-1]) if (@$component>4);
$component = [ map { my @parts = split(' ',$_); $parts[0]; } @$component ];
my $from = $self->param('from') || 0;
my $limit = $self->param('limit') || 100;
my $entries = $backend->taskdb->get_custom_entries({severity=>$component->[1],category=>$component->[2],
what=>$component->[3],from=>$from,limit=>$limit,
corpus=>$corpus_name,service=>$service_name,
repository=>$MAIN_REPOS, graph=>$META_GRAPH});
foreach my $entry(@$entries) {
$entry->[2] = $backend->docdb->entry_to_url($entry->[0]); }
$self->stash(severity=>$component->[1]);
$self->stash(category=>$component->[2]);
$self->stash(what=>$component->[3]);
$self->stash(entries=>$entries);
$self->stash(corpus_name=>$corpus_name);
$self->stash(service_name=>$service_name);
# Prepare exploration links:
my $count=0;
if ($component->[1] ne 'ok') {
my $whats = $backend->taskdb->get_result_summary(
repository=>$MAIN_REPOS,
corpus=>$corpus_name,
service=>$service_name,
countby=>$countby,
severity=>$component->[1],
category=>$component->[2]
);
$count = $whats->{$component->[3] ? $component->[3] : $component->[2]};
} else {
my $whats = $backend->taskdb->get_result_summary(
repository=>$MAIN_REPOS,
countby=>$countby,
corpus=>$corpus_name,
service=>$service_name);
$count = $whats->{$component->[1]};
}
$self->stash(count=>$count||0);
$self->stash(limit=>$limit);
$self->stash(from=>$from);
$self->stash(component=>$self->param('component'));
$self->render;
} => 'cortex-retval-detail';
# CONVENTION: !!!
# Parameters use dashes, any Perl-based variables use underscores !!!
# otherwise, all kinds of confusion + headaches come in
helper backend => sub {
my $self = shift;
my $dbfile = db_file_connect;
my $backend = CorTeX::Backend->new(%$dbfile);
$dbfile = db_file_disconnect;
return $backend;
};
helper register_proxy => sub {
my $self = shift;
my $dbfile = db_file_connect;
$dbfile->{proxy_url} = $self->param('http-proxy') if defined $self->param('http-proxy');
db_file_disconnect($dbfile);
$self->render(json=>{message=>"New Proxy URL registered!"});
};
helper register_databases => sub {
my $self = shift;
my %o = ();
$o{exist_url} = $self->param('exist-url')||'';
$o{sesame_url} = $self->param('sesame-url')||'';
$o{sql_url} = $self->param('sql-url')||'';
$o{docdb_type} = $self->param('docdb-type');
$o{metadb_type} = $self->param('metadb-type');
$o{taskdb_type} = $self->param('taskdb-type');
my $backend = CorTeX::Backend->new(%o);
if (($o{docdb_type} eq 'eXist') && (!$o{exist_url})) {
$self->render(json=>{message=>"Please specify the eXist URL!"});}
elsif ($o{exist_url} && (! $backend->exist)) {
$self->render(json=>{message=>"eXist URL fails to connect, registration cancelled."});}
elsif (($o{metadb_type} eq 'Sesame') && (!$o{sesame_url})) {
$self->render(json=>{message=>"Please specify the Sesame URL!"});}
elsif ($o{sesame_url} && (! $backend->sesame)) {
$self->render(json=>{message=>"Sesame URL fails to connect, registration cancelled."});}
# TODO: Also check whether MySQL and SQLite are accessible AND writeable
else {
my $dbfile = db_file_connect;
foreach (keys %o) {
$dbfile->{$_} = $o{$_};
}
db_file_disconnect($dbfile);
$self->render(json=>{message=>"Successfully configured databases!"});
}
};
helper register_workers => sub {
my $self = shift;
my $dbfile = db_file_connect;
my @urls = grep (length($_)>0, $self->param('gearman-urls'));
$dbfile->{gearman_urls} = join("\n",@urls);
db_file_disconnect($dbfile);
$self->render(json=>{message=>"Gearman URLs registered!"});
};
helper add_corpus => sub {
my ($self) = @_;
# Increase inactivity timeout for connection a bit
Mojo::IOLoop->stream($self->tx->connection)->timeout(3600); # 1 hour for import
# Import a new corpus from the $path
my $path = $self->param('path');
my $overwrite = $self->param('overwrite');
if (! -d $path) {
$self->render(json=>{message=>"Please enter a valid file path to the corpus!"});
return;
}
my $dbfile = db_file_connect();
my $upper_bound = $self->param('upper-bound');
my $entry_setup = $self->param('entry-setup');
my $importer = CorTeX::Import->new(
root=>$path,
upper_bound=>$upper_bound,
overwrite=>$overwrite,
main_repos=>$MAIN_REPOS,
meta_graph=>$META_GRAPH,
build_system_url=>$BUILD_SYSTEM_URL,
entry_setup=>$entry_setup,
verbosity=>1,
%$dbfile);
db_file_disconnect($dbfile);
while ($importer->process_next) {}
my $message="Successfully Imported $path";
$message .= ", capped at $upper_bound entries" if ($upper_bound && ($upper_bound>0));
$self->render(json => {message => $message});
};
helper add_service => sub {
my ($self) = @_;
my %service = ();
foreach (qw/name version id requires url xpath type inputformat outputformat resource/) {
$service{$_} = $self->param('service-'.$_); }
foreach my $key(qw/name version id type/) {
if (! $service{$key}) {
$self->render(json=>{
message=>"Please enter a valid $key of the service!"});
return; }}
$service{inputconverter} = $self->param("requires-converter");
my @requires_analyses = $self->param('requires-analyses[]');
$service{requires_analyses} = \@requires_analyses;
my @requires_aggregation = $self->param('requires-aggregation[]');
$service{requires_aggregation} = \@requires_aggregation;
my @corpora = $self->param('corpora[]');
$service{corpora} = \@corpora;
my $backend = $self->backend;
my ($success,$message) = $backend->taskdb->register_service(%service);
if ($success) {
$message="Successfully Registered $service{name}, version $service{version}!"; }
$self->render(json => {message => $message});
};
helper update_service => sub {
my ($self)=@_;
my %service = ();
foreach (qw/name version id oldid oldname requires url xpath type inputformat outputformat resource/) {
$service{$_} = $self->param('update-'.$_); }
foreach my $key(qw/name version id type/) {
if (! $service{$key}) {
$self->render(json=>{
message=>"Please enter a valid $key of the service!"});
return; }}
$service{inputconverter} = $self->param('update-requires-converter');
my @requires_analyses = $self->param('update-requires-analyses[]');
$service{requires_analyses} = \@requires_analyses;
my @requires_aggregation = $self->param('update-requires-aggregation[]');
$service{requires_aggregation} = \@requires_aggregation;
my @corpora = $self->param('update-corpora[]');
$service{corpora} = \@corpora;
my $backend = $self->backend;
my ($success,$message) = $backend->taskdb->update_service(%service);
if ($success) {
$message="Successfully Updated $service{name}, version $service{version}!"; }
$self->render(json => {message => $message});
};
helper service_description => sub {
my ($self) = @_;
my $service_name = $self->param("name");
my $backend = $self->backend;
my $service_description = $backend->taskdb->service_description($service_name);
$self->render(json => $service_description);
};
helper service_report => sub {
my ($self) = @_;
my $service_name = $self->param("name");
my $dbfile = db_file_connect();
my $backend = CorTeX::Backend->new(%$dbfile);
my $pid = $dbfile->{gears_workhorse_pid};
db_file_disconnect($dbfile);
# 1. Acquire statistical data:
my $service_db_report = $backend->taskdb->service_report($service_name);
my @rows;
foreach my $corpus(keys %$service_db_report) {
my $countstable = $service_db_report->{$corpus};
my $total_count = $backend->taskdb->count_entries(corpus=>$corpus,select=>'all');
my @counts = map {sprintf("%.2f",(100*(($countstable->{$_}||0) / $total_count)))} qw/ok warning error fatal processing queued blocked/;
my $corpus_link = "<a class='quietlink' href='/report?service=$service_name&corpus=$corpus'>$corpus</a>";
my $row_content = '<td>'.join("</td><td>",($corpus_link,@counts)).'</td>';
push @rows, $row_content;
}
my $report_message;
$report_message = '<table class="summary-table overview-table"><thead>
<th>Corpus</th>
<th colspan="7" style="text-align:center">%</th>
</thead><tbody><tr><td></td>
<td>OK</td>
<td>Warnings</td>
<td>Errors</td>
<td>Fatal</td>
<td>Processing</td>
<td>Queued</td>
<td>Blocked</td></tr>';
$report_message .= '<tr class="hover-row ">'
. join('</tr><tr class="hover-row ">',@rows)
. '</tr>';
$report_message .="</tbody></table>";
$report_message .="<br></br>";
$self->render(json => {report=>$report_message});
};
helper corpus_report => sub {
my ($self) = @_;
my $corpus_name = $self->param("name");
my $dbfile = db_file_connect();
my $backend = CorTeX::Backend->new(%$dbfile);
my $pid = $dbfile->{gears_workhorse_pid};
db_file_disconnect($dbfile);
# 1. Acquire statistical data:
my ($corpus_db_report) = $backend->taskdb->corpus_report($corpus_name);
my $total_count = $backend->taskdb->count_entries(corpus=>$corpus_name,select=>'all');
my @rows;
foreach my $service(keys %$corpus_db_report) {
my $countstable = $corpus_db_report->{$service};
my @counts = map {sprintf("%.2f",(100*(($countstable->{$_}||0) / $total_count)))} qw/ok warning error fatal processing queued blocked/;
my $service_link = "<a class='quietlink' href='/report?service=$service&corpus=$corpus_name'>$service</a>";
my $row_content = '<td>'.join("</td><td>",($service_link,@counts)).'</td>';
push @rows, $row_content;
}
my $report_message;
$report_message = '<table class="summary-table overview-table"><thead>
<th>Service</th>
<th colspan="7" style="text-align:center">%</th>
</thead><tbody><tr><td></td>
<td>OK</td>
<td>Warnings</td>
<td>Errors</td>
<td>Fatal</td>
<td>Processing</td>
<td>Queued</td>
<td>Blocked</td></tr>';
$report_message .= '<tr class="hover-row ">'
. join('</tr><tr class="hover-row ">',@rows)
. '</tr>';
$report_message .="</tbody></table>";
$report_message .="<br></br>";
$self->render(json => {report=>$report_message});
};
helper classic_report => sub {
my ($self) = @_;
my $backend = $self->backend;
my $corpus_name = $self->param("corpus");
my $service_name = $self->param("service");
my $countby = $self->param("countby")||'document';
$countby = 'document' if ($countby eq 'null');
my $entries_report = $backend->taskdb->count_entries(
corpus=>$corpus_name,
service=>$service_name);
my ($all_count,$completed_count)=(0,0);
foreach (keys %$entries_report) {
$completed_count += $entries_report->{$_} if $_ =~/^ok|warning|error|fatal$/;
$all_count += $entries_report->{$_}; }
$entries_report->{all} = $all_count;
$entries_report->{completed} = $completed_count;
foreach (qw/ok warning error fatal queued blocked processing/) {
$entries_report->{$_} //= '0'; }
# 2. Prepare report:
# 2.1 General report:
my $component = [ split(/:/, $self->param('component')) ];
# 3 items max, slurp anything that follows:
$component->[3] = join(":",@$component[3..scalar(@$component)-1]) if (@$component>4);
$component = [ map { my @parts = split(' ',$_); $parts[0]; } @$component ];
my $severity = $component->[1];
my $category = $component->[2];
my $what = $component->[3];
my $report_message=q{};
my $alive = 0;
if ($component->[0] eq 'general') {
my $General_Report = [];
$alive = $entries_report->{queued} || $entries_report->{processing};
push @$General_Report, ["Corpus", "<b>".$corpus_name."</b>"];
push @$General_Report, ["Service", "<b>".$service_name."</b>"];
push @$General_Report, [ "State", $alive ? ('<span class="ok">running</span>') :
('<span class="fatal">stopped</span>') ];
push @$General_Report, [ "Total entries", $entries_report->{all} ];
push @$General_Report, [ "Queued", $entries_report->{queued} ];
push @$General_Report, [ "In progress...", $entries_report->{processing} ];
push @$General_Report, [ "Pending dependencies", $entries_report->{blocked} ];
# push @$General_Report, [ "Concurrent jobs", $job_count ];
$report_message = '<table class="summary-table"><thead><th>General</th><th>Status</th></thead><tbody><tr class="hover-row ">';
$report_message .= join ("</tr><tr class='hover-row'>", map {"<td>".join("</td><td>", @$_)."</td>"} @$General_Report );
$report_message .="</tr></tbody></table>";
# 2.2 Results report:
my $detailed_report;
my $all_details=0;
if ($countby eq 'message') {
$detailed_report = $backend->taskdb->count_messages(corpus=>$corpus_name,service=>$service_name);
foreach (keys %$detailed_report) {
$all_details += $detailed_report->{$_}; }
$detailed_report->{all} = $all_details;
foreach (qw/ok warning error fatal queued blocked processing/) {
$detailed_report->{$_} //= '0'; }}
else {
$all_details = $all_count;
$detailed_report = $entries_report; }
my $Results_Report = {};
if ($completed_count && $all_details) {
$Results_Report->{ok}->{count} = $detailed_report->{ok};
$Results_Report->{ok}->{main} = ['<span class="ok severity">No Problems</span>','<span class="ok severity">'.$detailed_report->{ok}.'</span>',
'<span class="ok severity">'.sprintf("%.2f",(100*$detailed_report->{ok} / $all_details)).'</span>'];
$Results_Report->{warning}->{count} = $detailed_report->{warning};
$Results_Report->{warning}->{main} = ['<span class="warning severity">Warning</span>','<span class="warning severity">'.$detailed_report->{warning}.'</span>',
'<span class="warning severity">'.sprintf("%.2f",(100*$detailed_report->{warning} / $all_details)).'</span>'];
$Results_Report->{error}->{count} = $detailed_report->{error};
$Results_Report->{error}->{main} = ['<span class="error severity">Error</span>','<span class="error severity">'.$detailed_report->{error}.'</span>',
'<span class="error severity">'.sprintf("%.2f",(100*$detailed_report->{error} / $all_details)).'</span>'];
$Results_Report->{fatal}->{count} = $detailed_report->{fatal};
$Results_Report->{fatal}->{main} = ['<span class="fatal severity">Fatal</span>','<span class="fatal severity">'. $detailed_report->{fatal}.'</span>',
'<span class="fatal severity">'.sprintf("%.2f",(100*$detailed_report->{fatal} / $all_details)).'</span>'];
if ($severity) {
my $categories = $backend->taskdb->get_result_summary(
corpus=>$corpus_name,
service=>$service_name,
countby=>$countby,
severity=>$severity);
$categories = { map {encode_entities($_)=>$categories->{$_}} (keys %$categories) };
foreach (keys %$categories) {
$Results_Report->{$severity}->{inner}->{$_}->{count} = $categories->{$_};
$Results_Report->{$severity}->{inner}->{$_}->{main} = ['<span class="'.$_.' category">'.$_.'</span>','<span class="'.$_.' category">'.$categories->{$_}.'</span>',
'<span class="'.$_.' category">'.sprintf("%.2f",(100*$categories->{$_} / $all_details)).'</span>'];
}
if ($category) {
my $whats = $backend->taskdb->get_result_summary(
corpus=>$corpus_name,
service=>$service_name,
countby=>$countby,
severity=>$severity,
category=>$category);
$whats = { map {encode_entities($_)=>$whats->{$_}} (keys %$whats) };
foreach (keys %$whats) {
$Results_Report->{$severity}->{inner}->{$category}->{inner}->{$_}->{count} = $whats->{$_};
$Results_Report->{$severity}->{inner}->{$category}->{inner}->{$_}->{main} = ['<span class="'.$_.' what">'.$_.'</span>','<span class="'.$_.' what">'.$whats->{$_}.'</span>',
'<span class="'.$_.' what">'.sprintf("%.2f",(100*$whats->{$_} / $all_details)).'</span>'];
}
}
}
}
$report_message .= '<table class="summary-table stats-table"><thead><th>Results</th><th>'.
(($countby eq 'document') ?
'<select name="countby" class="selectcountby"><option selected="selected" value="document">Documents</option><option value="message">Messages</option></select>' :
'<select name="countby" class="selectcountby"><option value="document">Documents</option><option selected="selected" value="message">Messages</option></select>' )
.'</th><th>%</th></thead><tbody>';
$report_message .= $self->inner_report_message($Results_Report);
$report_message .="</tbody></table>";
$report_message .="<br></br>";
}
$self->render(json => {alive=>$alive,report=>$report_message});
};
helper inner_report_message => sub {
my ($self,$hashref) = @_;
my $report = q{};
foreach my $key(sort {$hashref->{$b}->{count} <=> $hashref->{$a}->{count}} keys %$hashref) {
$report .= "<tr class='stats-row hover-row'><td>".join("</td><td>", @{$hashref->{$key}->{main}})."</td></tr>";
if ($hashref->{$key}->{inner}) {
# There is inner content, we need a subtable:
$report.="<tr><td colspan='3'><table class='inner-table'><tbody>".$self->inner_report_message($hashref->{$key}->{inner})."</tbody></table></td></tr>";
}
}
$report;
};
helper queue_rerun => sub {
my ($self) = @_;
my $corpus_name=$self->param('corpus');
my $service_name=$self->param('service');
my $backend = $self->backend;
if ($self->param('entry')) {
# We only want a single entry here;
my $queued_success = $backend->taskdb->mark_entry_queued(
{entry=>$self->param('entry'),
corpus=>$corpus_name,service=>$service_name,
graph=>$META_GRAPH,repository=>$MAIN_REPOS});
$self->render(json=>{message=>$queued_success ? "Successfully queued!" : "Failed. Please contact your sysadmin."});
} else {
my $component = [ split(/:/, $self->param('component')) ];
# 3 items max, slurp anything that follows:
$component->[3] = join(":",@$component[3..scalar(@$component)-1]) if (@$component>4);
$component = [ map { my @parts = split(' ',$_); $parts[0]; } @$component ];
my $queued_success = $backend->taskdb->mark_custom_entries_queued(
{severity=>$component->[1],category=>$component->[2],what=>$component->[3],
corpus=>$corpus_name,service=>$service_name,
graph=>$META_GRAPH,repository=>$MAIN_REPOS});
$self->render(json=>{message=>$queued_success ? "Successfully queued!" : "Failed. Please contact your sysadmin."});
}
};
app->start;
__END__
=pod
=head1 NAME
C<cortex-frontend> - Mojolicious web server for the CorTeX framework
=head1 SYNOPSIS
=head1 DESCRIPTION
=head1 SEE ALSO
L<cortex-gears>
=head1 AUTHOR
Deyan Ginev <[email protected]>
=head1 COPYRIGHT
Research software, produced as part of work done by
the KWARC group at Jacobs University Bremen.
Released under the GNU Public License
=cut