Esempio n. 1
0
    def make_vis(self, title, faulty_id='', type_pri='HVENT'):  # {{{
        ''' 
        This method is for visualizing both errors and just how things look. 
        If faulty_id comes non-empty then we are signaling an error.
        '''

        if faulty_id != '':
            r = self.s.query(
                "SELECT name,floor FROM aamks_geom WHERE type_pri=? AND global_type_id=?",
                (type_pri, faulty_id))[0]
            fatal = "Fatal: {}: {}".format(r['name'], title)
            Vis({
                'highlight_geom': r['name'],
                'anim': None,
                'title': "<div id=python_msg>{}</div>".format(fatal),
                'srv': 1
            })
            print(fatal)
            sys.exit()
        else:
            Vis({
                'highlight_geom': None,
                'anim': None,
                'title': title,
                'srv': 1
            })
Esempio n. 2
0
    def __init__(self):  # {{{
        self.json = Json()
        self.s = Sqlite("{}/aamks.sqlite".format(os.environ['AAMKS_PROJECT']))

        self.evacuee_radius = self.json.read("{}/inc.json".format(
            os.environ['AAMKS_PATH']))['evacueeRadius']
        time = 1
        self.sim = rvo2.PyRVOSimulator(time, 40, 5, time, time,
                                       self.evacuee_radius, 30)
        self.make_nav("0")
        self._anim = {
            "simulation_id": 1,
            "simulation_time": 20,
            "time_shift": 0,
            "animations": {
                "evacuees": [],
                "rooms_opacity": []
            }
        }
        self._create_agents()
        self._load_obstacles()
        self._run()
        self._write_zip()
        Vis({
            'highlight_geom': None,
            'anim': '1/f1.zip',
            'title': 'x',
            'srv': 1
        })
Esempio n. 3
0
    def _navmesh(self):  # {{{
        ''' 
        1. Create obj file from aamks geometries.
        2. Build navmesh with golang, obj is input
        3. Query navmesh with python
        '''

        self.nav = OrderedDict()
        z = self.s.query("SELECT json FROM obstacles")
        for floor, faces in json.loads(z[0]['json'])['points'].items():
            self._obj_num = 0
            obj = ''
            for face in faces:
                obj += self._obj_elem(face, 99)
            for face in self._obj_platform(floor):
                obj += self._obj_elem(face, 0)

            with open("{}/{}.obj".format(os.environ['AAMKS_PROJECT'], floor),
                      "w") as f:
                f.write(obj)
            self.nav[floor] = Navmesh()
            self.nav[floor].build(obj, os.environ['AAMKS_PROJECT'], floor)
            self._navmesh_test(floor)

        Vis({
            'highlight_geom': None,
            'anim': None,
            'title': 'Navmesh test',
            'srv': 1
        })
Esempio n. 4
0
    def __init__(self):  # {{{
        self.Que = Staircase(floors=9)
        self.json = Json()
        self.s = Sqlite("{}/aamks.sqlite".format(os.environ['AAMKS_PROJECT']))

        self.evacuee_radius = self.json.read("{}/inc.json".format(
            os.environ['AAMKS_PATH']))['evacueeRadius']
        time = 1
        #self.sim rvo2.PyRVOSimulator TIME_STEP , NEIGHBOR_DISTANCE , MAX_NEIGHBOR , TIME_HORIZON , TIME_HORIZON_OBSTACLE , RADIUS , MAX_SPEED
        self.sim = rvo2.PyRVOSimulator(time, 40, 5, time, time,
                                       self.evacuee_radius, 30)
        self._anim = {
            "simulation_id": 1,
            "simulation_time": 20,
            "time_shift": 0,
            "animations": {
                "evacuees": [],
                "rooms_opacity": []
            }
        }
        self._create_agents()
        self._load_obstacles()
        Vis({
            'highlight_geom': None,
            'anim': '1/f1.zip',
            'title': 'x',
            'srv': 1
        })
        self.waitings = {}
Esempio n. 5
0
 def test(self):# {{{
     self.conf=self.json.read("{}/conf.json".format(os.environ['AAMKS_PROJECT']))
     agents_pairs=4
     ee=self.s.query("SELECT name,x0,y0 FROM aamks_geom WHERE type_pri='EVACUEE' AND floor=? ORDER BY global_type_id LIMIT ?", (self.floor, agents_pairs*2))
     if len(ee) == 0: return
     evacuees=list(self._chunks(ee,2))
     self._test_evacuees_pairs(evacuees)
     if self.conf['fire_model'] != 'FDS':
         self._test_room_leaves((ee[0]['x0'], ee[0]['y0']))
     Vis({'highlight_geom': None, 'anim': None, 'title': 'Nav {} test'.format(self.nav_name), 'srv': 1})
Esempio n. 6
0
    def __init__(self): # {{{
        ''' 
        Divide space into cells for smoke conditions queries asked by evacuees.
        A cell may be a square or a rectangle. First divide space into squares
        of self._square_side. Iterate over squares and if any square is crossed by an
        obstacle divide this square further into rectangles. 
        
        In the final structure of partition.json we encode each cell.
        Each cell is sorted by x, which allows quick bisections.

        * In each cell we always encode the first sub-cell - the square itself.
        (2000, 2449): OrderedDict([('x', (2000,)), ('y', (2449,))])

        * Then we can add more sub-cells (rectangles).
        (1600, 2449): OrderedDict([('x', (1600, 1600, 1842, 1842)), ('y', (2449, 2541, 2449, 2541))])

        Partition will be later used for filling the cells with smoke
        conditions. Finally we get a tool for quick altering of the state of an
        evacuee at x,y.

        '''

        self._square_side=300
        self.s=Sqlite("{}/aamks.sqlite".format(os.environ['AAMKS_PROJECT']))
        self.uprefs=GetUserPrefs()
        verbose=0
        if self.uprefs.get_var('partitioning_debug')==1: verbose=1

        try:
            self.s.query("DROP TABLE cell2compa")
            self.s.query("DROP TABLE query_vertices")
        except:
            pass
        self.s.query("CREATE TABLE cell2compa(json)")
        self.s.query("CREATE TABLE query_vertices(json)")

        self.json=Json() 
        self._cell2compa=OrderedDict()
        self._save=OrderedDict()
        floors=self.json.readdb("floors_meta")
        for floor in floors.keys():
            self._init_space(floor) 
            self._intersect_space() 
            self._optimize(floor)
            self._make_cell2compa(floor)
            if(verbose==1):
                self._plot_space(floor)  # debug
        if(verbose==1):
            Vis({'highlight_geom': None, 'anim': None, 'title': 'partitioning', 'srv': 1, 'skip_fire_origin': 1, 'skip_evacuees': 1}) # debug

        self._dbsave()
Esempio n. 7
0
    def __init__(self, verbose=0): # {{{
        ''' 
        Divide space into cells for smoke conditions queries asked by evacuees.
        A cell may be a square or a rectangle. First divide space into squares
        of self._square_side. Iterate over squares and if any square is crossed by an
        obstacle divide this square further into rectangles. 
        
        In the final structure of partition.json we encode each cell.
        Each cell is sorted by x, which allows quick bisections.

        * In each cell we always encode the first sub-cell - the square itself.
        (2000, 2449): OrderedDict([('x', (2000,)), ('y', (2449,))])

        * Then we can add more sub-cells (rectangles).
        (1600, 2449): OrderedDict([('x', (1600, 1600, 1842, 1842)), ('y', (2449, 2541, 2449, 2541))])

        Partition will be later used for filling the cells with smoke
        conditions. Finally we get a tool for quick altering of the state of an
        evacuee at x,y.

        '''

        self._square_side=300
        self.s=Sqlite("{}/aamks.sqlite".format(os.environ['AAMKS_PROJECT']))
        try:
            self.s.query("DROP TABLE cell2compa")
            self.s.query("DROP TABLE query_vertices")
        except:
            pass
        self.s.query("CREATE TABLE cell2compa(json)")
        self.s.query("CREATE TABLE query_vertices(json)")

        self.json=Json() 
        self._cell2compa=OrderedDict()
        self._save=OrderedDict()
        floors=json.loads(self.s.query("SELECT * FROM floors")[0]['json'])
        for floor in floors.keys():
            self._init_space(floor) 
            self._intersect_space() 
            self._optimize(floor)
            self._make_cell2compa(floor)
            if(verbose==1):
                self._plot_space(floor)  # debug
        if(verbose==1):
            Vis(None, 'image', 'partition') # debug
        self._dbsave()
Esempio n. 8
0
File: init.py Progetto: mzimny/aamks
 def __init__(self):  # {{{
     ''' Stuff that happens at the end of the project '''
     self.json = Json()
     self.conf = self.json.read("{}/conf.json".format(
         os.environ['AAMKS_PROJECT']))
     self.s = Sqlite("{}/aamks.sqlite".format(os.environ['AAMKS_PROJECT']))
     self.project_id = self.conf['project_id']
     self.scenario_id = self.conf['scenario_id']
     self.p = Psql()
     if self.conf['navmesh_debug'] == 1:
         self._navmeshes_for_floors()
     Vis({
         'highlight_geom': None,
         'anim': None,
         'title': "OnEnd()",
         'srv': 1
     })
     self._gearman_register_works()
Esempio n. 9
0
    def test(self):  # {{{
        agents_pairs = 6
        colors = [
            "#f80", "#f00", "#8f0", "#08f", "#f0f", "#f8f", "#0ff", "#ff0"
        ]
        navmesh_paths = []

        z = self.json.read('{}/dd_geoms.json'.format(
            os.environ['AAMKS_PROJECT']))
        evacuees = self.s.query(
            "SELECT x0,y0 FROM aamks_geom WHERE type_pri='EVACUEE' AND floor=? ORDER BY global_type_id LIMIT ?",
            (self.floor, agents_pairs * 2))
        for x, i in enumerate(self._chunks(evacuees, 2)):
            p0 = (i[0]['x0'], i[0]['y0'])
            p1 = (i[1]['x0'], i[1]['y0'])
            z[self.floor]['circles'].append({
                "xy": p0,
                "radius": 30,
                "fillColor": colors[x],
                "opacity": 1
            })
            z[self.floor]['circles'].append({
                "xy": p1,
                "radius": 30,
                "fillColor": colors[x],
                "opacity": 1
            })
            navmesh_paths.append(self.query((p0, p1), 300))
        self.json.write(z,
                        '{}/dd_geoms.json'.format(os.environ['AAMKS_PROJECT']))
        self._navmesh_vis(navmesh_paths, colors)
        Vis({
            'highlight_geom': None,
            'anim': None,
            'title': 'Nav {} test'.format(self.nav_name),
            'srv': 1
        })