Exemplo n.º 1
0
class PATH(object):
    from definitions import get_project_root
    PROJECT_DIR = get_project_root()

    print('PROJECT DICTIONARY: {}'.format(PROJECT_DIR))
    MODEL = '{}/data/models'.format(PROJECT_DIR)

    ADVERSARIAL_FILE = '{}/data/adversarial_examples'.format(PROJECT_DIR)

    FIGURES = '{}/data/figures'.format(PROJECT_DIR)
    RESULTS = '{}/data/results'.format(PROJECT_DIR)
    ANALYSE = '{}/data/analyse'.format(PROJECT_DIR)

    @classmethod
    def set_path_of_models(cls, model_base):
        cls.MODEL = '{}/{}'.format(cls.PROJECT_DIR, model_base)

    @classmethod
    def set_path_of_ae(cls, ae_base):
        cls.ADVERSARIAL_FILE = '{}/{}'.format(cls.PROJECT_DIR, ae_base)

    @classmethod
    def set_path_of_figs(cls, figure_base):
        cls.FIGURES = '{}/{}'.format(cls.PROJECT_DIR, figure_base)

    @classmethod
    def set_path_of_results(cls, result_base):
        cls.RESULTS = '{}/{}'.format(cls.PROJECT_DIR, result_base)

    @classmethod
    def set_path_of_analyse(cls, analyse_base):
        cls.ANALYSE = '{}/{}'.format(cls.PROJECT_DIR, analyse_base)
Exemplo n.º 2
0
class SafeTextFileWriter:
    file_lock = threading.Lock()
    templates_dir = os.path.join(definitions.get_project_root(),
                                 report_templates_path)

    def __init__(self, base_file_name: str, first_line: str):
        self.base_file_name = base_file_name
        self.first_line = first_line

    def write_line(self, line: str):
        with self.file_lock:
            with open(self.base_file_name, 'a') as fh:
                if fh.tell() == 0:
                    fh.write(f'{self.first_line}\n')
                fh.write(f'{line}\n')

    def full_path_plus_file_name(self, ext: str) -> str:
        return (
            f'{definitions.get_project_root()}/{report_save_path}/{report_file_name}'
            f'{self.base_file_name}.{ext}')

    def save_html_report_file(self, result: str, env_str: str) -> str:
        # https://code-maven.com/minimal-example-generating-html-with-python-jinja
        env = Environment(loader=FileSystemLoader(self.templates_dir))

        # template = env.get_template(report_templates_path+report_templates_name+'.'+report_file_extension)
        template = env.get_template('mlpa_report_template.html')

        full_file_name_html = self.full_path_plus_file_name('html')
        display_file_name = self.base_file_name.replace('_', ' ')
        with open(full_file_name_html, 'w') as fh:
            fh.write(
                template.render(report_name=f'{display_file_name}',
                                env_str=env_str,
                                data=result))
        return full_file_name_html
Exemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--box_function',
                        '-box',
                        type=str,
                        help='choices: without_box, with_box',
                        default='without_box',
                        required=False)
    parser.add_argument('--visualization',
                        '-vis',
                        type=str,
                        help='y, n',
                        default='y',
                        required=False)
    parser.add_argument('--time_horizon',
                        '-T',
                        type=float,
                        help='value like: T=2.2',
                        default=2.2,
                        required=False)
    parser.add_argument('--steps',
                        '-N',
                        type=int,
                        help='value like N=4',
                        default=6,
                        required=False)
    parser.add_argument('--debug',
                        '-deb',
                        type=str,
                        help='(y,n)',
                        default='n',
                        required=False)
    parser.add_argument('--window_x',
                        '-wix',
                        type=int,
                        help='windowsize in x-direction for savgol_filter',
                        default=101,
                        required=False)
    parser.add_argument('--window_y',
                        '-wiy',
                        type=int,
                        help='windowsize in y-direction for savgol_filter',
                        default=101,
                        required=False)
    parser.add_argument('--poly_x',
                        '-pox',
                        type=int,
                        help='polygon order in x-direction for savgol_filter',
                        default=2,
                        required=False)
    parser.add_argument('--poly_y',
                        '-poy',
                        type=int,
                        help='polygon order in y-direction for savgol_filter',
                        default=2,
                        required=False)
    parser.add_argument(
        '--program',
        '-pro',
        type=str,
        help=
        'a) only_reachability, b) only_mdp, c) two_agents_no_interaction d) two_agents_no_interaction_velocity',
        default='mdp_reachab',
        required=False)
    parser.add_argument('--face_color',
                        '-facol',
                        type=str,
                        help='name: orange, green or values',
                        default='cyan',
                        required=False)
    parser.add_argument('--gamma',
                        '-gam',
                        type=float,
                        help='gamma=0.9',
                        default='0.9',
                        required=False)
    parser.add_argument('--x_grid',
                        '-xgr',
                        type=int,
                        help='x_grid=5',
                        default='8',
                        required=False)
    parser.add_argument('--y_grid',
                        '-ygr',
                        type=int,
                        help='y_grid=5',
                        default='5',
                        required=False)
    parser.add_argument('--spline_interpolation',
                        '-spl',
                        type=int,
                        help='n_optimal=5',
                        default=23,
                        required=False)

    args = parser.parse_args()
    params = vars(args)
    params['PROJECT_ROOT'] = definitions.get_project_root()
    if (params['debug'] == 'y'):
        logging.basicConfig(format='%(levelname)s:%(message)s',
                            level=logging.DEBUG)
    #######################
    ### PROGRAM OPTIONS ###
    #######################
    if (params['program'] == 'only_reachability'):
        only_one_reachability(params)
    elif (params['program'] == 'only_mdp'):
        only_mdp(params)
    elif (params['program'] == 'two_agents_no_interaction'):
        two_agents_without_interaction_common_playground(params)
    elif (params['program'] == 'two_agents_no_interaction_velocity'):
        two_agents_without_interaction_common_playground_different_velocities(
            params)
    elif (params['program'] == 'mdp_reachab'):
        mdp_reachab()
Exemplo n.º 4
0
import definitions
import pandas as pdb
from typing import NamedTuple, Dict

_ROOT_DIR = definitions.get_project_root()


class ZipCodeEntry(NamedTuple):
    zip: str
    city: str
    state: str
    lat: str
    long: str
    time_zone: str
    dst_flags: bool


def _load_zip_codes() -> Dict[str, ZipCodeEntry]:
    df = pdb.read_csv(
        f'{_ROOT_DIR}/utils/us-zip-code-latitude-and-longitude.txt',
        dtype=str,
        sep=';')
    zip_code_list = {}
    # Zip;City;State;Latitude;Longitude;Timezone;Daylight savings time flag;geopoint
    for _, row in df.iterrows():
        zip_code = row.get('Zip')
        if zip_code:
            zip_code_entry = ZipCodeEntry(
                zip=zip_code,
                city=row.get('City'),
                state=row.get('State'),