def orbit2(): planets = [ Planet(1817514095, 1905216634, -1485460920), Planet(1817514095, 1905216634, -1722015868), Planet(1817514095, 1905216634, -455609026), Planet(1817514095, 1905216634, 272811578), Planet(1817514095, 1905216634, -393577255), Planet(1817514095, 1905216634, -1420756477), Planet(1817514095, 1905216634, -93488736), Star(1817514095, -1385166447, Star(1817514095, 1905216634)) ] t0 = epoch_from_string(str(datetime.now())) x_val = list() y_val = list() z_val = list() planet_positions = list() planet_names = list() planet_colors = list() for orbiter in planets: orbit_period = orbiter.planet.compute_period(epoch(0)) * SEC2DAY orbit_when = np.linspace(0, orbit_period, 60) x = np.zeros(60) y = np.zeros(60) z = np.zeros(60) for i, day in enumerate(orbit_when): r, _ = orbiter.planet.eph(epoch(t0.mjd2000 + day)) x[i] = r[0] / AU y[i] = r[1] / AU z[i] = r[2] / AU x_val.append(x.tolist()) y_val.append(y.tolist()) z_val.append(z.tolist()) planet_positions.append(list((x[0], y[0], z[0]))) if orbiter.id == -455609026: planet_colors.append("green") else: planet_colors.append("gray") planet_names.append(orbiter.name) return jsonify(success=True, x=x_val, y=y_val, z=z_val, p=planet_positions, c=planet_colors, n=planet_names) if has_app_context() else x_val
def test_init_stars_HTTPError(self, mock_get): """Test Star init with HTTPError on API stars.""" mock_get.side_effect = self.api_traversal[0:3] + [ HTTPError("Error", None) ] with self.assertRaises(HTTPError): _ = Star(1, 1)
def test_property_true_anomaly_at_epoch_primary(self, mock_get): """Test true anomaly at epoch property of primary Star.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get()] instance = Star(1, 1) self.assertIsNone(instance.true_anomaly_at_epoch)
def test_property_argument_of_periapsis_primary(self, mock_get): """Test argument of periapsis property of primary Star.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get()] instance = Star(1, 1) self.assertIsNone(instance.argument_of_periapsis)
def test_property_longitude_of_ascending_node_primary(self, mock_get): """Test longitude of ascending node property of primary Star.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get()] instance = Star(1, 1) self.assertIsNone(instance.longitude_of_ascending_node)
def test_property_inclination_primary(self, mock_get): """Test inclination property of primary Star.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get()] instance = Star(1, 1) self.assertIsNone(instance.inclination)
def test_property_eccentricity_primary(self, mock_get): """Test eccentricity property of primary Star.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get()] instance = Star(1, 1) self.assertIsNone(instance.eccentricity)
def test_property_semimajor_axis_primary(self, mock_get): """Test semimajor axis property of primary Star.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get()] instance = Star(1, 1) self.assertIsNone(instance.semimajor_axis)
def test_init(self, mock_get): """Test Star init.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get()] instance = Star(1, 1) expected_result = Star self.assertIsInstance(instance, expected_result)
def test_property_mass(self, mock_get): """Test mass property of Star.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get(mass=id(sentinel.mass))] instance = Star(1, 1) expected_result = id(sentinel.mass) self.assertEqual(instance.mass, expected_result)
def test_property_name(self, mock_get): """Test name property of Star.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get(name=id(sentinel.name))] instance = Star(1, 1) expected_result = str(id(sentinel.name)) self.assertEqual(instance.name, expected_result)
def test_property_id(self, mock_get): """Test id property of Star.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get(idnum=1)] instance = Star(1, 1) expected_result = 1 self.assertEqual(instance.id, expected_result)
def test_property_planet_primary(self, mock_get): """Test planet property of primary Star.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get()] instance = Star(1, 1) with self.assertRaises(ValueError): _ = instance.planet
def test_property_argument_of_periapsis_secondary(self, mock_get): """Test argument of periapsis property of secondary Star.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get(argument_of_periapsis=id(sentinel.argument_of_periapsis))] mock_star = MagicMock() instance = Star(1, 1, mock_star) expected_result = id(sentinel.argument_of_periapsis) self.assertEqual(instance.argument_of_periapsis, expected_result)
def test_property_inclination_secondary(self, mock_get): """Test inclination property of secondary Star.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get(inclination=id(sentinel.eccentricity))] mock_star = MagicMock() instance = Star(1, 1, mock_star) expected_result = id(sentinel.eccentricity) self.assertEqual(instance.inclination, expected_result)
def test_property_semimajor_axis_secondary(self, mock_get): """Test semimajor axis property of secondary Star.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get(semimajor_axis=id(sentinel.semimajor_axis))] mock_star = MagicMock() instance = Star(1, 1, mock_star) expected_result = id(sentinel.semimajor_axis) self.assertEqual(instance.semimajor_axis, expected_result)
def test_property_true_anomaly_at_epoch_secondary(self, mock_get): """Test true anomaly at epoch property of secondary Star.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get(true_anomaly_at_epoch=id(sentinel.true_anomaly_at_epoch))] mock_star = MagicMock() instance = Star(1, 1, mock_star) expected_result = id(sentinel.true_anomaly_at_epoch) self.assertEqual(instance.true_anomaly_at_epoch, expected_result)
def test_property_longitude_of_ascending_node_secondary(self, mock_get): """Test longitude of ascending node property of secondary Star.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get( longitude_of_ascending_node=id(sentinel.longitude_of_ascending_node))] mock_star = MagicMock() instance = Star(1, 1, mock_star) expected_result = id(sentinel.longitude_of_ascending_node) self.assertEqual(instance.longitude_of_ascending_node, expected_result)
def __init__(self, system_id, star_id, planet_id, server_url="http://trident.senorpez.com/"): req = requests.get(server_url) req.raise_for_status() systems_url = req.json()['_links']['trident-api:systems']['href'] req = requests.get(systems_url) req.raise_for_status() system_url = None for entry in req.json()['_embedded']['trident-api:system']: if entry['id'] == system_id: system_url = entry['_links']['self']['href'] req = requests.get(system_url) req.raise_for_status() stars_url = req.json()['_links']['trident-api:stars']['href'] req = requests.get(stars_url) req.raise_for_status() star_url = None for entry in req.json()['_embedded']['trident-api:star']: if entry['id'] == star_id: star_url = entry['_links']['self']['href'] req = requests.get(star_url) req.raise_for_status() planets_url = req.json()['_links']['trident-api:planets']['href'] req = requests.get(planets_url) req.raise_for_status() planet_url = None for entry in req.json()['_embedded']['trident-api:planet']: if entry['id'] == planet_id: planet_url = entry['_links']['self']['href'] req = requests.get(planet_url) req.raise_for_status() self.id = req.json()['id'] self.name = req.json()['name'] self.mass = req.json()['mass'] self.radius = req.json()['radius'] self.semimajor_axis = req.json()['semimajorAxis'] self.eccentricity = req.json()['eccentricity'] self.inclination = req.json()['inclination'] self.longitude_of_ascending_node = req.json( )['longitudeOfAscendingNode'] self.argument_of_periapsis = req.json()['argumentOfPeriapsis'] self.true_anomaly_at_epoch = req.json()['trueAnomalyAtEpoch'] self._star = Star(system_id, star_id)
def test_property_gm(self, mock_get, mock_constant): """Test gm property of Star.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get(mass=0.75)] mock_grav = MagicMock() type(mock_grav).value = PropertyMock(return_value=6.67408e-11) mock_solar_mass = MagicMock() type(mock_solar_mass).value = PropertyMock(return_value=1.9884e30) mock_constant.side_effect = [mock_solar_mass, mock_grav] instance = Star(1, 1) expected_result = 0.75 * 1.9884e30 * 6.67408e-11 self.assertEqual(instance.gm, expected_result)
def test_property_planet_secondary(self, mock_get, mock_constant): """Test planet property of secondary Star.""" mock_get.side_effect = self.api_traversal \ + [mocked_requests_get(mass=0.75, semimajor_axis=1)] mock_star = MagicMock() type(mock_star).gm = mock.PropertyMock(return_value=0.75 * 1.9884e30 * 6.67408e-11) mock_grav = MagicMock() type(mock_grav).value = PropertyMock(return_value=6.67408e-11) mock_solar_mass = MagicMock() type(mock_solar_mass).value = PropertyMock(return_value=1.9884e30) mock_constant.side_effect = [mock_solar_mass, mock_grav] instance = Star(1, 1, mock_star) expected_result = keplerian self.assertIsInstance(instance.planet, expected_result)
def test_property_true_anomaly_at_epoch_secondary(self): """Test 2 Eta Veneris true anomaly at epoch.""" instance = Star(1817514095, -1385166447, Star(1817514095, 1905216634)) expected_result = 6.0167522 self.assertEqual(instance.true_anomaly_at_epoch, expected_result)
def test_property_argument_of_periapsis_secondary(self): """Test 2 Eta Veneris argument of periapsis.""" instance = Star(1817514095, -1385166447, Star(1817514095, 1905216634)) expected_result = 2.9558303 self.assertEqual(instance.argument_of_periapsis, expected_result)
def test_property_longitude_of_ascending_node_secondary(self): """Test 2 Eta Veneris longitude of ascending node.""" instance = Star(1817514095, -1385166447, Star(1817514095, 1905216634)) expected_result = 4.8210096 self.assertEqual(instance.longitude_of_ascending_node, expected_result)
def test_property_inclination_secondary(self): """Test 2 Eta Veneris inclination.""" instance = Star(1817514095, -1385166447, Star(1817514095, 1905216634)) expected_result = 0.006273935 self.assertEqual(instance.inclination, expected_result)
def test_property_eccentricity_secondary(self): """Test 2 Eta Veneris eccentricity.""" instance = Star(1817514095, -1385166447, Star(1817514095, 1905216634)) expected_result = 0.5 self.assertEqual(instance.eccentricity, expected_result)
def test_property_semimajor_axis_secondary(self): """Test 2 Eta Veneris semimajor axis.""" instance = Star(1817514095, -1385166447, Star(1817514095, 1905216634)) expected_result = 70.0 self.assertEqual(instance.semimajor_axis, expected_result)
def test_property_mass_secondary(self): """Test 2 Eta Veneris mass.""" instance = Star(1817514095, -1385166447, Star(1817514095, 1905216634)) expected_result = 0.75 self.assertEqual(instance.mass, expected_result)
def test_property_name_secondary(self): """Test 2 Eta Veneris name.""" instance = Star(1817514095, -1385166447, Star(1817514095, 1905216634)) expected_result = "2 Eta Veneris" self.assertEqual(instance.name, expected_result)
def test_property_id_secondary(self): """Test 2 Eta Veneris id.""" instance = Star(1817514095, -1385166447, Star(1817514095, 1905216634)) expected_result = -1385166447 self.assertEqual(instance.id, expected_result)