Statistics
| Branch: | Revision:

mobicen / varie / simulator.py @ 9110387b

History | View | Annotate | Download (2 KB)

1
import configparser
2

    
3
class Simulator(object):
4

    
5
    def __init__(self, settingsFile, sectionExp):
6
        self.simParameters = self.getSimulationParameters(settingsFile, sectionExp)
7

    
8
    def getSimulationParameters(self,settingsFile, sectionExp):
9
        retParameters = {}
10
        settings = configparser.ConfigParser()
11
        settings._interpolation = configparser.ExtendedInterpolation()
12
        settings.read(settingsFile)
13
        mand = set([
14
            'min_x', 'min_y', 'housecleaning', 'nodes_number', 'max_velocity',
15
            'range', 'mobility_timer', 'min_velocity', 'duration', 'hello'
16
        ])
17
        opts = dict(settings.items(sectionExp))
18
        if (not mand.issubset(opts.keys())):
19
            sys.exit('You are missing a mandatory parameter!\n'
20
                     'These are required:\n' + ', '.join(mand))
21
        for option in settings.options(sectionExp):
22
            arg = settings.get(sectionExp, option)
23
            if option == 'duration':
24
                retParameters['duration'] = float(arg.strip('s'))
25
            if option == 'min_x':
26
                retParameters['min_x'] = int(arg)
27
            if option == 'min_y':
28
                retParameters['min_y'] = int(arg)
29
            if option == 'housecleaning':
30
                retParameters['housecleaning'] = float(arg.strip('s'))
31
            if option == 'nodes_number':
32
                retParameters['nodes_number'] = int(arg)
33
            if option == 'max_velocity':
34
                retParameters['max_velocity'] = float(arg)
35
            if option == 'min_velocity':
36
                retParameters['min_velocity'] = float(arg)
37
            if option == 'range':
38
                retParameters['range'] = float(arg)
39
            if option == 'mobility_timer':
40
                retParameters['mobility_timer'] = float(arg.strip('s'))
41
            if option == 'hello':
42
                retParameters['hello'] = float(arg.strip('s'))
43
            else:
44
                print 'Unparsed ', option, '=', settings.get(sectionExp, option)
45
        return retParameters