Example #1
0
def run_sim(integration_period: int, input_generators: list):
    '''runs the simulation that creates the input csv'''

    while True:
        print()
        time_interval = input_int(
            'How long is this time interval (in minutes)[enter 0 to end the simulation]: '
        )
        if time_interval == 0:
            return
        num_periods_interval = int(60 / integration_period * time_interval)
        input_at_interval(input_generators, num_periods_interval)
Example #2
0
def run_sim_state(integration_period: int, input_generators: list):
    while True:
        for inp_gen in input_generators:
            rlen = range(1, len(inp_gen.states()) + 1)
            str_rlen = set(str(x) for x in rlen)
            state = input_str('Which of the following states is \"{}\" in {}[enter 0 to end the simulation]: '.format(inp_gen.dev_name,\
                                sorted(zip(rlen, sorted(inp_gen.states())))), valid=inp_gen.states().union(str_rlen))
            if state == '0':
                return
            input_dict = dict(zip(rlen, sorted(inp_gen.states())))
            if not state in sorted(inp_gen.states()):
                state = input_dict[int(state)]
            time_interval = input_int(
                'How long is this time interval (in minutes)[enter 0 to end the simulation]: '
            )
            if time_interval == 0:
                return
            num_periods_interval = int(60 / integration_period * time_interval)
            inp_gen.write_on_state(state, num_periods_interval)
Example #3
0
            device_map[name_gen.generate_name(key)] = value
        elif inp == 'd':
            valid = set(device_map.keys())
            if len(valid) > 0:
                to_delete = input_str(
                    'Which device do you want to delete? {}: '.format(valid),
                    valid)
                del device_map[to_delete]
            else:
                print('There are no devices to delete\n')
        elif inp == 'p':
            pprint(device_map)
        elif inp == 'r':
            input_generators = make_input_generators(device_map)
            # Get Integration Period
            integration_period = input_int('Enter integration period: ')
            # Get Periods
            run_sim(integration_period, input_generators)

            # pickle run_perams
            with open(OUTPUT_PICKLE, 'wb') as fd:
                pickle.dump(
                    {
                        'integeration_period': integration_period,
                        'device_map': device_map
                    }, fd)

            # write info file
            write_to_ifile(OUTPUT_CSV, integration_period, input_generators)
            # write copy of the pickle file
            write_to_peramfile(OUTPUT_CONFIG, integration_period, device_map)
Example #4
0
            elif inp == 'd':
                valid = set(device_map.keys())
                if len(valid) > 0:
                    to_delete = input_str(
                        'Which device do you want to delete? {}: '.format(
                            valid), valid)
                    del device_map[to_delete]
                else:
                    print('There are no devices to delete\n')
            elif inp == 'p':
                pprint(device_map)
            elif inp == 'r':
                input_generators = make_input_generators(device_map)
                # Get Integration Period
                integration_period = input_int(
                    'Enter integration period for simulation calculation framework (whole seconds): '
                )
                # Get Periods
                run_sim_state(integration_period, input_generators)
                # run_sim(integration_period, input_generators)

                # pickle run_perams
                with open(OUTPUT_PICKLE, 'wb') as fd:
                    pickle.dump(
                        {
                            'integeration_period': integration_period,
                            'device_map': device_map
                        }, fd)

                # write info file
                write_to_ifile(OUTPUT_CSV, integration_period,
Example #5
0
        elif inp == 'd':
            valid = set(device_map.keys())
            if len(valid) > 0:
                to_delete = input_str(
                    'Which device do you want to delete? {}: '.format(valid),
                    valid)
                del device_map[to_delete]
            else:
                print('There are no devices to delete\n')
        elif inp == 'p':
            pprint(device_map)
        elif inp == 'r':
            input_generators = make_input_generators(device_map)
            # Get Integration Period
            integration_period = input_int(
                'Enter block period for simulation calculation framework (specify number of units that fit in an hour - e.g. 1 minute=60): '
            )
            # Get Periods
            run_sim_state(integration_period, input_generators)
            # run_sim(integration_period, input_generators)

            # pickle run_perams
            with open(OUTPUT_PICKLE, 'wb') as fd:
                pickle.dump(
                    {
                        'integeration_period': integration_period,
                        'device_map': device_map
                    }, fd)

            # write info file
            write_to_ifile(OUTPUT_CSV, integration_period, input_generators)