operation ViewGraph
    inputs: gb:Gradebook;
    outputs: gb':Gradebook;
    precondition: gb != nil; 
    postcondition: 
		(* Easygrader opens the graph window, by default is histogram *);
    description: 
		(*
        ViewGraph opens a graph window that has 2 tabs, one for pie chart, 
			and one for histogram.
   	 *);
end ViewGraph;

operation ViewHistogram
    inputs: gb:Gradebook, s:Section;
    outputs: h:Histogram, tmp:Student*, gb':Gradebook;
    precondition: ;
    postcondition: 
		(* Each histogrambar represents the students who recieved that score.	
			Changes in the Histogram are also reflected in the Gradebook and 
			Pie chart.
		 *)
	 forall (hb:HistogramBar) (hb in h.stars) iff 
		forall (st':Student|st' in s.students) ((st' in tmp) iff
			exists (sc':Score) (sc' in st'.scores 
				and sc'.associatedItem = gb.FinalGrade
				and sc'.pointsEarned = hb.percentage)) 
				and (hb.numberOfScores = #tmp);
	description: 
		(* 
     		ViewHistogram graphically displays the number of students who have 
			received a certain score, with visual +/- and color coded
     		thresholds. Each star represents
      	a student, and every row represents a grade.  
		*);
end ViewHistogram;

operation ViewPieChart
    inputs: gb:Gradebook, s:Section;
    outputs: p:PieChart,tmp:Student*, h:Histogram;
    precondition: ;
    postcondition: 
		(* Displays the grades, thresholds, and number of students per grade. 
			Affects the Gradebook and PieChart 
		 *)
		forall (sl:PieSlice) (sl in p.slices) iff
			forall(st':Student|st' in s.students) ((st' in tmp) iff
				exists (sc':Score) (sc' in st'.scores
					and sc'.associatedItem = gb.FinalGrade
					and sc'.pointsEarned = sl.percentage))
					and (sl.numberOfScores = #tmp); 
	description: 
		(* 
			ViewPieChart graphically displays the number of students who have received 
      	a certain score in pie slices and with a textual number. The thickness of the
      	slice represents the number of students, and each slice represents a certain grade.
		*);
end ViewPieChart;

operation ChangeThreshholds
	 inputs:gb:Gradebook, ot:Thresholds, nt:Thresholds;
	 outputs: gb':Gradebook, p:PieChart, h:Histogram;
	 precondition: 
		(* Thresholds must be less than or equal to 100, and must 
			be greater than 0
		*)
		ot.a_amThreshold >= ot.am_bpThreshold and 
		ot.am_bpThreshold >= ot.bp_bThreshold and 
		ot.bp_bThreshold >= ot.b_bmThreshold and 
		ot.b_bmThreshold >= ot.bm_cpThreshold and
		ot.bm_cpThreshold >= ot.cp_cThreshold and 
		ot.cp_cThreshold >= ot.c_cmThreshold and 
		ot.c_cmThreshold >= ot.cm_dpThreshold and 
		ot.cm_dpThreshold >= ot.dp_dThreshold and
		ot.dp_dThreshold >= ot.d_dmThreshold and 
		ot.d_dmThreshold >= ot.dm_fThreshold;
	 postcondition:
		(* Replace the old threshold. Also changes the values in the Pie
			Chart, Histogram, and Gradebook. Unknown description to
			describe the movement of slices or histograph bars.
		*)
        ot.a_amThreshold = nt.a_amThreshold and
		  ot.am_bpThreshold = nt.am_bpThreshold and 
        ot.bp_bThreshold = nt.bp_bThreshold and
        ot.b_bmThreshold = nt.b_bmThreshold and
        ot.bm_cpThreshold = nt.bm_cpThreshold and
        ot.cp_cThreshold = nt.cp_cThreshold and
        ot.c_cmThreshold = nt.c_cmThreshold and
        ot.cm_dpThreshold = nt.cm_dpThreshold and
        ot.dp_dThreshold = nt.dp_dThreshold and
        ot.d_dmThreshold = nt.d_dmThreshold and
        ot.dm_fThreshold = nt.dm_fThreshold; 
	description: 
		(* Changes the range of grades. Affects PieChart and Histogram*);
end ChangeThresholds;