Esempio n. 1
0
async def get_all_targets():
	ret = Target().getAll()
		
	if ( len(ret) == 0 ):
		raise HTTPException(status_code=404, detail="no targets found")
	else:
		return parseJson(ret)
Esempio n. 2
0
async def create_target(data: Struct):
	ret = Target(data=data)
	
	if ret:
		return {"state": "true"}
	else:
		raise HTTPException(status_code=422, detail="can't create target")
Esempio n. 3
0
    def setUpClass(cls):
        cls.directory = Path(tempfile.gettempdir())
        target = Target(layers=[
            Layer("layer1", [
                Element.from_string("Li 1.0")
            ], 0.01, 0.01, start_depth=0.0),
            Layer("layer2", [
                Element.from_string("Li 0.048"),
                Element.from_string("O 0.649"),
                Element.from_string("Mn 0.303")
            ], 90.0, 4.0, start_depth=0.01),
            Layer("subtrate", [
                Element.from_string("Si 1.0")
            ], 1000.0, 2.32, start_depth=90.01)
        ])
        cls.mcerd = MCERD(101, {
            "recoil_element": mo.get_recoil_element(),
            "sim_dir": tempfile.gettempdir(),
            "simulation_type": SimulationType.ERD,
            "target": target,
            "detector": mo.get_detector(),
            "beam": mo.get_beam(),

            # Following simulation parameters have been determined by the
            # rigorous application of the Stetson-Harrison method.
            "minimum_scattering_angle": 5.5,
            "minimum_main_scattering_angle": 6.5,
            "minimum_energy_of_ions": 8.15,
            "number_of_recoils": 15,
            "simulation_mode": SimulationMode.NARROW,
            "number_of_scaling_ions": 14,
            "number_of_ions_in_presimu": 100,
            "number_of_ions": 1000
        }, mo.get_element_simulation().get_full_name())
Esempio n. 4
0
async def update_target(id: str, item: Struct):
	target = Target(id)
	
	if not target.exists():
		raise HTTPException(status_code=404, detail="target not found")
	
	if not target.update(item):
		raise HTTPException(status_code=422, detail="error update target")
	
	return parseJson(target)
Esempio n. 5
0
    def create(self, data):
        log.write("create job: " + str(data), "debug")

        if (Job().getIdByName(data.name)):
            log.write("error job already exists: " + str(data), "debug")
            return False

        if not Target(data.target_id).exists():
            log.write("error target does not exist: " + str(data.target_id),
                      "debug")

        log.write("create target setup: " + str(data))

        doc = data.dict()
        if self.getDB().addDoc(doc):
            return True
        else:
            return False
Esempio n. 6
0
async def create_job(data: Struct):

    if (Job(name=data.name).exists()):
        raise HTTPException(status_code=422, detail="job already exist")

    for id in data.host_ids:
        if not Host(id):
            raise HTTPException(status_code=422, detail="host does not exist")

    for id in data.task_ids:
        if not Task(id):
            raise HTTPException(status_code=422, detail="task does not exist")

    if not Target(data.target_id):
        raise HTTPException(status_code=422, detail="target does not exist")

    j = Job(data=data)

    if j.getID():
        return {"state": "true"}
    else:
        raise HTTPException(status_code=422, detail="can't create target")
Esempio n. 7
0
    def test_serialization(self):
        t = Target(name="foo",
                   modification_time=random.randint(0, 100),
                   description="bar",
                   target_type="AFM",
                   image_size=(random.randint(0, 99), random.randint(0, 99)),
                   image_file="test",
                   target_theta=random.random(),
                   scattering_element=mo.get_element(randomize=True),
                   layers=[mo.get_layer()])

        with tempfile.TemporaryDirectory() as tmp_dir:
            tgt_file = Path(tmp_dir, ".target")
            t.to_file(tgt_file)

            t2 = Target.from_file(tgt_file, mo.get_request())
            self.assertIsNot(t, t2)
            self.assertEqual(t.name, t2.name)
            self.assertEqual(t.description, t2.description)
            self.assertEqual(t.layers[0].elements, t2.layers[0].elements)
            self.assertEqual(t.image_size, t2.image_size)
            self.assertEqual(t.target_theta, t2.target_theta)
            self.assertEqual(t.target_type, t2.target_type)
            self.assertEqual(t.scattering_element, t2.scattering_element)
Esempio n. 8
0
async def delete_target(id: str):
	ret = Target(id).delete()
	if ( ret == False ):
		raise HTTPException(status_code=404, detail="target not found")
	else:
		return parseJson(ret)
Esempio n. 9
0
async def search_for_target(filter: Struct):
	ret = Target().getAll(filter=shrinkJson(filter))
	return parseJson(ret)
Esempio n. 10
0
 def prepareTarget(self):
     self.target = Target(self.getTargetID())
Esempio n. 11
0
	def getTarget(self):
		if not hasattr(self, "target"):
			self.target = Target(self.target_id)
		return self.target
Esempio n. 12
0
	def getHost(self):
		if not hasattr(self, "source"):
			self.source = Target(self.host_id)
		return self.target
Esempio n. 13
0
def get_target() -> Target:
    """Returns a default Target object.
    """
    return Target()
Esempio n. 14
0
 def getHost(self):
     if not hasattr(self, "host"):
         self.host = Target(self.host_id)
     return self.target
     return ts
Esempio n. 15
0
                raise SystemError


# ====== #
#  Main  #
# ====== #
if __name__ == "__main__":
    if connection.clientID != -1:
        # Now send some data to CoppeliaSim in a non-blocking fashion:
        print('Connected to remote API server!')
        sim.simxAddStatusbarMessage(connection.clientID, 'Connected to remote API client!', sim.simx_opmode_oneshot)

        # ----- Initialization ----- #
        #  Get Objects from Simulation  # sysCall_init()
        robot = Pioneer('Pioneer_p3dx')
        target = Target('GPS')
        scene = Scene()

        # ----- Threads (Tasks) ----- #
        # thread1 = Thread(target=RobotStatus,  args=("Thread-1", robot))
        # thread1.start()
        # print("[Thread-1] 'RobotStatus' started!")

        # thread2 = Thread(target=TargetStatus, args=("Thread-2", target))
        # thread2.start()
        # print("[Thread-2] 'TargetStatus' started!")

        if doPlanning:
            thread3 = Thread(target=Planning, args=("Thread-3", robot, target, scene))
            thread3.start()
            print("[Thread-3] 'Planning' started!")