# *****************************************************************
#  Copyright 2013 MIT Lincoln Laboratory  
#  Project:            SPAR
#  Authors:            jch
#  Description:        A class for the row generated by data_generator_engine
# 
#  Modifications:
#  Date          Name           Modification
#  ----          ----           ------------
#  30 Oct 2013    jch           Original file
# *****************************************************************

import spar_python.data_generation.spar_variables as sv

class GeneratedRow(dict):

    """
    This class holds the row generated by the DataGeneratorEngine class. It is
    a child of the UserDict class, and so will implement the dictionary
    interface for backwards compatibility. In addition, it will implement 
    the following extra attribute for optimization:
    
    
    * in_query_aggregator_format: will map a field-ID into the value of 
      of self[id], but already converted into the format expected by the
      aggregators in query_aggregators.
    
    """

    def __init__(self, *args, **kwargs):

        dict.__init__(self, *args, **kwargs)
        self.in_query_aggregator_format = {}

    def __setitem__(self, field_id, value):
        dict.__setitem__(self, field_id, value)
        
        reformat = sv.VAR_CONVERTERS[field_id].to_agg_fmt
        reformatted_val = reformat(value)
        self.in_query_aggregator_format[field_id] = reformatted_val
        
# *****************************************************************
#  Copyright 2013 MIT Lincoln Laboratory  
#  Project:            SPAR
#  Authors:            jch
#  Description:        A class for the row generated by data_generator_engine
# 
#  Modifications:
#  Date          Name           Modification
#  ----          ----           ------------
#  30 Oct 2013    jch           Original file
# *****************************************************************

import spar_python.data_generation.spar_variables as sv

class GeneratedRow(dict):

    """
    This class holds the row generated by the DataGeneratorEngine class. It is
    a child of the UserDict class, and so will implement the dictionary
    interface for backwards compatibility. In addition, it will implement 
    the following extra attribute for optimization:
    
    
    * in_query_aggregator_format: will map a field-ID into the value of 
      of self[id], but already converted into the format expected by the
      aggregators in query_aggregators.
    
    """

    def __init__(self, *args, **kwargs):

        dict.__init__(self, *args, **kwargs)
        self.in_query_aggregator_format = {}

    def __setitem__(self, field_id, value):
        dict.__setitem__(self, field_id, value)
        
        reformat = sv.VAR_CONVERTERS[field_id].to_agg_fmt
        reformatted_val = reformat(value)
        self.in_query_aggregator_format[field_id] = reformatted_val
        
# ***************************************************************** #  Copyright 2013 MIT Lincoln Laboratory #  Project:            SPAR #  Authors:            jch #  Description:        A class for the row generated by data_generator_engine # #  Modifications: #  Date          Name           Modification #  ----          ----           ------------ #  30 Oct 2013    jch           Original file # ***************************************************************** This class holds the row generated by the DataGeneratorEngine class. It is     a child of the UserDict class, and so will implement the dictionary     interface for backwards compatibility. In addition, it will implement      the following extra attribute for optimization:               * in_query_aggregator_format: will map a field-ID into the value of        of self[id], but already converted into the format expected by the       aggregators in query_aggregators.