mathmaker
0.6(alpha)
|
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' : [''] 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 ('short_test', 'x_subkind1') : 00047 { 'exc' : [ [1, 6, 15], (1, 1), 00048 None, 1 00049 ], 00050 'ans' : [ [1, 6.5, 12], (1, 1), 00051 None, 1 00052 ] 00053 }, 00054 00055 ('short_test', 'x_subkind2') : 00056 { 'exc' : [ ['?', 6, 15], 'all' 00057 ], 00058 'ans' : [ [1, 6.5, 12], (1, 1), 00059 None, 1 00060 ] 00061 } 00062 } 00063 00064 # ------------------------------------------------------------------------------ 00065 # -------------------------------------------------------------------------- 00066 # ------------------------------------------------------------------------------ 00067 ## 00068 # @class X_Model 00069 # @brief Use it as a copy/paste model to create new exercises. 00070 class X_Model(X_Structure): 00071 00072 00073 00074 00075 00076 # -------------------------------------------------------------------------- 00077 ## 00078 # @brief Constructor. 00079 # @param embedded_machine The machine that will be used to write output. 00080 # - x_kind=<string> 00081 # see AVAILABLE_X_KIND_VALUES to check the 00082 # possible values to use and their matching 00083 # x_subkind options 00084 # @param **options Options detailed below : 00085 # - x_subkind=<string> 00086 # ... 00087 # ... 00088 # - start_number=<integer> 00089 # (should be >= 1) 00090 # - number_of_questions=<integer> 00091 # /!\ probably only useful if you use bypass 00092 # (should be >= 1) 00093 # @return One instance of exercise.Model 00094 def __init__(self, embedded_machine, x_kind='default_nothing', **options): 00095 self.derived = True 00096 X_Structure.__init__(self, embedded_machine, 00097 x_kind, AVAILABLE_X_KIND_VALUES, X_LAYOUTS, 00098 X_LAYOUT_UNIT, **options) 00099 # The purpose of this next line is to get the possibly modified 00100 # value of **options 00101 options = self.options 00102 00103 # BEGINING OF THE ZONE TO REWRITE (see explanations below) ------------ 00104 00105 # should be default_question = question.Something 00106 default_question = None 00107 00108 # TEXTS OF THE EXERCISE 00109 self.text = {'exc' : "", 00110 'ans' : "" 00111 } 00112 00113 # alternate texts section 00114 #if self.x_kind == '...': 00115 #self.text = {'exc' : "", 00116 # 'ans' : "" 00117 # } 00118 # 00119 #elif self.x_kind == '...': 00120 #self.text = {'exc' : "", 00121 # 'ans' : "" 00122 # } 00123 00124 # SHORT TEST & OTHER PREFORMATTED EXERCISES 00125 #if self.x_kind == 'short_test': 00126 # if self.x_subkind == 'sub1': 00127 # self.questions_list.append(default_question( \ 00128 # self.machine, 00129 # q_kind='product', 00130 # expression_number=0) 00131 # ) 00132 # etc. 00133 #elif self.x_kind == 'preformatted': 00134 # if self.x_subkind == '...': 00135 #self.questions_list.append(default_question( 00136 # self.machine, 00137 # 00138 # etc. 00139 00140 00141 # OTHER EXERCISES (BYPASS OPTION !) 00142 #else: 00143 # for i in xrange(self.q_nb): 00144 # self.questions_list.append( 00145 # default_question(self.machine, 00146 # q_kind=self.x_subkind, 00147 # expression_number=i+self.start_number, 00148 # **options) 00149 # ) 00150 00151 # END OF THE ZONE TO REWRITE ------------------------------------------ 00152 00153 00154 00155 00156 # INSTRUCTIONS TO CREATE A NEW EXERCISE ----------------------------------- 00157 # - Indicate its name in the header comment 00158 # the one of documentation (@class) 00159 # - Write the @brief description 00160 # - Replace the Model class name by the chosen one 00161 # - In the constructor comment, replace Model with the chosen name 00162 # at the @return line 00163 # - Write the class name of the default_question. You must mention it 00164 # because it will be used in the OTHER EXERCISES section. 00165 # - The different sections to rewrite are : 00166 # * TEXTS OF THE EXERCISE: 00167 # default text for all exercises of this class 00168 # * alternate texts section: 00169 # if you want to specify a different text for any particular kind 00170 # of exercise 00171 # * PREFORMATTED EXERCISES 00172 # that's where preformatted exercises are described (the ones that 00173 # won't repeat n times the same kind of randomly question) 00174 # * OTHER EXERCISES section is meant to all exercises that repeat 00175 # the same (maybe randomly chosen among many) kind of question. 00176 # shouldn't be rewritten 00177 # - Finally, if the write_* methods from the exercise.Structure don't 00178 # match your needs, copy & modify or rewrite them