Exemple #1
0
def test_register_constants_with_decorator():
    @polar_class
    class RegisterDecoratorTest:
        x = 1

    p = Polar()
    p.load_str("foo_rule(x: RegisterDecoratorTest, y) if y = 1;")
    p.load_str("foo_class_attr(y) if y = RegisterDecoratorTest.x;")
    assert (
        next(p.query_rule("foo_rule", RegisterDecoratorTest(), Variable("y")))[
            "bindings"
        ]["y"]
        == 1
    )
    assert next(p.query_rule("foo_class_attr", Variable("y")))["bindings"]["y"] == 1

    p = Polar()
    p.load_str("foo_rule(x: RegisterDecoratorTest, y) if y = 1;")
    p.load_str("foo_class_attr(y) if y = RegisterDecoratorTest.x;")
    assert (
        next(p.query_rule("foo_rule", RegisterDecoratorTest(), Variable("y")))[
            "bindings"
        ]["y"]
        == 1
    )
    assert next(p.query_rule("foo_class_attr", Variable("y")))["bindings"]["y"] == 1
def route_rings(board, **kwargs):
    kwargs['skip_start'] = False
    kwargs['include_end'] = True
    for net in board.netlist.values():
        if net.flag_routed or len(net.terminals) != OPT.lines.n_lines + 1:
            continue
        # Check if this has n LED or ring terminals
        cnt_led = len(filter(lambda x: x.component.name.startswith(OPT.lines.led_pfx) and x.component.flag_placed,
                             net.terminals))
        cnt_res = len(filter(lambda x: x.component.name.startswith(OPT.lines.res_pfx) and x.component.flag_placed,
                             net.terminals))
        if cnt_res == 0 and cnt_led == OPT.lines.n_lines:
            # Ok that's one of the two ring nets.
            OPT.rings.gnd_net = net.name
            radius = OPT.rings.gnd_radius
            overhang = OPT.rings.overhang
        elif cnt_res == OPT.lines.n_lines and cnt_led == 0:
            # Ok that's one of the two ring nets.
            OPT.rings.pwr_net = net.name
            radius = OPT.rings.pwr_radius
            overhang = -OPT.rings.overhang
        else:
            continue
        del net.tracks[:]
        intersection_angles = []
        for t in filter(lambda x: x.component.flag_placed, net.terminals):
            # Get the pad position
            term_pol = t.position.to_polar()
            # Decide the endpoint for the arc
            arc_endpt = Polar(term_pol.a + overhang, term_pol.r)
            # Draw an arc to that point
            net.tracks.append(Track(map(Polar.to_point, apx_arc_through_polars(term_pol, arc_endpt, **kwargs))))
            # Draw a segment down to the given radius
            net.tracks.append(Track([arc_endpt.to_point(), Polar(arc_endpt.a, radius).to_point()]))
            # Angle at which it intersects the ring
            intersection_angles.append(arc_endpt.a)
        # Ok now join all the pieces. Add all pieces at multiples of 15 degrees so that we can attach at several angles
        intersection_angles += list(map(lambda x: float(x) * math.pi / 6., range(24)))
        intersection_angles = list(sorted(map(normalize_angle, intersection_angles)))
        # Ok pairwise arcs
        p1 = Polar(intersection_angles[-1], radius)
        for angle in intersection_angles:
            p2 = Polar(angle, radius)
            net.tracks.append(Track(map(Polar.to_point, apx_arc_through_polars(p1, p2, **kwargs))))
            p1 = p2
Exemple #3
0
def add_model(model):
    def from_polar(kwargs_dict=None, *, model=model, **actual_kwargs):
        try:
            if kwargs_dict:
                return model.objects.get(**kwargs_dict)
            else:
                return model.objects.get(**actual_kwargs)
        except ObjectDoesNotExist:
            return None

    setattr(model, "_from_polar", from_polar)
    Polar().register_class(model, from_polar=model._from_polar)
Exemple #4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("filename", nargs="+")

    args = parser.parse_args()
    polar = Polar()

    for filename in args.filename:
        if filename.endswith(".py"):
            load_python(filename, polar)

    for filename in args.filename:
        if filename.endswith(".polar"):
            load(filename, polar)
Exemple #5
0
def polar():
    """ Set up a polar instance and tear it down after the test."""
    p = Polar()
    yield p
    del p
def project_on_ring(pt, radius):
    a = math.asin(pt.y / radius)
    return Polar(a if pt.x >= 0. else math.pi - a, radius).to_point()
Exemple #7
0
 def addPolar(self, id, home, sources, callback=None):
     self._polars[id] = Polar(id, home, sources, callback)
     return self._polars[id]
Exemple #8
0
from boat import *
from environment import Environment
from simulator import Simulator
from polar import Polar

# import configuration
if os.path.isfile('config.py'):
    import config
else:
    print(
        "Please copy config_default.py to config.py to add your own strategies"
    )
    import config_default as config

# load polar
polar = Polar(os.path.join('data', 'polars', 'first-27.csv'))

# setup boat
real_boat = len(sys.argv) == 2 and sys.argv[1] == 'real'

if real_boat:
    print('Using real boat, happy sailing!')
    env = Environment(wind_speed_var=1, wind_direction_var=0)
    boat = RealBoat(env, ip_address='192.168.43.185')
    shuffle_interval = 0
else:
    print('Using simulator boat')
    env = Environment()
    boat = SimBoat(env, polar=polar)
    shuffle_interval = 20
Exemple #9
0
def test_load_and_query():
    p = Polar()
    p.load_str("f(1); f(2); ?= f(1); ?= not f(3);")

    with pytest.raises(exceptions.PolarException):
        p.load_str("g(1); ?= g(2);")
Exemple #10
0
	def renew(self):

		####### prepare points
		planesPoints = {}
		polarsPoints = {}

		for qid, queue in self._queues.items():
			points = queue.dequeue()
			if not points:
				continue

			for point in points:
				code = point.info('code')
				if code not in planesPoints:
					planesPoints[code] = []
				planesPoints[code].append(point)

				if qid not in polarsPoints:
					polarsPoints[qid] = []
				polarsPoints[qid].append(point)

		####### handle planes
		added = {}
		updated = {}

		for code, points in planesPoints.items():
			if code not in self._planes:
				self._planes[code] = Plane(points)
				added[code] = self._planes[code]
			else:
				updated[code] = (self._planes[code], self._planes[code].pointsCount())
				self._planes[code].addPoints(points)

		if added:
			self.planesAdded.emit(added)
		if updated:
			self.planesUpdated.emit(updated)


		####### handle polars
		added = {}
		updated = {}

		for qid, points in polarsPoints.items():
			if qid not in self._polars:
				self._polars[qid] = Polar(self._home, points)
				added[qid] = self._polars[qid]
			else:
				if self._polars[qid].addPoints(points):
					updated[qid] = self._polars[qid]

		if added:
			self.polarsAdded.emit(added)
		if updated:
			self.polarsUpdated.emit(updated)

		####### remove timed out planes
		t = time()
		removed = []
		for id, plane in self._planes.items():
			if t > plane.lastSeen() + PLANE_TIMEOUT:
				self._planes.pop(id)
				removed.append(id)
		self.planesRemoved.emit(removed)