5.3. InstructorListing.rsl

module InstructorModule;

   from ScheduleModule import Schedule;

   export InstructorDB;    

   export Instructor;

   object Instructor is
      components: first:FirstName and last:LastName and wtu:WTU and alloted:AllotedWTU and seniority:Seniority and timeGen:TimeGenerosity and courseGen:CourseGenerosity and times:TimePref* and courses:CoursePref* and disabled:IsDisabled;
      description: (*
      An Instructor represents one faculty member that is used in scheduling classes. An Instructor has and first and last name, work time units, alloted units, a seniority level, time preferences, and course preferences.
      *);
   end Instructor;
	
   object FirstName is string;
   
   object LastName is string;
   
   object WTU is integer;

   object AllotedWTU is integer;

   object Seniority is integer;

   object TimeGenerosity is integer;
   
   object CourseGenerosity is integer;

   object IsDisabled is boolean;

   object TimePref is
      components: day:Day and time:HalfHourTime and choice:Choice;
      description: (*
         A TimePref is a rating of a time, Choice, for a given Time and Day.
      *);
   end TimePref;

   object Day is M or T or W or R or F or S or U;

   object HalfHourTime is string;

   object Choice is integer;
	
   object M;
   object T;
   object W;
   object R;
   object F;
   object S;
   object U;

   object CoursePref is
      components: num:CourseNum and rating:Rating and media:CourseMultimedia*;
      description: (*
         A CoursePref contains the Instructor's prefences to teach a given course.
      *);
   end CoursePref;

   object CourseNum is string;

   object Rating is integer;

   object CourseMultimedia is boolean;

   object LocalInstructor inherits from Instructor
      components: used:BeingUsed, schedule:InstructorSchedule;
      description: (*
         An instructor being used in a local database. It is just an instructor with an extra boolean to describe whether it is currently in use.
       *);
   end LocalInstructor;

   object BeingUsed is boolean;

   object InstructorSchedule inherits from Schedule
      description: (*
         Represents the schedule for a single instructor;
      *);
   end InstructorSchedule;

   object InstructorDB is
      components: Instructor*;
      description: (*
         The list of all instructors for a particular project.
      *);
   end InstructorDB;

   operation CreateInstructor is
      inputs: frst:FirstName, lst:LastName, units:WTU, allt:AllotedWTU, snr:Seniority, dsbl:IsDisabled;
      outputs: instruct':Instructor;
      preconditions:
         (snr <= 5) and (snr >= 0) and
         (allt < units) and (units > 0) and (allt > 0);

      postconditions:
         (instruct'.first = frst) and (instruct'.last = lst) and
         (instruct'.wtu = units) and (instruct'.alloted = allt) and
         (instruct'.disabled = dsbl);
      
      description : (*
         Checks the fields that are entered in to make sure they are valid entries, then creates a new Instructor based from them.
   *);
   end  CreateInstructor;

   operation AddInstructor is
      inputs: frst:FirstName, lst:LastName, units:WTU, allt:AllotedWTU, snr:Seniority, dsbl:IsDisabled, instruct:Instructor, insdb:InstructorDB;
      outputs: insdb':InstructorDB;
      preconditions:
         (instruct = CreateInstructor(frst, lst, units, allt, snr, dsbl)) and 
         not (exist(instruct' in insdb) ((instruct.first = instruct'.first) and (instruct.last = instruct'.last)));
      postconditions: 
         forall (instruct':Instructor) (instruct' in insdb') iff ((instruct' in insdb) or (instruct' = instruct));
      description: (*
         Inserts Instructor into InstructorDB.
      *);
   end AddInstructor;

   operation RemoveInstructor is
      inputs: instruct:Instructor, idb:InstructorDB;
      outputs: idb':InstructorDB;
      preconditions: (instruct in idb);
      postconditions: forall (ins' in idb) (ins' in idb') iff (ins' != instruct);
      description: (*
         Removes Instructor from InstructorDB.
      *);
   end RemoveInstructor;

   operation ChangeTimePrefs is
      inputs: insdb:InstructorDB, instruct:Instructor, prefs:TimePref*;
      outputs: insdb':InstructorDB;
      preconditions: 
         (forall(times in prefs) ((times.choice <= 5) and (times.choice >= 0))) and
         (instruct in insdb);
      postconditions: 
         (forall(inst' in insdb) (inst' in insdb') iff
         ((inst'.first != instruct.first) and (inst'.last != instruct.last))) and
         (instruct.times = prefs) and
         (instruct.timeGen = GetTimeGen(instruct.wtu - instruct.alloted, prefs)) and
         (instruct in insdb');
      description: (*
         Replace the instructor's time preferences with new preferences.
      *);
   end ChangeTimePrefs;

   operation ParseTimeString is
      inputs: timeString:string;
      outputs: days:Day*, times:HalfHourTime*;
      preconditions: ;
      postconditions: ;
      description: (*
         Parses out a string into Days and Times.
      *);
   end ParseTimeString;

   operation AdjustTime is
      inputs: prefs:TimePref*, days:Day*, times:HalfHourTime*, choice:Choice;
      outputs: prefs':TimePref*;
      preconditions: (*None*);
      postconditions: (forall (entry in prefs) (entry in prefs' iff (not((entry.day in days) and (entry.time in times))))) and (forall (day' in days) (forall (time' in times) (exists (entry' in prefs') ((entry'.day = day') and (entry'.time = time')))));
      description: (*
         Adjust the time preferences at TimeString to Choice.
      *);
   end AdjustTime;

   operation GetTimeGen is
      inputs: available:integer, prefs:TimePref*;
      outputs: gen:TimeGenerosity;
      preconditions: (*None*);
      postconditions:
    		   gen = ((SumTimes(prefs) / (2 * available)) - 1) * 100;
      description: (*
      *);
   end GetTimeGen;


   function SumTimes(prefs:TimePref*) =
      if (#prefs = 0) then 0
      else prefs[1].choice + SumTimes(prefs[2:#prefs]);

   operation ChangeCoursePrefs is
      inputs: insdb:InstructorDB, instruct:Instructor, prefs:CoursePref*;
      outputs: insdb':InstructorDB;
      preconditions: 
         (forall(courses in prefs) ((courses.rating <= 10) and (courses.rating >= 0))) and
         (instruct in insdb);
      postconditions: 
         (forall(inst' in insdb) (inst' in insdb') iff
         ((inst'.first != instruct.first) and (inst'.last != instruct.last))) and
         (instruct.courses = prefs) and (instruct.courseGen = GetCourseGen(prefs)) and
         (instruct in insdb');
      description: (*
         Replace the instructor's course preferences with new preferences.
      *);
   end ChangeCoursePrefs;

   operation GetCourseGen is
      inputs: prefs:CoursePref*;
      outputs: gen:CourseGenerosity;
      preconditions: (*None*);
      postconditions: 
    		   gen = (SumCourses(prefs) / (#prefs * 10)) * 100;
      description: (*
      *);
   end GetCourseGen;

   function SumCourses(prefs:CoursePref*) =
      if (#prefs = 0) then 0
      else prefs[1].rating + SumCourses(prefs[2:#prefs]);

   operation ChangeGeneralPrefs is
      inputs: insdb:InstructorDB, instruct:Instructor, frst:FirstName, lst:LastName, units:WTU, allt:AllotedWTU, snr:Seniority, dsbl:IsDisabled;
      outputs: instruct':Instructor, insdb':InstructorDB; 
      preconditions: 
         (#frst != 0) and (#lst != 0) and
         (snr <= 5) and (snr >= 0) and
         (allt < units) and (units > 0) and (allt > 0) and
         (instruct in insdb);
      postconditions: 
         ((forall(inst' in insdb) (inst' in insdb') iff (inst' != instruct)) and
         (instruct'.first = frst) and (instruct'.last = lst) and (instruct'.wtu = units) and
         (instruct'.alloted = allt) and (instruct'.seniority = snr) and (instruct'.disabled = dsbl) and (instruct'.timeGen = instruct.timeGen) and (instruct'.courseGen = instruct.courseGen) and (instruct'.times = instruct.times) and (instruct'.courses = instruct.courses) and (instruct' in insdb'));
      description: (*
         Replace the instructor's general settings with new settings.
      *);
   end ChangeGeneralPrefs;

end InstructorModule;

Prev: Schedule.rsl | Next: CourseListing.rsl | Up: Specification | Top: index