fix last bugs, make stexaminer work under new regime
[scpubgit/stemmatology.git] / stemmaweb / lib / stemmaweb / Controller / Stexaminer.pm
CommitLineData
5c9ecf66 1package stemmaweb::Controller::Stexaminer;
2376359f 2use Moose;
3use namespace::autoclean;
4use File::Temp;
5use JSON;
a44aaf2a 6use Text::Tradition::Analysis qw/ run_analysis wit_stringify /;
2376359f 7
8BEGIN { extends 'Catalyst::Controller' }
9
10
11=head1 NAME
12
5c9ecf66 13stemmaweb::Controller::Stexaminer - Simple controller for stemma display
2376359f 14
15=head1 DESCRIPTION
16
17The stemma analysis tool with the pretty colored table.
18
19=head1 METHODS
20
21 GET stexaminer/$textid
22
23Renders the application for the text identified by $textid.
24
25=head2 index
26
27=cut
28
29sub index :Path :Args(1) {
30 my( $self, $c, $textid ) = @_;
31 my $m = $c->model('Directory');
32 my $tradition = $m->tradition( $textid );
1c0900ef 33 if( $tradition->stemma_count ) {
34 my $stemma = $tradition->stemma(0);
35 # TODO Think about caching the stemma in a session
36 $c->stash->{svg} = $stemma->as_svg;
37 $c->stash->{text_title} = $tradition->name;
38 $c->stash->{template} = 'stexaminer.tt';
39 # TODO Run the analysis as AJAX from the loaded page.
40 my $t = run_analysis( $tradition );
a44aaf2a 41 # Stringify the reading groups
42 foreach my $loc ( @{$t->{'variants'}} ) {
43 my $mst = wit_stringify( $loc->{'missing'} );
44 $loc->{'missing'} = $mst;
45 foreach my $rhash ( @{$loc->{'readings'}} ) {
46 my $gst = wit_stringify( $rhash->{'group'} );
47 $rhash->{'group'} = $gst;
48 }
49 }
1c0900ef 50 $c->stash->{variants} = $t->{'variants'};
51 $c->stash->{total} = $t->{'variant_count'};
52 $c->stash->{genealogical} = $t->{'genealogical_count'};
53 $c->stash->{conflict} = $t->{'conflict_count'};
54 } else {
55 $c->stash->{error} = 'Tradition ' . $tradition->name
56 . 'has no stemma for analysis.';
57 }
2376359f 58}
59
60=head2 end
61
62Attempt to render a view, if needed.
63
64=cut
65
66sub end : ActionClass('RenderView') {}
67
68=head1 AUTHOR
69
70Tara L Andrews
71
72=head1 LICENSE
73
74This library is free software. You can redistribute it and/or modify
75it under the same terms as Perl itself.
76
77=cut
78
79__PACKAGE__->meta->make_immutable;
80
811;