(* * This file models, the databases: Instructor, course * and Room. *) module Database; from Time import TimePeriod; export all; (* RoomDatabase Start *) object RoomDatabase is components: room:Room*; description: (* The Room Database holds all the rooms that the computer science deparment can use.*); end RoomDatabase; object Room components:bldg:Building and num:Number and MapLocation and rt:RoomType and Availability* and Equipment; description:(* A Room is a Building Number, Room Number, Map Location, RoomType, the availabile times and Equipment.*); end Room; object Building components: string; description: (* This is the building number of the classroom. The reason it is not an integer is because, some Buildings are not Numbers they are a word. *); end Building; object Number is components: string; description: (* The room's number within the Building. This is object used for the classroom database as well. The room/course number is a string because there are courses/rooms with letters in them*); end Number; object MapLocation components:string; description: (* The location on a grided cal poly map. *); end MapLocation; object RoomType components: string; description: (* Room type is the type of Room it is It is a string because the user can create their own costume type of rooms.*); end RoomType; object Availability components: startTime:TimePeriod and endTime:TimePeriod and Preference; description: (* When the Room can or can not be used for the given time period. The availability preference starts at start time and ends at end time.*); end Availability; object Preference components: boolean; description:(* A preference is if the class is useable or not. This is associated with a timer period.*); end Preference; operation AddRoom inputs: rd:RoomDatabase, r:Room; outputs: rd':RoomDatabase; precondition: (* The new room to added is not in the database and number, building and Room type are not nill. *) (not (exists (r' in rd ) r'.num = r.num and r'.bldg = r.bldg)) and r.num != nil and r.bldg !=nil and r.rt != nil; postcondition: (* The record is in the database, and no other records were removed or added. *) forall (r':Room) (r' in rd') iff ((r' = r) or (r' in rd)); end AddRoom; operation EditRoom inputs: rd:RoomDatabase, old_r:Room, new_r:Room; outputs:rd':RoomDatabase; precondition: (* The room that is edited is in the database. Number , Room type and building are not nil *) (old_r != new_r) and (old_r in rd) and (not (exists (new_r' in rd) new_r'.num = new_r.num and new_r'.bldg = new_r.bldg)) and new_r.num != nil and new_r.bldg !=nil and new_r.rt != nil; postcondition: (* The edited room replaces the old room Also, no other records from the database have changed.*) forall(r':Room) (r' in rd') iff ((r' = new_r) or (r' in rd) and (r' != old_r)); end EditRoom; operation Remove inputs: rd:RoomDatabase, r:Room; outputs: rd':RoomDatabase; precondition:(* The room to be removed is in the database *) r in rd; postcondition: (* The record is removed from the database and no other records were removed or added *) (forall (r':Room) (r' in rd' ) iff ((r' != r ) and (r' in rd))); end Remove; (*Room Database End * *) (*Course Datbase start*) object CourseDatabase components: course*; description:(*Holds all the courses for the scheduling program*); end CourseDatabase; object course is components: p:prefix and n:Number and s:su and w:wu and sn:SectionNumber and ss:SectionsScheduled and lob:lecturelab and lb:LinkedLab and re:RequiredEquipement*; description:(* A course has the components prefix, Number, SU, WU , lecture/lab, linked lab, and required Equipment*); end course; object prefix is components: string; description: (*The prefix to a course *); end prefix; object su is components: integer; description:(* Student units for the class. *); end su; object wu is components:integer; description:(* WU Is the work unit for the course *); end wu; object SectionNumber components: integer; description:(* The number of sections for a given class. It is only used for a term database and the user does not see it in the database dialouge.*); end SectionNumber; object SectionsScheduled components: integer; description:(* The number of sections that are scheduled. This is used only for term databases and the user does not see it *); end SectionsScheduled; object lecturelab is components: courseType; description:(* Lecture lab is the type of course being taught. *); end lecturelab; object courseType is components:string; description:(* Course Type is a string with the type of course. If it is linked lab then, a value maybe entered into linked lab. *); end CourseType; object LinkedLab is components:string; description:(* The lab that is linked to a certain class.*); end LinkedLab; object RequiredEquipement is components: Equipment*; description:(* The needed Equipment for a given classRoom *); end RequiredEquipement; object Equipment is components: string; description: (* The equipment for a eoom or required for a course. *); end Equipment; operation AddCourse inputs: cd:CourseDatabase, c:course; outputs:cd':CourseDatabase; precondition:(* The new course is not in the database. Also, SU, WU, CourseType prefix and number are not nill *) (not (exists (c' in cd ) c'.n = c.n and c'.p = c.p)) and c.s != nil and c.w != nil and c.lob != nil and c.p != nil and c.n != nil; postcondition:(*The new course is in the database and no other records have changed*) forall (c':course) (c' in cd') iff ((c' = c) or (c' in cd)); end AddCourse; operation EditCourse inputs: cd:CourseDatabase, new_c:course,old_c:course; outputs:cd':CourseDatabase; precondition:(* The course that is to be edited is in the database. SU,WU, course type , prefix, number are not nill *) (old_c != new_c) and (old_c in cd) and (not (exists (c' in cd) c'.n = new_c.n and c'.p = new_c.p)) and new_c.s != nil and new_c.w != nil and new_c.lob != nil and new_c.p != nil and new_c.n != nil; postcondition: (* The edited course is changed and everythign else is the same *) forall(c':course) (c' in cd') iff ((c' = new_c) or (c' in cd) and (c' != old_c)); end EditCourse; operation RemoveCourse inputs: cd:CourseDatabase, c:course; outputs: cd':CourseDatabase; precondition: (* The course to be removed is in the database*) c in cd; postcondition:(* The course is no longer in the databse everything else is the same *) (forall (c':course) (c' in cd' ) iff ((c' != c ) and (c' in cd))); end RemoveCourse; (* Course Database end * *) object InstructorDatabase is components: teachers:Instructor*; description:(* Holds all the instructor records *); end InstructorDatabase; object Instructor is components: fn:Fname and ln:Lname and ph:Phone and em:Email and wtu:WTU and schWTU:ScheduledWTU and di:Disability and pref:Preferences and co:comments; description:(* A instructor is a first name, last name, phone, email, WTU, disablity, Preference and comments *); end Instructor; object Fname is components: string; description: (* The first name of a instructor *); end Fname; object Lname is components: string; description: (* The last name of the instructor *); end Lname; object Phone is components: string; description: (* The phone Number of a instructor *); end Phone; object Email is components: string; description: (* The instructor's email address *); end Email; object WTU is components: integer; description: (* The Number of units this instructor will work *); end WTU; object ScheduledWTU is components: integer; description: (*This is not shown to the user in the master or per term database. However, it is used for schedule generation.*); end ScheduledWTU; object Disability is components: boolean; description: (* Wheter the instructor is disabled or not *); end Disability; object Preferences is components: timePrefs:TimePreference* and coursePrefs:CoursePreference* and distPrefs:DistancePreference*; description: (* The Instructor preferece for distance, course and time *); end Preferences; object TimePreference is components: TimePeriod and PreferenceNumber; description: (*Time chunk and preference given*); end TimePreference; object CoursePreference is components: prefix and Number and PreferenceNumber; description: (*Course and preference given*); end CoursePreference; object DistancePreference is components: distance and PreferenceNumber; description: (*distance and preference given*); end DistancePreference; object PreferenceNumber components:integer; description:(* The preference number for a given preference *); end PreferenceNumber; object distance components: integer; description: (*How far a teacher wants to have between adjacent time slots.*); end distance; object comments is components: string; description: (* The commnets for a instructor such as they don't like Rooms with 3 windows *); end comments; operation AddInstructor inputs:id: InstructorDatabase, i:Instructor; outputs:id':InstructorDatabase; precondition:(*The given instructor is not in the database. Fname, Lname,WTU phone, and email is not nill *) (not (exists (i' in id ) i'.fn = i.fn and i'.ln = i.ln)) and i.ln != nil and i.fn !=nil and i.wtu != nil and i.ph != nil and i.em != nil; postcondition:(* The given instructor is in the database and everythign else is the same *) forall (i':Instructor) (i' in id') iff ((i' = i) or (i' in id)); end Addinstructor; operation EditInstructor inputs: id:InstructorDatabase,old_i:Instructor,new_i:Instructor; outputs:id':InstructorDatabase; precondition:(* The insturctor is in the database also, fname, lname, wtu, phone and email is not nill *) (old_i != new_i) and (old_i in id) and (not (exists (i' in id ) i'.fn = new_i.fn and i'.ln = new_i.ln)) and new_i.ln != nil and new_i.fn !=nil and new_i.wtu != nil and new_i.ph != nil and new_i.em != nil; postcondition:(* The instructor is changed in the database and eveyrthing else is the same *) forall(i':Instructor) (i' in id') iff ((i' = new_i) or (i' in id) and (i' != old_i)); end EditInstructor; operation RemoveInstructor inputs: id:InstructorDatabase,i:Instructor; outputs: id':InstructorDatabase; precondition:(* The instructor is in the database*) i in id; postcondition:(*The instructor is out of the database and everything else is the same *) (forall (i':Instructor) (i' in id' ) iff ((i' != i ) and (i' in id))); end RemoveInstructor; end Database;