mathmaker  0.6(alpha)
mamk_misc/doc/mathmaker4doxygen/sheet/exercise/X_MentalCalculation.py
00001 # -*- coding: utf-8 -*-
00002 
00003 # Mathmaker creates automatically maths exercises sheets
00004 # with their answers
00005 # Copyright 2006-2014 Nicolas Hainaux <nico_h@users.sourceforge.net>
00006 
00007 # This file is part of Mathmaker.
00008 
00009 # Mathmaker is free software; you can redistribute it and/or modify
00010 # it under the terms of the GNU General Public License as published by
00011 # the Free Software Foundation; either version 3 of the License, or
00012 # any later version.
00013 
00014 # Mathmaker is distributed in the hope that it will be useful,
00015 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 # GNU General Public License for more details.
00018 
00019 # You should have received a copy of the GNU General Public License
00020 # along with Mathmaker; if not, write to the Free Software
00021 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023 from lib import *
00024 from X_Structure import X_Structure
00025 import question
00026 
00027 # Here the list of available values for the parameter x_kind='' and the
00028 # matching x_subkind values
00029 # Note : the bypass value allows to give the value of *x_subkind* directly to
00030 # the matching question Constructor, bypassing the action of the present class
00031 AVAILABLE_X_KIND_VALUES = \
00032     {#'short_test' : ['x_subkind1', 'x_subkind2'],
00033      #'preformatted' : [''],
00034      'bypass' : ['10m_2-9', '10m_4-9', '5m_3rm_2d_2-9']
00035     }
00036 
00037 X_LAYOUT_UNIT = "cm"
00038 # ----------------------  lines_nb    col_widths   questions
00039 X_LAYOUTS = {'default' :
00040               { 'exc' : [ None,                    'all'
00041                         ],
00042                 'ans' : [ None,                    'all'
00043                         ]
00044               }
00045             }
00046 
00047 # ------------------------------------------------------------------------------
00048 # --------------------------------------------------------------------------
00049 # ------------------------------------------------------------------------------
00050 ##
00051 # @class X_MentalCalculation
00052 # @brief Creates a tabular with n questions and answers
00053 class X_MentalCalculation(X_Structure):
00054 
00055 
00056 
00057 
00058 
00059     # --------------------------------------------------------------------------
00060     ##
00061     #   @brief Constructor.
00062     #   @param embedded_machine The machine that will be used to write output.
00063     #   @param **options Options detailed below :
00064     #          - start_number=<integer>
00065     #                         (should be >= 1)
00066     #          - number_of_questions=<integer>
00067     #            /!\ only useful if you use x_kind and not preformatted
00068     #                         (should be >= 1)
00069     #          - x_kind=<string>
00070     #                         ...
00071     #                         ...
00072     #          - preformatted=<string>
00073     #            /!\ preformatted is useless with short_test
00074     #            /!\ number_of_questions is useless with preformatted
00075     #            /!\ if you use it with the x_kind option, ensure there's a
00076     #                preformatted possibility with this option
00077     #                         'yes'
00078     #                         'OK'
00079     #                         any other value will be understood as 'no'
00080     #          - short_test=<string>
00081     #            /!\ the x_kind option above can't be used along this option
00082     #            use subtype if you need to make different short_test exercises
00083     #                         'yes'
00084     #                         'OK'
00085     #                         any other value will be understood as 'no'
00086     #          - subtype=<string>
00087     #                         ...
00088     #                         ...
00089     #   @todo Complete the description of the possible options !
00090     #   @return One instance of exercise.Model
00091     def __init__(self, embedded_machine, x_kind='default_nothing', **options):
00092         self.derived = True
00093         X_Structure.__init__(self, embedded_machine,
00094                              x_kind, AVAILABLE_X_KIND_VALUES, X_LAYOUTS,
00095                              X_LAYOUT_UNIT, **options)
00096         # The purpose of this next line is to get the possibly modified
00097         # value of **options
00098         options = self.options
00099 
00100         # BEGINING OF THE ZONE TO REWRITE (see explanations below) ------------
00101 
00102         # should be default_question = question.Something
00103         default_question = question.Q_MentalCalculation
00104 
00105         # TEXTS OF THE EXERCISE
00106         self.text = {'exc' : "",
00107                      'ans' : ""
00108                     }
00109 
00110         for i in range(self.q_nb):
00111             self.questions_list.append(                                   \
00112                          default_question(self.machine,
00113                                     q_kind=self.x_subkind,
00114                                     expression_number=i+self.start_number,
00115                                     **options)
00116                                           )
00117 
00118 
00119 
00120 
00121 
00122         # OTHER EXERCISES
00123 
00124 
00125 
00126         # END OF THE ZONE TO REWRITE ------------------------------------------
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136     # INSTRUCTIONS TO CREATE A NEW EXERCISE -----------------------------------
00137     # - Indicate its name in the header comment
00138     #   the one of documentation (@class)
00139     # - Write the @brief description
00140     # - Replace the Model class name by the chosen one
00141     # - In the constructor comment, replace Model with the chosen name
00142     #   at the @return line
00143     # - Write the class name of the default_question. You must mention it
00144     #   because it will be used in the OTHER EXERCISES section.
00145     # - The different sections to rewrite are :
00146     #   * TEXTS OF THE EXERCISE:
00147     #       default text for all exercises of this class
00148     #   * alternate texts section:
00149     #       if you want to specify a different text for any particular kind
00150     #       of exercise
00151     #   * PREFORMATTED EXERCISES
00152     #       that's where preformatted exercises are described (the ones that
00153     #       won't repeat n times the same kind of randomly question)
00154     #   * OTHER EXERCISES section is meant to all exercises that repeat
00155     #       the same (maybe randomly chosen among many) kind of question.
00156     #       shouldn't be rewritten
00157     # - Finally, if the write_* methods from the exercise.Structure don't
00158     #   match your needs, copy & modify or rewrite them