Example #1
0
from boat import Boat
from vehicle import Vehicle
from corvette import Corvette
from motorcycle import Motorcycle
from plane import Plane
from truck import Truck

boat = Boat()
boat.drive()

vette = Corvette()
vette.drive()

moto = Motorcycle()
moto.drive()
moto.stop()
moto.turn("left")

plane = Plane()
plane.drive()
plane.stop()
plane.turn("right")

truck = Truck()
truck.drive()
truck.stop()
truck.turn("left")
Example #2
0
fusion = Car("Ford", "Fusion")
fusion.doors = "4"
fusion.fuel_type = "hybrid"
fusion.battery_capacity = "13 kwh"
fusion.fuel_capacity = "12 gallons"
fusion.main_color = "white"
fusion.maximum_occupancy = "5"

#motorcycle
harley = Motorcycle("Harley-Davidson", "Panhead")
harley.maximum_occupancy = "2"
harley.main_color = "black"
harley.fuel_capacity = "7 gallons"

#actions of vehicles
f150.drive()
f150.turn("left")
f150.stop()

fusion.drive()
fusion.turn("right")
fusion.stop()
fusion.drive_electric()

pullman.drive()
pullman.turn("left")
pullman.stop()

harley.drive()
harley.turn("left")
harley.stop()
Example #3
0
class Publisher(Thread):
    def __init__(self, id_truck, id_driver, id_itinerary):
        Thread.__init__(self)
        self.id_truck = id_truck
        self.id_driver = id_driver
        new_driver = driver_to_db({'iddriver': id_driver})
        self.id_itinerary = id_itinerary
        self.truck = Truck(self.id_truck)
        self.connection = None
        self.departure, self.arrival = self.truck.drive()
        self.departure = [self.departure['lng'], self.departure['lat']]
        self.arrival = [self.arrival['lng'], self.arrival['lat']]
        new_itinerary = itinerary_to_db({
            'iditinerary': id_itinerary,
            'mission': 'Undefined',
            'departure': self.departure,
            'arrival': self.arrival
        })
        if new_driver == 0:
            print('Driver id #%i created' % (self.id_driver))
        elif new_driver == 1:
            print('Driver id #%i already in DB' % (self.id_driver))
        if new_itinerary == 0:
            print('Itinerary id #%i created' % (self.id_itinerary))
        elif new_itinerary == 1:
            print('Itinerary id #%i already in DB' % (self.id_itinerary))

    def emit_message(self, payload):
        amqp_url = os.environ['AMQP_URL']

        parameters = pika.URLParameters(amqp_url)
        self.connection = pika.BlockingConnection(parameters)
        channel = self.connection.channel()

        channel.queue_declare(queue='exchange', durable=True)
        channel.basic_publish(
            exchange='',
            routing_key='exchange',
            body=json.dumps(payload),
        )
        print(" [x] Message publisher %r" % payload)
        self.connection.close()

    def run(self):
        journey_ended = False
        t = 0
        while not journey_ended:
            position = self.truck.get_position_at_time(t)
            status = self.truck.get_status_at_time(t)
            payload = {
                "iddriver": self.id_driver,
                "idtruck": self.id_truck,
                "status": status,
                "iditinerary": self.id_itinerary,
                "position": position,
                "timestamp": datetime.now().strftime("%m/%d/%Y %H:%M:%S"),
                "departure": self.departure,
                "arrival": self.arrival,
                "mission": "Unregistred"
            }
            self.emit_message(payload)
            t += 1
            time.sleep(1)
Example #4
0
    label_x = kwargs.get('x_label', '')
    label_y1 = kwargs.get('y1_label', '')
    label_y2 = kwargs.get('y2_label', '')
    color_y1 = kwargs.get('y1_color', 'tab:red')
    color_y2 = kwargs.get('y2_color', 'tab:blue')
    path = kwargs.get('path', 'graph.png')

    ax1.plot(x_data, y1_data, color=color_y1)
    ax1.set_xlabel(label_x)
    ax1.set_ylabel(label_y1)
    ax2 = ax1.twinx()
    ax2.plot(x_data, y2_data, color=color_y2)
    ax2.set_ylim(0,80)
    ax2.set_ylabel(label_y2)

    fig.tight_layout()
    plt.savefig(path)


t = Truck(id=1)
t.drive()
coord = t.get_coordinates()
distances = [i*10 for i in range(len(coord))]
timestamps = [elt[2] for elt in coord]
speed = [elt[3] * 3.6 for elt in coord]
dual_axis_plot(x_data=distances,
               y1_data=timestamps,
               y2_data=speed,
               x_label="Distance",
               y1_label='Timestamps (s)',
               y2_label='speed (km/h)')