Show
Ignore:
Timestamp:
03/10/10 12:32:00 (6 months ago)
Author:
acracia
Branch:
default
Message:

[api]to_dict method on the model, tailored to use as input of the api

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pdw/pd/__init__.py

    r325 r326  
    5858 
    5959now = datetime.datetime.now() 
     60 
    6061def float_date(year, month=0, day=0): 
     62    '''to convert a date in a float type''' 
    6163    return swiss.date.FlexiDate(year, month, day).as_float() 
    6264 
     
    6466    # now dispatch on jurisdiction (+ work type?) 
    6567    # note two letter country codes based on ISO 3166 
    66     #  
     68    # need to add 'when' parameter here and deeper  
    6769    if jurisdiction == 'us': 
    6870        pd_calculator = CalculatorUnitedStates 
     
    8082    To create a Work object and analize its pd status from a  
    8183    python or json dict 
     84    @param  params: json formatted string 
     85    @type   params: string 
    8286    ''' 
    83  
    8487    params = json.loads(json_data) 
    8588    jur = params['jurisdiction']  
     
    108111        return "date_pd=%s pd_prob=%s log=%s" % (self.date_pd, self.pd_prob, self.log) 
    109112 
     113    @classmethod 
     114    def to_dict(cls, self): 
     115        '''Creates a dict result to give back as json in the api 
     116        ''' 
     117        out_dict = { 'confidence': 1-self.uncertainty, 
     118                    'pd probability': self.pd_prob, 
     119                    'date pd': self.date_pd, 
     120                    'log': self.log, 
     121                   } 
     122        return out_dict 
     123#TODO 
     124 
    110125class CalculatorBase(object): 
    111126    """A Public Domain Calculator 
     
    114129    def __init__(self, when): 
    115130        self.author_list = None 
     131        self.death_dates = [] 
     132        self.names = [] 
    116133        if when: 
    117           self._now = when 
     134            self._now = when 
    118135        else: 
    119136            self._now = float_date(datetime.date.today().year)