Package excu :: Module excursion :: Class Excursion
[hide private]
[frames] | no frames]

Class Excursion

object --+
         |
        Excursion

The class Excursion represents excursions that students can sign up for. Each excursion object has a maximum number of "places" for students, a name and a sequence number which indicates if the excursion is a "re-run" of a previous one. An excursion object keeps track of which students have signed up for the excursion. There may be more students signed up for an excursion than there are places, in the hopes that places are freed by cancellations or more places are added to the excursion. Such students are called "reserves". See the method sign_up for more details about the signing up and queuing process.

Instance Methods [hide private]
 
__init__(self, name, number, places)
Creates a new excursion with the given name, sequence number and number of places.
string
get_description(self)
Returns a string description of the excursion's main data.
 
add_places(self, increase)
Adds more places to the excursion.
int
get_places(self)
Returns the number of students that can take part in the excursion.
boolean
has_place(self, student)
Returns a boolean value indicating if, as matters currently stand, the student will be able to take part in the excursion.
int
get_reserve_position(self, student)
Determines if the given student is a "reserve", that is, if the student has signed up but currently does not have a place available.
 
sign_up(self, new_student)
Signs up the given student for the excursion.
 
cancel(self, student)
Cancels the given students registration for the excursion.
string
get_participant_listing(self)
Returns a listing of the students who currently have places on the excursion, in order.
list of student objects
get_reserves(self)
Returns the students who are in reserve for this excursion.
excursion object
redo(self, places)
Creates and returns a new excursion which is a "re-run" of this excursion.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, name, number, places)
(Constructor)

 

Creates a new excursion with the given name, sequence number and number of places. No students are registered yet for the new excursion.

Parameters:
  • name (string) - the name of the excursion, e.g. "Nokian aula"
  • number (int) - the sequence number of the excursion. 1 indicates that the excursion is organized for the first time, a higher number indicates a re-run of a previously organized excursion.
  • places (int) - the number of students that can take part in the excursion
Overrides: object.__init__

get_description(self)

 

Returns a string description of the excursion's main data. This description is of the form "Name #Number (StudentCount/Places)" where StudentCount is the total number of students who have signed up for the excursion, including reserves. Examples:

  • Nokia #1 (25/50)- Nokia #3 (53/50)
Returns: string
a string description of the excursion

add_places(self, increase)

 

Adds more places to the excursion.

Parameters:
  • increase (int) - a positive number indicating how many more students the excursion can now accommodate

get_places(self)

 

Returns the number of students that can take part in the excursion.

Returns: int
number of places

has_place(self, student)

 

Returns a boolean value indicating if, as matters currently stand, the student will be able to take part in the excursion. That is, a return value of True means that the student will be able to participate if not too many younger students sign up later. A return value of False means that either the given student has not even tried to sign up for the excursion, or that the student is a "reserve" and will not be able to participate unless places are freed due to cancellations or more places are added to the excursion.

Parameters:
  • student (student object) - a student
Returns: boolean
a boolean value indicating the student's queuing status, as described above

get_reserve_position(self, student)

 

Determines if the given student is a "reserve", that is, if the student has signed up but currently does not have a place available. If so, determines the position of the student in the queue of reserves. A positive return value indicates the students position: 1 means the first of the reserves (the one who will be the first to get a place if someone cancels), 2 means the next reserve, and so on.

Parameters:
  • student (student object) - a student
Returns: int
zero if the student is not a reserve, a positive number indicating the student's position amongst the reserves otherwise.

sign_up(self, new_student)

 

Signs up the given student for the excursion. If the given student was already signed up for the excursion, nothing needs to be done. Otherwise, the excursion determines the position in which the student is placed amongst other students who have signed up. This is done according to two rules:

  • Younger students (in terms of years studied) always have the preference over older students. That is, a younger student will be able to "cut the line" and get in before older ones.
  • Of the students with the same year of study, the one that signs up first will have the preference.
Parameters:
  • new_student (student object) - the student who is signing up

cancel(self, student)

 

Cancels the given students registration for the excursion.

Parameters:
  • student (student object) - the cancelling student

get_participant_listing(self)

 

Returns a listing of the students who currently have places on the excursion, in order. The listing is prefaced by a generic description of the excursion obtained by calling self.get_description() The rest of the listing consists of lines of the form " - StudentName (YearOfStudy)". E.g.:

   MiniExqu #1 (5/3)
    - Bob (1)
    - Adam (1)
    - Cecilia (3)

Note that students in reserve are not included in this listing.

Returns: string
a multi-line participant listing
See Also:
has_place(Student), Student.get_description()

get_reserves(self)

 

Returns the students who are in reserve for this excursion. That is, returns a list containing the students who are queuing up in hopes of cancellations or additional available places.

Returns: list of student objects
a list of the reserves, in queueing order (if there are none, an empty list is returned)

redo(self, places)

 

Creates and returns a new excursion which is a "re-run" of this excursion. The new excursion has the same name as this one, a sequence number which is higher by one than this one's, and the given number of places available. Furthermore, all this excursion's reserve students are moved (in the same order) to the newly created re-run excursion. ("Moving" means that they are removed from the old excursion and added to the new one.)

Parameters:
  • places (int) - number of places in the new excursion
Returns: excursion object
the new re-run excursion