def createFromSqlResult(result): """ Creates a new Target instance initialized using the request from an SQL query. """ c = Conversions() target = Target(min_lst = c.sexHrs2rad(result['MINIMUM_LST']) , max_lst = c.sexHrs2rad(result['MAXIMUM_LST']) # TBF: why bother importing? It is soooo FUBAR! #, elevation_min = result['ELEVATION_MINIMUM'] , pst_max_lst = result['MAXIMUM_LST'] , pst_min_lst = result['MINIMUM_LST'] , pst_elevation_min = result['ELEVATION_MINIMUM'] ) target.save() return target
def createFromSqlResult(proposal_id, result): """ Creates a new Session instance initialized using the request from an SQL query. """ c = Conversions() epoch = SourceCoordinateEpoch.objects.get(epoch = result['coordinate']) sys = SourceCoordinateSystem.objects.get(system = result['coordinate_system']) vType = SourceVelocityType.objects.get(type = result['velocity_type']) ref = SourceReferenceFrame.objects.get(frame = result['referenceFrame']) con = SourceConvention.objects.get(convention = result['convention']) # Occasionally this string can be something dumb like '?' try: vRedshift = float(result['velocity_redshift']) except: vRedshift = None source = Source(pst_source_id = result['source_id'] # Don't use result's because that's for the # PST, not our GB PHT DB! , proposal_id = proposal_id , target_name = result['target_name'] , ra = c.sexHrs2rad(result['right_ascension']) , ra_range = c.sexHrs2rad(result['right_ascension_range']) , dec = c.sexDeg2rad(result['declination']) , dec_range = c.sexDeg2rad(result['declination_range']) , coordinate_epoch = epoch , coordinate_system = sys , velocity_units = vType , velocity_redshift = vRedshift , convention = con , reference_frame = ref , pst_ra = result['right_ascension'] , pst_ra_range = result['right_ascension_range'] , pst_dec = result['declination'] , pst_dec_range = result['declination_range'] ) source.save() return source
def setUp(self): self.c = Conversions()
class TestConversions(unittest.TestCase): def setUp(self): self.c = Conversions() def test_tryHourConversions(self): # varaitions off HH:MM:SS.S tests = ['10:00:00.0' , '10:00:00.000' , '10:00:00' , '010:00:00' # varaitions off HH MM SS.S , '10 00 00.0' , '10 00 00.0' # varaitions off ##h ##m ##s , '10d00m00s' , '10h00m00s' , '10d 00m 00s' , '10d 00m 00.0s' # simple , '10.0' ] for t in tests: anyMatch, value = self.c.tryHourConversions(t) self.assertEqual(True, anyMatch) self.assertAlmostEquals(10.0, value, 2) # spot check anyMatch, value = self.c.tryHourConversions(' 09:43:25') self.assertEqual(True, anyMatch) self.assertAlmostEquals(9.723, value, 2) anyMatch, value = self.c.tryHourConversions('23:30:00') self.assertEqual(True, anyMatch) self.assertAlmostEquals(23.50, value, 2) anyMatch, value = self.c.tryHourConversions('123:30:00') self.assertTrue(value is None) def test_tryDegreeConversions(self): # varaitions off HH:MM:SS.S tests = ['310:00:00.0' , '310:00:00.000' , '-310:00:00.000' , '310:00:00' , '0310:00:00' # varaitions off HH MM SS.S , '310 00 00.0' , '310 00 00.0' , '-310 00 00.0' # varaitions off ##h ##m ##s , '310d00m00s' , '310d00m00s' , '-310d00m00s' , '310d 00m 00s' , '310d 00m 00.0s' # simple , '310.0' ] for t in tests: anyMatch, value = self.c.tryDegreeConversions(t) self.assertEqual(True, anyMatch) self.assertAlmostEquals(310.0, abs(value), 2) # spot check anyMatch, value = self.c.tryDegreeConversions(' 09:43:25') self.assertEqual(True, anyMatch) self.assertAlmostEquals(9.723, value, 2) anyMatch, value = self.c.tryDegreeConversions('23:30:00') self.assertEqual(True, anyMatch) self.assertAlmostEquals(23.50, value, 2) anyMatch, value = self.c.tryDegreeConversions('523:30:00') self.assertTrue(value is None) anyMatch, value = self.c.tryDegreeConversions('23 13 13') self.assertEqual(True, anyMatch) self.assertAlmostEquals(23.220, value, 2) anyMatch, value = self.c.tryDegreeConversions('+23 13 13') self.assertEqual(True, anyMatch) self.assertAlmostEquals(23.220, value, 2) anyMatch, value = self.c.tryDegreeConversions('-23 13 13') self.assertEqual(True, anyMatch) self.assertAlmostEquals(-23.220, value, 2)