BreakingBytes / simkit

Model Simulation Framework
http://breakingbytes.github.io/simkit/
BSD 3-Clause "New" or "Revised" License
27 stars 16 forks source link

move common settings to Meta #40

Closed mikofski closed 8 years ago

mikofski commented 8 years ago

there are several settings that have to be removed from the parameters, that should be set in Meta, and can be removed from the class more easily than the way they currently are.

EG: DataSourceBase removes reader so it can get the properties and then if it's set in the subclass resets it. Instead set this in Meta

class MyDataSource(DataSource):
    class Meta:
        data_reader = JSONReader
        data_cache_enabled = False
        data_path = 'my_proj'
        data_file = 'my_params.json'
    parameter1 = parameters.FloatField(
        'first parameter', units='W/m**2', sheet='Sheet1', range=[[2, 8762], 2]
    )

This would allow parameters to be read more easily and also even allow mixing of file params and class params.

This requires one of the common base meta classes to filter the meta out first, but it's already doing this for hardcoded settings.

There are several related TODO's like this in the SimEng2 project, for setting data reader parameters in the class so that the parameter structure is more consistent between readers. Currently, every reader has a different format. The idea of creating a parameter field class is in another issue somewhere too. Or reusing or repurposing a generic serializer like Marshmallow.

class solar_data(DataSource):
    # TODO: make parameters consistent for all readers
    # TODO: parameters set by attributes in data source model fields
    ghi = FloatField('GHI', units='W/m**2')
    solar_azimuth = FloatField('solar azimuth', units='degrees')
    # TODO: some parameters set in class Meta
    class Meta:
        args = ['GHI', 'azimuth']  # names to use for the first two args are positional
        data_reader = ArgumentReader