let stemmaweb use interim analysis database
Tara L Andrews [Wed, 8 Aug 2012 20:47:47 +0000 (22:47 +0200)]
stemmaweb/lib/stemmaweb/Controller/Stexaminer.pm
stemmaweb/lib/stemmaweb/Model/Analysis.pm [new file with mode: 0644]
stemmaweb/root/css/stexaminer.css
stemmaweb/root/js/stexaminer.js
stemmaweb/root/src/stexaminer.tt
stemmaweb/stemmaweb.conf

index 4b8bff6..3c8b7bd 100644 (file)
@@ -32,6 +32,7 @@ Renders the application for the text identified by $textid.
 sub index :Path :Args(1) {
     my( $self, $c, $textid ) = @_;
     my $m = $c->model('Directory');
+    my $am = $c->model('Analysis');
        my $tradition = $m->tradition( $textid );
        if( $tradition->stemma_count ) {
                my $stemma = $tradition->stemma(0);
@@ -49,7 +50,7 @@ sub index :Path :Args(1) {
                $c->stash->{'show_type1'} = $use_type1;
                $c->stash->{'ignore_variant'} = $ignore_sort;
                # TODO Run the analysis as AJAX from the loaded page.
-               my %analysis_options;
+               my %analysis_options = ( calcdir => $am );
                $analysis_options{'exclude_type1'} = !$use_type1;
                if( $ignore_sort eq 'spelling' ) {
                        $analysis_options{'merge_types'} = [ qw/ spelling orthographic / ];
@@ -65,8 +66,8 @@ sub index :Path :Args(1) {
                        foreach my $rhash ( @{$loc->{'readings'}} ) {
                                my $gst = wit_stringify( $rhash->{'group'} );
                                $rhash->{'group'} = $gst;
-                               my $roots = join( ', ', @{$rhash->{'independent_occurrence'}} );
-                               $rhash->{'independent_occurrence'} = $roots;
+                               _stringify_element( $rhash, 'independent_occurrence' );
+                               _stringify_element( $rhash, 'reversions' );
                                unless( $rhash->{'text'} ) {
                                        $rhash->{'text'} = $rhash->{'readingid'};
                                }
@@ -85,6 +86,12 @@ sub index :Path :Args(1) {
        }
 }
 
+sub _stringify_element {
+       my( $hash, $key ) = @_;
+       my $str = join( ', ', @{$hash->{$key}} );
+       $hash->{$key} = $str;
+}
+
 =head2 graphsvg
 
   POST stexaminer/graphsvg
diff --git a/stemmaweb/lib/stemmaweb/Model/Analysis.pm b/stemmaweb/lib/stemmaweb/Model/Analysis.pm
new file mode 100644 (file)
index 0000000..75e6732
--- /dev/null
@@ -0,0 +1,11 @@
+package stemmaweb::Model::Analysis;
+use strict;
+use warnings;
+use Moose;
+use Text::Tradition::Directory;
+
+extends 'Catalyst::Model::KiokuDB';
+
+has '+model_class' => ( default => 'Text::Tradition::Directory' );
+
+1;
index 703dfc1..a30416a 100644 (file)
@@ -41,7 +41,7 @@
 .readinglabel {
        font-weight: bold;
 }
-.readingroots {
+.readingroots .reversionroots {
        font-weight: bold;
        color: #488dd2;
 }
@@ -63,6 +63,9 @@
 .conflict {
     background: #ff6666;
 }
+.reversion {
+       background: #ffd700;
+}
 .active_variant_row {
     background: #c6dcf1;
     font-style: italic;
index 7469615..b68c3c2 100644 (file)
@@ -69,29 +69,45 @@ function show_stats( rs ) {
                rdgstats.find('.reading_changed').append( rdghash.not_followed );
                rdgstats.find('.reading_unclear').append( rdghash.follow_unknown );
                rdgstats.find('.readingroots').append( rdghash.independent_occurrence );
-               if( ! $.isEmptyObject( rdghash.reading_parents ) ) {
-                       var parentstats = $('#reading_parent_template').clone();
-                       $.each( rdghash.reading_parents, function( parentid, pdata ) {
-                               var parentdesc = pdata.label;
-                               if( pdata.relation ) {
-                                       parentdesc += ' - variant type ' + pdata.relation.type;
-                                       if( pdata.relation.annotation ) {
-                                               parentdesc += ' [ ' + pdata.relation.annotation + ' ]';
-                                       }
-                               } else {
-                                       parentdesc += ' - no syntactic relation';
-                               }
-                               var parentitem = $('<li>').append( parentdesc );
-                               parentstats.find('.reading_parent_list').append( parentitem );
-                       });
-                       rdgstats.find('.reading_statistics').append( parentstats.contents() );
+               if( rdghash.is_reverted ) {
+                       rdgstats.find('.reversionroots').append( rdghash.reversions );
+               } else {
+                       rdgstats.find('.readingreversions').empty();
                }
+               rdgstats.find('.reading_statistics').append( 
+                       fill_parent_template( rdghash, 'source' ) );
+               rdgstats.find('.reading_statistics').append( 
+                       fill_parent_template( rdghash, 'reversion' ) );
                rshtml.append( rdgstats.contents() );
        });
        $('#row_statistics').empty();
        $('#row_statistics').append( rshtml.contents() );
+       
 };
 
+function fill_parent_template( rdghash, type ) {
+       var objname = type + '_parents';
+       var template_id = '#reading_' + type + '_template';
+       var list_class = '.reading_' + type + '_list';
+       if( ! $.isEmptyObject( rdghash[objname] ) ) {
+               var parentstats = $( template_id ).clone();
+               $.each( rdghash[objname], function( parentid, pdata ) {
+                       var parentdesc = pdata.label;
+                       if( pdata.relation ) {
+                               parentdesc += ' - variant type ' + pdata.relation.type;
+                               if( pdata.relation.annotation ) {
+                                       parentdesc += ' [ ' + pdata.relation.annotation + ' ]';
+                               }
+                       } else {
+                               parentdesc += ' - no syntactic relation';
+                       }
+                       var parentitem = $('<li>').append( parentdesc );
+                       parentstats.find( list_class ).append( parentitem );
+               });
+               return( parentstats.contents() );
+       }
+}
+
 // Save the original unextended SVG for when we need it.
 $(document).ready(function () {
        original_svg = $('#stemma_graph > svg').clone();
index 63505f7..d122ca0 100644 (file)
@@ -48,14 +48,22 @@ var graphdot = '[% graphdot %]';
                <div class="reading_statistics">
                        <span class="readinglabel"></span> - copied <span class="reading_copied"></span> time(s), changed <span class="reading_changed"></span> time(s)<br/>
                        Reading root(s) at <span class="readingroots"></span><br/>
-                       <!-- reading_parent_template will be appended here if there are parents -->
+                       <span class="readingreversions">Reading reversion(s) at <span class="reversionroots"></span><br/></span>
+                       <!-- source_parent_template will be appended here if there are parents -->
+                       <!-- reversion_parent_template will be appended here if there are reversions -->
                </div>
     </div>
     
-       <div id="reading_parent_template" class="template">
+       <div id="reading_source_template" class="template">
                <div class="parent_statistics">
                        Reading parent(s):
-                       <ul class="reading_parent_list"></ul>
+                       <ul class="reading_source_list"></ul>
+               </div>
+       </div>
+       <div id="reading_reversion_template" class="template">
+               <div class="parent_statistics">
+                       Reverted reading parent(s):
+                       <ul class="reading_reversion_list"></ul>
                </div>
        </div>
        
@@ -77,17 +85,15 @@ var graphdot = '[% graphdot %]';
     
 
 [% BLOCK variantrow -%]
+[% SET rowclass = 'class="coincidental"' -%]
 [% SET rowclass = 'class="genealogical"' IF row.genealogical -%]
-[% SET rowclass = 'class="coincidental"' UNLESS row.genealogical -%]
         <tr [% rowclass %]>
           <th><span class="rowid" onclick="handle_row_click($(this))">[% row.id %]</span></th>
 [% FOREACH reading IN row.readings -%]
-[% SET cellclass = 'clickable conflict' IF reading.conflict -%]
-[% SET cellclass = 'clickable' IF !reading.conflict -%]
+[% SET cellclass = 'clickable' -%]
+[% SET cellclass = 'clickable reversion' IF reading.is_reverted -%]
+[% SET cellclass = 'clickable conflict' IF reading.is_conflict -%]
           <td class="[% cellclass %]"><span onclick="color_nodes($(this).parent().index(), [% reading.group %], [% row.missing %]);$(this).parents('tr').addClass('active_variant_row');$(this).parent().addClass('active_variant_cell cellb'+($(this).parent().index()-1))">[% reading.text %]</span></td>
 [% END -%]
-[% FILTER repeat( row.empty ) -%]
-          <td/>
-[% END -%]
         </tr>
 [% END -%]
index a0169dc..7983257 100644 (file)
@@ -1,6 +1,9 @@
 # rename this file to stemmaweb.yml and put a ':' after 'name' if
 # you want to use YAML like in old versions of Catalyst
 name = stemmaweb
+<Model Analysis>
+    dsn dbi:SQLite:dbname=db/analysis.db
+</Model>
 <Model Directory>
     dsn dbi:SQLite:dbname=db/traditions.db
 </Model>