radboy 0.0.713__py3-none-any.whl → 0.0.715__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of radboy might be problematic. Click here for more details.

@@ -25,65 +25,451 @@ import json,sys,math,re,calendar,hashlib,haversine
25
25
  from time import sleep
26
26
  import itertools
27
27
  import decimal
28
+ from decimal import localcontext,Decimal
28
29
  unit_registry=pint.UnitRegistry()
29
- def area_triangle():
30
- height=None
31
- base=None
32
- '''
33
- A=hbb/2
34
- '''
35
- while True:
30
+ import math
31
+
32
+ def volume():
33
+ with localcontext() as ctx:
34
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
35
+ #print(f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow}")
36
+ height=Prompt.__init2__(None,func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} height?: ",helpText="height=1",data="dec.dec")
37
+ if height is None:
38
+ return
39
+ elif height in ['d',]:
40
+ height=Decimal('1')
41
+
42
+ width=Prompt.__init2__(None,func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} width?: ",helpText="width=1 ",data="dec.dec")
43
+ if width is None:
44
+ return
45
+ elif width in ['d',]:
46
+ width=Decimal('1')
47
+
48
+
49
+
50
+ length=Prompt.__init2__(None,func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} length?: ",helpText="length=1",data="dec.dec")
51
+ if length is None:
52
+ return
53
+ elif length in ['d',]:
54
+ length=Decimal('1')
55
+
56
+ return length*width*height
57
+
58
+ def volume_pint():
59
+ with localcontext() as ctx:
60
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
61
+ height=Prompt.__init2__(None,func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} height?: ",helpText="height=1",data="string")
62
+ if height is None:
63
+ return
64
+ elif height in ['d',]:
65
+ height='1'
66
+
67
+ width=Prompt.__init2__(None,func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} width?: ",helpText="width=1 ",data="string")
68
+ if width is None:
69
+ return
70
+ elif width in ['d',]:
71
+ width='1'
72
+
73
+
74
+
75
+ length=Prompt.__init2__(None,func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} length?: ",helpText="length=1",data="string")
76
+ if length is None:
77
+ return
78
+ elif length in ['d',]:
79
+ length='1'
80
+
81
+ return unit_registry.Quantity(length)*unit_registry.Quantity(width)*unit_registry.Quantity(height)
82
+
83
+ def inductance_pint():
84
+ with localcontext() as ctx:
85
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
86
+ relative_permeability=Prompt.__init2__(None,func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} relative_permeability?: ",helpText="relative_permeability(air)=1",data="string")
87
+ if relative_permeability is None:
88
+ return
89
+ elif relative_permeability in ['d',]:
90
+ relative_permeability='1'
91
+ relative_permeability=float(relative_permeability)
92
+
93
+ turns_of_wire_on_coil=Prompt.__init2__(None,func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} turns_of_wire_on_coil?: ",helpText="turns_of_wire_on_coil=1",data="string")
94
+ if turns_of_wire_on_coil is None:
95
+ return
96
+ elif turns_of_wire_on_coil in ['d',]:
97
+ turns_of_wire_on_coil='1'
98
+ turns_of_wire_on_coil=int(turns_of_wire_on_coil)
99
+
100
+ #convert to meters
101
+ core_cross_sectional_area_meters=Prompt.__init2__(None,func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} core_cross_sectional_area_meters?: ",helpText="core_cross_sectional_area_meters=1",data="string")
102
+ if core_cross_sectional_area_meters is None:
103
+ return
104
+ elif core_cross_sectional_area_meters in ['d',]:
105
+ core_cross_sectional_area_meters='1m'
36
106
  try:
37
- base=Control(func=FormBuilderMkText,ptext="base",helpText="base width",data="string")
38
- if base is None:
39
- return
40
- elif base in ['d',]:
41
- base=unit_registry.Quantity('1')
42
- else:
43
- base=unit_registry.Quantity(base)
44
- break
107
+ core_cross_sectional_area_meters=unit_registry.Quantity(core_cross_sectional_area_meters).to("meters")
45
108
  except Exception as e:
46
- print(e)
109
+ print(e,"defaulting to meters")
110
+ core_cross_sectional_area_meters=unit_registry.Quantity(f"{core_cross_sectional_area_meters} meters")
111
+
112
+ length_of_coil_meters=Prompt.__init2__(None,func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} length_of_coil_meters?: ",helpText="length_of_coil_meters=1",data="string")
113
+ if length_of_coil_meters is None:
114
+ return
115
+ elif length_of_coil_meters in ['d',]:
116
+ length_of_coil_meters='1m'
117
+ try:
118
+ length_of_coil_meters=unit_registry.Quantity(length_of_coil_meters).to('meters')
119
+ except Exception as e:
120
+ print(e,"defaulting to meters")
121
+ length_of_coil_meters=unit_registry.Quantity(f"{length_of_coil_meters} meters")
122
+
123
+ numerator=((turns_of_wire_on_coil**2)*core_cross_sectional_area_meters)
124
+ f=relative_permeability*(numerator/length_of_coil_meters)*1.26e-6
125
+ f=unit_registry.Quantity(f"{f.magnitude} H")
126
+ return f
127
+
128
+ def resonant_inductance():
129
+ with localcontext() as ctx:
130
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
131
+ hertz=1e9
132
+ while True:
133
+ try:
134
+ hertz=Control(func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} frequency in hertz[530 kilohertz]? ",helpText="frequency in hertz",data="string")
135
+ if hertz is None:
136
+ return
137
+ elif hertz in ['d','']:
138
+ hertz="530 megahertz"
139
+ print(hertz)
140
+ x=unit_registry.Quantity(hertz)
141
+ if x:
142
+ hertz=x.to("hertz")
143
+ else:
144
+ hertz=1e6
145
+ break
146
+ except Exception as e:
147
+ print(e)
148
+
149
+
150
+ while True:
151
+ try:
152
+ capacitance=Control(func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} capacitance[365 picofarads]? ",helpText="capacitance in farads",data="string")
153
+ if capacitance is None:
154
+ return
155
+ elif capacitance in ['d',]:
156
+ capacitance="365 picofarads"
157
+ x=unit_registry.Quantity(capacitance)
158
+ if x:
159
+ x=x.to("farads")
160
+ farads=x.magnitude
161
+ break
162
+ except Exception as e:
163
+ print(e)
164
+
165
+ inductance=1/(decc(4*math.pi**2)*decc(hertz.magnitude**2,cf=13)*decc(farads,cf=13))
166
+
167
+ L=unit_registry.Quantity(inductance,"henry")
168
+ return L
169
+
170
+ def air_coil_cap():
171
+ with localcontext() as ctx:
172
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
173
+ '''C = 1 / (4π²f²L)'''
174
+ while True:
175
+ try:
176
+ frequency=Control(func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} frequency? ",helpText="frequency",data="string")
177
+ if frequency is None:
178
+ return
179
+ elif frequency in ['d',]:
180
+ frequency="1410 kilohertz"
181
+ x=unit_registry.Quantity(frequency)
182
+ if x:
183
+ x=x.to("hertz")
184
+ frequency=decc(x.magnitude**2)
185
+ break
186
+ except Exception as e:
187
+ print(e)
188
+
189
+ while True:
190
+ try:
191
+ inductance=Control(func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} inductance(356 microhenry): ",helpText="coil inductance",data="string")
192
+ if inductance is None:
193
+ return
194
+ elif inductance in ['d',]:
195
+ inductance="356 microhenry"
196
+ x=unit_registry.Quantity(inductance)
197
+ if x:
198
+ x=x.to("henry")
199
+ inductance=decc(x.magnitude,cf=20)
200
+ break
201
+ except Exception as e:
202
+ print(e)
203
+
204
+
205
+
206
+ farads=1/(inductance*frequency*decc(4*math.pi**2))
207
+ return unit_registry.Quantity(farads,"farad")
208
+
209
+ def air_coil():
210
+ with localcontext() as ctx:
211
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
212
+ '''
213
+ The formula for inductance - using toilet rolls, PVC pipe etc. can be well approximated by:
214
+
215
+
216
+ 0.394 * r2 * N2
217
+ Inductance L = ________________
218
+ ( 9 *r ) + ( 10 * Len)
219
+ Here:
220
+ N = number of turns
221
+ r = radius of the coil i.e. form diameter (in cm.) divided by 2
222
+ Len = length of the coil - again in cm.
223
+ L = inductance in uH.
224
+ * = multiply by
225
+ '''
226
+ while True:
47
227
  try:
48
- base=Control(func=FormBuilderMkText,ptext="base no units",helpText="base width,do not include units",data="dec.dec")
228
+ diameter=Control(func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} diameter in cm [2 cm]? ",helpText="diamater of coil",data="string")
229
+ if diameter is None:
230
+ return
231
+ elif diameter in ['d',]:
232
+ diameter="2 cm"
233
+ x=unit_registry.Quantity(diameter)
234
+ if x:
235
+ x=x.to("centimeter")
236
+ diameter=x.magnitude
237
+ break
238
+ except Exception as e:
239
+ print(e)
240
+ radius=decc(diameter/2)
241
+ while True:
242
+ try:
243
+ length=Control(func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} length in cm [2 cm]? ",helpText="length of coil",data="string")
244
+ if length is None:
245
+ return
246
+ elif length in ['d',]:
247
+ length="2 cm"
248
+ x=unit_registry.Quantity(length)
249
+ if x:
250
+ x=x.to("centimeter")
251
+ length=x.magnitude
252
+ break
253
+ except Exception as e:
254
+ print(e)
255
+ while True:
256
+ try:
257
+ turns=Control(func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} number of turns? ",helpText="turns of wire",data="integer")
258
+ if turns is None:
259
+ return
260
+ elif turns in ['d',]:
261
+ turns=1
262
+ LTop=decc(0.394)*decc(radius**2)*decc(turns**2)
263
+ LBottom=(decc(9)*radius)+decc(length*10)
264
+ L=LTop/LBottom
265
+ print(pint.Quantity(L,'microhenry'))
266
+ different_turns=Control(func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} use a different number of turns?",helpText="yes or no",data="boolean")
267
+ if different_turns is None:
268
+ return
269
+ elif different_turns in ['d',True]:
270
+ continue
271
+ break
272
+ except Exception as e:
273
+ print(e)
274
+
275
+
276
+ return pint.Quantity(L,'microhenry')
277
+
278
+ def circumference_diameter():
279
+ with localcontext() as ctx:
280
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
281
+ radius=0
282
+ while True:
283
+ try:
284
+ diameter=Control(func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} diameter unit[4 cm]? ",helpText="diamater with unit",data="string")
285
+ if diameter is None:
286
+ return
287
+ elif diameter in ['d',]:
288
+ diameter="4 cm"
289
+ x=unit_registry.Quantity(diameter)
290
+ radius=pint.Quantity(decc(x.magnitude/2),x.units)
291
+ break
292
+ except Exception as e:
293
+ print(e)
294
+ if isinstance(radius,pint.registry.Quantity):
295
+ result=decc(2*math.pi)*decc(radius.magnitude)
296
+
297
+ return pint.Quantity(result,radius.units)
298
+ else:
299
+ return
300
+
301
+ def circumference_radius():
302
+ with localcontext() as ctx:
303
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
304
+ radius=0
305
+ while True:
306
+ try:
307
+ diameter=Control(func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} radius unit[2 cm]? ",helpText="radius with unit",data="string")
308
+ if diameter is None:
309
+ return
310
+ elif diameter in ['d',]:
311
+ diameter="2 cm"
312
+ x=unit_registry.Quantity(diameter)
313
+ radius=pint.Quantity(decc(x.magnitude),x.units)
314
+ break
315
+ except Exception as e:
316
+ print(e)
317
+ if isinstance(radius,pint.registry.Quantity):
318
+ result=decc(2*math.pi)*decc(radius.magnitude)
319
+
320
+ return pint.Quantity(result,radius.units)
321
+ else:
322
+ return
323
+
324
+ def area_of_circle_radius():
325
+ with localcontext() as ctx:
326
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
327
+ '''
328
+ A = πr²
329
+ '''
330
+ radius=0
331
+ while True:
332
+ try:
333
+ diameter=Control(func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} radius unit[2 cm]? ",helpText="radius with unit",data="string")
334
+ if diameter is None:
335
+ return
336
+ elif diameter in ['d',]:
337
+ diameter="2 cm"
338
+ x=unit_registry.Quantity(diameter)
339
+ radius=pint.Quantity(decc(x.magnitude),x.units)
340
+ break
341
+ except Exception as e:
342
+ print(e)
343
+ if isinstance(radius,pint.registry.Quantity):
344
+ result=decc(math.pi)*decc(radius.magnitude**2)
345
+
346
+ return pint.Quantity(result,radius.units)
347
+ else:
348
+ return
349
+
350
+ def lc_frequency():
351
+ with localcontext() as ctx:
352
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
353
+ inductance=None
354
+ capacitance=None
355
+ while True:
356
+ try:
357
+ inductance=Control(func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} inductance(356 microhenry): ",helpText="coil inductance",data="string")
358
+ if inductance is None:
359
+ return
360
+ elif inductance in ['d',]:
361
+ inductance="356 microhenry"
362
+ x=unit_registry.Quantity(inductance)
363
+ if x:
364
+ x=x.to("henry")
365
+ inductance=decc(x.magnitude,cf=20)
366
+ break
367
+ except Exception as e:
368
+ print(e)
369
+ while True:
370
+ try:
371
+ capacitance=Control(func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} capacitance[365 picofarads]? ",helpText="capacitance in farads",data="string")
372
+ if capacitance is None:
373
+ return
374
+ elif capacitance in ['d',]:
375
+ capacitance="365 picofarads"
376
+ x=unit_registry.Quantity(capacitance)
377
+ if x:
378
+ x=x.to("farads")
379
+ farads=decc(x.magnitude,cf=20)
380
+ break
381
+ except Exception as e:
382
+ print(e)
383
+ frequency=1/(decc(2*math.pi)*decc(math.sqrt(farads*inductance),cf=20))
384
+ return unit_registry.Quantity(frequency,"hertz")
385
+
386
+ def area_of_circle_diameter():
387
+ with localcontext() as ctx:
388
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
389
+ '''
390
+ A = πr²
391
+ '''
392
+ radius=0
393
+ while True:
394
+ try:
395
+ diameter=Control(func=FormBuilderMkText,ptext=f"{Fore.light_green}Precision {ctx.prec}{Fore.light_yellow} diameter unit[4 cm]? ",helpText="diamater value with unit",data="string")
396
+ if diameter is None:
397
+ return
398
+ elif diameter in ['d',]:
399
+ diameter="4 cm"
400
+ x=unit_registry.Quantity(diameter)
401
+ radius=pint.Quantity(decc(x.magnitude/2),x.units)
402
+ break
403
+ except Exception as e:
404
+ print(e)
405
+ if isinstance(radius,pint.registry.Quantity):
406
+ result=decc(math.pi)*decc(radius.magnitude**2)
407
+
408
+ return pint.Quantity(result,radius.units)
409
+ else:
410
+ return
411
+
412
+
413
+ def area_triangle():
414
+ with localcontext() as ctx:
415
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
416
+ height=None
417
+ base=None
418
+ '''
419
+ A=hbb/2
420
+ '''
421
+ while True:
422
+ try:
423
+ base=Control(func=FormBuilderMkText,ptext="base",helpText="base width",data="string")
49
424
  if base is None:
50
425
  return
51
426
  elif base in ['d',]:
52
- base=decc(1)
427
+ base=unit_registry.Quantity('1')
428
+ else:
429
+ base=unit_registry.Quantity(base)
53
430
  break
54
431
  except Exception as e:
55
- continue
432
+ print(e)
433
+ try:
434
+ base=Control(func=FormBuilderMkText,ptext="base no units",helpText="base width,do not include units",data="dec.dec")
435
+ if base is None:
436
+ return
437
+ elif base in ['d',]:
438
+ base=decc(1)
439
+ break
440
+ except Exception as e:
441
+ continue
56
442
 
57
- while True:
58
- try:
59
- height=Control(func=FormBuilderMkText,ptext="height",helpText="height width",data="string")
60
- if height is None:
61
- return
62
- elif height in ['d',]:
63
- height=unit_registry.Quantity('1')
64
- else:
65
- height=unit_registry.Quantity(height)
66
- break
67
- except Exception as e:
68
- print(e)
443
+ while True:
69
444
  try:
70
- height=Control(func=FormBuilderMkText,ptext="height no units",helpText="height width, do not include units",data="dec.dec")
445
+ height=Control(func=FormBuilderMkText,ptext="height",helpText="height width",data="string")
71
446
  if height is None:
72
447
  return
73
448
  elif height in ['d',]:
74
- height=decc(1)
449
+ height=unit_registry.Quantity('1')
450
+ else:
451
+ height=unit_registry.Quantity(height)
75
452
  break
76
453
  except Exception as e:
77
- continue
78
- print(type(height),height,type(base))
79
- if isinstance(height,decimal.Decimal) and isinstance(base,decimal.Decimal):
80
- return decc((height*base)/decc(2))
81
- elif isinstance(height,pint.Quantity) and isinstance(base,pint.Quantity):
82
- return ((height.to(base)*base)/2)
83
- elif isinstance(height,pint.Quantity) and isinstance(base,decimal.Decimal):
84
- return ((height*unit_registry.Quantity(base,height.units))/2)
85
- elif isinstance(height,decimal.Decimal) and isinstance(base,pint.Quantity):
86
- return ((unit_registry.Quantity(height,base.units)*base)/2)
454
+ print(e)
455
+ try:
456
+ height=Control(func=FormBuilderMkText,ptext="height no units",helpText="height width, do not include units",data="dec.dec")
457
+ if height is None:
458
+ return
459
+ elif height in ['d',]:
460
+ height=decc(1)
461
+ break
462
+ except Exception as e:
463
+ continue
464
+ print(type(height),height,type(base))
465
+ if isinstance(height,decimal.Decimal) and isinstance(base,decimal.Decimal):
466
+ return decc((height*base)/decc(2))
467
+ elif isinstance(height,pint.Quantity) and isinstance(base,pint.Quantity):
468
+ return ((height.to(base)*base)/2)
469
+ elif isinstance(height,pint.Quantity) and isinstance(base,decimal.Decimal):
470
+ return ((height*unit_registry.Quantity(base,height.units))/2)
471
+ elif isinstance(height,decimal.Decimal) and isinstance(base,pint.Quantity):
472
+ return ((unit_registry.Quantity(height,base.units)*base)/2)
87
473
 
88
474
  class Taxable:
89
475
  def general_taxable(self):
@@ -196,144 +582,152 @@ juices)''',
196
582
 
197
583
  #tax rate tools go here
198
584
  def AddNewTaxRate(excludes=['txrt_id','DTOE']):
199
- with Session(ENGINE) as session:
200
- '''AddNewTaxRate() -> None
585
+ with localcontext() as ctx:
586
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
587
+ with Session(ENGINE) as session:
588
+ '''AddNewTaxRate() -> None
201
589
 
202
- add a new taxrate to db.'''
203
- tr=TaxRate()
204
- session.add(tr)
205
- session.commit()
206
- session.refresh(tr)
207
- fields={i.name:{
208
- 'default':getattr(tr,i.name),
209
- 'type':str(i.type).lower()} for i in tr.__table__.columns if i.name not in excludes
210
- }
590
+ add a new taxrate to db.'''
591
+ tr=TaxRate()
592
+ session.add(tr)
593
+ session.commit()
594
+ session.refresh(tr)
595
+ fields={i.name:{
596
+ 'default':getattr(tr,i.name),
597
+ 'type':str(i.type).lower()} for i in tr.__table__.columns if i.name not in excludes
598
+ }
211
599
 
212
- fd=FormBuilder(data=fields)
213
- if fd is None:
214
- session.delete(tr)
215
- return
216
- for k in fd:
217
- setattr(tr,k,fd[k])
600
+ fd=FormBuilder(data=fields,passThruText=f"Precision {ctx.prec}")
601
+ if fd is None:
602
+ session.delete(tr)
603
+ return
604
+ for k in fd:
605
+ setattr(tr,k,fd[k])
218
606
 
219
-
220
- session.add(tr)
221
- session.commit()
222
- session.refresh(tr)
223
- print(tr)
224
- return tr.TaxRate
607
+
608
+ session.add(tr)
609
+ session.commit()
610
+ session.refresh(tr)
611
+ print(tr)
612
+ return tr.TaxRate
225
613
 
226
614
  def GetTaxRate(excludes=['txrt_id','DTOE']):
227
- with Session(ENGINE) as session:
228
- '''GetTaxRate() -> TaxRate:Decimal
615
+ with localcontext() as ctx:
616
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
617
+ with Session(ENGINE) as session:
618
+ '''GetTaxRate() -> TaxRate:Decimal
229
619
 
230
- search for and return a Decimal/decc
231
- taxrate for use by prompt.
232
- '''
233
- tr=TaxRate()
234
- fields={i.name:{
235
- 'default':getattr(tr,i.name),
236
- 'type':str(i.type).lower()} for i in tr.__table__.columns if i.name not in excludes
237
- }
620
+ search for and return a Decimal/decc
621
+ taxrate for use by prompt.
622
+ '''
623
+ tr=TaxRate()
624
+ fields={i.name:{
625
+ 'default':getattr(tr,i.name),
626
+ 'type':str(i.type).lower()} for i in tr.__table__.columns if i.name not in excludes
627
+ }
238
628
 
239
- fd=FormBuilder(data=fields,passThruText="GetTaxRate Search -> ")
240
- if fd is None:
241
- return
242
- for k in fd:
243
- setattr(tr,k,fd[k])
244
- #and_
245
- filte=[]
246
- for k in fd:
247
- if fd[k] is not None:
248
- if isinstance(fd[k],str):
249
- filte.append(getattr(TaxRate,k).icontains(fd[k]))
250
- else:
251
- filte.append(getattr(tr,k)==fd[k])
252
-
253
- results=session.query(TaxRate).filter(and_(*filte)).all()
254
- ct=len(results)
255
- htext=[]
256
- for num,i in enumerate(results):
257
- m=std_colorize(i,num,ct)
258
- print(m)
259
- htext.append(m)
260
- htext='\n'.join(htext)
261
- if ct < 1:
262
- print(f"{Fore.light_red}There is nothing to work on in TaxRates that match your criteria.{Style.reset}")
263
- return
264
- while True:
265
- select=Control(func=FormBuilderMkText,ptext="Which index to return for tax rate[NAN=0.0000]?",helpText=htext,data="integer")
266
- print(select)
267
- if select is None:
629
+ fd=FormBuilder(data=fields,passThruText=f"Precision {ctx.prec} ; GetTaxRate Search -> ")
630
+ if fd is None:
268
631
  return
269
- elif isinstance(select,str) and select.upper() in ['NAN',]:
270
- return 0
271
- elif select in ['d',]:
272
- return results[0].TaxRate
273
- else:
274
- if index_inList(select,results):
275
- return results[select].TaxRate
632
+ for k in fd:
633
+ setattr(tr,k,fd[k])
634
+ #and_
635
+ filte=[]
636
+ for k in fd:
637
+ if fd[k] is not None:
638
+ if isinstance(fd[k],str):
639
+ filte.append(getattr(TaxRate,k).icontains(fd[k]))
640
+ else:
641
+ filte.append(getattr(tr,k)==fd[k])
642
+
643
+ results=session.query(TaxRate).filter(and_(*filte)).all()
644
+ ct=len(results)
645
+ htext=[]
646
+ for num,i in enumerate(results):
647
+ m=std_colorize(i,num,ct)
648
+ print(m)
649
+ htext.append(m)
650
+ htext='\n'.join(htext)
651
+ if ct < 1:
652
+ print(f"{Fore.light_red}There is nothing to work on in TaxRates that match your criteria.{Style.reset}")
653
+ return
654
+ while True:
655
+ select=Control(func=FormBuilderMkText,ptext="Which index to return for tax rate[NAN=0.0000]?",helpText=htext,data="integer")
656
+ print(select)
657
+ if select is None:
658
+ return
659
+ elif isinstance(select,str) and select.upper() in ['NAN',]:
660
+ return 0
661
+ elif select in ['d',]:
662
+ return results[0].TaxRate
276
663
  else:
277
- continue
664
+ if index_inList(select,results):
665
+ return results[select].TaxRate
666
+ else:
667
+ continue
278
668
 
279
669
  def price_by_tax(total=False):
280
- fields={
281
- 'price':{
282
- 'default':0,
283
- 'type':'dec.dec'
284
- },
285
- 'rate':{
286
- 'default':GetTaxRate(),
287
- 'type':'dec.dec'
670
+ with localcontext() as ctx:
671
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
672
+ fields={
673
+ 'price':{
674
+ 'default':0,
675
+ 'type':'dec.dec'
676
+ },
677
+ 'rate':{
678
+ 'default':GetTaxRate(),
679
+ 'type':'dec.dec'
680
+ }
288
681
  }
289
- }
290
- fd=FormBuilder(data=fields,passThruText="Tax on Price ->")
291
- if fd is None:
292
- return
293
- else:
294
- price=fd['price']
295
- rate=fd['rate']
296
- if price is None:
297
- price=0
298
- if fd['rate'] is None:
299
- rate=0
300
- if total == False:
301
- return decc(price,cf=4)*decc(rate,cf=4)
682
+ fd=FormBuilder(data=fields,passThruText=f"Precision {ctx.prec} ; Tax on Price ->")
683
+ if fd is None:
684
+ return
302
685
  else:
303
- return (decc(price,cf=4)*decc(rate,cf=4))+decc(price,cf=4)
686
+ price=fd['price']
687
+ rate=fd['rate']
688
+ if price is None:
689
+ price=0
690
+ if fd['rate'] is None:
691
+ rate=0
692
+ if total == False:
693
+ return decc(price,cf=4)*decc(rate,cf=4)
694
+ else:
695
+ return (decc(price,cf=4)*decc(rate,cf=4))+decc(price,cf=4)
304
696
 
305
697
  def price_plus_crv_by_tax(total=False):
306
- fields={
307
- 'price':{
308
- 'default':0,
309
- 'type':'dec.dec'
698
+ with localcontext() as ctx:
699
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
700
+ fields={
701
+ 'price':{
702
+ 'default':0,
703
+ 'type':'dec.dec'
704
+ },
705
+ 'crv_total_for_pkg':{
706
+ 'default':0,
707
+ 'type':'dec.dec',
310
708
  },
311
- 'crv_total_for_pkg':{
312
- 'default':0,
313
- 'type':'dec.dec',
314
- },
315
- 'rate':{
316
- 'default':GetTaxRate(),
317
- 'type':'dec.dec'
709
+ 'rate':{
710
+ 'default':GetTaxRate(),
711
+ 'type':'dec.dec'
712
+ }
318
713
  }
319
- }
320
- fd=FormBuilder(data=fields,passThruText="Tax on (Price+CRV)")
321
- if fd is None:
322
- return
323
- else:
324
- price=fd['price']
325
- rate=fd['rate']
326
- crv=fd['crv_total_for_pkg']
327
- if price is None:
328
- price=0
329
- if crv is None:
330
- crv=0
331
- if fd['rate'] is None:
332
- rate=0
333
- if total == False:
334
- return (decc(price,cf=4)+decc(crv,cf=4))*decc(rate,cf=4)
714
+ fd=FormBuilder(data=fields,passThruText=f"Precision {ctx.prec};Tax on (Price+CRV)")
715
+ if fd is None:
716
+ return
335
717
  else:
336
- return (price+crv)+((decc(price,cf=4)+decc(crv,cf=4))*decc(rate,cf=4))
718
+ price=fd['price']
719
+ rate=fd['rate']
720
+ crv=fd['crv_total_for_pkg']
721
+ if price is None:
722
+ price=0
723
+ if crv is None:
724
+ crv=0
725
+ if fd['rate'] is None:
726
+ rate=0
727
+ if total == False:
728
+ return (decc(price,cf=4)+decc(crv,cf=4))*decc(rate,cf=4)
729
+ else:
730
+ return (price+crv)+((decc(price,cf=4)+decc(crv,cf=4))*decc(rate,cf=4))
337
731
 
338
732
  def DeleteTaxRate(excludes=['txrt_id','DTOE']):
339
733
  with Session(ENGINE) as session:
@@ -460,3 +854,264 @@ def EditTaxRate(excludes=['txrt_id','DTOE']):
460
854
  else:
461
855
  continue
462
856
 
857
+ def heronsFormula():
858
+ with localcontext() as ctx:
859
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
860
+ '''
861
+ Calculate the semi-perimeter (s): Add the lengths of the three sides and divide by 2.
862
+ s = (a + b + c) / 2
863
+ '''
864
+ fields={
865
+ 'side 1':{
866
+ 'default':1,
867
+ 'type':'dec.dec'
868
+ },
869
+ 'side 2':{
870
+ 'default':1,
871
+ 'type':'dec.dec'
872
+ },
873
+ 'side 3':{
874
+ 'default':1,
875
+ 'type':'dec.dec'
876
+ },
877
+ }
878
+ fd=FormBuilder(data=fields,passThruText=f"Precision {ctx.prec}")
879
+ if fd is None:
880
+ return
881
+
882
+ s=(fd['side 1']+fd['side 2']+fd['side 3'])/2
883
+ '''Apply Heron's formula: Substitute the semi-perimeter (s) and the side lengths (a, b, and c) into the formula:
884
+ Area = √(s(s-a)(s-b)(s-c))'''
885
+ Area=math.sqrt(s*(s-fd['side 1'])*(s-fd['side 2'])*(s-fd['side 3']))
886
+ return Area
887
+
888
+ def volumeCylinderRadius():
889
+ with localcontext() as ctx:
890
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
891
+ '''
892
+ Volume of a cylinder: Used for cylindrical storage bins, silos, or tanks.(V=pi r^{2}h)
893
+ '''
894
+ fields={
895
+ 'height':{
896
+ 'default':1,
897
+ 'type':'dec.dec'
898
+ },
899
+ 'radius':{
900
+ 'default':1,
901
+ 'type':'dec.dec'
902
+ },
903
+ }
904
+ fd=FormBuilder(data=fields,passThruText=f"Precision {ctx.prec}")
905
+ if fd is None:
906
+ return
907
+
908
+ volume=Decimal(math.pi)*(fd['radius']**2)*fd['height']
909
+ return volume
910
+
911
+ def volumeCylinderDiameter():
912
+ with localcontext() as ctx:
913
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
914
+ '''
915
+ Volume of a cylinder: Used for cylindrical storage bins, silos, or tanks.(V=pi r^{2}h)
916
+ '''
917
+ fields={
918
+ 'height':{
919
+ 'default':1,
920
+ 'type':'dec.dec'
921
+ },
922
+ 'diameter':{
923
+ 'default':1,
924
+ 'type':'dec.dec'
925
+ },
926
+ }
927
+ fd=FormBuilder(data=fields,passThruText=f"Precision {ctx.prec}")
928
+ if fd is None:
929
+ return
930
+
931
+ volume=Decimal(math.pi)*((fd['diameter']/2)**2)*fd['height']
932
+ return volume
933
+
934
+ def volumeConeRadius():
935
+ with localcontext() as ctx:
936
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
937
+ '''
938
+ Volume of a cylinder: Used for cylindrical storage bins, silos, or tanks.(V=pi r^{2}h)
939
+ '''
940
+ fields={
941
+ 'height':{
942
+ 'default':1,
943
+ 'type':'dec.dec'
944
+ },
945
+ 'radius':{
946
+ 'default':1,
947
+ 'type':'dec.dec'
948
+ },
949
+ }
950
+ fd=FormBuilder(data=fields,passThruText=f"Precision {ctx.prec}")
951
+ if fd is None:
952
+ return
953
+
954
+ volume=Decimal(1/3)*(Decimal(math.pi)*(fd['radius']**2)*fd['height'])
955
+ return volume
956
+
957
+ def volumeConeDiameter():
958
+ with localcontext() as ctx:
959
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
960
+ '''
961
+ Volume of a cylinder: Used for cylindrical storage bins, silos, or tanks.(V=pi r^{2}h)
962
+ '''
963
+ fields={
964
+ 'height':{
965
+ 'default':1,
966
+ 'type':'dec.dec'
967
+ },
968
+ 'diameter':{
969
+ 'default':1,
970
+ 'type':'dec.dec'
971
+ },
972
+ }
973
+ fd=FormBuilder(data=fields,passThruText=f"Precision {ctx.prec}")
974
+ if fd is None:
975
+ return
976
+
977
+ volume=Decimal(1/3)*(Decimal(math.pi)*((fd['diameter']/2)**2)*fd['height'])
978
+ return volume
979
+
980
+ def volumeHemisphereRadius():
981
+ with localcontext() as ctx:
982
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
983
+ '''
984
+ Volume of a hemisphere = (2/3) x 3.14 x r3
985
+ '''
986
+ fields={
987
+ 'radius':{
988
+ 'default':1,
989
+ 'type':'dec.dec'
990
+ },
991
+ }
992
+ fd=FormBuilder(data=fields,passThruText=f"Precision {ctx.prec}")
993
+ if fd is None:
994
+ return
995
+
996
+ volume=Decimal(2/3)*Decimal(math.pi)*(fd['radius']**3)
997
+ return volume
998
+
999
+ def volumeHemisphereDiameter():
1000
+ with localcontext() as ctx:
1001
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
1002
+ '''
1003
+ Volume of a hemisphere = (2/3) x 3.14 x r3
1004
+ '''
1005
+ fields={
1006
+ 'diameter':{
1007
+ 'default':1,
1008
+ 'type':'dec.dec'
1009
+ },
1010
+ }
1011
+ fd=FormBuilder(data=fields,passThruText=f"Precision {ctx.prec}")
1012
+ if fd is None:
1013
+ return
1014
+
1015
+ volume=Decimal(2/3)*Decimal(math.pi)*((fd['diameter']/2)**3)
1016
+ return volume
1017
+
1018
+ def areaCircleDiameter():
1019
+ with localcontext() as ctx:
1020
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
1021
+ '''
1022
+ Volume of a hemisphere = (2/3) x 3.14 x r3
1023
+ '''
1024
+ fields={
1025
+ 'diameter':{
1026
+ 'default':1,
1027
+ 'type':'dec.dec'
1028
+ },
1029
+ }
1030
+ fd=FormBuilder(data=fields,passThruText=f"Precision {ctx.prec}")
1031
+ if fd is None:
1032
+ return
1033
+
1034
+ volume=Decimal(math.pi)*((fd['diameter']/2)**2)
1035
+ return volume
1036
+
1037
+
1038
+ def areaCircleRadius():
1039
+ with localcontext() as ctx:
1040
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
1041
+ '''
1042
+ Volume of a hemisphere = (2/3) x 3.14 x r3
1043
+ '''
1044
+ fields={
1045
+ 'radius':{
1046
+ 'default':1,
1047
+ 'type':'dec.dec'
1048
+ },
1049
+ }
1050
+ fd=FormBuilder(data=fields,passThruText=f"Precision {ctx.prec}")
1051
+ if fd is None:
1052
+ return
1053
+
1054
+ volume=Decimal(math.pi)*((fd['radius'])**2)
1055
+ return volume
1056
+
1057
+ ###newest
1058
+ def circumferenceCircleRadiu():
1059
+ #get the circumference of a circle using radius
1060
+ with localcontext() as ctx:
1061
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
1062
+ '''
1063
+ 2πr
1064
+ '''
1065
+ fields={
1066
+ 'radius':{
1067
+ 'default':1,
1068
+ 'type':'dec.dec'
1069
+ },
1070
+ }
1071
+ fd=FormBuilder(data=fields,passThruText=f"Precision {ctx.prec}")
1072
+ if fd is None:
1073
+ return
1074
+
1075
+ circumference=2*Deimal(math.pi)*fd['radius']
1076
+ return circumference
1077
+
1078
+ def circumferenceCircleDiameter():
1079
+ #get the circumference of a circle using diameter
1080
+ with localcontext() as ctx:
1081
+ ctx.prec=int(db.detectGetOrSet("lsbld ROUNDTO default",4,setValue=False,literal=True))
1082
+ '''
1083
+ 2π(d/2)
1084
+ '''
1085
+ fields={
1086
+ 'diameter':{
1087
+ 'default':1,
1088
+ 'type':'dec.dec'
1089
+ },
1090
+ }
1091
+ fd=FormBuilder(data=fields,passThruText=f"Precision {ctx.prec}")
1092
+ if fd is None:
1093
+ return
1094
+
1095
+ circumference=2*Deimal(math.pi)*Decimal(fd['diameter']/2)
1096
+ return circumference
1097
+
1098
+ '''
1099
+ Ellipse: area=πab
1100
+ , where 2a
1101
+ and 2b
1102
+ are the lengths of the axes of the ellipse.
1103
+
1104
+ Sphere: vol=4πr3/3
1105
+ , surface area=4πr2
1106
+ .
1107
+
1108
+ Cylinder: vol=πr2h
1109
+ , lateral area=2πrh
1110
+ , total surface area=2πrh+2πr2
1111
+ .
1112
+
1113
+
1114
+ Cone: vol=πr2h/3
1115
+ , lateral area=πrr2+h2−−−−−−√
1116
+ , total surface area=πrr2+h2−−−−−−√+πr2
1117
+ '''