Beispiel #1
0
class AmazonCar(Vehicle.Class()):
    '''
  classdocs
  '''

    _Aflag = True

    @dimension(bool)
    def Aflag(self):
        return self._Aflag

    @Aflag.setter
    def Aflag(self, value):
        self._Aflag = value

    def becomeAmazonCar(self):
        self.Aflag = True

    def __init__(self, uid=None):
        self.ID = uid
        self.Length = 30

    _Waypoint = Waypoint()

    @dimension(Waypoint)
    def Waypoint(self):
        return self._Waypoint

    @Waypoint.setter
    def Waypoint(self, value):
        self._Waypoint = value
Beispiel #2
0
class AmazonCar(Vehicle.Class()):
  '''
  classdocs
  '''

  _Aflag = True
  SPEED = 5
  @dimension(bool)
  def Aflag(self):
    return self._Aflag

  @Aflag.setter
  def Aflag(self, value):
    self._Aflag = value

  def becomeAmazonCar(self):
    self.Aflag = True

  def __init__(self, uid=None):
    self.ID = uid
    self.Position = Vector3(0, 0, 0)
    self.Velocity = Vector3(0, 0, 0)
    self.Length = 0
    self.Width = 0
    self.Name = ""
    self.Aflag = True
    self.Waypoints = []
    self.FinalPosition = {}

  @dimension(list)
  def Waypoints(self):
    return self._Waypoints

  @Waypoints.setter
  def Waypoints(self, value):
    self._Waypoints = value

  @dimension(int)
  def CurrentNode(self):
    return self._CurrentNode

  @CurrentNode.setter
  def CurrentNode(self, value):
    self._CurrentNode = value

  @dimension(list)
  def FinalPosition(self):
    return self._FinalPosition

  @FinalPosition.setter
  def FinalPosition(self, value):
    self._FinalPosition = value
Beispiel #3
0
class UberCar(Vehicle.Class()):

    _Speed = 20

    @dimension(float)
    def Speed(self):
        return self._Speed

    @Speed.setter
    def Speed(self, value):
        self._Speed = value

    _Route = None

    @dimension(list)
    def Route(self):
        return self._Route

    @Route.setter
    def Route(self, value):
        self._Route = value

    _NextNodeIdx = 0

    @dimension(int)
    def NextNodeIdx(self):
        return self._NextNodeIdx

    @NextNodeIdx.setter
    def NextNodeIdx(self, idx):
        self._NextNodeIdx = idx

    def adjustSpeed(self, newSpeed):
        self.Velocity.X = self.Velocity.X / self.Speed * newSpeed
        self.Velocity.Y = self.Velocity.Y / self.Speed * newSpeed
        self.Speed = newSpeed

    def __init__(self, uid=None):
        self.ID = uid
        self.Velocity = Vector3(0, 0, 0)
        self.Name = "uberCar"
        self.Position = Vector3(0, 0, 40.5)
        self.Velocity = Vector3(0, 0, 0)
        self.Length = 10
        self.Width = 10
Beispiel #4
0
class Car_akshatp(Vehicle.Class()):

    _Route = []

    @dimension(list)
    def Route(self):
        return self._Route

    @Route.setter
    def Route(self, value):
        self._Route = value

    @dimension(float)
    def RouteLength(self):
        if len(self._Route) > 1:
            l = 0
            for i in range(1, len(self._Route)):
                x1 = self._Route[i - 1]['X']
                y1 = self._Route[i - 1]['Y']
                x2 = self._Route[i]['X']
                y2 = self._Route[i]['Y']
                l += math.sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) *
                                                          (y2 - y1)))
            return l
        else:
            return 0

    @RouteLength.setter
    def RouteLength(self, RouteLength):
        pass

    @dimension(list)
    def CarRotatedBox(self):
        p = self.Position
        prevp = self.PrevPosition

        cangle = complex(prevp.X - p.X, prevp.Y - p.Y)
        cangle = 0 if abs(cangle) == 0 else (cangle / abs(cangle))

        center = complex(p.X, p.Y)

        x1 = p.X - self.Length / 2
        y1 = p.Y - self.Width / 2
        x2 = p.X + self.Length / 2
        y2 = p.Y - self.Width / 2
        x3 = p.X + self.Length / 2
        y3 = p.Y + self.Width / 2
        x4 = p.X - self.Length / 2
        y4 = p.Y + self.Width / 2

        xy1 = cangle * (complex(x1, y1) - center) + center
        xy2 = cangle * (complex(x2, y2) - center) + center
        xy3 = cangle * (complex(x3, y3) - center) + center
        xy4 = cangle * (complex(x4, y4) - center) + center

        return [
            xy1.real, xy1.imag, xy2.real, xy2.imag, xy3.real, xy3.imag,
            xy4.real, xy4.imag
        ]

    @CarRotatedBox.setter
    def CarRotatedBox(self, CarBox):
        pass

    @dimension(list)
    def CarRotatedHitBox(self):
        p = self.Position
        prevp = self.PrevPosition

        cangle = complex(prevp.X - p.X, prevp.Y - p.Y)
        cangle = 0 if abs(cangle) == 0 else (cangle / abs(cangle))

        center = complex(p.X, p.Y)

        hx1 = p.X - self.Length / 2 - self.Velocity.X * 4
        hy1 = p.Y - self.Width / 2 - self.Width / 2

        hx2 = p.X - self.Length / 2
        hy2 = p.Y - self.Width / 2 - self.Width / 2

        hx3 = p.X - self.Length / 2
        hy3 = p.Y + self.Width / 2 + self.Width / 2

        hx4 = p.X - self.Length / 2 - self.Velocity.X * 4
        hy4 = p.Y + self.Width / 2 + self.Width / 2

        hxy1 = cangle * (complex(hx1, hy1) - center) + center
        hxy2 = cangle * (complex(hx2, hy2) - center) + center
        hxy3 = cangle * (complex(hx3, hy3) - center) + center
        hxy4 = cangle * (complex(hx4, hy4) - center) + center

        return [
            hxy1.real, hxy1.imag, hxy2.real, hxy2.imag, hxy3.real, hxy3.imag,
            hxy4.real, hxy4.imag
        ]

    @CarRotatedHitBox.setter
    def CarRotatedHitBox(self, CarBox):
        pass

    _CurrentRoute = 0

    @dimension(int)
    def CurrentRoute(self):
        return self._CurrentRoute

    @CurrentRoute.setter
    def CurrentRoute(self, value):
        self._CurrentRoute = value

    _PrevPosition = Vector3(0, 0, 0)

    @dimension(Vector3)
    def PrevPosition(self):
        return self._PrevPosition

    @PrevPosition.setter
    def PrevPosition(self, value):
        self._PrevPosition = value

    _TopSpeed = 0

    @dimension(int)
    def TopSpeed(self):
        return self._TopSpeed

    @TopSpeed.setter
    def TopSpeed(self, value):
        self._TopSpeed = value

    def __init__(self):
        self.ID = str(uuid.uuid4())
        self.Position = Vector3(0, 0, 40.5)
        self.Velocity = Vector3(0, 0, 0)
        self.Length = 0
        self.Width = 0
        self.Name = ""
Beispiel #5
0
class ArchitCar(Vehicle.Class()):
    '''
    classdocs
    '''

    _Color = Color.Red

    @dimension(Color)
    def Color(self):
        return self._Color

    @Color.setter
    def Color(self, value):
        self._Color = value

    _TopSpeed = 0

    @dimension(int)
    def TopSpeed(self):
        return self._TopSpeed

    @TopSpeed.setter
    def TopSpeed(self, value):
        self._TopSpeed = value

    _Speed = 0

    @dimension(int)
    def Speed(self):
        return self._Speed

    @Speed.setter
    def Speed(self, value):
        self._Speed = value

    _Route = []

    @dimension(list)
    def Route(self):
        return self._Route

    @Route.setter
    def Route(self, value):
        self._Route = value

    _CurrentSegment = 0

    @dimension(int)
    def CurrentSegment(self):
        return self._CurrentSegment

    @CurrentSegment.setter
    def CurrentSegment(self, value):
        self._CurrentSegment = value

    def get_next_point(self, x1, y1, x2, y2, speed):
        """
          x1, y1, x2, y2 - start and end coordinates
          speed - distances at which the points will be returned
          step - current step in the line segment
        """
        l = sqrt((x2 - x1)**2 + (y2 - y1)**2)
        slope = (y2 - y1) / (x2 - x1)
        angle = atan(slope)

        velx = speed * sin(angle)
        vely = speed * cos(angle)

        next_x = x1 + ((speed) / l) * (x2 - x1)
        next_y = y1 + ((speed) / l) * (y2 - y1)
        return round(next_x, 2), round(next_y, 2), velx, vely

    def __init__(self, uid=None):
        self.Position = Vector3(0, 0, 40.5)
        self.Velocity = Vector3(0, 0, 0)
        self.Speed = 0
        # self.Length = 0
        # self.Width = 0
        self.Name = "ArchitCars"
Beispiel #6
0
class WPCar(Vehicle.Class()):
    #_ID = None
    #@primarykey(str)
    #def ID(self):
    #  return self._ID

    #@ID.setter
    #def ID(self, value):
    #  self._ID = value

    #_Position = Vector3(0, 0, 0)
    #@dimension(Vector3)
    #def Position(self):
    #  return self._Position

    #@Position.setter
    #def Position(self, value):
    #  self._Position = value

    #_Velocity = Vector3(0, 0, 0)
    #@dimension(Vector3)
    #def Velocity(self):
    #  return self._Velocity

    #@Velocity.setter
    #def Velocity(self, value):
    #  self._Velocity = value

    _IsAssigned = False

    @dimension(bool)
    def IsAssigned(self):
        return self._IsAssigned

    @IsAssigned.setter
    def IsAssigned(self, value):
        self._IsAssigned = value

    _Route = []

    @dimension(list)
    def Route(self):
        return self._Route

    @Route.setter
    def Route(self, value):
        self._Route = value

    _RouteSection = 0

    @dimension(int)
    def RouteSection(self):
        return self._RouteSection

    @RouteSection.setter
    def RouteSection(self, value):
        self._RouteSection = value

    _LastTickTime = time.time()

    @dimension(float)
    def LastTickTime(self):
        return self._LastTickTime

    @LastTickTime.setter
    def LastTickTime(self, value):
        self._LastTickTime = value

    _AccelMode = "Cruising"

    @dimension(float)
    def AccelMode(self):
        return self._AccelMode

    @AccelMode.setter
    def AccelMode(self, value):
        self._AccelMode = value

    def __init__(self, uid=None):
        #logger.debug("!!!!" )
        self.ID = uid
        self.LastTickTime = time.time()
        super(self.Class(), self).__init__()
Beispiel #7
0
class Car_teja(Vehicle.Class()):
    '''
    classdocs
    '''
    #SPEED = 4; # move 4 units for tick

    _ID = None

    @primarykey(str)
    def ID(self):
        return self._ID

    @ID.setter
    def ID(self, value):
        self._ID = value

    _Position = Vector3(0, 0, 0)

    @dimension(Vector3)
    def Position(self):
        return self._Position

    @Position.setter
    def Position(self, value):
        self._Position = value

    _Velocity = 0  # changed velocity to number of units to move per tick Vector3(0, 0, 0)

    @dimension(int)
    def Velocity(self):
        return self._Velocity

    @Velocity.setter
    def Velocity(self, value):
        self._Velocity = value

    _Color = Color.White

    @dimension(Color)
    def Color(self):
        return self._Color

    @Color.setter
    def Color(self, value):
        self._Color = value

    _Length = 0

    @dimension(int)
    def Length(self):
        return self._Length

    @Length.setter
    def Length(self, value):
        self._Length = value

    _Width = 0

    @dimension(int)
    def Width(self):
        return self._Width

    @Width.setter
    def Width(self, value):
        self._Width = value

    #teja start

    _Lines = None

    @dimension(list)
    def Lines(self):
        return self._Lines

    @Lines.setter
    def Lines(self, value):
        self._Lines = value

    _FINAL_POSITION = 0

    @dimension(int)
    def FINAL_POSITION(self):
        return self._FINAL_POSITION

    @FINAL_POSITION.setter
    def FINAL_POSITION(self, value):
        self._FINAL_POSITION = value

    _CurrentSourceIndex = 0

    @dimension(int)
    def CurrentSourceIndex(self):
        return self._CurrentSourceIndex

    @CurrentSourceIndex.setter
    def CurrentSourceIndex(self, value):
        self._CurrentSourceIndex = value

    #teja end

    #def __init__(self, uid=None):
    def __init__(self, uid=None):
        self.ID = uid
        self.Length = 30
        self._Velocity = 0
        # car at start is zero speed

    def setRoute(self, route=[]):
        try:
            path_data = os.path.dirname(os.path.realpath(__file__))
            #trying to initialize this in client side using route request.
            self.Lines = [
                line.rstrip('\n')
                for line in open(os.path.join(path_data, 'package/car-4.rd'))
            ]
            #self.Lines = route.Waypoints
            self.Lines = []
            for value in route.Waypoints:
                t = (value['X'], value['Y'])
                self.Lines.append(t)

            self.CurrentSourceIndex = 0
            #a,b,c =str(self.Lines[0]).split(',');
            #i,a= a.split(':');
            #i,b= b.split(':');
            temp = self.Lines[0]
            self.Position.X = temp[0]
            self.Position.Y = temp[1]

            temp = self.Lines[len(self.Lines) - 1]
            temp1 = temp[0]
            temp2 = temp[1]
            self.FINAL_POSITION = [temp1, temp2]
            print(self.Lines[0])

            temp = self.Lines[0]
            x, y = temp[0], temp[1]
            print x
            print y
        except:
            print(ex.message)

    def slope(self):
        a, b = str(self.Lines[self.CurrentSourceIndex]).split(',')
        x1 = float(a)
        y1 = float(b)
        a, b = str(self.Lines[self.CurrentSourceIndex + 1]).split(',')
        x2 = float(a)
        y2 = float(b)
        return ((y2 - y1) / (x2 - x1))
        #not handling perpendicular line

    def toadd(self, m):
        return float(self.Velocity / math.sqrt(1 + m * m))
Beispiel #8
0
class SilverCar(Vehicle.Class()):
  '''
  classdocs
  '''
  #_Waypoints = get_points("/Users/Pedro/Dev/spacetime/python/datamodel/silverCar/car-4.rd")
  _Waypoints = []
  SPEED = 2
  route = None
  numRequestedRoutes = 0
  numRoutesFinished = 0
  ticks = 0
  _Name = ""
  #FINAL_POSITION = 7000

  def __init__(self, uid = None):
    self.ID = uid
    self._Length = 30
    self._Width = 10
    self._ticksToTarget = 0
    self._Velocity = Vector3(0,0,0)
    self._Position = Vector3(0, 0, 40.5)
    logger.debug("%s car created", LOG_HEADER)


  @dimension(list)
  def Waypoints(self):
    return self._Waypoints

  @Waypoints.setter
  def Waypoints(self, value):
    self._Waypoints = value
    #logger.debug("%s assigned route for car {0}".format(self._ID), LOG_HEADER)


  _Color = Color.White
  @dimension(Color)
  def Color(self):
    return self._Color

  @Color.setter
  def Color(self, value):
    self._Color = value


  def updateVelocity(self):
    #if(self.route is not None):
    if(len(self._Waypoints) == 1):
        self.numRoutesFinished += 1
        logger.debug("Route Finished after {0} Ticks".format(self.ticks))
        self.ticks = 0
        self._Velocity = Vector3(0,0,0)
    else:
        d = 0.5
        if((self._Waypoints[1]['Y'] - self._Waypoints[0]['Y']) == 0):
            m = -1 #check this later, just to avoid division by 0
        else:
            m = (self._Waypoints[1]['X'] - self._Waypoints[0]['X'])/(self._Waypoints[1]['Y'] - self._Waypoints[0]['Y'])*-1
        #x0 = math.sqrt(math.pow(d,2)/(1+math.pow(m,2))) + self._Waypoints[0]['X']
        #x1 = math.sqrt(math.pow(d,2)/(1+math.pow(m,2))) + self._Waypoints[1]['X']
        #y0 = m*(x0 - self._Waypoints[0]['X']) + self._Waypoints[0]['Y']
        #y1 = m*(x1 - self._Waypoints[1]['X']) + self._Waypoints[1]['Y']
        #temp = Vector3(x1 - x0, y1 - y0, self._Waypoints[1]['Z'] - self._Waypoints[0]['Z'])
        temp = Vector3(self._Waypoints[1]['X'] - self._Waypoints[0]['X'], self._Waypoints[1]['Y'] - self._Waypoints[0]['Y'], self._Waypoints[1]['Z'] - self._Waypoints[0]['Z'])
        #print("Original: X = {0}, Y = {1}; Novo: X = {2}, Y = {3}".format(self._Waypoints[0]['X'], self._Waypoints[0]['Y'], x0, y0))
        #print("Original: X = {0}, Y = {1}; Novo: X = {2}, Y = {3}".format(self._Waypoints[1]['X'], self._Waypoints[1]['Y'], x1, y1))

        module = math.sqrt(math.pow(temp.X, 2) + math.pow(temp.Y, 2) + math.pow(temp.Z, 2))
        if(module != 0):
            temp.X = (temp.X / module) * self.SPEED
            temp.Y = (temp.Y / module) * self.SPEED
            temp.Z = (temp.Z / module) * self.SPEED
        else:
            temp.X = 0
            temp.Y = 0
            temp.Z = 0
        self._Velocity = temp
        self._Waypoints.pop(0)
        self._ticksToTarget = self.TicksToNextTarget()

  @staticmethod
  def __predicate__(c):
    return c.Velocity != Vector3(0,0,0)

  def move(self):
    self.ticks += 1

    #logger.debug("[SilverCar]: Current velocity: {0}, New position {1}, TicketsToTarget {2}".format(self.Velocity, self.Position, self._ticksToTarget));

    if(self._ticksToTarget <= 0):
        self.updateVelocity()

    if(self._ticksToTarget > 0):
        self.Position = Vector3(self.Position.X + self.Velocity.X, self.Position.Y + self.Velocity.Y, self.Position.Z + self.Velocity.Z)

    self._ticksToTarget -= 1
    # End of ride
    #if (self.Position.X >= self.FINAL_POSITION or self.Position.Y >= self.FINAL_POSITION):
    #if(len(self._Waypoints) == 0):
    #  self.stop();

  def stop(self):
    logger.debug("%s: {0} stopping".format(self.ID), LOG_HEADER);
    self.Position.X = 0;
    self.Position.Y = 0;
    self.Position.Z = 0;
    self.Velocity.X = 0;
    self.Velocity.Y = 0;
    self.Velocity.Z = 0;

  def start(self):
    logger.debug("[CAR]: {0} starting at position {1} {2}".format(self.ID,self.Position.X, self.Position.Y))
    #self.Velocity = Vector3(self.SPEED, 0, 0)
    self.updateVelocity()

  def collision(self, otherCar):
    collided = False
    for i in self.carToSegments():
        for j in otherCar.carToSegments():
            if(doIntersect(i.p1, i.p2, j.p1, j.p2)):
                collided = True
                print "Car {0} collided with car {1}".format(self.ID, otherCar.ID)
                return True
    if not collided:
        print "1: ",self.ID, self.Position.X, self.Position.Y, "2: ",otherCar.ID, otherCar.Position.X, otherCar.Position.Y
    #    print "No collision detected"

    return collided


  def carToSegments(self):
      px = self.Position.X
      py = self.Position.Y
      widthBy2 = self._Width / 2
      lengthBy2 = self._Length / 2

      seg1 = Segment()
      x1 = px - widthBy2
      x2 = px + widthBy2
      y1 = py + lengthBy2
      y2 = py + lengthBy2
      seg1.p1 = Vector3(x1,y1,0)
      seg1.p2 = Vector3(x2,y2,0)

      seg2 = Segment()
      x1 = px + widthBy2
      x2 = px + widthBy2
      y1 = py + lengthBy2
      y2 = py - lengthBy2
      seg2.p1 = Vector3(x1,y1,0)
      seg2.p2 = Vector3(x2,y2,0)

      seg3 = Segment()
      x1 = px + widthBy2
      x2 = px - widthBy2
      y1 = py - lengthBy2
      y2 = py - lengthBy2
      seg3.p1 = Vector3(x1,y1,0)
      seg3.p2 = Vector3(x2,y2,0)

      seg4 = Segment()
      x1 = px - widthBy2
      x2 = px - widthBy2
      y1 = py - lengthBy2
      y2 = py + lengthBy2
      seg4.p1 = Vector3(x1,y1,0)
      seg4.p2 = Vector3(x2,y2,0)

      return [seg1, seg2, seg3, seg4]



  _ticksToTarget = 0
  @dimension(int)
  def TicksToTarget(self):
    return self._ticksToTarget

  @TicksToTarget.setter
  def TicksToTarget(self, value):
    self._ticksToTarget = value

  def TicksToNextTarget(self):
      return math.ceil(math.sqrt(math.pow(self._Waypoints[0]['X'] - self.Position.X, 2) + math.pow(self._Waypoints[0]['Y'] - self.Position.Y, 2) + math.pow(self._Waypoints[0]['Z'] - self.Position.Z, 2))/self.SPEED)