mathmaker  0.6(alpha)
mamk_misc/doc/mathmaker4doxygen/sheet/exercise/X_RightTriangle.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 from lib.common.cst import *
00027 
00028 # Here the list of available values for the parameter x_kind='' and the
00029 # matching x_subkind values
00030 # Note : the bypass value allows to give the value of *x_subkind* directly to
00031 # the matching question Constructor, bypassing the action of the present class
00032 AVAILABLE_X_KIND_VALUES = \
00033     {'short_test' : ['pythagorean_theorem_one_of_each',
00034                      'converse_of_pythagorean_theorem',
00035                      'contrapositive_of_pythagorean_theorem']
00036      #'preformatted' : [''],
00037      #'bypass' : ['']
00038     }
00039 
00040 X_LAYOUT_UNIT = "cm" #[1,         9, 9],       (1, 1)
00041 # ----------------------  lines_nb    col_widths   questions
00042 X_LAYOUTS = {'default' :
00043               { 'exc' : [ None,                    'all'
00044                         ],
00045                 'ans' : [ None,                    'all'
00046                         ]
00047               }
00048             }
00049 
00050 # ------------------------------------------------------------------------------
00051 # --------------------------------------------------------------------------
00052 # ------------------------------------------------------------------------------
00053 ##
00054 # @class X_RightTriangle
00055 # @brief All exercices about the Right Triangle.
00056 class X_RightTriangle(X_Structure):
00057 
00058 
00059 
00060 
00061 
00062     # --------------------------------------------------------------------------
00063     ##
00064     #   @brief Constructor.
00065     #   @param embedded_machine The machine that will be used to write output.
00066     #          - x_kind=<string>
00067     #                         see AVAILABLE_X_KIND_VALUES to check the
00068     #                         possible values to use and their matching
00069     #                         x_subkind options
00070     #   @param **options Options detailed below :
00071     #          - x_subkind=<string>
00072     #                         ...
00073     #                         ...
00074     #          - start_number=<integer>
00075     #                         (should be >= 1)
00076     #          - number_of_questions=<integer>
00077     #            /!\ probably only useful if you use bypass
00078     #                         (should be >= 1)
00079     #   @return One instance of exercise.X_RightTriangle
00080     def __init__(self, embedded_machine, x_kind='default_nothing', **options):
00081         self.derived = True
00082         X_Structure.__init__(self, embedded_machine,
00083                              x_kind, AVAILABLE_X_KIND_VALUES, X_LAYOUTS,
00084                              X_LAYOUT_UNIT, **options)
00085         # The purpose of this next line is to get the possibly modified
00086         # value of **options
00087         options = self.options
00088 
00089         # BEGINING OF THE ZONE TO REWRITE (see explanations below) ------------
00090 
00091         # should be default_question = question.Something
00092         default_question = question.Q_RightTriangle
00093 
00094         # TEXTS OF THE EXERCISE
00095         self.text = {'exc' : "",
00096                      'ans' : ""
00097                     }
00098 
00099         # alternate texts section
00100         #if self.x_kind == 'short_test' \
00101         #    and self.x_subkind == 'pythagorean_theorem_one_of_each':
00102         ##___
00103         #    self.text = {'exc' : "",
00104         #                 'ans'   : _("The drawings below are only sketches.")
00105         #                }
00106         #
00107         #elif self.x_kind == '...':
00108             #self.text = {'exc' : "",
00109             #             'ans'   : ""
00110             #            }
00111 
00112         # SHORT TEST & OTHER PREFORMATTED EXERCISES
00113         units = ['m', 'dm', 'cm', 'mm']
00114         angles = randomly.pop([[0, 180], [90, 270]])
00115         random_signs = [randomly.pop([-1, 1]),
00116                         randomly.pop([-1, 1])
00117                        ]
00118 
00119         if self.x_kind == 'short_test':
00120             if self.x_subkind == 'pythagorean_theorem_one_of_each':
00121 
00122                 q_subkinds = ['calculate_hypotenuse', 'calculate_one_leg']
00123 
00124                 if randomly.heads_or_tails():
00125 
00126                     self.questions_list.append(default_question(
00127                                               self.machine,
00128                                               q_kind='pythagorean_theorem',
00129                                               q_subkind=randomly.pop(q_subkinds),
00130                                               use_pythagorean_triples=True,
00131                                               use_decimals=True,
00132                                               final_unit=randomly.pop(units),
00133                                               number_of_the_question='a',
00134                                               figure_in_the_text='no',
00135                                               rotate_around_barycenter=\
00136                      randomly.pop(angles) + random_signs[0]*randomly.integer(0,
00137                                                                              20)
00138 
00139                                                                )
00140                                                )
00141 
00142                     self.questions_list.append(default_question(
00143                                               self.machine,
00144                                               q_kind='pythagorean_theorem',
00145                                               q_subkind=randomly.pop(q_subkinds),
00146                                               use_pythagorean_triples=False,
00147                                               round_to=randomly.pop([TENTH,
00148                                                                      HUNDREDTH]),
00149                                               final_unit=randomly.pop(units),
00150                                               number_of_the_question='b',
00151                                               figure_in_the_text='no',
00152                                               rotate_around_barycenter=\
00153                      randomly.pop(angles) + random_signs[1]*randomly.integer(0,
00154                                                                              20)
00155                                                                )
00156                                                )
00157 
00158                 else:
00159 
00160                     self.questions_list.append(default_question(
00161                                               self.machine,
00162                                               q_kind='pythagorean_theorem',
00163                                               q_subkind=randomly.pop(q_subkinds),
00164                                               use_pythagorean_triples=False,
00165                                               round_to=randomly.pop([TENTH,
00166                                                                      HUNDREDTH]),
00167                                               final_unit=randomly.pop(units),
00168                                               number_of_the_question='a',
00169                                               figure_in_the_text='no',
00170                                               rotate_around_barycenter=\
00171                      randomly.pop(angles) + random_signs[0]*randomly.integer(0,
00172                                                                              20)
00173 
00174                                                                )
00175                                                )
00176 
00177                     self.questions_list.append(default_question(
00178                                               self.machine,
00179                                               q_kind='pythagorean_theorem',
00180                                               q_subkind=randomly.pop(q_subkinds),
00181                                               use_pythagorean_triples=True,
00182                                               use_decimals=True,
00183                                               final_unit=randomly.pop(units),
00184                                               number_of_the_question='b',
00185                                               figure_in_the_text='no',
00186                                               rotate_around_barycenter=\
00187                      randomly.pop(angles) + random_signs[1]*randomly.integer(0,
00188                                                                              20)
00189                                                                )
00190                                                )
00191 
00192             elif self.x_subkind == 'converse_of_pythagorean_theorem':
00193 
00194                 self.questions_list.append(default_question(
00195                                           self.machine,
00196                                           q_kind='converse_of_pythagorean_theorem',
00197                                           q_subkind='default',
00198                                           use_pythagorean_triples=True,
00199 #                                          use_decimals=randomly.heads_or_tails(),
00200                                           final_unit=randomly.pop(units),
00201                                           figure_in_the_text='no',
00202                                           rotate_around_barycenter=\
00203                  randomly.pop(angles) + random_signs[0]*randomly.integer(0,
00204                                                                          20),
00205                                           **options
00206 
00207                                                            )
00208                                            )
00209 
00210             elif self.x_subkind == 'contrapositive_of_pythagorean_theorem':
00211 
00212                 self.questions_list.append(default_question(
00213                                           self.machine,
00214                                           q_kind='contrapositive_of_pythagorean_theorem',
00215                                           q_subkind='default',
00216 #                                          use_decimals=randomly.heads_or_tails(),
00217                                           final_unit=randomly.pop(units),
00218                                           figure_in_the_text='no',
00219                                           rotate_around_barycenter=\
00220                  randomly.pop(angles) + random_signs[0]*randomly.integer(0,
00221                                                                          20),
00222                                           **options
00223 
00224                                                            )
00225                                            )
00226 
00227 
00228 
00229         #elif self.x_kind == 'preformatted':
00230         #    if self.x_subkind == '...':
00231                 #self.questions_list.append(default_question(
00232                 #                           self.machine,
00233                 #
00234                 # etc.
00235 
00236 
00237         # OTHER EXERCISES (BYPASS OPTION !)
00238         #else:
00239          #   for i in xrange(self.q_nb):
00240          #       self.questions_list.append(
00241          #                    default_question(self.machine,
00242          #                              q_kind=self.x_subkind,
00243          #                               expression_number=i+self.start_number,
00244          #                               **options)
00245          #                                 )
00246 
00247         # END OF THE ZONE TO REWRITE ------------------------------------------
00248 
00249 
00250 
00251 
00252     # INSTRUCTIONS TO CREATE A NEW EXERCISE -----------------------------------
00253     #   * PREFORMATTED EXERCISES
00254     #       that's where preformatted exercises are described (the ones that
00255     #       won't repeat n times the same kind of randomly question)
00256     #   * OTHER EXERCISES section is meant to all exercises that repeat
00257     #       the same (maybe randomly chosen among many) kind of question.
00258     #       shouldn't be rewritten