コード例 #1
0
def add_initial_values():
    _, Ses = run_database()
    session = Ses()

    user1 = User("aala", "test")
    user2 = User("ela", "password")
    user3 = User("ala", "test")
    user4 = User("ela2", "kot")

    session.add(user1)
    session.add(user2)
    session.add(user3)
    session.add(user4)

    trip = [Trip("Paris", date(2020, 6, 5), date(2020, 6, 10), user1),
            Trip("Warsaw", date(2020, 5, 30), date(2020, 6, 7), user1),
            Trip("Cracow", date(2020, 7, 10), date(2020, 7, 12), user2),
            Trip("Brussels", date(2020, 6, 11), date(2020, 6, 13), user2),
            Trip("Warsaw", date(2020, 6, 15), date(2020, 6, 20), user3),
            Trip("Liverpool", date(2020, 8, 10), date(2020, 8, 15), user3),
            Trip("Malta", date(2020, 6, 5), date(2020, 6, 7), user3),
            Trip("London", date(2020, 6, 9), date(2020, 6, 10), user3)]

    for t in trip:
        session.add(t)

    participants = [Participant(user1, trip[2]), Participant(user4, trip[3]), Participant(user3, trip[2]),
                    Participant(user2, trip[0]), Participant(user4, trip[0]), Participant(user2, trip[1]),
                    Participant(user4, trip[1]),
                    Participant(user3, trip[1])]

    for p in participants:
        session.add(p)

    commit_and_close(session)
コード例 #2
0
        def build_trip(response, trip_id, route_id, route_name, destination,
                       departure_time):
            trip_details = response.json()

            if 'vehicle' in trip_details.get('data').get('entry'):
                location = trip_details.get('data').get('entry').get(
                    'vehicle').get('location')
            else:
                location = {'lat': None, 'lon': None}

            stop_times_obj = trip_details.get('data').get('entry').get(
                'stopTimes')
            current_time = trip_details.get('currentTime')
            stops_obj = trip_details.get('data').get('references').get('stops')
            stop_times = [
                StopTime(
                    stop_id=stop_times_obj[i].get('stopId'),
                    stop_name=stops_obj.get(
                        stop_times_obj[i].get('stopId')).get('name'),
                    station_id=stops_obj.get(stop_times_obj[i].get(
                        'stopId')).get('parentStationId'),
                    ref_timestamp=stop_times_obj[i].get('arrivalTime')
                    if i > 0 else stop_times_obj[i].get('departureTime'),
                    actual_timestamp=stop_times_obj[i].get(
                        'predictedArrivalTime') if i > 0 else
                    stop_times_obj[i].get('predictedDepartureTime'),
                    # location={'lat': None, 'lon': None},
                    is_predicted=True,
                    is_next=False) for i in range(len(stop_times_obj))
            ]
            return Trip(trip_id, route_id, route_name, departure_time,
                        destination, stop_times, location)
コード例 #3
0
def index():
    # If the form is filled out, add trip and redirect back to the home page
    form = IndexForm()
    if request.method == 'POST':
        newTrip = Trip(*form.tripString.data.split(','))
        trips.append(newTrip)
        return redirect(url_for('index'))

    data = []
    for t in trips:
        data.append({"id": t.id, "origin": t.places[0], "end": t.places[-1]})

    return render_template("index.html", data=data, form=form)
コード例 #4
0
    def restore_segment(self, segment):
        for trip_record in segment:
            trip_id = trip_record.get('trip_id')
            response = self.api_connector.trip_details(trip_id="BKK_" +
                                                       trip_id)
            if response.status_code != 200:
                print(
                    f"ERROR:\t{response.json().get('text')} [{response.status_code}]"
                )
                error_record = self.create_error_record(
                    trip_id=trip_id,
                    error_code=response.status_code,
                    cause='restore',
                    description=response.json().get('text'),
                    snapshot=trip_record)
                self.failedDTO.append(error_record)

            else:
                stop_time_refs = trip_record.get('stop_times')
                stop_times = [
                    StopTime(
                        stop_id=stop_time_refs[i].get('stop_id'),
                        stop_name=stop_time_refs[i].get('stop_name'),
                        station_id=stop_time_refs[i].get('station_id'),
                        ref_timestamp=stop_time_refs[i].get(
                            'reference_timestamp'),
                        actual_timestamp=stop_time_refs[i].get(
                            'actual_timestamp'),
                        # location=trip_record.get('stop_times')[i].get('location'),
                        is_predicted=stop_time_refs[i].get('is_predicted'),
                        is_next=stop_time_refs[i].get('is_next'))
                    for i in range(len(stop_time_refs))
                ]

                trip = Trip(trip_id=trip_record.get('trip_id'),
                            route_id=trip_record.get('route_id'),
                            route_name=trip_record.get('route_name'),
                            departure_time=trip_record.get('departure_time'),
                            destination=trip_record.get('destination'),
                            stop_times=stop_times,
                            location=trip_record.get('location'))

                self.auto_config_trip(trip)

                self.trips.append(trip)
コード例 #5
0
def get_route_prices(plan, route):
    url = ALL_PRICES_URL.format(route.outbound_airport.iataCode, route.inbound_airport.iataCode)
    params = {  'outboundDateFrom': plan.outboundDateFrom,
                'outboundDateTo': plan.outboundDateTo,
                'inboundDateFrom': plan.inboundDateFrom,
                'inboundDateTo': plan.inboundDateTo
    }

    json = _json_response(url, params)
    for outbound_fare in json['outbound']['fares']:
        if _is_valid_fare(outbound_fare):
            outbound_flight = Flight(route, outbound_fare['day'], outbound_fare['price']['value'])
            for inbound_fare in json['inbound']['fares']:
                if _is_valid_fare(inbound_fare):
                    inbound_flight = Flight(route.return_route, inbound_fare['day'], inbound_fare['price']['value'])
                    plan.add_trip(Trip(outbound_flight, inbound_flight))

    return plan
コード例 #6
0
ファイル: app.py プロジェクト: madihaghani/TripGen-WebApp
def index():
    msg = ''
    msg_type = ''
    if not _all_trips:
        msg = 'No trip exist, nothing to display!'
        msg_type = 'warn'
        return render_template('trips.html', trips=_all_trips, msg=msg, msg_type=msg_type)
    if request.method == 'POST':
        new_trip = request.form['add-trip']
        if len(new_trip) == 0:
            msg = "You must enter stop(s) to add new stop(s) on your trip!"
            msg_type = 'warn'
        else:
            new_trip = new_trip.split(",")
            new_places = Trip(*new_trip).details
            _all_trips.append(new_places)
            msg = "New trip added successfully!"
            msg_type = 'success'
    return render_template('trips.html', trips=_all_trips, msg=msg, msg_type=msg_type)
コード例 #7
0
ファイル: app.py プロジェクト: madihaghani/TripGen-WebApp
def trip_details(id):
    trip = None
    for i, trip in enumerate(_all_trips):
        if trip['id'] == id:
            stops = _get_all_stops(trip['details']['stops'])
            if request.method == 'POST':
                new_stop = request.form['add-stop']
                stops = Trip(*stops) + new_stop
                trip = stops.details
                trip['id'] = id
                trip['details']['id'] = id
                _all_trips[i] = trip
                msg = 'Stop added successfully!'
                msg_type = 'success'
                return render_template('trip_details.html', details=trip['details'], stops=trip['details']['stops'],
                                       msg=msg, msg_type=msg_type)
            msg = ''
            return render_template('trip_details.html', details=trip['details'], stops=trip['details']['stops'], msg=msg)
    msg = 'Trip does not exist!'
    msg_type = 'warn'
    return render_template('trips.html', trips=_all_trips, msg=msg, msg_type=msg_type)
コード例 #8
0
ファイル: server.py プロジェクト: Ula2017/trip_server
def add_trip(username):
    if not request.json or ('trip_name' not in request.json
                            or 'date_from' not in request.json
                            or 'date_to' not in request.json
                            or 'participants' not in request.json):
        return make_response(jsonify({'error': 'Missing required parameter'}),
                             422)

    datetime_format = '%Y-%m-%d'  # The format
    participants = request.json.get('participants')
    date_from = datetime.strptime(request.json.get('date_from'),
                                  datetime_format).date()
    date_to = datetime.strptime(request.json.get('date_to'),
                                datetime_format).date()
    trip_name = request.json.get('trip_name')

    e = create_engine("sqlite:///trip_communicator.db")
    Ses = sessionmaker(bind=e)
    session = Ses()

    user = session.query(User).filter_by(username=username).first()
    if user is None:
        commit_and_close(session)
        return make_response(jsonify({'Response': 'Incorrect username'}), 400)

    trip = Trip(trip_name, date_from, date_to, user)
    session.add(trip)
    session.commit()
    for p in participants:
        participant = add_participant_from_response(session, p, trip)
        if participant is not None:
            session.add(participant)
    owner_participant = Participant(user, trip)
    session.add(owner_participant)
    session.commit()
    trip_id = trip.trip_id

    session.close()
    return make_response(jsonify({'Trip id': trip_id}), 201)
コード例 #9
0
ファイル: seeds.py プロジェクト: KristianS1991/SEI-Project-04
from models.Trip import Trip
from models.Location import Location
from models.User import User, UserSchema

db.drop_all_tables(with_all_data=True)
db.create_tables()

with db_session():
    #User
    schema = UserSchema()
    Kristian = User(username='******',
                    email='*****@*****.**',
                    password_hash=schema.generate_hash('pass'))

    # Trips
    trip_one = Trip(name="Trip One", user=Kristian)
    trip_two = Trip(name="Trip Two", user=Kristian)

    # Locations - Trip One
    location_one = Location(name="Clapham Junction",
                            postcode="SW111PW",
                            latitude=51.4652,
                            longitude=-0.1708,
                            trip=trip_one)
    location_two = Location(name="Vauxhall",
                            postcode="SW84ET",
                            latitude=51.4862,
                            longitude=-0.1229,
                            trip=trip_one)
    location_three = Location(name="Southfields",
                              postcode="SW196LL",