Beispiel #1
0
    def mainstart(self):
        bucle = True
        while bucle:
            try:
                option = int(input("Digita la opción que desees ejecutar: "))
                print()
                if option == 1:
                    Clients().start()
                    self.menu()
                elif option == 2:
                    Vehicles().start()
                    self.menu()
                elif option == 3:
                    Service().start()
                    self.menu()
                elif option == 4:
                    Facturas().get_all()
                    self.menu()
                elif option == 5:
                    Facturas().hola()
                    self.menu()
                elif option == 6:
                    self.menu()
                elif option == 7:
                    bucle = False

                    print()
            except NameError:
                print(NameError)
                print("7. Mostrar menú de modulos [7]")
                print(
                    "La opción digitada es invalida (debe ser un número en el menú)."
                )
                print()
Beispiel #2
0
    def setup(self):
        nn = self.options['num_nodes']
        nv = self.options['num_vehicles']

        self.add_subsystem('vehicles',
                           Vehicles(num_nodes=nn, num_v=nv),
                           promotes=['*'])

        self.add_subsystem('demux', DeMux(num_nodes=nn, nv=nv), promotes=['*'])
        nc = 0
        for i in range(nv):
            for k in range(i + 1, nv):

                self.add_subsystem('dist_%i_%i' % (i, k),
                                   AllDistComp(num_nodes=nn, limit=limit))

                self.connect('x_%i' % i, 'dist_%i_%i.x1' % (i, k))
                self.connect('y_%i' % i, 'dist_%i_%i.y1' % (i, k))
                self.connect('x_%i' % k, 'dist_%i_%i.x2' % (i, k))
                self.connect('y_%i' % k, 'dist_%i_%i.y2' % (i, k))

                nc += 1

        self.add_subsystem('aggmux', AggregateMux(num_nodes=nn, nc=nc))

        nc = 0
        for i in range(nv):
            for k in range(i + 1, nv):
                self.connect('dist_%i_%i.dist' % (i, k), 'aggmux.dist_%i' % nc)
                nc += 1
    def setup(self):
        nn = self.options['num_nodes']
        nv = self.options['num_vehicles']
        separation = self.options['separation']
        """Add in the old trajectory as a meta model
            """

        mm = MetaModelStructuredComp(method='slinear',
                                     vec_size=nn,
                                     extrapolate=True)
        mm.add_input('t', val=np.zeros(nn), training_data=old_t)
        mm.add_output('interp_x', val=np.zeros(nn), training_data=old_X)
        mm.add_output('interp_y', val=np.zeros(nn), training_data=old_Y)
        self.add_subsystem('mm', mm, promotes=['*'])

        # now add in trajectories to be solved with dymos
        self.add_subsystem('vehicles',
                           Vehicles(num_nodes=nn, num_v=nv),
                           promotes=['*'])

        # add in distance calcs for solved trajectories
        self.add_subsystem('distances1',
                           GridDistComp(num_nodes=nn, num_v=nv, limit=limit),
                           promotes=['*'])

        # add in distance calcs for solved trajectories to the fixed ones
        self.add_subsystem('distances2',
                           SingleDistance(num_nodes=nn, num_v=nv),
                           promotes=['*'])
        self.connect('interp_x', 'fixed_x')
        self.connect('interp_y', 'fixed_y')
    def setup(self):
        nn = self.options['num_nodes']
        nv = self.options['num_vehicles']

        self.add_subsystem('schedule',
                           Schedule(num_nodes=nn, num_v=nv),
                           promotes=['*'])
        self.add_subsystem('vehicles',
                           Vehicles(num_nodes=nn, num_v=nv),
                           promotes=['*'])
Beispiel #5
0
    def setup(self):
        nn = self.options['num_nodes']
        nv = self.options['num_vehicles']

        self.add_subsystem('vehicles', Vehicles(num_nodes=nn, 
                                                num_v=nv), 
                                       promotes=['*'])
        self.add_subsystem('distances', GridDistComp(num_nodes=nn, 
                                                     num_v=nv, 
                                                     limit=limit,
                                                     method=1), 
                                        promotes=['*'])
Beispiel #6
0
    def __init__(self):
        """Populates vehicles and rental costs from file. Raises IOError."""
        
        self.__vehicles = Vehicles()
        self.__vehicle_costs = VehicleCosts()
        self.__reservations = Reservations()
        self.__vehicle_info_file = None

        try:
            self.__vehicle_info_file = open(VEHICLES_FILENAME, 'r')
            self.__rental_cost_file = open(VEHICLE_COSTS_FILENAME, 'r')
            
            self.__populateVehicles(self.__vehicle_info_file)
            self.__populateCosts(self.__rental_cost_file)
        except InvalidFileFormatError as e:
            print(e)
            raise IOError
        except IOError:
            if self.__vehicle_info_file == None:
                print('FILE NOT FOUND:', VEHICLES_FILENAME)
            else:
                print('FILE NOT FOUND:', VEHICLE_COSTS_FILENAME)
            raise IOError
Beispiel #7
0
def main():
    context = zmq.Context()

    # Socket to receive messages on
    receiver = context.socket(zmq.PULL)
    receiver.bind("tcp://*:3000")

    # Socket to send messages to clients
    client = context.socket(zmq.PUB)
    client.bind("tcp://*:3001")

    # Socket to send messages to ventillator
    combMngSys = context.socket(zmq.REQ)
    combMngSys.connect("tcp://localhost:4001")

    while True:
        event = json.loads(receiver.recv())

        if event['event'] & EVENT_NEW_VEHICLE:
            arguments = event['arguments']
            vehicles = Vehicles(**arguments)
            #print vehicles
        elif event['event'] & EVENT_KILL:
            arguments = event['id']
            event = {'id': arguments, 'event': EVENT_KILL}
            client.send(json.dumps(event))

        # If vehicles enter radar and not in invisible cone send data
        if vehicles.check_distance(
                RADAR_ZONE, True) and (vehicles.invisible_cone(CONE_ANGLE)):

            combMngSys.send(json.dumps(vehicles.package_data()))
            combMngSys.recv()

        # Target(s) entirely out of range quit connection
        elif vehicles.check_distance(WORLD_ZONE, False):
            event = {'id': vehicles.identity, 'event': EVENT_KILL}
            client.send(json.dumps(event))
Beispiel #8
0
class SystemInterface:
    """This class provides the system interface of the vehicle rental
       system.
    """
    def __init__(self):
        """Populates vehicles and rental costs from file. Raises IOError."""
        
        self.__vehicles = Vehicles()
        self.__vehicle_costs = VehicleCosts()
        self.__reservations = Reservations()
        self.__vehicle_info_file = None

        try:
            self.__vehicle_info_file = open(VEHICLES_FILENAME, 'r')
            self.__rental_cost_file = open(VEHICLE_COSTS_FILENAME, 'r')
            
            self.__populateVehicles(self.__vehicle_info_file)
            self.__populateCosts(self.__rental_cost_file)
        except InvalidFileFormatError as e:
            print(e)
            raise IOError
        except IOError:
            if self.__vehicle_info_file == None:
                print('FILE NOT FOUND:', VEHICLES_FILENAME)
            else:
                print('FILE NOT FOUND:', VEHICLE_COSTS_FILENAME)
            raise IOError

    def numAvailVehicles(self, vehicle_type):
        """Returns the number of available vehiles. Returns 0 if no
           no vehicles available.
        """
        
        return self.__vehicles.numAvailVehicles(vehicle_type)


    def getVehicle(self, vin):
        """Returns Vehicle type for given vin."""

        return self.__vehicles.getVehicle(vin)


    def getVehicleTypes(self):
        """Returns all vehicle types as a tuple of strings."""

        return VEHICLE_TYPES


    def getVehicleCosts(self, vehicle_type):
        """Returns vehicle costs for provided vehicle type as a list.

           List of form [daily rate, weekly rate, weekend rate,
                         num free miles, per mile charge, insur rate]
        """

        return self.__vehicle_costs.getVehicleCost(vehicle_type).getCosts()


    def getAvailVehicles(self, vehicle_type):
        """Returns a list of descriptions of unreserved vehicles."""
        
        avail_vehicles = self.__vehicles.getAvailVehicles(vehicle_type)
        return [veh for veh in avail_vehicles]
        

    def isReserved(self, vin):

        return self.__reservations.isReserved(vin)


    def findReservation(self, credit_card):

        return self.__reservations.findReservation(credit_card)

    
    def addReservation(self, resv):
        """Creates reservation and marks vehicles as reserved."""

        self.__reservations.addReservation(resv)


    def cancelReservation(self, credit_card):
        """Cancels reservation made with provided credit card."""

        vin = self.__reservations.getVinForReserv(credit_card)

        self.__vehicles.unreserveVehicle(vin)
        self.__reservations.cancelReservation(credit_card)
        

    def calcRentalCost(self, vehicle_type, rental_period,
                       want_insurance, miles_driving):
        """Returns estimate of rental cost for provided parameter values.

           Returns dictionary with key values: {'base_charges', 'insur_rate',
           'num_free_miles', 'per_mile_charge', 'estimated_mileage_charges'}
        """

        return self.__vehicle_costs.calcRentalCost(vehicle_type, rental_period,
                                            want_insurance, miles_driving)

    # ---- Private Methods

    def __populateVehicles(self, vehicle_file):
        """Gets vehicles from vehicle_file. Raises InvalidFileFormatError."""
        
        empty_str = ''

        # init vehicle string file headers
        vehicle_file_headers = ('#CARS#', '#VANS#', '#TRUCKS#')
        vehicle_type_index = 0
        
        # read first line of file (#CARS# expected)
        vehicle_str = vehicle_file.readline()
        vehicle_info = vehicle_str.rstrip().split(',')
        file_header_found = vehicle_info[0]
        expected_header = vehicle_file_headers[0]

        if file_header_found != expected_header:
            raise InvalidFileFormatError(expected_header, VEHICLES_FILENAME)
        else:
            # read next line of file after #CARS# header line
            vehicle_str = vehicle_file.readline()
            
            while vehicle_str != empty_str:

                # convert comma-separated string into list of strings
                vehicle_info = vehicle_str.rstrip().split(',')

                if vehicle_info[0][0] == '#':
                    vehicle_type_index = vehicle_type_index + 1
                    file_header_found = vehicle_info[0]
                    expected_header = vehicle_file_headers[vehicle_type_index]

                    if file_header_found !=  expected_header:
                        raise InvalidFileFormatError(expected_header,
                                                     VEHICLES_FILENAME)
                else:    

                    # create new vehicle object of the proper type
                    if file_header_found == '#CARS#':
                        vehicle = Car(*vehicle_info)
                    elif file_header_found == '#VANS#':
                        vehicle = Van(*vehicle_info)
                    elif file_header_found == '#TRUCKS#':
                        vehicle = Truck(*vehicle_info)
                    
                    # add new vehicle to vehicles list
                    self.__vehicles.addVehicle(vehicle)

                # read next line of vehicle information
                vehicle_str = vehicle_file.readline()


    def __populateCosts(self, cost_file):
        """Populates RentalCost objects from provided file object."""
               
        # skip file header / read first line of file
        cost_file.readline()
        cost_str = cost_file.readline()
        
        for veh_type in VEHICLE_TYPES:
            # strip off newline (last) character and split into list
            cost_info = cost_str.rstrip().split(',')

            for cost_item in cost_info:
                cost_item = cost_item.strip()
                
            # add Vehicle Type/Rental Cost key/value to dictionary
            self.__vehicle_costs.addVehicleCost(veh_type, VehicleCost(*cost_info))    

            # read next line of vehicle costs
            cost_str = cost_file.readline() 
        def setup(self):
            nn = self.options['num_nodes']
            nv = self.options['num_vehicles']
            separation = self.options['separation']

            self.add_subsystem('vehicles',
                               Vehicles(num_nodes=nn, num_v=nv),
                               promotes=['*'])

            if separation == 'grid':
                self.add_subsystem('distances',
                                   GridDistComp(num_nodes=nn,
                                                num_v=nv,
                                                limit=limit),
                                   promotes=['*'])

            elif separation == 'pairwise':
                self.add_subsystem('demux',
                                   DeMux(num_nodes=nn, nv=nv),
                                   promotes=['*'])
                nc = 0
                for i in range(nv):
                    for k in range(i + 1, nv):

                        self.add_subsystem(
                            'dist_%i_%i' % (i, k),
                            AllDistComp(num_nodes=nn, limit=limit))

                        self.connect('x_%i' % i, 'dist_%i_%i.x1' % (i, k))
                        self.connect('y_%i' % i, 'dist_%i_%i.y1' % (i, k))
                        self.connect('x_%i' % k, 'dist_%i_%i.x2' % (i, k))
                        self.connect('y_%i' % k, 'dist_%i_%i.y2' % (i, k))

                        nc += 1

                if aggregate == 'mine':
                    self.add_subsystem('aggmux',
                                       AggregateMux(num_nodes=nn, nc=nc))

                    nc = 0
                    for i in range(nv):
                        for k in range(i + 1, nv):
                            self.connect('dist_%i_%i.dist' % (i, k),
                                         'aggmux.dist_%i' % nc)
                            nc += 1

                elif aggregate == 'ks':
                    self.add_subsystem('aggmux',
                                       AggregateMuxKS(num_nodes=nn, nc=nc))
                    nc = 0
                    for i in range(nv):
                        for k in range(i + 1, nv):
                            self.connect('dist_%i_%i.dist' % (i, k),
                                         'aggmux.dist_%i' % nc)
                            nc += 1

                    self.add_subsystem('ks', om.KSComp(width=nc, vec_size=nn))
                    self.connect('aggmux.distks', 'ks.g')

                elif aggregate == 'none':
                    self.add_subsystem('aggmux',
                                       AggregateMuxKS(num_nodes=nn, nc=nc))
                    nc = 0
                    for i in range(nv):
                        for k in range(i + 1, nv):
                            self.connect('dist_%i_%i.dist' % (i, k),
                                         'aggmux.dist_%i' % nc)
                            nc += 1
Beispiel #10
0
# Number of frames a track needs to exist for in order to be drawn on the image (> 2 ish?, which will cut down on single frame false positives).
# Number of frames a track can exist before being killed (probably kill immediately unless false negatives are a problem).

# Initial image:
# Assign a track to each detection, but don't draw anything yet.

# Tracks can be "new", "alive", "almostdead" or "dead"
# "new" if ageSinceBirth < drawThresh # THESE CAN BE ASSIGNED NEW DETECTIONS BUT ARE NOT PLOTTED
# "alive" if ((ageSinceBirth >= drawThresh) & ( ageSinceLastSeen <= 0)) # THESE CAN BE ASSIGNED NEW DETECTIONS AND ARE PLOTTED
# "almostdead" if ((ageSinceLastSeen > 0) & (ageSinceLastSeen <= ageKillThresh)) # THESE CAN BE ASSIGNED NEW DETECTIONS BUT ARE NOT PLOTTED
# "dead" if ageSinceLastSeen > ageKillThresh # THESE CANNOT BE ASSIGNED NEW DETECTIONS AND ARE NOT PLOTTED

# Track objects are (status{"new","alive","almostdead","dead"}, ageSinceBirth, ageSinceLastSeen, {bbox age 1, bbox age 2, ...})

# INITIALIZE THE VEHICLES TO START THE TRACKER
vehicles = Vehicles(MydistThresh=40, MydrawThresh=5, MyageKillThresh=12)

import sys, traceback

try:
    clip1 = VideoFileClip(Input_video)
    video_clip = clip1.fl_image(
        process_image)  # This function expects color images.
    video_clip.write_videofile(Output_video, audio=False)
    del clip1.reader
    del clip1
except:
    tb = traceback.format_exc()
else:
    tb = "Complete!"
finally: