#!/usr/bin/env python
"""
plugins.distant_planets

MOPS Alert Rule that returns DerivedObjects for which
    a > 60 AU
"""

from base import DerivedObjectRule
from MOPS.Alerts.plugins.Constants import CH_PLANETS
import sys


class DistantPlanets(DerivedObjectRule):
    """
    Return all new or newly modified DerivedObject instances.
    """
    def isDistantPlanet(self, obj):
        """
        Return True if obj has a > 60 AU

        q = a * ( 1 - e )

        @param obj: DerivedObject instance
        """
        return(obj.alertObj.orbit.q / (1 - obj.alertObj.orbit.e) > 60)

    
    def evaluate(self):
        """
        Return a list of DerivedObject instances that satisfy the rule.
        """
        #Set the channel that will be used to publish the alert.
        self.channel = CH_PLANETS
        return([obj for obj in self.newAlerts \
                if self.isDistantPlanet(obj)])
# <-- end class

def main(args=sys.argv[1:]):
    rule = DistantPlanets()
    alerts = rule.evaluate()
    
    for alert in alerts:
        print(alert + '\n\n')
# <-- end main    

if(__name__ == '__main__'):
    sys.exit(main())
# <-- end if