Module money_op_pycalcar
[hide private]
[frames] | no frames]

Source Code for Module money_op_pycalcar

  1  #!/usr/bin/env python 
  2  # -*-coding:utf-8 -* 
  3   
  4  #       Pycalcar 
  5  #       Copyright (C) 2013 GALODE A. 
  6  # 
  7  #       This file is part of Pycalcar. 
  8  #  
  9  #       Pycalcar is free software: you can redistribute it and/or modify 
 10  #       it under the terms of the GNU General Public License as published by 
 11  #       the Free Software Foundation, either version 3 of the License, or 
 12  #       (at your option) any later version. 
 13  #  
 14  #       Pycalcar is distributed in the hope that it will be useful, 
 15  #       but WITHOUT ANY WARRANTY; without even the implied warranty of 
 16  #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 17  #       GNU General Public License for more details. 
 18  # 
 19  #       You should have received a copy of the GNU General Public License 
 20  #       along with Pycalcar.  If not, see <http://www.gnu.org/licenses/> 
 21   
 22  """ 
 23          Manage the operation on money 
 24           
 25          G{importgraph} 
 26  """ 
 27   
28 -class MoneyOp:
29 """ 30 Class which execute operations on money 31 32 G{classtree} 33 """ 34 35 36 #===================================================# 37 # Init # 38 #===================================================#
39 - def __init__(self) :
40 None
41 42 43 44 45 46 #===================================================# 47 # Conversion en unite de base d'une devise # 48 #===================================================#
49 - def f_convert_base(self,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8):
50 """ 51 Convert a mount into base unit 52 53 PARAMETERS 54 ========== 55 u0 => u9 56 -------- 57 Mount in the different units of the money 58 tx0 => tx8 59 ---------- 60 Rate between the different units of the money 61 62 RETURNS 63 ======= 64 Mount in the base unit of the money 65 """ 66 temp = u9 * tx8 67 base = u8 + temp 68 temp = base * tx7 69 base = u7 + temp 70 temp = base * tx6 71 base = u6 + temp 72 temp = base * tx5 73 base = u5 + temp 74 temp = base * tx4 75 base = u4 + temp 76 temp = base * tx3 77 base = u3 + temp 78 temp = base * tx2 79 base = u2 + temp 80 temp = base * tx1 81 base = u1 + temp 82 temp = base * tx0 83 base = u0 + temp 84 85 return base
86 87 88 89 90 #===================================================# 91 # Conversion en unite d'une devise depuis la base # 92 #===================================================#
93 - def f_convert_total(self,base,tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8):
94 """ 95 Convert a base unit into different unit of a money 96 97 PARAMETERS 98 ========== 99 base 100 ---- 101 Mount in the base unit of the money 102 tx0 => tx8 103 ---------- 104 Rate between the different units of the money 105 106 RETURNS 107 ======= 108 Mount in the different units of the money 109 """ 110 rate0 = tx0 111 rate1 = tx1 * rate0 112 rate2 = tx2 * rate1 113 rate3 = tx3 * rate2 114 rate4 = tx4 * rate3 115 rate5 = tx5 * rate4 116 rate6 = tx6 * rate5 117 rate7 = tx7 * rate6 118 rate8 = tx8 * rate7 119 120 u9 = u8 = u7 = u6 = u5 = u4 = u3 = u2 = u1 = u0 = 0 121 122 if base >= 0: 123 reste = base 124 else: 125 reste = -1 * base 126 127 if rate8 <> 0: 128 u9 = base / rate8 129 reste = reste - u9 * rate8 130 if rate7 <> 0: 131 u8 = reste / rate7 132 reste = reste - u8 * rate7 133 if rate6 <> 0: 134 u7 = reste / rate6 135 reste = reste - u7 * rate6 136 if rate5 <> 0: 137 u6 = reste / rate5 138 reste = reste - u6 * rate5 139 if rate4 <> 0: 140 u5 = reste / rate4 141 reste = reste - u5 * rate4 142 if rate3 <> 0: 143 u4 = reste / rate3 144 reste = reste - u4 * rate3 145 if rate2 <> 0: 146 u3 = reste / rate2 147 reste = reste - u3 * rate2 148 if rate1 <> 0: 149 u2 = reste / rate1 150 reste = reste - u2 * rate1 151 if rate0 <> 0: 152 u1 = reste / rate0 153 reste = reste - u1 * rate0 154 if base >=0: 155 u0 = reste 156 else: 157 u0 = -1 * reste 158 159 return u0,u1,u2,u3,u4,u5,u6,u7,u8,u9
160 161 162 163 164 #===================================================# 165 # Addition # 166 #===================================================#
167 - def f_money_add(self,u10,u11,u12,u13,u14,u15,u16,u17,u18,u19, \ 168 u20,u21,u22,u23,u24,u25,u26,u27,u28,u29, \ 169 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8):
170 """ 171 Make an add operation 172 173 PARAMETERS 174 ========== 175 u10 => u19 176 ---------- 177 First line of operation, in the different units of the money 178 u20 => u29 179 ---------- 180 Second line of operation, in the different units of the money 181 tx0 => tx8 182 ---------- 183 Rate between the different units of the money 184 185 RETURNS 186 ======= 187 Sum of the two lines in the different units of the money 188 """ 189 mount1 = self.f_convert_base(u10, u11, u12, u13, u14, u15, u16, u17, u18, u19,\ 190 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8) 191 mount2 = self.f_convert_base(u20, u21, u22, u23, u24, u25, u26, u27, u28, u29,\ 192 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8) 193 result = mount1 + mount2 194 195 return self.f_convert_total(result, tx0, tx1, tx2, tx3, tx4, tx5, tx6, tx7, tx8)
196 197 198 199 200 #===================================================# 201 # Soustraction # 202 #===================================================#
203 - def f_money_sub(self,u10,u11,u12,u13,u14,u15,u16,u17,u18,u19, \ 204 u20,u21,u22,u23,u24,u25,u26,u27,u28,u29, \ 205 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8):
206 """ 207 Make a substract operation 208 209 PARAMETERS 210 ========== 211 u10 => u19 212 ---------- 213 First line of operation, in the different units of the money 214 u20 => u29 215 ---------- 216 Second line of operation, in the different units of the money 217 tx0 => tx8 218 ---------- 219 Rate between the different units of the money 220 221 RETURNS 222 ======= 223 Difference between first & second line, in the different units of the money 224 """ 225 mount1 = self.f_convert_base(u10, u11, u12, u13, u14, u15, u16, u17, u18, u19,\ 226 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8) 227 mount2 = self.f_convert_base(u20, u21, u22, u23, u24, u25, u26, u27, u28, u29,\ 228 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8) 229 result = mount1 - mount2 230 231 return self.f_convert_total(result, tx0, tx1, tx2, tx3, tx4, tx5, tx6, tx7, tx8)
232 233 234 235 236 #===================================================# 237 # Multiplication # 238 #===================================================#
239 - def f_money_mult(self,mult,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8):
240 """ 241 Make a multiplion operation 242 243 PARAMETERS 244 ========== 245 mult 246 ---- 247 Value of the multiplicator 248 u0 => u9 249 -------- 250 Mount in the different units of the money 251 tx0 => tx8 252 ---------- 253 Rate between the different units of the money 254 255 RETURNS 256 ======= 257 Result of the multiplication operation, in the different units of the money 258 """ 259 base = self.f_convert_base(u0, u1, u2, u3, u4, u5, u6, u7, u8, u9, \ 260 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8) 261 result = base * mult 262 263 return self.f_convert_total(result, tx0, tx1, tx2, tx3, tx4, tx5, tx6, tx7, tx8)
264 265 266 267 268 #===================================================# 269 # Division # 270 #===================================================#
271 - def f_money_div(self,div,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8):
272 """ 273 Make a division operation 274 275 PARAMETERS 276 ========== 277 div 278 --- 279 Value of the divisor 280 u0 => u9 281 -------- 282 Mount in the different units of the money 283 tx0 => tx8 284 ---------- 285 Rate between the different units of the money 286 287 RETURNS 288 ======= 289 Result of the division operation, in the different units of the money, & the rest of the division 290 """ 291 base = self.f_convert_base(u0, u1, u2, u3, u4, u5, u6, u7, u8, u9, \ 292 tx0,tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8) 293 result = base // div #permet d'effectuer une division entiere 294 reste = base%div 295 296 return self.f_convert_total(result, tx0, tx1, tx2, tx3, tx4, tx5, tx6, tx7, tx8), reste
297 298 299 #===================================================# 300 # Main de la classe # 301 #===================================================# 302 if __name__ == '__main__': 303 None 304