module Databases;
from Edit import Clipboard, Selection, SelectionContext;
from File import FileSpace, File, Workspace;
from Admin import AdminDB, Username;
export CourseDB, Course, CourseTitle, Section,
ChosenTimeArrangements,
TimeArrangement, InstructorDB, Instructor, Name,
FirstName, MiddleName, LastName, ID, Password, Handicapped,
InstructorCoursePreferenceDB, InstructorCoursePreference,
InstructorTimePreferenceDB, InstructorTimePreference,
AvailBlock, Days, Day,
ClassroomDB, Classroom, Room, BuildingNumber, RoomNumber,
HandicapCapable, LabCapable, ScheduleDB, ScheduleRecord, CallNum,
Rating, Time, TimeBlock, Hour, Minute, AmOrPm, AM, PM;
object CourseDB is cl:Course*
description: (* A CourseDB contains zero or more courses. *);
end CourseDB;
object ClassroomDB is cl:Classroom*
description: (* A ClassroomDB contains zero or more classrooms. *);
end ClassroomDB;
object InstructorDB is il:Instructor*
description: (* A InstructorDB contains zero or more instructors. *);
end InstructorDB;
object Course is
components: title:CourseTitle and desc:Description and units:Units
and wtus:WTUs and tas:ChosenTimeArrangements and sec:integer
and sizes:Size* and notes:Notes;
description: (* A Course contains the above fields used to distinguish them
from other courses. *);
end Course;
object CourseTitle is string
description: (* CourseTitle is a free-form string indicating in what
course it is. An example is "CPE 101"*);
end CourseTitle;
object Description is string
description: (*
Description is a free-form string describing the object.
*);
end Description;
object Units is integer
description: (*
The numeric value of the number of units the course is worth.
*);
end Units;
object WTUs is integer
description: (*
The numeric value of the number of WTUs(work time units) the course
is worth.
*);
end WTUs;
object ChosenTimeArrangements is TimeArrangement*
description: (*
The chosen time arrangements are taken from a tuple of predefined
time arrangements.
*);
end ChosenTimeArrangements;
object TimeArrangementDB is tas:TimeArrangement*
description: (* A database containing all possible time arrangements *);
end TimeArrangementDB;
object TimeArrangement is
components: wtus:WTUs and desc:Description and lec_hrs:real
and lab_hrs:real and act_hrs:real and days:Days
and lab_and_lec_linked:boolean;
description: (*
The time arrangements define when on what days a course can be held,
what types of course it is, and how many hours per day it is held.
*);
end TimeArrangements;
object Size is integer
description: (*
The number of students allowed to take the course.
*);
end Size;
object Notes is string
description: (*
Notes is a free-form string used for details about the course.
Ex. "high demand course".
*);
end Notes;
object Instructor is
components: title:InstructTitle and name:Name and Degree
and is_handicap:Handicapped and id:ID and pass:Password;
description: (*
An Instructor contains the above fields used to distinguish
them from other instructors.
*);
end Course;
object InstructTitle is string
description: (*
InstructTitle is a person's title, such as Mr., Ms., etc.
*);
end InstructTitle;
object Name is first:FirstName and middle:MiddleName and last:LastName
description: (* A name composed of a first, middle, and last portion *);
end Name;
object FirstName is string
description: (*
This is a free-form string indicating the instructor's first name
*);
end FirstName;
object MiddleName is string
description: (*
This is a free-form string indicating the instructor's middle name
*);
end MiddleName;
object LastName is string
description: (*
This is a free-form string indicating the instructor's last name
*);
end LastName;
object Degree is string
description: (*
This is a free-form string indicating the instructor's degree.
*);
end Degree;
object Handicapped is boolean
description: (*
This is a boolean indicating if the instructor is handicapped.
*);
end Handicapped;
object ID is string
description: (*
This is an id which is unique to the instuctor and is used to log in
for the instructor preference interface.
*);
end ID;
object Password is string
description: (* Contains an administrator password for securtiy.
*);
end Password;
object Classroom is
components: rm:Room and desc:Description and Size and Location
and is_lab:LabCapable and is_handicap:HandicapCapable
and avail_times:Availability and resources:Resource*;
description: (* A Classroom contains the above fields used to distinguish
them from other classrooms.
*);
end Classroom;
object Room is
components: bn:BuildingNumber and rn:RoomNumber;
description: (* A Room is located by finding its building and room number.
*);
end Room;
object BuildingNumber is integer
description: (*
This is the Building where you can find this classroom.
*);
end BuildingNumber;
object RoomNumber is integer
description: (*
This is the specific Room number for this classroom.
*);
end RoomNumber;
object Location is x:integer and y:integer
description: (*
This is the specific Location to find the room.
*);
end Location;
object LabCapable is boolean
description: (*
This boolean tells us if the room is a lab room.
*);
end LabCapable;
object HandicapCapable is boolean
description: (*
This boolean tells us if the room is accessible for the handicapped.
*);
end HandicapCapable;
object Availability is AvailabilityBlock*
description: (*
This tells the scheduler when the room is available for scheduling.
*);
end Availability;
object AvailabilityBlock is TimeBlock and Day
description: (*
This tells the scheduler when the room is available for scheduling.
*);
end AvailabilityBlock;
object TimeBlock is start:Time and stop:Time
description: (*
This indicates the starting and stoping times of a timeblock.
*);
end TimeBlock;
object Resource is string
description: (* A resource which a room can include, such as a projector or
* VCR.
*);
end Resource;
object ScheduleDB is sl:ScheduleRecord*
description: (*
Contains a list of scheduled courses.
*);
end ScheduleDB;
object ScheduleRecord is
components: title:CourseTitle and sec:Section and is_lec:boolean and
is_lab:boolean and call_num:CallNum and instr_name:Name and instr_id:ID
and days:Days and lec_start:Time and lec_stop:Time and lec_rm:Room
and lab_start:Time and lab_stop:Time and lab_rm:Room
and is_locked:boolean;
description: (*
Each schedule record holds the information for a scheduled course.
*);
end ScheduleRecord;
object Section is integer
description: (*
This is an integer describing the which section of that
course is in the ScheduledRecord.
*);
end Section;
object CallNum is integer
description: (*
This is an integer describing the call number used to capture the course.
*);
end CallNum;
object Days is Day*
description: (*
This is a list of days.
*);
end Days;
object Day is mon:Monday or tue:Tuesday or wed:Wednesday or thu:Thursday
or fri:Friday
description: (*
The seven standard names of the days of the week.
*);
end Day;
object Monday
description: (* One of the five days of the school week. *);
end;
object Tuesday
description: (* One of the five days of the school week. *);
end;
object Wednesday
description: (* One of the five days of the school week. *);
end;
object Thursday
description: (* One of the five days of the school week. *);
end;
object Friday
description: (* One of the five days of the school week. *);
end;
object Time is hr:Hour and min:Minute and aorp:AmOrPm
description: (*
A Time consists of an hour, minute, and AM or PM indicator. A time
value is expressed using a 12-hour or 24-hour clock style. The clock
style is set as an option by the user. If the clock style is 24-hour,
the AmOrPm indicator is nil.
*);
end Time;
object Hour is integer
description: (*
The hour component of a time value, between 1 and 12 or 0 and 24 based
on the clock style in use.
*);
end Hour;
object Minute is integer
description: (*
The minute component of a time value, between 0 and 59.
*);
end Minute;
object AmOrPm is am:AM or pm:PM
description: (* Standard suffix used in 12-hour time value.
*);
end AmOrPm;
object AM
description: (* The 12-hour time suffix indicating a morning time. *);
end;
object PM
description: (* The 12-hour time suffix indicating an afternoon time. *);
end;
operation GenerateSchedule is
inputs: Workspace;
outputs: Workspace;
precondition: ;
postcondition: ;
description: (*
GenerateSchedule takes a workspace and creates a schedule which is
a database of schedule records.
*);
end GenerateSchedule;
operation NewClassroom is
inputs: cldb:ClassroomDB, cl:Classroom;
outputs: cldb':ClassroomDB;
description: (* This operation adds a classroom to the classroom database.
*);
precondition:
(*
There is no classroom in the ClassroomDB with the same room and
building number as the classroom to be added.
*)
(not(exists (cl' in cldb)((cl'.rm.rn = cl.rm.rn) and (cl'.rm.bn= cl.rm.bn))))
and
(* The room and building number fields are not empty. *)
((cl.rm.rn != nil) and (cl.rm.bn != nil));
postcondition:
(* The classroom is in the outputted ClassroomDB. *)
cldb' = cldb + cl;
end NewClassroom;
operation EditClassroom is
inputs: cldb:ClassroomDB, old_cr:Classroom, new_cr:Classroom;
outputs: cldb':ClassroomDB;
description: (* This operation edits a classroom in the classroom database.
*);
precondition: (*None Yet*);
postcondition:
(* The classroom is in the outputted ClassroomDB if and only if it is the
new record to be added or it is in the input db, and it is not the old
record.
*)
forall (cr':Classroom)
(cr' in cldb') iff (((cr' = new_cr) or (cr' in cldb)) and
(cr' != old_cr));
end EditClassroom;
operation DeleteClassroom is
inputs: cldb:ClassroomDB, cl:Classroom;
outputs: cldb':ClassroomDB;
description: (* This operation deletes a classroom in the classroom database.
*);
precondition:
(* The given classroom is in the given ClassroomDB. *)
cl in cldb;
postcondition:
(*
* A classroom is in the output db if and only if it is not the
* existing classroom to be deleted and it is in the input db.
*)
(forall (cl':Classroom)
(cl' in cldb') iff ((cl' != cl) and (cl' in cldb)));
end DeleteClassroom;
operation NewCourse is
inputs: cdb: CourseDB, course:Course;
outputs: cdb':CourseDB;
description: (* This operation adds a course to the course database.
*);
precondition: (* None *);
postcondition:
(* The course is in the outputted CourseDB. *)
cdb' = cdb + course;
end NewCourse;
operation EditCourse is
inputs: cdb: CourseDB, old_cr:Course, new_cr:Course;
outputs: cdb':CourseDB;
description: (* This operation edits a course in the course database.
*);
precondition: (*None Yet*);
postcondition:
(* The course is in the outputted courseDB. *)
forall (cr':Course)
(cr' in cdb') iff (((cr' = new_cr) or (cr' in cdb)) and
(cr' != old_cr));
end EditCourse;
operation DeleteCourse is
inputs:cdb: CourseDB, course:Course;
outputs: cdb':CourseDB;
description: (* This operation deletes a course in the course database.
*);
precondition:
(* The given course is in the given courseDB. *)
course in cdb;
postcondition:
(*
* A course is in the output db if and only if it is not the
* existing course to be deleted and it is in the input db.
*)
(forall (course':Course)
(course' in cdb') iff ((course' != course) and (course' in cdb)));
end DeleteCourse;
operation NewInstructor is
inputs: idb:InstructorDB, instructor:Instructor;
outputs: idb':InstructorDB;
description: (* This operation adds a new instructor to the instructor database.
*);
precondition:
(* There is no instructor in the InstructorDB with the same id as
the instructor to be added.
*)
(not(exists (instructor' in idb)(instructor'.id = instructor.id) ));
postcondition:
(* The instructor is in the outputted instructorDB. *)
idb' = idb + instructor;
end NewInstructor;
operation EditInstructor is
inputs: idb:InstructorDB, old_ir:Instructor, new_ir:Instructor;
outputs: idb':InstructorDB;
description: (* This operation edits an instructor in the instructor database.
*);
precondition: (*None Yet*);
postcondition:
(* The instructor is in the outputted InstructorDB. *)
forall (ir':Instructor)
(ir' in idb') iff (((ir' = new_ir) or (ir' in idb)) and
(ir' != old_ir));
end EditInstructor;
operation DeleteInstructor is
inputs: idb:InstructorDB, instructor:Instructor;
outputs: idb':InstructorDB;
description: (* This operation deletes an instructor in the instructor database.
*);
precondition:
(* The given instructor is in the inputted InstructorDB. *)
instructor in idb;
postcondition:
(*
* A instructor is in the output db if and only if it is not the
* existing instructor to be deleted and it is in the input db.
*)
(forall (instructor':Instructor)
(instructor' in idb') iff ((instructor' != instructor)
and (instructor' in idb)));
end DeleteInstructor;
object InstructorCoursePreferenceDB is InstructorCoursePreference*
description: (* A InstructorCoursePreferenceDB contains zero or more
InstructorCoursePreferences.
*);
end InstructorCoursePreferenceDB;
object InstructorCoursePreference is
components: instr_id:ID and and title:CourseTitle and rating:Rating and
tas:InstructorTimeArrangementPreference* and resources:Resource*;
description: (* Contains an instructor's rating for teaching ability of
* a course and a list of ratings for time arrangement
* preferences for the course
*);
end InstructorCoursePreference;
object InstructorTimeArrangementPreference is
components: ta:TimeArrangement, rating:Rating;
description: (* Associates an instructor's rating with a given time
* arrangement for a course
*);
end InstructorTimeArrangementPreference;
object InstructorTimePreferenceDB is InstructorTimePreference*
description: (* A InstructorTimePreferenceDB contains zero or more
InstructorTimePreferences.
*);
end InstructorTimePreferenceDB;
object InstructorTimePreference is instr_id:ID and availblocks:AvailBlock*
description: (* Contains a day and time for when an instructor is
* available to work.
*);
end InstructorTimePreference;
object AvailBlock is day:Day and open_times:TimeBlock*;
object Rating is integer
description: (*Rating is an integer form 0 to 5 based on the instructor's
likes/dislikes about a course or time.
*);
end Rating;
--John Azevedo's Section
object CourseView is title:CourseTitle and desc:Description and sections:integer
and is_lec:boolean and is_lab:boolean and units:Units and
wtus:WTUs;
object InstructorView is name:Name and deg:Degree and is_handicap:Handicapped;
object ClassroomView is room:Room and size:Size and loc:Location
and is_handicap:HandicapCapable and is_lab:LabCapable
and resources:Resource*;
object ScheduleView is crs:CourseTitle and sec:Section and call_num:CallNum
and is_lec:boolean
and is_lab:boolean and instr_name:Name and days:Days
and start:Time and stop:Time and rm:Room;
operation ViewCourses is
description: (* Creates a window which lists selected information about
* all courses in the course DB *);
inputs: cdb:CourseDB;
outputs: cvl':CourseView*;
precondition: (* none *);
postcondition:
forall (cs in cdb)
( exists (cv in cvl')
( cs.title = cv.title)
)
and #cdb = #cvl';
end ViewCourses;
operation ViewInstructors is
description: (* Creates a window which lists selected information about all
* the instructors in the instructor DB *);
inputs: idb:InstructorDB;
outputs: ivl':InstructorView*;
precondition: (* none *);
postcondition:
forall (inst in idb)
( exists (instv in ivl')
( inst.name = instv.name)
)
and #idb = #ivl';
end ViewCourses;
operation ViewClassrooms is
description: (* Creates a window which lists selected information about all
* the classrooms in the classrooms DB *);
inputs: crdb:ClassroomDB;
outputs: crvl':ClassroomView*;
precondition: (* none *);
postcondition:
forall (cr in crdb)
( exists (crv in crvl')
( cr.rm = crv.room)
)
and #crdb = #crvl';
end ViewCourses;
operation ViewSchedule is
description: (* Creates a window which lists selected information about all
* the scheduleRecords in the schedule DB *);
inputs: sdb:ScheduleDB;
outputs: svl':ScheduleView*;
precondition: (* none *);
postcondition:
forall (sch in sdb)
( exists (schv in svl')
( sch.call_num = schv.call_num)
)
and #sdb = #svl';
end ViewCourses;
operation AddInstructorCoursePreference is
inputs: InstrCrsPref:InstructorCoursePreference,
CPDB:InstructorCoursePreferenceDB, InstDB:InstructorDB,
CrseDB:CourseDB;
outputs: CPDB':InstructorCoursePreferenceDB;
description: (* Add a new InstructorCoursePreference to the
InstructorCoursePreferenceDB. This is done by the admins
and for each instructor in the InstructorDB, there are as
many InstructorCoursePreferences as there are courses. So a
complete InstuctorCoursePreferenceDB has
(size of the InstructorDB) x (size fo the CourseDB)
number of entries. *);
precondition:
exists (Instr in InstDB) (Instr.id = InstrCrsPref.instr_id) and
exists (Crs in CrseDB) (Crs.title = InstrCrsPref.title) and
not (exists(Pref in CPDB) (Pref.instr_id = InstrCrsPref.instr_id and
Pref.title = InstrCrsPref.title));
postcondition: CPDB' = CPDB + InstrCrsPref;
end AddInstructorCoursePreference;
operation EditInstructorCoursePreference is
inputs: CPDB:InstructorCoursePreferenceDB, old_CP:InstructorCoursePreference,
new_CP:InstructorCoursePreference;
outputs: CPDB':InstructorCoursePreferenceDB;
description:(* Edit an InstructorCoursePerference already in the
InstructorCoursePreferenceDB. Inputs the DB, the old
preference, and the new Preference. Outputs the new DB. *);
precondition: new_CP.instr_id = old_CP.instr_id
and new_CP.title = old_CP.title
and old_CP in CPDB;
postcondition: forall (p':InstructorCoursePreference) (p' in CPDB')
iff (((p' = new_CP) or (p' in CPDB)) and (p' != old_CP));
end EditInstructorCoursePreference;
operation AddInstructorTimePreference is
inputs: InstDB:InstructorDB, InstrTimePref:InstructorTimePreference,
IPDB:InstructorTimePreferenceDB;
outputs: IPDB':InstructorTimePreferenceDB;
description: (* Add a new InstructorTimePreference to the
InstructorTimePreferenceDB. This is done by the admins and
for each instructor in the InstructorDB, there are as many
InstructorTimePreferences as there are instructors. *);
precondition:
exists (Instr in InstDB) (Instr.id = InstrTimePref.instr_id) and
not (exists(Pref in IPDB) (Pref.instr_id = InstrTimePref.instr_id));
postcondition: IPDB' = IPDB + InstrTimePref;
end AddInstructorTimePreference;
operation EditInstructorTimePreference is
inputs: IPDB:InstructorTimePreferenceDB, old_IP:InstructorTimePreference,
new_IP:InstructorTimePreference;
outputs: IPDB':InstructorTimePreferenceDB;
description:(* Edit an InstructorTimePerference already in the
InstructorTimePreferenceDB. Inputs the DB, the old
preference, and the new Preference. Outputs the new DB.*);
precondition:
new_IP.instr_id = old_IP.instr_id
and old_IP in IPDB;
postcondition:
forall (p':InstructorTimePreference)
(p' in IPDB') iff (((p' = new_IP) or (p' in IPDB)) and (p' != old_IP));
end EditInstructorTimePreference;
--end John Azevedo's Section
end Databases;
Prev: edit rsl | Next: schedule rsl | Up: spec | Top: index