Changeset 3345

Show
Ignore:
Timestamp:
05/14/08 14:47:26 (2 months ago)
Author:
hana
Message:

(hana) prepare_for_run method added

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/opus_core/allocation_model.py

    r3298 r3345  
    1515 
    1616from opus_core.model import Model 
    17 from opus_core.datasets.dataset import DatasetSubset 
     17from opus_core.datasets.dataset import Dataset, DatasetSubset 
    1818from opus_core.logger import logger 
    1919from numpy import where, ones, zeros, logical_and, clip, round_ 
     
    3131        given by the attribute 'control_total_attribute' of the 'control_totals' Dataset. If it is not given, it is assumed  
    3232        to have the same name as 'outcome_attribute'. The 'weight_attribute' of 'dataset' determines the allocation weights. 
    33         The 'control_totals' Dataset contains an attribute 'year' (or alternatively, anattribute given by the 'year_attribute' argument) 
     33        The 'control_totals' Dataset contains an attribute 'year' (or alternatively, an attribute given by the 'year_attribute' argument) 
    3434        and optionally other attributes that must be known to the 'dataset' (such as a geography). For each row of the control_totals dataset 
    3535        for which year matches the 'current_year', the total amount is distributed among the corresponding members of 'dataset' according to weights. 
     
    5656            attrs_to_compute.append(capacity_attribute) 
    5757        for attr in attrs_to_compute: 
    58             dataset.compute_one_variable_with_unknown_package(attr, dataset_pool=dataset_pool) 
     58            try: 
     59                dataset.compute_variables(attr, dataset_pool=dataset_pool) 
     60            except: 
     61                dataset.compute_one_variable_with_unknown_package(attr, dataset_pool=dataset_pool) 
    5962         
    6063        # create subset of control totals for the current year 
     
    103106            logger.log_status('New values stored into attribute %s of dataset %s.' % (outcome_attribute, dataset.get_dataset_name())) 
    104107        return outcome 
     108     
     109    def prepare_for_run(self, storage, table_name, id_name, dataset_name='control_totals'): 
     110        control_totals = Dataset(in_storage=storage, in_table_name=table_name, id_name=id_name, dataset_name=dataset_name) 
     111        return control_totals 
    105112     
    106113from opus_core.tests import opus_unittest