// subGroups returns a list of subgroups to be analysed.
func subGroups(g group.Group) []subGroup {

	groups := []subGroup{}
	for _, def := range groupDefs {
		groups = append(groups, subGroup{def.Name, template.URL(def.Query), g.SubGroup(def.Filter)})
	}
	return groups
}
func subjectGrid(sheet *xlsx.Sheet, g group.Group, subj *subject.Subject, natYear string) {

	pg := g.ProgressGrid(subj, natYear)

	row := sheet.AddRow()
	row = sheet.AddRow()
	blankCell(row)
	newCell(row, "Progress Grid: "+subj.Subj, newStyle("Title", "None", "None", "Left"))

	row = sheet.AddRow()
	row = sheet.AddRow()
	blankCell(row)
	newCell(row, "KS2", newStyle("Bold", "None", "Bottom", "Left"))
	for _, grd := range pg.Grades {
		newCell(row, grd, newStyle("Bold", "None", "Bottom", "Center"))
	}
	newCell(row, "VA", newStyle("Bold", "None", "Bottom", "Center"))

	for i, ks2 := range pg.KS2 {
		row := sheet.AddRow()
		blankCell(row)
		newCell(row, ks2, newStyle("Bold", "None", "None", "Left"))
		for j := range pg.Grades {
			pgCell := pg.Cells[i][j]
			switch {
			case pg.CellVA[i][j] < -0.33:
				newInt(row, len(pgCell.Students), newStyle("Default", "Red", "None", "Center"))
			case pg.CellVA[i][j] > 0.67:
				newInt(row, len(pgCell.Students), newStyle("Default", "Green", "None", "Center"))
			default:
				newInt(row, len(pgCell.Students), newStyle("Default", "Yellow", "None", "Center"))
			}

		}
		newFloat(row, pg.RowVA[i], "+0.00;-0.00;0.00", newStyle("Default", "None", "None", "Center"))
	}

	row = sheet.AddRow()
	blankCell(row)
	newCell(row, "Total", newStyle("Bold", "None", "None", "None"))
	for i := range pg.Grades {
		newInt(row, pg.Counts[i], newStyle("Bold", "None", "None", "Center"))
	}
	newFloat(row, g.SubjectVA(subj.Subj).VA, "+0.00;-0.00;0.00", newStyle("Bold", "None", "None", "Center"))
}
// groupMatrix returns a 2-d list of subgroups.  Headers are used for
// both column and row headers
func groupMatrix(g group.Group) subGroupMatrix {

	headers := []string{}
	var groups [][]subGroup

	for i, def1 := range groupDefs[1:] {
		headers = append(headers, def1.Name)
		row := []subGroup{}
		for j, def2 := range groupDefs[1:] {
			switch {
			case i == j:
				row = append(row, subGroup{def1.Name, template.URL(def1.Query), g.SubGroup(def1.Filter)})
			default:
				row = append(row, subGroup{def1.Name + " & " + def2.Name, template.URL(def1.Query + def2.Query),
					g.SubGroup(def1.Filter, def2.Filter)})
			}
		}
		groups = append(groups, row)
	}

	return subGroupMatrix{headers, groups}
}