def reschedule(self, cm_id, d):
    '''Used to update or modify an old reservation.
    Requires old reservation id and new reservation
    object that will replace the old reservation'''

    reservation = cself.find(cm_id)
    d["cm_id"] = cm_id

    Reservation.update(d)
Esempio n. 2
0
def reschedule(self, cm_id, d):
    '''Used to update or modify an old reservation.
    Requires old reservation id and new reservation
    object that will replace the old reservation'''

    reservation = cself.find(cm_id)
    d["cm_id"] = cm_id

    Reservation.update(d)
Esempio n. 3
0
    def find_id(self, id):
        '''displays the reservation object

        :param id: the cm_id
        '''
        reservation = Reservation.objects(cm_id=id)
        return reservation
Esempio n. 4
0
    def find_user(self, username):
        '''Selects all the reservations made by a user

        :param username: the user name
        '''
        reservations = Reservation.objects(user=username)
        return reservations
    def find_label(self, label):
        '''Finds all reservations with a given label

        :param label: the label
        '''
        reservations = Reservation.objects(label=label)
        return reservations
    def find_user(self, username):
        '''Selects all the reservations made by a user

        :param username: the user name
        '''
        reservations = Reservation.objects(user=username)
        return reservations
    def find_id(self, id):
        '''displays the reservation object

        :param id: the cm_id
        '''
        reservation = Reservation.objects(cm_id=id)
        return reservation
Esempio n. 8
0
    def find_label(self, label):
        '''Finds all reservations with a given label

        :param label: the label
        '''
        reservations = Reservation.objects(label=label)
        return reservations
Esempio n. 9
0
def create_reservation(flight_id, user_id, reserved_class,
                       passenger_first_name, passenger_last_name):
    new_reservation = Reservation(flight_id=flight_id,
                                  user_id=user_id,
                                  reserved_class=reserved_class,
                                  passenger_first_name=passenger_first_name,
                                  passenger_last_name=passenger_last_name)
    db.session.add(new_reservation)
    db.session.commit()
    return new_reservation.id
Esempio n. 10
0
def meal_events_api():
    user = utils.get_logged_in_user()

    # TODO handle no logged in user
    meal_events = Reservation.get_meal_events_for_host(user)

    if meal_events is None:
        abort(404)

    return jsonify(meal_events)
Esempio n. 11
0
def reservation_api():
    user = utils.get_logged_in_user()

    # TODO handle no logged in user
    reservation = Reservation.active_reservation_for_user(user)

    if reservation is None:
        abort(404)

    serialized_meal = reservation.serialize()
    serialized_meal["userPhoneNumber"] = user.phone_number

    return jsonify(serialized_meal)
Esempio n. 12
0
def submit_reservation():
    meal_id = int(request.form.get('meal_id'))
    # TODO handle null meal_id

    user = utils.get_logged_in_user()
    # TODO handle no user logged in

    success = Reservation.create(twilio_client, meal_id, user)

    print(success)
    if success:
        return redirect("/reservations")
    else:
        return redirect("/")
Esempio n. 13
0
def checkReservation():
    reservations = Reservation.query(
        Reservation.start_datetime_string == getCurrentDatetime().strftime("%m/%d/%y,%H:%M"))
    for reservation in reservations:
        mail.send_mail(sender="Open Reservation Team <*****@*****.**>",
                       to=reservation.user,
                       subject='Reservation Start Notification',
                       body='''
Dear %s:

Your reservation of %s starts now!

The Open Reservation Team
''' % (reservation.user, reservation.resource_name))
Esempio n. 14
0
def checkReservation():
    reservations = Reservation.query(
        Reservation.start_datetime_string == getCurrentDatetime().strftime(
            "%m/%d/%y,%H:%M"))
    for reservation in reservations:
        mail.send_mail(sender="Open Reservation Team <*****@*****.**>",
                       to=reservation.user,
                       subject='Reservation Start Notification',
                       body='''
Dear %s:

Your reservation of %s starts now!

The Open Reservation Team
''' % (reservation.user, reservation.resource_name))
Esempio n. 15
0
def checkReservationConflict(resname, dt_start, dt_end):
    reservations = Reservation.query(Reservation.resource_name == resname).order(Reservation.start_datetime)
    prev_end_time = None
    last_reservation = None

    for reservation in reservations:
        if dt_end <= reservation.start_datetime:
            if prev_end_time is None or dt_start >= prev_end_time:
                return True
            else:
                return False
        last_reservation = reservation
    if last_reservation is None or dt_start >= last_reservation.end_datetime:
        return True
    return False
Esempio n. 16
0
def checkReservationConflict(resname, dt_start, dt_end):
    reservations = Reservation.query(
        Reservation.resource_name == resname).order(Reservation.start_datetime)
    prev_end_time = None
    last_reservation = None

    for reservation in reservations:
        if dt_end <= reservation.start_datetime:
            if prev_end_time is None or dt_start >= prev_end_time:
                return True
            else:
                return False
        last_reservation = reservation
    if last_reservation is None or dt_start >= last_reservation.end_datetime:
        return True
    return False
def create_reservation(date, time, num_people, available_tables, user_id):
    """Create reservation and return Reservation object."""

    best_table = None

    for table in available_tables:

        if not best_table:
            best_table = table

        elif table.people_count < best_table.people_count:
            best_table = table

    best_table_id = best_table.table_id

    new_reservation = Reservation(date=date, time=time,
        people_in_party=num_people, table_id = best_table_id, user_id=user_id)

    return new_reservation
Esempio n. 18
0
def populate_reservations():
    """Create minimum sample data for the reservations table."""

    Reservation.query.delete()

    for i, row in enumerate(open('seed_data/reservations.csv')):
        animal_id, person_id, service_id, start_date, end_date, cost, note = row.rstrip(
        ).split(',')

        r = Reservation(animal_id=animal_id,
                        person_id=person_id,
                        service_id=service_id,
                        start_date=start_date,
                        end_date=end_date,
                        cost=cost,
                        note=note)
        db.session.add(r)
    db.session.commit()
    return None
Esempio n. 19
0
    def reserve(data):
        try:
            if "date_from" not in data or "date_to" not in data:
                raise Exception("Missing dates")

            date_from = dt.datetime.strptime(data["date_from"], "%Y-%m-%d").date()
            date_to = dt.datetime.strptime(data["date_to"], "%Y-%m-%d").date()
            del data["date_from"]
            del data["date_to"]
                
            r = Reservation(**data)

            delta = date_to - date_from
            for i in range(delta.days):
                date = date_from + dt.timedelta(days=i)
                ReservationDay(reservation_id=r.id, date=date, price=0)

            return True
        except Exception as e:
            logging.exception("Error saving data")
Esempio n. 20
0
def deleteOutDateReservation():
    out_date_res = Reservation.query(
        Reservation.end_datetime < getCurrentDatetime())
    for reservation in out_date_res:
        reservation.key.delete()
Esempio n. 21
0
def timeline_plot(out_filename):
    format = "svg"
    db = reservation_connect()


    reservations = Reservation.objects()

    hosts = set()
    times = set()

    data = []
    for reservation in reservations:
        hosts.add(reservation["host"])
        times.add(reservation["start_time"])
        times.add(reservation["start_time"])
        #print reservation
        data.append("{0} {1} {2} {3}".format(reservation.host,
                                            reservation.start_time.strftime("%Y/%m/%d.%H:%M"),
                                            reservation.end_time.strftime("%Y/%m/%d.%H:%M"),
                                            reservation.label)
            )

    # print hosts
    # print min(times)
    # print max(times)

    delta = max(times) - min(times)

    height = len(hosts) - 1
    if height <=1:
        height = 2

    script = \
    """
    #proc getdata
    data: {data}

    #proc areadef
       title: Cloudmesh Reservation
       rectangle: 1 1 10 {no_hosts}
       xscaletype: datetime YYYY/mm/dd.hh:mm
       #xrange: {tmin} {tmax}
       xautorange: datafield=2,3
       yscaletype: categories
       ycategories: {labels} 

    #proc xaxis
       stubs: datematic

    #proc yaxis
       stubs: categories

    #proc bars
       clickmapurl: @CGI?channel=@@1&starttime=@@2&endtime=@@3&title=@@4
       color: powderblue2
       axis: x
       locfield: 1
       segmentfields: 2 3
       labelfield: 4
       longwayslabel: yes
       labeldetails: size=6
    """.format(tmin=min(times).strftime("%Y/%m/%d.%H:%M"),
               tmax=max(times).strftime("%Y/%m/%d.%H:%M"),
               labels="\n\t" + "\n\t".join(hosts),
               data="\n\t" + "\n\t".join(data),
               no_hosts=height
               )


    #print script

    filename ="/tmp/ploticus.txt"    

    with open(filename, "w") as file:
        file.write(script)

    
    if sys.platform in ["darwin"]:
        ploticus = "/usr/local/bin/pl"
    else:
        ploticus = "/usr/bin/ploticus"
    
    command = "{ploticus} {filename} -{format} -o {out}.{format}".format(out=out_filename, filename=filename, format=format, ploticus=ploticus )

    os.system(command)
Esempio n. 22
0
def deleteOutDateReservation():
    out_date_res = Reservation.query(Reservation.end_datetime < getCurrentDatetime())
    for reservation in out_date_res:
        reservation.key.delete()
Esempio n. 23
0
def generate(arguments):

    if arguments['clean']:

        db = reservation_connect()
        reservations = Reservation.objects({})
        print "deleting:"
        for reservation in reservations:
            print reservation.label,
            reservation.delete()
        print

    elif arguments["--rst"]:

        print "generate"
        print 70 * "="
        print "\n::\n"
        lines = __doc__.split("\n")
        for line in lines:
            print "  ", line

    else:

        reservations = int(arguments["RESERVATIONS"])
        duration = int(arguments["DURATION"])
        server_string = arguments["SERVERS"]
        servers = hostlist.expand_hostlist(server_string)
        if arguments["START"] in ["now"]:
            first_time = datetime.datetime.now()
        else:
            first_time = timeparse(arguments("START"))

        print 70 * "="
        print "Servers:     ", servers
        print "Reservations:", reservations
        print "Duration:    ", duration
        print "First date:  ", first_time
        print 70 * "="

        db = reservation_connect()

        def random_delta(duration):
            r = randint(0, duration)
            return datetime.timedelta(seconds=timeparse("{0} h".format(r)))

        t_start = {}
        t_end = {}
        for s in xrange(0, len(servers)):
            t_start[s] = []
            t_end[s] = []

            t_start[s].append(first_time + random_delta(duration))
            t_end[s].append(t_start[s][0] + random_delta(duration))

        for s in range(0, len(servers)):
            for n in range(1, reservations):
                t_start[s].append(t_end[s][n - 1] + random_delta(duration))
                t_end[s].append(t_start[s][n] + random_delta(duration))

        for s in range(0, len(servers)):
            for n in range(0, reservations):
                print s, n, t_start[s][n], t_end[s][n]

        pprint("start: " + str(t_start))
        pprint("end  : " + str(t_end))

        for s in range(0, len(servers)):
            for n in range(0, reservations):
                entry = {
                    "cm_id": "cm_reservation-{0}-{1}".format(s, n),
                    "label": "exp-{0}-{1}".format(s, n),
                    "summary": "task-{0}-{1}".format(s, n),
                    "host": servers[s],
                    "user": "******",
                    "project": "fg82",
                    "start_time": str(t_start[s][n]),
                    "end_time": str(t_end[s][n]),
                }

                print entry
                r = Reservation(cm_id=entry["cm_id"],
                                host=entry["host"],
                                label=entry["label"],
                                user=entry["user"],
                                summary=entry["summary"],
                                project=entry["project"],
                                start_time=entry["start_time"],
                                end_time=entry["end_time"])
                r.save()

        print 70 * "A"
        reservations = Reservation.objects()
        print len(reservations)
        for reservation in reservations:
            pprint(reservation)
        print 70 * "B"

        for reservation in reservations:
            print reservation
Esempio n. 24
0
def timeline_plot(out_filename):
    format = "svg"
    db = reservation_connect()

    reservations = Reservation.objects()

    hosts = set()
    times = set()

    data = []
    for reservation in reservations:
        hosts.add(reservation["host"])
        times.add(reservation["start_time"])
        times.add(reservation["start_time"])
        #print reservation
        data.append("{0} {1} {2} {3}".format(
            reservation.host,
            reservation.start_time.strftime("%Y/%m/%d.%H:%M"),
            reservation.end_time.strftime("%Y/%m/%d.%H:%M"),
            reservation.label))

    # print hosts
    # print min(times)
    # print max(times)

    delta = max(times) - min(times)

    height = len(hosts) - 1
    if height <= 1:
        height = 2

    script = \
    """
    #proc getdata
    data: {data}

    #proc areadef
       title: Cloudmesh Reservation
       rectangle: 1 1 10 {no_hosts}
       xscaletype: datetime YYYY/mm/dd.hh:mm
       #xrange: {tmin} {tmax}
       xautorange: datafield=2,3
       yscaletype: categories
       ycategories: {labels} 

    #proc xaxis
       stubs: datematic

    #proc yaxis
       stubs: categories

    #proc bars
       clickmapurl: @CGI?channel=@@1&starttime=@@2&endtime=@@3&title=@@4
       color: powderblue2
       axis: x
       locfield: 1
       segmentfields: 2 3
       labelfield: 4
       longwayslabel: yes
       labeldetails: size=6
    """.format(tmin=min(times).strftime("%Y/%m/%d.%H:%M"),
               tmax=max(times).strftime("%Y/%m/%d.%H:%M"),
               labels="\n\t" + "\n\t".join(hosts),
               data="\n\t" + "\n\t".join(data),
               no_hosts=height
               )

    #print script

    filename = "/tmp/ploticus.txt"

    with open(filename, "w") as file:
        file.write(script)

    if sys.platform in ["darwin"]:
        ploticus = "/usr/local/bin/pl"
    else:
        ploticus = "/usr/bin/ploticus"

    command = "{ploticus} {filename} -{format} -o {out}.{format}".format(
        out=out_filename, filename=filename, format=format, ploticus=ploticus)

    os.system(command)
Esempio n. 25
0
def generate(arguments):
    """
    ::
    
        Usage:
            generate -h | --help | --rst
            generate clean
            generate SERVERS RESERVATIONS DURATION START
            generate list [--json|--table|--calendar]

        Arguments:
            SERVERS       Number of servers for which we generate 
                          reservations

            RESERVATIONS  Number of reservations per server

            DURATION      The maximum duration of a reservation 
                          (determined randomly)

            START         The start date. if now is specified, the current
                          time is used, otherwise an offset is used in the
                          form of 1m, or 1h, or 1w[default: now]

        Description:
            This program generates a number of reservations so they can be
            used to test the reservation package.

            generate clean
                deletes all reservations from the reservation database

            generate SERVERS RESERVATIONS DURATION
                generates a number of reservations where the servers are
                specified as hostlist (e.g. i[001-003]. The reservations
                specifies how many reservations there will be for each
                server. The duration is a random number between [0,duration]
                that specified not only a duration, but also the time delta
                between two reservations on the same host.

            generate list
                retiurns the list of reservations in the specified
                format. Thoe format can be list, table, or calendar

        Bugs:
            Not implemented:

            * clean 
            * list
            * the generation function does not yet have a start date

        See Also:
            * https://pypi.python.org/pypi/pytimeparse/1.1.0

    """

    if arguments['clean']:

        db = reservation_connect()
        reservations = Reservation.objects({})
        print "deleting:"
        for reservation in reservations:
            print reservation.label,
            reservation.delete()
        print
        
    elif arguments["--rst"]:

        print "generate"
        print 70 * "="
        print "\n::\n"
        lines = generate.__doc__.split("\n")
        for line in lines:
            print "  ", line

    else:

        reservations = int(arguments["RESERVATIONS"])
        duration = int(arguments["DURATION"])
        server_string = arguments["SERVERS"]
        servers = hostlist.expand_hostlist(server_string)
        if arguments["START"] in ["now"]:
            first_time = datetime.datetime.now()
        else:
            first_time = timeparse(arguments("START"))

        print 70 * "="
        print "Servers:     ", servers
        print "Reservations:", reservations
        print "Duration:    ", duration
        print "First date:  ", first_time
        print 70 * "="

        db = reservation_connect()        

        def random_delta(duration):
            r = randint(0, duration)
            return datetime.timedelta(seconds=timeparse("{0} h".format(r)))
        
        t_start = {}
        t_end = {}
        for s in xrange(0, len(servers)):
            t_start[s] = []
            t_end[s] = []
            
            t_start[s].append(first_time + random_delta(duration))
            t_end[s].append(t_start[s][0] + random_delta(duration))

        for s in range(0, len(servers)):        	
            for n in range(1, reservations):
                t_start[s].append(t_end[s][n - 1] + random_delta(duration))
                t_end[s].append(t_start[s][n] +  random_delta(duration))

        for s in range(0, len(servers)):
            for n in range(0, reservations):
                print s, n, t_start[s][n], t_end[s][n]
                

        pprint("start: " + str(t_start))
        pprint("end  : " + str(t_end))

        for s in range(0, len(servers)):
            for n in range(0, reservations):
                entry = {
                    "cm_id": "cm_reservation-{0}-{1}".format(s,n),
                    "label": "exp-{0}-{1}".format(s,n),
                    "summary": "task-{0}-{1}".format(s,n),
                    "host": servers[s],
                    "user": "******",
                    "project" : "fg82",
                    "start_time": str(t_start[s][n]),
                    "end_time": str(t_end[s][n]),
                    }

                print entry
                r = Reservation(
                    cm_id=entry["cm_id"],
                    host=entry["host"],
                    label=entry["label"],
                    user=entry["user"],
                    summary=entry["summary"],                    
                    project=entry["project"],
                    start_time=entry["start_time"],
                    end_time=entry["end_time"]
                    )
                r.save()

        print 70 * "A"
        reservations = Reservation.objects()
        print len(reservations)
        for reservation in reservations:
           pprint(reservation)
        print 70 * "B"

        for reservation in reservations:
            print reservation
Esempio n. 26
0
def generate(arguments):

    if arguments["clean"]:

        db = reservation_connect()
        reservations = Reservation.objects({})
        print "deleting:"
        for reservation in reservations:
            print reservation.label,
            reservation.delete()
        print

    elif arguments["--rst"]:

        print "generate"
        print 70 * "="
        print "\n::\n"
        lines = __doc__.split("\n")
        for line in lines:
            print "  ", line

    else:

        reservations = int(arguments["RESERVATIONS"])
        duration = int(arguments["DURATION"])
        server_string = arguments["SERVERS"]
        servers = hostlist.expand_hostlist(server_string)
        if arguments["START"] in ["now"]:
            first_time = datetime.datetime.now()
        else:
            first_time = timeparse(arguments("START"))

        print 70 * "="
        print "Servers:     ", servers
        print "Reservations:", reservations
        print "Duration:    ", duration
        print "First date:  ", first_time
        print 70 * "="

        db = reservation_connect()

        def random_delta(duration):
            r = randint(0, duration)
            return datetime.timedelta(seconds=timeparse("{0} h".format(r)))

        t_start = {}
        t_end = {}
        for s in xrange(0, len(servers)):
            t_start[s] = []
            t_end[s] = []

            t_start[s].append(first_time + random_delta(duration))
            t_end[s].append(t_start[s][0] + random_delta(duration))

        for s in range(0, len(servers)):
            for n in range(1, reservations):
                t_start[s].append(t_end[s][n - 1] + random_delta(duration))
                t_end[s].append(t_start[s][n] + random_delta(duration))

        for s in range(0, len(servers)):
            for n in range(0, reservations):
                print s, n, t_start[s][n], t_end[s][n]

        pprint("start: " + str(t_start))
        pprint("end  : " + str(t_end))

        for s in range(0, len(servers)):
            for n in range(0, reservations):
                entry = {
                    "cm_id": "cm_reservation-{0}-{1}".format(s, n),
                    "label": "exp-{0}-{1}".format(s, n),
                    "summary": "task-{0}-{1}".format(s, n),
                    "host": servers[s],
                    "user": "******",
                    "project": "fg82",
                    "start_time": str(t_start[s][n]),
                    "end_time": str(t_end[s][n]),
                }

                print entry
                r = Reservation(
                    cm_id=entry["cm_id"],
                    host=entry["host"],
                    label=entry["label"],
                    user=entry["user"],
                    summary=entry["summary"],
                    project=entry["project"],
                    start_time=entry["start_time"],
                    end_time=entry["end_time"],
                )
                r.save()

        print 70 * "A"
        reservations = Reservation.objects()
        print len(reservations)
        for reservation in reservations:
            pprint(reservation)
        print 70 * "B"

        for reservation in reservations:
            print reservation
Esempio n. 27
0
 def addRow(self, slotid, start_ts, end_ts):
     reserv = Reservation(psid=slotid, startts=start_ts, endts=end_ts)
     db.session.add(reserv)
     db.session.commit()
     print "Record Added"