• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TOMToolkit / tom_base / 6713509976

31 Oct 2023 11:13PM UTC coverage: 86.773% (+0.7%) from 86.072%
6713509976

push

github-actions

web-flow
Merge pull request #699 from TOMToolkit/dev

Multi-Feature Merge. Please Review Carefully.

795 of 795 new or added lines in 39 files covered. (100.0%)

8253 of 9511 relevant lines covered (86.77%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

44.9
/tom_alerts/brokers/scout.py
1
import requests
1✔
2
from dateutil.parser import parse
1✔
3
from urllib.parse import urlencode
1✔
4

5
from astropy import units as u
1✔
6
from astropy.coordinates import Angle
1✔
7
from crispy_forms.layout import HTML, Layout
1✔
8

9
from tom_alerts.alerts import GenericAlert, GenericQueryForm, GenericBroker
1✔
10
from tom_targets.models import Target
1✔
11

12
SCOUT_URL = 'https://ssd-api.jpl.nasa.gov/scout.api'
1✔
13

14

15
class ScoutQueryForm(GenericQueryForm):
1✔
16
    def __init__(self, *args, **kwargs):
1✔
17
        super().__init__(*args, **kwargs)
×
18
        self.helper.layout = Layout(
×
19
            HTML('''
20
                <p>
21
                Please see the <a href="https://ssd-api.jpl.nasa.gov/doc/scout.html target="_blank"">Scout API
22
                Reference</a> for a detailed description of the service.
23
                </p>
24
            '''),
25
            self.common_layout,
26
        )
27

28

29
def hours_min_to_decimal(val):
1✔
30
    hours, minutes = val.split(':')
×
31
    angle = Angle('{0}h{1}m'.format(hours, minutes))
×
32
    return angle.to(u.degree).value
×
33

34

35
class ScoutBroker(GenericBroker):
1✔
36
    """
37
    The ``ScoutBroker`` is the interface to the Scout alert broker. For information regarding the Scout Broker,
38
    please see https://cneos.jpl.nasa.gov/scout/intro.html, as well as https://ssd-api.jpl.nasa.gov/doc/scout.html.
39
    """
40

41
    name = 'Scout'
1✔
42
    form = ScoutQueryForm
1✔
43

44
    @classmethod
1✔
45
    def clean_parameters(clazz, parameters):
1✔
46
        parameters.pop('query_name')
×
47
        parameters.pop('broker')
×
48
        return {k.replace('_', '-'): v for k, v in parameters.items() if v}
×
49

50
    def fetch_alerts(self, parameters):
1✔
51
        broker_feedback = ''
×
52
        args = urlencode(self.clean_parameters(parameters))
×
53
        url = '{0}?{1}'.format(SCOUT_URL, args)
×
54
        response = requests.get(url)
×
55
        response.raise_for_status()
×
56
        parsed = response.json()['data']
×
57
        parsed.sort(key=lambda x: parse(x['lastRun']), reverse=True)
×
58
        return iter(parsed), broker_feedback
×
59

60
    def fetch_alert(self, alert_id):
1✔
61
        url = f'{SCOUT_URL}/{alert_id}/?format=json'
×
62
        url = '{0}?tdes={1}'.format(SCOUT_URL, alert_id)
×
63
        response = requests.get(url)
×
64
        response.raise_for_status()
×
65
        return response.json()
×
66

67
    def process_reduced_data(self, target, alert=None):
1✔
68
        pass
×
69

70
    def to_target(self, alert):
1✔
71
        target = Target.objects.create(
×
72
            name=alert['objectName'],
73
            type='NON_SIDEREAL',
74
            ra=hours_min_to_decimal(alert['ra']),
75
            dec=alert['dec'],
76
            eccentricity=alert['elong']
77
        )
78
        return target
×
79

80
    def to_generic_alert(self, alert):
1✔
81
        timestamp = parse(alert['lastRun'])
×
82
        url = 'https://cneos.jpl.nasa.gov/scout/#/object/' + alert['objectName']
×
83

84
        return GenericAlert(
×
85
            timestamp=timestamp,
86
            url=url,
87
            id=alert['objectName'],
88
            name=alert['objectName'],
89
            ra=hours_min_to_decimal(alert['ra']),
90
            dec=alert['dec'],
91
            mag=alert['H'],
92
            score=alert['neoScore']
93
        )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc