File:  [LON-CAPA] / loncom / interface / statistics / lonproblemanalysis.pm
Revision 1.24: download - view: text, annotated - select for diffs
Mon Sep 29 21:13:23 2003 UTC (20 years, 8 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
It's probably unneccessary to have people translate html tags.

# The LearningOnline Network with CAPA
#
# $Id: lonproblemanalysis.pm,v 1.24 2003/09/29 21:13:23 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
# (Navigate problems for statistical reports
# YEAR=2002
# 5/12,7/26,9/7,11/22 Behrouz Minaei
#
###

package Apache::lonproblemanalysis;

use strict;
use Apache::lonnet();
use Apache::lonhtmlcommon();
use Apache::loncoursedata();
use Apache::lonstatistics;
use Apache::lonlocal;

sub BuildProblemAnalysisPage {
    my ($r,$c)=@_;
    $r->print('<h2>'.&mt('Option Response Problem Analysis').'</h2>');
    if (exists($ENV{'form.problemchoice'})) {
        # This is me getting around my own cleverness:
        &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
                                          undef);
        #
        my ($symb,$id) = &get_problem_symb(
                     &Apache::lonnet::unescape($ENV{'form.problemchoice'})
                                           );
        $r->print('<hr />');
        my $resource = &get_resource_from_symb($symb);
        if (defined($resource)) {
            $r->print('<table bgcolor="ffffff"><tr><td>'.
                      # Oh this is dumb!  Need to rewrite relative links
                      # otherwise images (for example) will not show.
                      &Apache::lonnet::ssi_body($resource->{'src'}).
                      '</td></tr></table>');
        } else {
            $r->print('resource is undefined');
        }
        $r->print('<ol>');
        $r->print("<li />render problem\n");
        $r->print("<li />image tag for plot\n");
        $r->print("<li />plot key\n");
        $r->print('</ol>');
        $r->print("<pre>\nProblem choice = $symb $id\n</pre>\n");
        $r->print('<hr />');
    }
    $r->print('<input type="hidden" name="analysisfirstcall" value="no" />');
    $r->print(&CreateInterface());
    if (! exists($ENV{'form.analysisfirstcall'})) {
        return;
    }
    # Okay, they asked for data, so make sure we get the latest data.
    &Apache::lonnet::logthis('got here for some reason');
#    &Apache::lonstatistics::Gather_Full_Student_Data($r);
    $r->print(&OptionResponseProblemSelector());
}

sub get_problem_symb {
    my $problemstring = shift();
    my ($symb,$id) = ($problemstring=~ /^(.*):([^:]*)$/);
    return ($symb,$id);
}

sub CreateInterface {
    my $Str = '';
    $Str .= '<table cellspacing="5">'."\n";
    $Str .= '<tr>';
    $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
    $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
    $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
    $Str .= '</tr>'."\n";
    #
    $Str .= '<tr><td align="center">'."\n";
    $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
    $Str .= '</td><td align="center">';
    $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
    $Str .= '</td><td align="center">';
    my $only_seq_with_assessments = sub { 
        my $s=shift;
        if ($s->{'num_assess'} < 1) { 
            return 0;
        } else { 
            return 1;
        }
    };
    $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
                                              $only_seq_with_assessments);
    $Str .= '</td></tr>'."\n";
    $Str .= '</table>'."\n";
    $Str .= '<input type="submit" name="ProblemAnalysis" value="'.
        &mt('Analyze Problem').'" />';
    $Str .= '&nbsp;'x5;
    $Str .= '<input type="submit" name="ClearCache" value="'.
        &mt('Clear Caches').'" />';
    $Str .= '&nbsp;'x5;
    return ($Str);
}

sub OptionResponseProblemSelector {
    my $Str;
    $Str = "\n<table>\n";
    foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
        next if ($seq->{'num_assess'}<1);
        my $seq_str = '';
        foreach my $res (@{$seq->{'contents'}}) {
#            &Apache::lonnet::logthis('checking '.$res->{'title'});
#            next if ($res->{'type'} ne 'assessment');
            foreach my $part (@{$res->{'parts'}}) {
                my $partdata = $res->{'partdata'}->{$part};
                if (! exists($partdata->{'option'}) || 
                    $partdata->{'option'} == 0) {
                    next;
                }
                for (my $i=0;$i<scalar(@{$partdata->{'ResponseTypes'}});$i++){
                    my $respid = $partdata->{'ResponseIds'}->[$i];
                    my $resptype = $partdata->{'ResponseTypes'}->[$i];
                    if ($resptype eq 'option') {
                        my $value = &Apache::lonnet::escape($res->{'symb'}.':'.$respid);
                        my $checked = '';
                        if ($ENV{'form.problemchoice'} eq $value) {
                            $checked = 'checked ';
                        }
                        $seq_str .= '<tr><td>'.
  '<input type="radio" name="problemchoice" value="'.$value.'" '.$checked.'/>'.
  '</td><td>'.
  '<a href="'.$res->{'src'}.'">'.$res->{'title'}.'</a> ';
                        if ($partdata->{'option'} > 1) {
                            $seq_str .= &mt('response').' '.$respid;
                        }
                        $seq_str .= "</td></tr>\n";
                    }
                }
            }
        }
        if ($seq_str ne '') {
            $Str .= '<tr><td>&nbsp</td><td><b>'.$seq->{'title'}.'</b></td>'.
                "</tr>\n".$seq_str;
        }
    }
    $Str .= "</table>\n";
    return $Str;
}

sub get_resource_from_symb {
    my ($symb) = @_;
    &Apache::lonnet::logthis('target symb = :'.$symb.':');
    foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
        foreach my $res (@{$seq->{'contents'}}) {
            &Apache::lonnet::logthis('symb = :'.$res->{'symb'}.':');
            if ($res->{'symb'} eq $symb) {
                return $res;
            }
        }
    }
    return undef;
}

=pod

sub InitAnalysis {
    my ($resource,$sname,$sdom)=@_;
    my $symb = $resource->
    my $URI = $hash{'src_'.$rid};

    my $Answ=&Apache::lonnet::ssi($URI,('grade_target' => 'analyze',
                                  'grade_username' => $sname,
                                  'grade_domain' => $sdom,
                                  'grade_courseid' => $cid,
                                  'grade_symb' => $symb));
#    my $Answ=&Apache::lonnet::ssi($URI,('grade_target' => 'analyze'));

    (my $garbage,$Answ)=split(/_HASH_REF__/,$Answ,2);
    %Answer=();
    %Answer=&Apache::lonnet::str2hash($Answ);

    my $parts='';
    foreach my $elm (@{$Answer{"parts"}}) {
        $parts.="$elm,";
    }
    chop($parts);
    my $conc='';
    foreach my $elm (@{$Answer{"$parts.concepts"}}) {
        $conc.="$elm@";
    }
    chop($conc);

    @Concepts=split(/\@/,$conc);
    foreach my $concept (@{$Answer{"$parts.concepts"}}) {
        foreach my $foil (@{$Answer{"$parts.concept.$concept"}}) {
            $foil_to_concept{$foil} = $concept;
            #$ConceptData{$foil} = $Answer{"$parts.foil.value.$foil"};
        }
    }
    return $symb;
}

=cut

1;

__END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>