mathmaker  0.6(alpha)
mamk_misc/doc/mathmaker4doxygen/sheet/exercise/X_Calculation.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' : ['fraction_simplification', 'fractions_product',
00034                        'fractions_quotient', 'fractions_sum']
00035      #'bypass' : ['']
00036     }
00037 
00038 X_LAYOUT_UNIT = "cm"
00039 # ----------------------  lines_nb  col_widths             questions
00040 X_LAYOUTS = {'default' :
00041               { 'exc' : [ ['?',     9, 9],                 'all'
00042                         ],
00043                 'ans' : [ ['?',     6, 6, 6],              'all'
00044                         ]
00045               }
00046 
00047             }
00048 
00049 # ------------------------------------------------------------------------------
00050 # --------------------------------------------------------------------------
00051 # ------------------------------------------------------------------------------
00052 ##
00053 # @class X_Calculation
00054 # @brief Calculation questions (calculate : 2-(3+5)×4, simplify a fraction...)
00055 class X_Calculation(X_Structure):
00056 
00057 
00058 
00059 
00060 
00061     # --------------------------------------------------------------------------
00062     ##
00063     #   @brief Constructor.
00064     #   @param embedded_machine The machine that will be used to write output.
00065     #   @param **options Any options
00066     #   @return One instance of exercise.Calculation
00067     def __init__(self, embedded_machine, x_kind='default_nothing', **options):
00068         self.derived = True
00069         X_Structure.__init__(self, embedded_machine,
00070                              x_kind, AVAILABLE_X_KIND_VALUES, X_LAYOUTS,
00071                              X_LAYOUT_UNIT, **options)
00072         # The purpose of this next line is to get the possibly modified
00073         # value of **options
00074         options = self.options
00075 
00076         default_question = question.Q_Calculation
00077 
00078         # TEXTS OF THE EXERCISE
00079         self.text = {'exc' : "",
00080                      'ans' : ""
00081                     }
00082 
00083         # alternate texts section
00084         if self.x_kind == 'preformatted':
00085             if self.x_subkind == 'fraction_simplification':
00086                 self.text = {'exc' : _("Simplify the following fractions :"),
00087                              'ans' : ""
00088                             }
00089             elif self.x_subkind == 'fractions_product' \
00090                  or self.x_subkind == 'fractions_quotient' \
00091                  or self.x_subkind == 'fractions_sum':
00092             #___
00093                 self.text = {'exc' : _( \
00094                     "Calculate and give the result as a simplified fraction :"),
00095                              'ans' : ""
00096                             }
00097 
00098         # PREFORMATTED EXERCISES
00099         if self.x_kind == 'preformatted':
00100             if self.x_subkind == 'fraction_simplification':
00101                 #self.text = _("Simplify the following fractions :")
00102 
00103                 for i in range(int(self.q_nb // 2)):
00104                     q=question.Q_Calculation(self.machine,
00105                                            self.x_subkind,
00106                                            expression_number=i,
00107                                            **options)
00108 
00109                     self.questions_list.append(q)
00110 
00111                 for i in range(self.q_nb - int(self.q_nb // 2)):
00112                     q=question.Q_Calculation(self.machine,
00113                                           self.x_subkind,
00114                                           expression_number=i+int(self.q_nb//2),
00115                                           with_ten_powers=0.3,
00116                                           **options)
00117 
00118                     self.questions_list.append(q)
00119 
00120             elif self.x_subkind == 'fractions_product' \
00121                  or self.x_subkind == 'fractions_quotient' \
00122                  or self.x_subkind == 'fractions_sum':
00123             #___
00124                 #self.text = _( \
00125                 #    "Calculate and give the result as a simplified fraction :")
00126 
00127                 for i in range(self.q_nb):
00128                     q=question.Q_Calculation(self.machine,
00129                                            self.x_subkind,
00130                                            expression_number=i,
00131                                            **options)
00132 
00133                     self.questions_list.append(q)
00134 
00135 
00136 
00137 
00138     # --------------------------------------------------------------------------
00139     ##
00140     #   @brief Writes the text of the exercise to the output.
00141     #def write_text(self):
00142     #    M = self.machine
00143 
00144     #    if self.text != "":
00145     #        M.write(self.text)
00146     #        M.write_new_line()
00147 
00148     #    final_str = ""
00149 
00150     #    for i in xrange(len(self.questions_list)):
00151     #        final_str += self.questions_list[i].write_text(redirect='to_str')
00152 
00153     #    M.write(final_str, multicolumns=2)
00154 
00155 
00156 
00157 
00158 
00159     # --------------------------------------------------------------------------
00160     ##
00161     #   @brief Writes the answers of the questions to the output.
00162     #def write_answer(self):
00163     #    M = self.machine
00164     #    j = 0
00165 
00166     #    M.write_tabular_begins("p{4.5 cm} p{4.5 cm} p{4.5 cm} p{4.5 cm}")
00167     #    for i in xrange(len(self.questions_list)):
00168     #        j += 1
00169     #        self.questions_list[i].write_answer()
00170     #        if j == 2 and i < len(self.questions_list) - 1:
00171     #            M.write_separator_tabular_columns()
00172     #            j = 0
00173     #        #M.write_new_line()
00174 
00175     #    M.write_tabular_ends()
00176 
00177         #M.write_new_line()
00178 
00179 
00180 
00181 
00182     # END ---------------------------------------------------------------------
00183     # Instructions to create a new exercise :
00184     # - Indicate its name in the header comment
00185     #   the one of documentation (@class)
00186     # - Write the @brief description
00187     # - Replace the Model class name by the chosen one
00188     # - In the constructor comment, replace Model with the chosen name
00189     #   at the @return line
00190     # - Go to the rewriting zone and for each question, just follow this example
00191     #   [THIS COMMENT IS TO COMPLETE]
00192     # - Finally, edit or delete the two write_* functions