示例#1
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
        })
示例#2
0
    def __init__(self):# {{{
        ''' 
        installer/navmesh_installer.sh installs all the dependencies.

        * navmesh build from the obj geometry file
        thanks to https://github.com/arl/go-detour !

        * navmesh query
        thanks to https://github.com/layzerar/recastlib/ !

        ============================================

        This is how we are supposed to be called:

        nav=Navmesh()
        nav.build(floor)
        nav.nav_query(src, dst)

            or if you want to block r1 and r2 and have the navmeshes named

        navs=dict()
        navs[('r1','r2')]=Navmesh()
        navs[('r1','r2')].build(floor,('r1','r2'))
        navs[('r1','r2')].nav_query(src, dst)

        '''

        self.json=Json()
        self.s=Sqlite("{}/aamks.sqlite".format(os.environ['AAMKS_PROJECT']))
        self._test_colors=[ "#f80", "#f00", "#8f0", "#08f" ]
        self.navmesh=OrderedDict()
        self.partition_query={}
        self.evacuee_radius=self.json.read('{}/inc.json'.format(os.environ['AAMKS_PATH']))['evacueeRadius']
示例#3
0
 def prepare_rooms_list(self):
     self.s = Sqlite("aamks.sqlite")
     rooms_f = self.s.query(
         'SELECT name from aamks_geom where type_pri="COMPA" and floor = "{}"'
         .format(self.floor))
     for item in rooms_f:
         self.room_list.update({item['name']: 0.0})
示例#4
0
    def __init__(self):  # {{{
        ''' 
        installer/navmesh_installer.sh installs all the dependencies.

        * navmesh build from the obj geometry file
        thanks to https://github.com/arl/go-detour !

        * navmesh query
        thanks to https://github.com/layzerar/recastlib/ !

        ============================================

        This is how we are supposed to be called:

        nav=Navmesh()
        nav.build(floor)
        nav.query([(1300,600), (3100,1800)])

            or if you want to block r1 and r2 and have the navmeshes named

        navs=dict()
        navs[('r1','r2')]=Navmesh()
        navs[('r1','r2')].build(floor,('r1','r2'))
        navs[('r1','r2')].query([(1300,600), (3100,1800)])

        '''

        self.json = Json()
        self.s = Sqlite("{}/aamks.sqlite".format(os.environ['AAMKS_PROJECT']))
        self.navmesh = OrderedDict()
示例#5
0
文件: geom.py 项目: kowalskiw/aamks
 def __init__(self):  # {{{
     self.json = Json()
     self.s = Sqlite("{}/aamks.sqlite".format(os.environ['AAMKS_PROJECT']))
     self.raw_geometry = self.json.read("{}/cad.json".format(
         os.environ['AAMKS_PROJECT']))
     self.conf = self.json.read("{}/conf.json".format(
         os.environ['AAMKS_PROJECT']))
     self._doors_width = 32
     self._wall_width = 4
     self._make_elem_counter()
     self._geometry2sqlite()
     self._enhancements()
     self._init_dd_geoms()
     self._make_fake_wells()
     self._floors_details()
     self._aamks_geom_into_polygons()
     self._make_id2compa_name()
     self._find_intersections_within_floor()
     self._get_faces()
     self._hvents_per_room()
     self._find_intersections_between_floors()
     self._vvents_per_room()
     self._add_names_to_vents_from_to()
     self._calculate_sills()
     self._auto_detectors_and_sprinklers()
     self._create_obstacles()
     self.make_vis('Create obstacles')
     self._navmesh()
     self._assert_faces_ok()
     self._assert_room_has_door()
示例#6
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 = {}
示例#7
0
文件: worker.py 项目: kowalskiw/aamks
    def create_geom_database(self):

        self.s = Sqlite("aamks.sqlite")
        #self.s.dumpall()
        self.obstacles = json.loads(
            self.s.query('SELECT * FROM obstacles')[0]['json'],
            object_pairs_hook=OrderedDict)
示例#8
0
    def _collect_final_vars(self):# {{{
        ''' 
        Create finals.sqlite for this very sim_id. Convert CFAST csvs into sqlite.
        '''

        finals=[]

        for letter in ['n', 's']:
            f = 'cfast_{}.csv'.format(letter)
            with open(f, 'r') as csvfile:
                reader = csv.reader(csvfile, delimiter=',')
                for x in range(4):
                    next(reader)
                for row in reader:
                    record=[float(j) for j in row]
                    record[0]=int(float(row[0]))
                    for i,param in enumerate(self._headers[letter]['params']):
                        if param != 'Time':
                            if self._headers[letter]['geoms'][i] != 'outside':
                                if self._headers[letter]['geoms'][i] != 'medium':
                                    compa=self._headers[letter]['geoms'][i][0]
                                    finals.append((record[0], param, record[i], self._headers[letter]['geoms'][i], compa))

        try:
            os.remove("finals.sqlite")
        except:
            pass
        self.sf=Sqlite("finals.sqlite")
        self.sf.query("CREATE TABLE finals('time','param','value','compa','compa_type')")
        self.sf.executemany('INSERT INTO finals VALUES ({})'.format(','.join('?' * len(finals[0]))), finals)
示例#9
0
 def __init__(self):  # {{{
     self.json = Json()
     self.conf = self.json.read("{}/conf.json".format(
         os.environ['AAMKS_PROJECT']))
     if self.conf['fire_model'] == 'FDS':
         return
     self.s = Sqlite("{}/aamks.sqlite".format(os.environ['AAMKS_PROJECT']))
     self.raw_geometry = self.json.read("{}/cad.json".format(
         os.environ['AAMKS_PROJECT']))
     self.geomsMap = self.json.read("{}/inc.json".format(
         os.environ['AAMKS_PATH']))['aamksGeomsMap']
     self.doors_width = 32
     self.walls_width = 4
     self._geometry2sqlite()
     self._enhancements()
     self._init_dd_geoms()
     self._towers_slices()
     self._floors_meta()
     self._world_meta()
     self._aamks_geom_into_polygons()
     self._make_id2compa_name()
     self._find_intersections_within_floor()
     self._get_faces()
     self._hvents_per_room()
     self._find_intersections_between_floors()
     self._vvents_per_room()
     self._add_names_to_vents_from_to()
     self._recalculate_vents_from_to()
     self._calculate_sills()
     self._terminal_doors()
     self._auto_detectors_and_sprinklers()
     self._assert_faces_ok()
     self._assert_room_has_door()
     self._debug()
示例#10
0
    def __init__(self):  # {{{
        ''' Generate montecarlo cfast.in. Log what was drawn to psql. '''

        self.json = Json()
        self.hrrpua = 0
        self.alpha = 0
        self.fire_origin = None
        self.conf = self.json.read("{}/conf.json".format(
            os.environ['AAMKS_PROJECT']))
        if self.conf['fire_model'] == 'FDS':
            return
        self.s = Sqlite("{}/aamks.sqlite".format(os.environ['AAMKS_PROJECT']))
        self.p = Psql()
        self._psql_collector = OrderedDict()
        self.s.query(
            "CREATE TABLE fire_origin(name,is_room,x,y,z,floor,sim_id)")

        si = SimIterations(self.conf['project_id'], self.conf['scenario_id'],
                           self.conf['number_of_simulations'])

        for self._sim_id in range(*si.get()):
            seed(self._sim_id)
            self._new_psql_log()
            self._make_cfast()
            self._write()
示例#11
0
    def create_geom_database(self):

        self.s = Sqlite("aamks.sqlite")
        #self.report_log_issue(message=self.s.dumpall(), mode='DEBUG')
        doors = self.s.query('SELECT floor, name, center_x, center_y from aamks_geom where type_pri="HVENT" AND vent_to_name="outside"')
        self.vars['conf']['doors']=doors
        self.obstacles = json.loads(self.s.query('SELECT * FROM obstacles')[0]['json'], object_pairs_hook=OrderedDict)
        self.wlogger.info('SQLite load successfully')
示例#12
0
        def _fire_origin_coords(self, sim_id):  # {{{
            room = self.meta['fire_origin']

            self.s = Sqlite("{}/aamks.sqlite".format(
                self.meta['path_to_project']))
            z = self.s.query(
                "SELECT center_x, center_y FROM aamks_geom WHERE name=?",
                (room, ))[0]
            return (z['center_x'], z['center_y'])
示例#13
0
 def __init__(self):# {{{
     self.json=Json()
     self.conf=self.json.read("{}/conf.json".format(os.environ['AAMKS_PROJECT']))
     self.fire_model=self.conf['fire_model'];
     self.s=Sqlite("{}/aamks.sqlite".format(os.environ['AAMKS_PROJECT']))
     self.world_meta=self.json.readdb("world_meta")
     self.floors_meta=self.json.readdb("floors_meta")
     self.floors=self.floors_meta.keys()
     self.walls_width=self.world_meta['walls_width']
     self._create_obstacles('aamks_geom', 'obstacles')
示例#14
0
 def __init__(self):  # {{{
     if len(sys.argv) < 2:
         self.zbior = 'office123/sesja1'
     else:
         self.zbior = sys.argv[1]
     self.json = Json()
     self.debug = 1
     self.make_segments_map()
     self.make_db_czynnosci()
     self.s = Sqlite("sqlite/firetrucks.db")
     self.main()
示例#15
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()
示例#16
0
 def __init__(self):  # {{{
     self.json = Json()
     self.conf = self.json.read("{}/conf.json".format(
         os.environ['AAMKS_PROJECT']))
     self.world_meta = self.json.readdb("world_meta")
     self.s = Sqlite("{}/aamks.sqlite".format(os.environ['AAMKS_PROJECT']))
     self.floors_meta = self.json.readdb("floors_meta")
     self.floors = self.floors_meta.keys()
     self.walls_width = self.world_meta['walls_width']
     self.projections = {'top': dict(), 'side': dict()}
     self._top_projection_make()
     self._top_proj_lines()
     self._meta_translate_y()
     self._world2d_boundaries()
示例#17
0
    def __init__(self, floor):# {{{
        '''
        * On class init we read cell2compa map and and query_vertices from sqlite.
        * We are getting read_cfast_record(T) calls in say 10s intervals:
          We only store this single T'th record in a dict.
        * We are getting lots of get_conditions((x,y),param) calls after
          read_cfast_record(T) returns the needed CFAST record.

        Sqlite sends: 
            a) cell2compa:
                (1000, 600): R_1

            b) query_vertices:
                (1000, 600): [1000, 1100, 1200], [ 10, 10, 12 ]

        After CFAST produces the conditions at time T, feed _compa_conditions.
        For any evacuee's (x,y) it will be easy to find the square he is in. If
        we have rectangles in our square we use some optimizations to find the
        correct rectangle. Finally fetch the conditions via cell-compa map.
        ''' 

        self.json = Json()
        try:
            self.s=Sqlite("aamks.sqlite", 1) # We are the worker with aamks.sqlite copy in our working dir
        except:
            self.s=Sqlite("{}/aamks.sqlite".format(os.environ['AAMKS_PROJECT']), 1) # We are the server

        self.floor=str(floor)
        self.floors_meta=json.loads(self.s.query("SELECT * FROM floors_meta")[0]['json'])
        self.uprefs=GetUserPrefs()
        self.config=self.json.read('{}/evac/config.json'.format(os.environ['AAMKS_PATH']))
        self._sqlite_query_vertices()
        self._sqlite_cell2compa()
        self._init_compa_conditions()

        if self.uprefs.get_var('use_fire_model')==1: 
            self._cfast_headers() 
示例#18
0
    def __init__(self, floor):
        '''
        * On class init we read cell2compa map and and query_vertices from sqlite.
        * We are getting read_cfast_record(T) calls in say 10s intervals:
          We only store this single T'th record in a dict.
        * We are getting lots of get_conditions((x,y),param) calls after
          read_cfast_record(T) returns the needed CFAST record.

        Sqlite sends: 
            a) cell2compa:
                (1000, 600): R_1

            b) query_vertices:
                (1000, 600): [1000, 1100, 1200], [ 10, 10, 12 ]

        After CFAST produces the conditions at time T, feed _compa_conditions.
        For any evacuee's (x,y) it will be easy to find the square he is in. If
        we have rectangles in our square we use some optimizations to find the
        correct rectangle. Finally fetch the conditions via cell-compa map.
        '''

        self.json = Json()
        try:
            self.s = Sqlite("aamks.sqlite", 1)
        except:
            print("mimooh CFAST fallback, not for production!")
            self.s = Sqlite(
                "{}/aamks.sqlite".format(os.environ['AAMKS_PROJECT']), 1)

        self.config = self.json.read('{}/evac/config.json'.format(
            os.environ['AAMKS_PATH']))
        self._sqlite_query_vertices(floor)
        self._sqlite_cell2compa(floor)
        self._init_compa_conditions()
        #print("smoke_query, enable me")
        self._cfast_headers()  # TODO needs to enable!
示例#19
0
    def __init__(self):  # {{{
        ''' Stuff that happens at the beggining of the project '''

        if len(sys.argv) > 1: os.environ["AAMKS_PROJECT"] = sys.argv[1]
        if len(sys.argv) > 2: os.environ["AAMKS_USER_ID"] = sys.argv[2]
        self.json = Json()
        self.conf = self.json.read("{}/conf.json".format(
            os.environ['AAMKS_PROJECT']))
        self.project_id = self.conf['project_id']
        self.scenario_id = self.conf['scenario_id']
        self.p = Psql()
        self._clear_srv_anims()
        self._clear_sqlite()
        self.s = Sqlite("{}/aamks.sqlite".format(os.environ['AAMKS_PROJECT']))
        self._setup_simulations()
        self._create_sqlite_tables()
示例#20
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()
示例#21
0
    def __init__(self):  # {{{
        ''' Generate montecarlo cfast.in. Log what was drawn to psql. '''

        self.s = Sqlite("{}/aamks.sqlite".format(os.environ['AAMKS_PROJECT']))
        self.p = Psql()
        self.json = Json()
        self.conf = self.json.read("{}/conf.json".format(
            os.environ['AAMKS_PROJECT']))
        self._psql_collector = OrderedDict()

        si = SimIterations(self.conf['project_id'],
                           self.conf['number_of_simulations'])
        for self._sim_id in range(*si.get()):
            seed(self._sim_id)
            self._new_psql_log()
            self._make_cfast()
            self._write()
示例#22
0
 def __init__(self):  # {{{
     self.json = Json()
     self.conf = self.json.read("{}/conf.json".format(
         os.environ['AAMKS_PROJECT']))
     if self.conf['fire_model'] == 'CFAST':
         return
     self.s = Sqlite("{}/aamks.sqlite".format(os.environ['AAMKS_PROJECT']))
     self.cadfds = self.json.read("{}/cadfds.json".format(
         os.environ['AAMKS_PROJECT']))
     self.doors_width = 32
     self.walls_width = 4
     self._geometry2sqlite()
     self.geomsMap = self.json.read("{}/inc.json".format(
         os.environ['AAMKS_PATH']))['aamksGeomsMap']
     self._floors_meta()
     self._world_meta()
     self._fire_origin()
     self._debug()
示例#23
0
    def __init__(self):# {{{
        ''' Generate montecarlo evac.conf. '''
        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.evacuee_radius=self.json.read('{}/inc.json'.format(os.environ['AAMKS_PATH']))['evacueeRadius']
        self.floors=[z['floor'] for z in self.s.query("SELECT DISTINCT floor FROM aamks_geom ORDER BY floor")]
        self._project_name=os.path.basename(os.environ['AAMKS_PROJECT'])

        si=SimIterations(self.conf['project_id'], self.conf['scenario_id'], self.conf['number_of_simulations'])
        sim_ids=range(*si.get())
        for self._sim_id in sim_ids:
            seed(self._sim_id)
            self._fire_obstacle()
            self._static_evac_conf()
            self._dispatch_evacuees()
            self._make_evac_conf()
        self._evacuees_static_animator()
示例#24
0
文件: init.py 项目: 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()
示例#25
0
 def calculate_building_area(self):
     s = Sqlite("{}/aamks.sqlite".format(self.dir))
     result = s.p.query("SELECT sum(room_area) as total FROM aamks_geom")
     return result[0]['total']
示例#26
0
 def _access_hosts(self):  # {{{
     self.s = Sqlite("/tmp/manage_aamks.sqlite")
     self._sqlite_import_hosts()