Ejemplo n.º 1
0
    def _do_create_obj(self, req):
        """Adds an object and its description into the database from the
            data passed from the web user interface.

        Status is enabled by default on an object's creation.
        """
        if req.args.get('newobjname') != '':
            obj = Object(self.env)
            obj['name'] = req.args.get('newobjname')
            obj['description'] = req.args.get('newobjdesc')
            obj.insert()
Ejemplo n.º 2
0
    def _do_create(self, req, db=None):
        if not req.args.get('component'):
            raise TracError('Requirements must contain a component.')
        
        if not req.args.get('fp'):
            raise TracError('Requirements must contain a functional primitive.')
        
        if not req.args.get('object'):
            raise TracError('Requirements must contain an object.')

        requirement = Requirement(self.env, db=db)
        requirement.populate(req.args)
        try:
            # if a known hyponym was used, get corresponding fp.
            temp_hyp = Hyponym(self.env, name=req.args.get('fp'), db=db)
            temp_fp = Fp(self.env, id=temp_hyp['fp'], db=db)
        except TracError:
            try:
                #or, if a known fp was used, get instance of Fp
                temp_fp = Fp(self.env, name=req.args.get('fp'), db=db)
            except TracError:
                #run check funtion for enabled adding fp
                #if unknown fp used, insert it into the database
                if(Fp(self.env).check_on_fly_fp() == "enabled"):
                    temp_fp = Fp(self.env, db=db)
                    temp_fp['name'] = req.args.get('fp')
                    temp_fp.insert(db=db)
                else:
                    raise TracError("On the fly creation of Fps disabled")
        requirement.values['fp'] = temp_fp['id']
        try:
            temp_object = Object(self.env, name=req.args.get('object'), db=db)
        except TracError:
        #run check for function enabling obj
            if(Object(self.env).check_on_fly_obj() == "enabled"): 
                temp_object = Object(self.env, db=db)
                temp_object['name'] = req.args.get('object')
                temp_object.insert(db=db)
            else:
                raise TracError("On the fly creation of objects disabled")
        requirement.values['object'] = temp_object['id']
        requirement.values['creator'] = get_reporter_id(req, 'creator')
        requirement.insert(db=db)

        # Notify
        try:
            rn = RequirementNotifyEmail(self.env)
            rn.notify(requirement, newrequirement=True)
        except Exception, e:
            self.log.exception("Failure sending notification on creation of "
                               "requirement <%s %s>: %s" % 
                               (temp_fp['name'], temp_object['name'], e))
Ejemplo n.º 3
0
    def __init__(self, name, folder, longitudes, latitudes, initialCoordinate,
                 velocity, game):
        '''
        longitudes = columns
        latitudes = lines
        initialCoordinate = [longitude,latitude]'''
        self.name = name
        self.folder = folder
        self.longitudes = longitudes
        self.latitudes = latitudes
        self.coordinateSize = [
            game.size[0] // game.longitudesImageOnScreen,
            game.size[1] // game.latitudesImageOnScreen
        ]
        self.scale = game.scaleRange / game.latitudesImageOnScreen
        self.coordinatesIndex = self.longitudes * self.latitudes
        ###- the variable below needs some work
        initialPosition = [initialCoordinate[0], initialCoordinate[1]]
        self.imagePath = game.imagePath + self.name + '.png'
        self.size = [
            self.coordinateSize[0] * self.longitudes,
            self.coordinateSize[1] * self.latitudes
        ]
        self.cenarioImage = imageFunction.getImage(self.imagePath, self.size,
                                                   game)
        self.rect = pg.Rect(0, 0, self.size[0], self.size[1])
        self.cenarioImageSurface = imageFunction.newImageSurface(
            self.cenarioImage, self.size)
        self.coordinatesName = []
        for coordinateIndex in range(self.coordinatesIndex):
            coordinatePosition = [
                initialPosition[0] + int(
                    np.ceil((coordinateIndex % self.longitudes) *
                            self.coordinateSize[0])), initialPosition[1] + int(
                                np.ceil((coordinateIndex % self.latitudes) *
                                        self.coordinateSize[1]))
            ]
            cenarioSubImage = self.cenarioImageSurface.subsurface(
                (coordinatePosition[0], coordinatePosition[1],
                 self.coordinateSize[0], self.coordinateSize[1]))
            cenarioSubImageName = self.name + str(coordinateIndex)
            cenarioSubImagePath = game.imagePath + self.folder + Object.ObjectTypes.getType(
                Object.ObjectTypes.CENARIO
            ) + '/' + cenarioSubImageName + '.png'
            imageFunction.saveImage(cenarioSubImage, cenarioSubImagePath)

            ###- the line bellow actually creates these objects
            self.coordinatesName.append(
                Object.Object(cenarioSubImageName,
                              self.folder,
                              coordinatePosition,
                              self.coordinateSize,
                              self.scale,
                              velocity,
                              game,
                              type=Object.ObjectTypes.CENARIO).name)
Ejemplo n.º 4
0
 def __init__(self, name, folder, velocity, game):
     cenarioPosition = [0, 0]
     Object.Object(name,
                   folder,
                   cenarioPosition,
                   game.size,
                   game.scaleRange,
                   velocity,
                   game,
                   type=Object.ObjectTypes.CENARIO)
Ejemplo n.º 5
0
 def get(self):
     query = Object.gql("where orbiting = :1 order by noradid asc", True)
     count = 0
     while True:
         result = query.fetch(1000)
         count += len(result)
         if len(result) < 1000:
             break
         cursor = query.cursor()
         query.with_cursor(cursor)
     memcache.set(key='count', value=str(count), time=24*3600)
Ejemplo n.º 6
0
    def _do_modify_obj(self, req):
        """Modifies an object, its description, and or its status and updates it         database from the data passed from the web user interface.

        """

        obj_dict_str = base64.b64decode(req.args['obj_state_dict'])
        obj_dict = pickle.loads(obj_dict_str)
        checked_obj_names = [name[7:] for name in req.args.keys() if name[:7] ==
"status_"]
        changed_obj_names = [name[11:] for name in req.args.keys() if name[:11]
=="change_obj_"]
        changed_desc = [name[12:] for name in req.args.keys() if name[:12] == "change_desc_"]
    
        for obj in obj_dict:
            tmp = Object(self.env, name = obj['name'])
            changed = False
            if obj['name'] in checked_obj_names:
                #It was was checked
                if obj['status'] != "enabled":
                    tmp['status'] = "enabled"
                    changed = True
            else:
                #It wasn't checked 
                if obj['status'] == "enabled":
                    tmp['status'] = "disabled"
                    changed = True

            if obj['name'] in changed_desc:
                tmp_desc = req.args['change_desc_' + obj['name']] 
                if tmp_desc != obj['description']:
                    tmp['description'] = \
                    req.args['change_desc_' + obj['name']]
                    changed = True
 
            if obj['name'] in changed_obj_names:
                if req.args['change_obj_' + obj['name']] != "":
                    tmp['name'] = req.args['change_obj_' + obj['name']]
                    changed = True
            if changed:
                tmp.save_changes(req.authname, "Object modified.")
Ejemplo n.º 7
0
def processSection(file, startwith, dt):
    logging.info("Processing section %s. Starting with %s. %d seconds left." % (file, startwith, (dt + timedelta(seconds = 10) - datetime.now()).seconds))
    orbiting = []
    startfound = (startwith == "")
    
    src = memcache.get("src_%s" % file).replace("\r", "").split("\n")
    logging.info("Web resource fetched. %d seconds left." % (dt + timedelta(seconds = 10) - datetime.now()).seconds)
    for i in range(0, len(src), tleutil.linecount):
        if len(src[i: i + tleutil.linecount]) < 3:
            break
        noradid, name, body, timestamp = tleutil.parseTLE(src[i: i + tleutil.linecount])
        if startfound and startwith == "":
            startwith = noradid
        if startwith == noradid:
            startfound = True
        if not startfound:
            continue
        
        #if memcache.get(key="name_%d" % noradid) is None:
        #    if Object.gql("where noradid = :1", noradid).count() == 0:
        obj = Object(noradid=noradid, name=name, section=file, orbiting=True)
        obj.put()
        logging.debug("New object %d (%s) discovered. %d seconds left." % (noradid, name, (dt + timedelta(seconds = 10) - datetime.now()).seconds))
        memcache.set(key="name_%d" % noradid, value=name, time=24*3600)
        
        #if TLE.gql("where noradid = :1 and timestamp = :2", noradid, timestamp).count() == 0:
        tle = TLE(noradid=noradid, section=file, body=body, timestamp=timestamp)
        tle.put()
        logging.debug("Writing new TLE for object %d. %d seconds left." % (noradid, (dt + timedelta(seconds = 10) - datetime.now()).seconds))
        memcache.set(key="tle_%d" % noradid, value=body, time=24*3600)
        
        orbiting.append(noradid)
        
        if dt + timedelta(seconds = 10) < datetime.now():
            for obj in Object.gql("where section = :1 and noradid < :2 and noradid > :3", file, noradid, startwith):
                if obj.noradid not in orbiting:
                    obj.orbiting = False
                    logging.debug("Object %d (%s) has decayed [1]. %d seconds left." % (obj.noradid, obj.name))
            logging.info("Section %s processor nearing expiration, returning at %d (%s)" % (file, noradid, name))
            return str(noradid)
    
    for obj in Object.gql("where section = :1 and noradid > :2", file, startwith):
        if obj.noradid not in orbiting:
            obj.orbiting = False
            logging.debug("Object %d (%s) has decayed [2] " % (obj.noradid, obj.name))
    logging.info("Section %s successfully processed." % file)
    return ""
Ejemplo n.º 8
0
    def newObject(self, folder, game):
        if len(game.objects) < self.amountOfThings:
            if len(game.objects
                   ) < self.amountOfThings * self.percentualBigThings / 100:
                objectProportion = self.objectBigProportion
            else:
                objectProportion = self.objectSmallProportion

            Object.Object(self.objectName + str(len(game.objects)),
                          folder, [
                              game.size[0] * np.random.random_sample(),
                              game.size[1] * np.random.random_sample()
                          ],
                          self.objectSize,
                          objectProportion,
                          self.objectVelocity,
                          game,
                          spaceCostSize=self.objectSpaceCostSize)
        else:
            self.populated = True
            print('PerformanceMeasurement is populated')
Ejemplo n.º 9
0
    def __init__(self,
                 game,
                 folder,
                 amountOfThings,
                 percentualBigThings,
                 objectSize,
                 objectSpaceCostSize,
                 objectBigProportion,
                 objectSmallProportion,
                 objectVelocity,
                 mustPopulate=False):
        self.mustPopulate = mustPopulate
        self.populated = False
        self.amountOfThings = amountOfThings
        self.percentualBigThings = percentualBigThings
        self.objectName = 'performance_measurement_object'
        self.objectSize = objectSize
        self.objectSpaceCostSize = objectSpaceCostSize
        self.objectBigProportion = objectBigProportion
        self.objectSmallProportion = objectSmallProportion
        self.objectVelocity = objectVelocity

        bigObjectSize = self.objectSize.copy()
        bigObjectPosition = [200, 200]
        bigObjectScale = 100
        bigObjectSpaceCostSize = self.objectSpaceCostSize.copy()
        # bigObjectSpaceCostSize = None
        if self.mustPopulate:
            Object.Object(self.objectName,
                          folder,
                          bigObjectPosition,
                          bigObjectSize,
                          bigObjectScale,
                          1.5,
                          game,
                          spaceCostSize=bigObjectSpaceCostSize)

            while not self.populated:
                self.populateTheScreen(folder, game)
Ejemplo n.º 10
0
    def _do_modify_obj(self, req):
        """Modifies an object, its description, and or its status and updates it         database from the data passed from the web user interface.

        """

        obj_dict_str = base64.b64decode(req.args['obj_state_dict'])
        obj_dict = pickle.loads(obj_dict_str)

        checked_obj_names = [name[7:] for name in req.args.keys() if name[:7] ==
"status_"]

        for obj in obj_dict:
            if obj['name'] in checked_obj_names:
                #It was was checked
                if obj['status'] != "enabled":
                    tmp = Object(self.env, name = obj['name'])
                    tmp['status'] = "enabled"
                    tmp.save_changes(req.authname, "Object enabled")
            else:
                #It wasn't checked 
                if obj['status'] == "enabled":
                    tmp = Object(self.env, name = obj['name'])
                    tmp['status'] = "disabled"
                    tmp.save_changes(req.authname, "Object disabled")
Ejemplo n.º 11
0
 def processSection(self, file, startwith, dt):
     logging.info("Working on section %s. Starting with '%s'." % (file, startwith))
     orbiting = []
     startfound = True
     if startwith != "":
         startwith = int(startwith)
         startfound = False
     
     src = memcache.get("src_%s" % file).replace("\r", "").split("\n")
     logging.debug("Resource %s fetched from cache." % file)
     for i in range(0, len(src), tleutil.linecount):
         if len(src[i: i + tleutil.linecount]) < 3:
             break
         noradid, name, body, timestamp = tleutil.parseTLE(src[i: i + tleutil.linecount])
         if startwith == "" and startfound:
             startwith = noradid
         if startwith == noradid:
             startfound = True
             continue
         if not startfound:
             continue
         
         if Object.gql("where noradid = :1 and section = :2", noradid, file).count() == 0:
             obj = Object(noradid=noradid, name=name, section=file, orbiting=True)
             obj.put()
             logging.debug("New object %d (%s) discovered." % (noradid, name))
         memcache.set(key="name_%d" % noradid, value=name, time=24*3600)
         
         if TLE.gql("where noradid = :1 and timestamp = :2", noradid, timestamp).count() == 0:
             tle = TLE(noradid=noradid, section=file, body=body, timestamp=timestamp)
             tle.put()
             logging.debug("Writing new TLE for object %d." % (noradid))
         memcache.set(key="tle_%d" % noradid, value=body, time=24*3600)
         
         orbiting.append(noradid)
         
         if dt + timedelta(seconds = 10) < datetime.now():
             for obj in Object.gql("where section = :1 and noradid < :2 and noradid > :3", file, noradid, startwith):
                 if obj.noradid not in orbiting:
                     obj.orbiting = False
                     obj.put()
                     logging.debug("Object %d (%s) has decayed." % (obj.noradid, obj.name))
             logging.info("Section %s processor nearing expiration, returning at %d (%s)" % (file, noradid, name))
             return str(noradid)
     
     for obj in Object.gql("where section = :1 and noradid > :2", file, startwith):
         if obj.noradid not in orbiting:
             obj.orbiting = False
             obj.put()
             logging.debug("Object %d (%s) has decayed." % (obj.noradid, obj.name))
     logging.info("Section %s successfully processed." % file)
     return ""
Ejemplo n.º 12
0
if __name__ == '__main__':
    from utils.read_write import read_off_file
    from common import MODEL_DETAILS, Models, Coords, FileDetails, Face
    from model import Object

    # Select model to use
    model = Models.triangle
    model_details = MODEL_DETAILS[model]
    file_path = model_details[FileDetails.FILE_PATH]
    camera_pos = model_details[FileDetails.CAMERA_POS]
    light_source_pos = model_details[FileDetails.LIGHT_SOURCE_POS]
    camera_direction = [0, 0, -1]

    # Create model object
    obj = Object(*read_off_file(file_path).values())

    # Get camera coordinates
    obj.get_camera_coords(camera_pos)

    # Get face normals
    obj.get_face_normals()

    # Get View frustum
    obj.get_view_frustum(camera_pos)

    # Get Normalized Coords
    obj.get_normalized_coords()

    # Backface Detection
    obj.backface_detection(camera_direction)
Ejemplo n.º 13
0
 def insert_object(id_uri, object_uri, object_cost, object_meter,
                   object_floor, object_pic):
     add = Object(id_uri, object_uri, object_cost, object_meter,
                  object_floor, object_pic)
     session.add(add)
     session.commit()
Ejemplo n.º 14
0
                glVertex2i(j, HEIGHT - i)
    glEnd()
    glFlush()


if __name__ == '__main__':
    # Select model to use
    model = Models.wolf02
    model_details = MODEL_DETAILS[model]
    file_path = model_details[FileDetails.FILE_PATH]
    camera_pos = model_details[FileDetails.CAMERA_POS]
    light_source_pos = model_details[FileDetails.LIGHT_SOURCE_POS]
    camera_direction = [0, 0, -1]

    # Create model object
    obj = Object(*read_off_file(file_path).values())
    scene = Scene(camera_pos, camera_direction, light_source_pos,
                  (WIDTH, HEIGHT))
    scene.add_object(obj)
    scene.simulate_model()
    DISPLAY_MATRIX = scene.display_coords

    # Render openGL function
    # main(render)

    # # Display some values
    # print(f"World Coords: {obj.vertices[Coords.WORLD][:3]}")
    # print(f"Camera Coords: {obj.vertices[Coords.CAMERA][:3]}")
    # print("---Face 1---")
    # for i, vertex_index in enumerate(obj.faces[Face.INDICES][0]):
    #     print(