示例#1
0
        def updateDB(self, conn, server_id):
            cursor = conn.cursor()

            for floor_awms_id in self.floors:
                name = self.floors[floor_awms_id]
                latitude = self.floors_latitude[floor_awms_id]
                longitude = self.floors_longitude[floor_awms_id]
                img_path = self.floors_img_path[floor_awms_id]
                img_width = self.floors_img_width[floor_awms_id]
                img_length = self.floors_img_length[floor_awms_id]
                building_awms_id = self.floors_building_id[floor_awms_id]
                building_id = ale_dbi.buildingIDToDBID(conn, building_awms_id)
                if building_id == 0:
                    campus_id = ale_dbi.updateCampus(conn, "UNKNOWN",
                                                     "UNKNOWN", server_id)
                    building_id = ale_dbi.updateBuilding(
                        conn, building_awms_id, "UNKNOWN", campus_id)

                level = self.floors_level[floor_awms_id]
                units = self.floors_units[floor_awms_id]
                grid_size = self.floors_grid_size[floor_awms_id]

                ale_dbi.updateFloor(conn, floor_awms_id, name, latitude,
                                    longitude, img_path, img_width, img_length,
                                    building_id, level, units, grid_size)
示例#2
0
        def updateDB(self,conn,server_id):
            cursor = conn.cursor()
            
            for floor_awms_id in self.floors:
                name = self.floors[floor_awms_id]
                latitude = self.floors_latitude[floor_awms_id]
                longitude = self.floors_longitude[floor_awms_id]
                img_path = self.floors_img_path[floor_awms_id]
                img_width = self.floors_img_width[floor_awms_id]
                img_length = self.floors_img_length[floor_awms_id]
                building_awms_id = self.floors_building_id[floor_awms_id]
                building_id = ale_dbi.buildingIDToDBID(conn,building_awms_id)
                if building_id == 0:
                    campus_id = ale_dbi.updateCampus(conn,"UNKNOWN","UNKNOWN",server_id)
                    building_id = ale_dbi.updateBuilding(conn,building_awms_id,"UNKNOWN",campus_id)
                
                level = self.floors_level[floor_awms_id]
                units = self.floors_units[floor_awms_id]
                grid_size = self.floors_grid_size[floor_awms_id]

                ale_dbi.updateFloor(conn,floor_awms_id,name,latitude,longitude,img_path,img_width,img_length,building_id,level,units,grid_size)
def processLocationMsg(cnt, msg):
    global conn

    location = msg.location    
    # unpack mac address
    macaddr = str(":".join("%02x" % ord(a) for a in location.sta_eth_mac.addr))
    try:
        measured_x = float(location.sta_location_x)
    except ValueError:
        measured_x = 0.0
    try:
        measured_y = float(location.sta_location_y)
    except ValueError:
        measured_y = 0.0
    isAssociated = location.associated

    utctimestamp = msg.timestamp - timezoneOffsetInSeconds
    timestamp = datetime.datetime.fromtimestamp(utctimestamp).strftime('%Y-%m-%d %H:%M:%S')

    algo_str = "Unknown"
    algo_str = ale_enums.algorithm[location.loc_algorithm]

    # for hex encoded strings, use <thing>.encode("hex")
    floor_id = location.floor_id.encode("hex").upper()
    building_id = location.building_id.encode("hex").upper()
    campus_id = location.campus_id.encode("hex").upper()
    

    if location.HasField("unit"):
        unit = location.unit    
    else:
        unit = None
    
    if storeInDB:
        floor_db_id = ale_dbi.floorIDToDBID(conn,floor_id)
        building_db_id = ale_dbi.buildingIDToDBID(conn,building_id)
        campus_db_id = ale_dbi.campusIDToDBID(conn,campus_id)
        if campus_db_id == 0: 
            campus_db_id = ale_dbi.updateCampus(conn,campus_id,"UNKNOWN",server_id)
        if building_db_id == 0:
            building_db_id = ale_dbi.updateBuilding(conn,building_id,"UNKNOWN",campus_db_id)
        if floor_db_id == 0:
            floor_db_id = ale_dbi.updateFloor(conn,floor_id,"UNKNOWN",None,None,None,None,None,building_db_id,None,None,None)
    else:
        floor_db_id = 0
        building_db_id = 0
        campus_db_id = 0

    if verbose >= 1:
        print "---- LOCATION [record %.5d : %s] ------------" % (cnt, macaddr)
        if verbose >= 2:
            print "Timestamp:    %s (UTC)" % timestamp
            print "Coordinates:  (%.1f, %.1f) " % (measured_x, measured_y)
            if unit != None:
                print "Unit:         %s " % (ale_enums.measurement_unit[unit])
            print "Algorithm:    %s" % (algo_str)
            print "Station Mac:  %s" % (macaddr)
            print "Associated:   %s" % (isAssociated)
            print "FloorID:      %s (%d)" % (floor_id, floor_db_id)
            print "BuildingID:   %s (%d)" % (building_id, building_db_id)
            print "CampusID:     %s (%d)" % (campus_id, campus_db_id)


    if storeInDB:
        endpoint_id = ale_dbi.updateEndpointByMac(conn,macaddr,'location',isAssociated)

        if storeLocationInDB:
            ale_dbi.addLocation(conn,endpoint_id,timestamp,
                ale_dbi.campusIDToDBID(conn,campus_id),
                ale_dbi.buildingIDToDBID(conn,building_id),
                ale_dbi.floorIDToDBID(conn,floor_id),
                measured_x,
                measured_y,
                location.loc_algorithm)
        
    return('SUCCESS','')
示例#4
0
 def updateDB(self, conn, server_id):
     for campus_id in self.campuses:
         ale_dbi.updateCampus(conn, campus_id, self.campuses[campus_id],
                              server_id)
示例#5
0
 def updateDB(self,conn,server_id):
     for campus_id in self.campuses:
         ale_dbi.updateCampus(conn,campus_id,self.campuses[campus_id],server_id)