#!/usr/bin/env python
"""
plugin.centaurs

MOPS Alert Rule that returns DerivedObjects that can be defined as
Centaurs (5.2 < a < 29, 5.2 < q < 29).

Added May 14th 2008 by Tommy Grav.
"""
from base import DerivedObjectRule
from MOPS.Alerts.plugins.Constants import CH_CENTAURS
import sys


class Centaurs(DerivedObjectRule):
    """
    Return all new or newly modified DerivedObjects instances.
    """
    def __init__(self, includeSyntheticObjects=False, channel='grav',
                 minArcLength=None):
        return(super(Centaurs, self).__init__(includeSyntheticObjects,
                                              channel,
                                              minArcLength))
    
    def is_centaur(self,obj):
        """
        Return True if obj has 5.2 < a < 29 and 5.2 < q < 29,
        where q = a*(1 - e)
        
        @param obj: DerivedObject instance
        """
        centaur = False
        a = obj.alertObj.orbit.q/(1 - obj.alertObj.orbit.e)
        return 5.2 < a < 29. and 5.2 < obj.alertObj.orbit.q < 29.
    
    def evaluate(self):
        """
        Return a list of DerivedObjects that satisfy the rule.
        """
        #Set the channel that will be used to publish the alert.
        self.channel = CH_CENTAURS
        return([obj for obj in self.newAlerts if self.is_centaur(obj)])

# <-- end class

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

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