Skip to content

Commit

Permalink
Timetable Grid: MWF/TTh days, room type filter
Browse files Browse the repository at this point in the history
- added ability to show Monday - Wednesday - Friday or Tuesday - Thursday days only
- added ability to filter rooms by type, using type term (e.g., type:classrooms)
  • Loading branch information
tomas-muller committed Feb 17, 2016
1 parent 1f5cea3 commit d41d5c0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
5 changes: 5 additions & 0 deletions JavaSource/org/unitime/timetable/solver/TimetableSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@
import org.unitime.timetable.model.Department;
import org.unitime.timetable.model.DepartmentalInstructor;
import org.unitime.timetable.model.Location;
import org.unitime.timetable.model.RoomType;
import org.unitime.timetable.model.Solution;
import org.unitime.timetable.model.SolverGroup;
import org.unitime.timetable.model.TimePattern;
import org.unitime.timetable.model.dao.DatePatternDAO;
import org.unitime.timetable.model.dao.DepartmentalInstructorDAO;
import org.unitime.timetable.model.dao.LocationDAO;
import org.unitime.timetable.model.dao.RoomTypeDAO;
import org.unitime.timetable.model.dao.SolutionDAO;
import org.unitime.timetable.model.dao.SolverGroupDAO;
import org.unitime.timetable.model.dao.TimePatternDAO;
Expand Down Expand Up @@ -673,6 +675,9 @@ public boolean match(String attr, String term) {
return rc.getName().matches(term);
} else if ("find".equals(attr)) {
return rc.getName().toLowerCase().indexOf(term.toLowerCase()) >= 0;
} else if ("type".equals(attr) && rc.getType() != null) {
RoomType type = RoomTypeDAO.getInstance().get(rc.getType());
return type != null && (term.equalsIgnoreCase(type.getReference()) || term.equalsIgnoreCase(type.getLabel()));
} else if ("size".equals(attr)) {
int min = 0, max = Integer.MAX_VALUE;
Size prefix = Size.eq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void export(OutputStream out) throws Exception {

if (iTable.isDispModeInRow()) {
for (iDay=iTable.startDay();iDay<=iTable.endDay();iDay++) {
if (iTable.skipDay(iDay)) continue;
int rowNumber=0;
for (Enumeration e = iTable.models().elements(); e.hasMoreElements(); rowNumber++) {
printToPdf((TimetableGridModel)e.nextElement(),rowNumber);
Expand Down Expand Up @@ -345,6 +346,7 @@ public void printToPdf(TimetableGridModel model, int rowNumber) throws Exception
}
} else if (iTable.isDispModePerWeekHorizontal()) {
for (int day=iTable.startDay();day<=iTable.endDay();day++) {
if (iTable.skipDay(day)) continue;
int maxIdx = model.getMaxIdxForDay(day,iTable.firstSlot(),iTable.lastSlot());
for (int idx=0;idx<=maxIdx;idx++) {
PdfPCell c = createCell();
Expand Down Expand Up @@ -412,7 +414,7 @@ public void printToPdf(TimetableGridModel model, int rowNumber) throws Exception
int date = d + iTable.iFirstDay;
if (model.getFirstDay() >= 0 && (date < model.getFirstDay() || date > model.getFirstDay() + 6)) continue;
int day = d % 7;
if (day < iTable.startDay() || day > iTable.endDay()) continue;
if (day < iTable.startDay() || day > iTable.endDay() || iTable.skipDay(day)) continue;
boolean hasClasses = false;
for (int slot=iTable.firstSlot();slot<=iTable.lastSlot();slot++) {
if (model.getCell(day, slot, 0, date) != null) {
Expand Down Expand Up @@ -478,6 +480,7 @@ public void printToPdf(TimetableGridModel model, int rowNumber) throws Exception
}
} else { //isDispModePerWeekVertical
for (int day=iTable.startDay();day<=iTable.endDay();day++) {
if (iTable.skipDay(day)) continue;
int maxIdx = model.getMaxIdxForDay(day,iTable.firstSlot(),iTable.lastSlot());
for (int idx=0;idx<=maxIdx;idx++) {
PdfPCell c = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public TimetableGridContext(TimetableGridTable table, Session session) {
iLastSlot = table.lastSlot();
iDayCode = 0;
for (int day = table.startDay(); day <= table.endDay(); day ++)
iDayCode += Constants.DAY_CODES[day];
if (!table.skipDay(day))
iDayCode += Constants.DAY_CODES[day];
iPattern = dp.getPatternBitSet();
iNrWeeks = dp.getEffectiveNumberOfWeeks();

Expand All @@ -73,14 +74,14 @@ public TimetableGridContext(TimetableGridTable table, Session session) {
daysInWeek[dow] ++;
}
}
float weekDays = 1f / (table.endDay() - table.startDay() + 1);
float weekDays = 1f / table.nrDays();
if (weekDays >= 0.2f) {
iNrWeeks = weekDays * nrDays;
} else {
iNrWeeks = 0.2f * (daysInWeek[0] + daysInWeek[1] + daysInWeek[2] + daysInWeek[3] + daysInWeek[4]);
}
}
iSlotsPerWeek = (iLastSlot - iFirstSlot + 1) * (table.endDay() - table.startDay() + 1);
iSlotsPerWeek = (iLastSlot - iFirstSlot + 1) * table.nrDays();
}

public String getFilter() { return iFilter; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class TimetableGridTable {
public static final int sDaysSun = 8;
public static final int sDaysMonThu = 9;
public static final int sDaysFriSat = 10;
public static final int sDaysMWF = 11;
public static final int sDaysTTh = 12;
public static String[] sDays = new String[] {
"All",
"All except Weekend",
Expand All @@ -86,7 +88,9 @@ public class TimetableGridTable {
"Saturday",
"Sunday",
"Monday - Thursday",
"Friday & Saturday"
"Friday & Saturday",
"Monday, Wednesday, Friday",
"Tuesday, Thursday",
};
public static final int sDispModeInRow = 0;
public static final int sDispModePerWeekHorizontal = 1;
Expand Down Expand Up @@ -283,6 +287,8 @@ public int startDay() {
case sDaysSun : return 6;
case sDaysMonThu: return 0;
case sDaysFriSat : return 4;
case sDaysMWF: return 0;
case sDaysTTh: return 1;
default : return 0;
}
}
Expand All @@ -300,8 +306,32 @@ public int endDay() {
case sDaysSun : return 6;
case sDaysMonThu: return 3;
case sDaysFriSat : return 5;
case sDaysMWF: return 4;
case sDaysTTh: return 3;
default : return 4;
}
}
}

public boolean skipDay(int day) {
switch (iDays) {
case sDaysMWF:
return day == 1 || day == 3;
case sDaysTTh:
return day == 2;
default:
return false;
}
}

public int nrDays() {
switch (iDays) {
case sDaysMWF:
return 3;
case sDaysTTh:
return 2;
default:
return endDay() - startDay() + 1;
}
}

/*
Expand Down Expand Up @@ -365,13 +395,15 @@ else if (model.getSize() > 0)
out.println("</th>");
if (isDispModePerWeekVertical()) {
for (int day=startDay(); day<=endDay(); day++) {
if (skipDay(day)) continue;
boolean eol = (day==endDay());
out.println("<th colspan='"+(1+model.getMaxIdxForDay(day,firstSlot(),lastSlot()))+"'class='TimetableHeadCellVertical"+(eol?"EOL":"")+"'>");
out.println(Constants.DAY_NAME[day]);
out.println("</th>");
}
} else { //isDispModeInRow() || isDispModePerWeekVertical()
for (int day=startDay();(isDispModeInRow() && day<=endDay()) || (isDispModePerWeek() && day==startDay());day++) {
if (skipDay(day)) continue;
for (int slot=firstSlot();slot<=lastSlot();slot+=nrSlotsPerPeriod()) {
int time = slot*Constants.SLOT_LENGTH_MIN + Constants.FIRST_SLOT_TIME_MIN;
boolean eod = (slot+nrSlotsPerPeriod()-1==lastSlot());
Expand Down Expand Up @@ -437,6 +469,7 @@ else if (model.getSize() > 0)
if (idx>0)
out.println("</tr><tr valign='top'>");
for (int day=startDay();day<=endDay();day++) {
if (skipDay(day)) continue;
for (int slot=firstSlot();slot<=lastSlot();slot++) {
int slotsToEnd = lastSlot()-slot+1;
TimetableGridCell cell = model.getCell(day,slot,idx);
Expand Down Expand Up @@ -500,6 +533,7 @@ else if (model.getSize() > 0)
}
} else if (isDispModePerWeekHorizontal()) {
for (int day=startDay();day<=endDay();day++) {
if (skipDay(day)) continue;
if (day>startDay())
out.println("</tr><tr valign='top'>");
int maxIdx = model.getMaxIdxForDay(day,firstSlot(),lastSlot());
Expand Down Expand Up @@ -579,7 +613,7 @@ else if (model.getSize() > 0)
int date = d + iFirstDay;
if (model.getFirstDay() >= 0 && (date < model.getFirstDay() || date > model.getFirstDay() + 6)) continue;
int day = d % 7;
if (day < startDay() || day > endDay()) continue;
if (day < startDay() || day > endDay() || skipDay(day)) continue;
boolean hasClasses = false;
for (int slot=firstSlot();slot<=lastSlot();slot++) {
if (model.getCell(day, slot, 0, date) != null) {
Expand Down Expand Up @@ -671,6 +705,7 @@ else if (model.getSize() > 0)
out.println("<th class='TimetableHeadCellInVertical'>&nbsp;</th>");
}
for (int day=startDay();day<=endDay();day++) {
if (skipDay(day)) continue;
int maxIdx = model.getMaxIdxForDay(day,firstSlot(),lastSlot());
for (int idx=0;idx<=maxIdx;idx++) {
TimetableGridCell cell = model.getCell(day,slot, idx);
Expand Down Expand Up @@ -782,6 +817,8 @@ public boolean match(String attr, String term) {
return location.getLabel().matches(term);
} else if ("find".equals(attr)) {
return location.getLabel().toLowerCase().indexOf(term.toLowerCase()) >= 0;
} else if ("type".equals(attr)) {
return term.equalsIgnoreCase(location.getRoomType().getReference()) || term.equalsIgnoreCase(location.getRoomType().getLabel());
} else if ("size".equals(attr)) {
int min = 0, max = Integer.MAX_VALUE;
Size prefix = Size.eq;
Expand Down

0 comments on commit d41d5c0

Please sign in to comment.