예제 #1
0
 def test_solve_for_r0_multiple_units(self):
     result = solenoid_convert(5, 27 * ureg.millimeter, None, 0.0045 * ureg.meter, "30", 0 * ureg.millimeter, 1.80131 * ureg.lbf, 350, 'millimeter')
     self.assertAlmostEqual(result, 2.3, 2)
예제 #2
0
def formHandle(request):
    data = {
        'voltage': '',
        'length': '',
        'r0': '',
        'ra': '',
        'x': '',
        'force': '',
        'awg': '',
        'compute': '',
        'relative_permeability': '',
        'length_unit': '',
        'r0_unit': '',
        'ra_unit': '',
        'x_unit': '',
        'force_unit': ''
    }
    if request.method == "POST":
        form = DataSetForm(request.POST)
        if form.is_valid():
            data['voltage'] = form.cleaned_data['voltage']
            data['length'] = form.cleaned_data['length']
            data['r0'] = form.cleaned_data['r0']
            data['ra'] = form.cleaned_data['ra']
            data['x'] = form.cleaned_data['x']
            data['force'] = form.cleaned_data['force']
            data['awg'] = form.cleaned_data['awg']
            data['compute'] = form.cleaned_data['compute']
            data['relative_permeability'] = form.cleaned_data[
                'relative_permeability']

            data['length_unit'] = form.cleaned_data['length_unit']
            data['r0_unit'] = form.cleaned_data['r0_unit']
            data['ra_unit'] = form.cleaned_data['ra_unit']
            data['x_unit'] = form.cleaned_data['x_unit']
            data['force_unit'] = form.cleaned_data['force_unit']

            # Use Pint to convert raw values to Unit Quantities to be used in conversion
            data['length'] = data['length'] * ureg(data['length_unit'])
            data['r0'] = data['r0'] * ureg(data['r0_unit'])
            data['ra'] = data['ra'] * ureg(data['ra_unit'])
            data['x'] = data['x'] * ureg(data['x_unit'])
            data['force'] = data['force'] * ureg(data['force_unit'])

            compute = data['compute']
            data[compute] = None

            if compute in ['length', 'r0', 'ra', 'x', 'force']:
                output_unit = data[compute + "_unit"]
            else:
                output_unit = None

            try:
                data[compute] = solenoid_convert(data['voltage'],
                                                 data['length'], data['r0'],
                                                 data['ra'], data['awg'],
                                                 data['x'], data['force'],
                                                 data['relative_permeability'],
                                                 output_unit)

                data[compute] = round(data[compute], sig_figs)
            except NoSolution:
                data[compute] = "No Solution Found"

            for k, v in data.items():
                data[k] = str(v)

            return JsonResponse(data, safe=False)
예제 #3
0
 def test_solve_for_length_multiple_units(self):
     result = solenoid_convert(5, None, 0.09055118 * ureg.inch, 0.0045 * ureg.meter, "30", 0 * ureg.millimeter, 1.80131 * ureg.lbf, 350, 'millimeter')
     self.assertAlmostEqual(result,27.0,2)
예제 #4
0
 def test_solve_for_force_multiple_units(self):
     result = solenoid_convert(5, 27 * ureg.millimeter, 0.09055118 * ureg.inch, 0.0045 * ureg.meter, "30", 0 * ureg.millimeter, None, 350, 'lbf')
     self.assertAlmostEqual(result,1.8013,4) #Comparing the result to the pre-converted answer from newton to lbl
예제 #5
0
 def test_solve_for_force_mm_n(self):
     result = solenoid_convert(5, 27 * ureg.millimeter, 2.3 * ureg.millimeter, 4.5 * ureg.millimeter,"30", 0 * ureg.millimeter,None, 350, 'newton')
     self.assertAlmostEqual(result,8.01266,4)
예제 #6
0
 def test_permeability_with_different_units(self):
     result = solenoid_convert(5, 27 * ureg.millimeter, 0.09055118 * ureg.inch, 0.0045 * ureg.meter, "30", 0 * ureg.centimeter, 1.80131 * ureg.lbf, None, None)
     self.assertEqual(result,350)
예제 #7
0
 def test_solve_for_length_nonzero_location(self):
     result = solenoid_convert(5, None, 0.09055118 * ureg.inch, 4.5 * ureg.millimeter, "30", 0.05 * ureg.meter, 0.00550422 * ureg.lbf, 350, 'millimeter')
     self.assertAlmostEqual(result,300.0,None,"Not equal",0.5)