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

MOPS Alert Rule that returns DerivedObjects for which
    q > 50AU (Sedbas and detached scattered disk objects)

Added November 25th 2008 by Emily Schaller
"""

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


class sednas(DerivedObjectRule):
    """
    Return all new or newly modified DerivedObject instances.
    """
    def __init__(self, includeSyntheticObjects=False, channel='schaller', minArcLength=None):
        """
        Provide our own constructor to change the channel.
        """
        return(super(sednas, self).__init__(includeSyntheticObjects, channel, minArcLength))

    def issednas(self, obj):
        """
        Return True if obj has q > 50 AU

        q = a * ( 1 - e )

        @param obj: DerivedObject instance
        """
        return(obj.alertObj.orbit.q  > 50)


    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_SEDNAS
        return([obj for obj in self.newAlerts if self.issednas(obj)])
# <-- end class

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

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