Skip to content

Commit

Permalink
gwt: Display separate tables for team and individual results.
Browse files Browse the repository at this point in the history
  • Loading branch information
calin-iorgulescu committed Feb 10, 2015
1 parent 83868d9 commit 0ebec6a
Show file tree
Hide file tree
Showing 16 changed files with 227 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ro.pub.cs.vmchecker.client.i18n;

import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.Constants;

public interface StatisticsConstants extends Constants {

String title();
String noSubmissionAvailable();
String teams();
String individual();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
title = General results
noSubmissionAvailable = No submissions have yet been made for this course
teams = Teams
individual = Individual
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
title = Résultats
noSubmissionAvailable = Aucune solution n'a été envoyée pour ce cours
teams = Équipes
individual = Individuel
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
title = Rezultate generale
noSubmissionAvailable = Încă nu au fost trimise soluții pentru acest curs
teams = Echipe
individual = Individual
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,4 @@ public interface VmcheckerConstants extends Constants,
String exceptionError();
String exceptionErrorText();
String exceptionErrorContent();

String statisticsTitle();
String statisticsNoSubmissionAvailable();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ exceptionErrorText = Unhandled exception
exceptionErrorContent = Exception Stack Trace

popupCloseButton = close

statisticsTitle = General results
statisticsNoSubmissionAvailable = No submissions have yet been made for this course
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ exceptionErrorText = Unhandled exception
exceptionErrorContent = Exception Stack Trace

popupCloseButton = fermer

statisticsTitle = Résultats
statisticsNoSubmissionAvailable = Aucune solution n'a été envoyée pour ce cours
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ exceptionErrorText = Unhandled exception
exceptionErrorContent = Exception Stack Trace

popupCloseButton = închide

statisticsTitle = Rezultate generale
statisticsNoSubmissionAvailable = Încă nu au fost trimise soluții pentru acest curs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ro.pub.cs.vmchecker.client.model;

import java.util.HashMap;

public class ResultInfo {

public enum OwnerType {
USER,
TEAM
};

public OwnerType owner;
public String name;
public HashMap<String, String> results;

public ResultInfo(OwnerType owner, String name, HashMap<String, String> results) {
this.owner = owner;
this.name = name;
this.results = results;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ro.pub.cs.vmchecker.client.presenter;

import java.util.ArrayList;

import ro.pub.cs.vmchecker.client.i18n.VmcheckerConstants;
import ro.pub.cs.vmchecker.client.event.StatusChangedEvent;
import ro.pub.cs.vmchecker.client.model.Assignment;
import ro.pub.cs.vmchecker.client.model.EvaluationResult;
import ro.pub.cs.vmchecker.client.model.StudentInfo;
import ro.pub.cs.vmchecker.client.model.ResultInfo;
import ro.pub.cs.vmchecker.client.model.User;
import ro.pub.cs.vmchecker.client.service.HTTPService;

Expand All @@ -19,11 +21,40 @@
public class StatisticsPresenter implements Presenter {

public interface Widget {
HTMLTable getTable();
void displayInfo(User user, Assignment[] assignments, StudentInfo[] studentInfo);
HTMLTable getTeamTable();
HTMLTable getStudentTable();
void displayInfo(User user, Assignment[] assignments, ResultInfo[] teamResultInfo, ResultInfo[] studentResultInfo);
void displayResultDetails(String htmlDetails);
}

private class TableClickHandler implements ClickHandler {
final HTMLTable table;
final ResultInfo[] resultsInfo;

public TableClickHandler(HTMLTable table, ResultInfo[] resultsInfo) {
this.table = table;
this.resultsInfo = resultsInfo;
}

@Override
public void onClick(ClickEvent event) {
HTMLTable.Cell cell = this.table.getCellForEvent(event);
if (cell != null) {
GWT.log("Click for cell " + cell, null);
ResultInfo resultInfo = this.resultsInfo[cell.getRowIndex() - 1];
String assignmentId = assignments[cell.getCellIndex() - 1].id;
if (resultInfo.results.containsKey(assignmentId)) {
if (resultInfo.owner == ResultInfo.OwnerType.USER) {
loadAndShowUserResultDetails(assignmentId, resultInfo.name);
} else {
loadAndShowTeamResultDetails(assignmentId, resultInfo.name);
}
}
}
}
}


private HandlerManager eventBus;
private HTTPService service;
private static VmcheckerConstants constants = GWT
Expand All @@ -34,7 +65,7 @@ public interface Widget {
private String courseId;
private User user;
private Assignment[] assignments;
private StudentInfo[] studentsInfo;
private ResultInfo[] teamResultsInfo, studentResultsInfo;

public StatisticsPresenter(HandlerManager eventBus, HTTPService service,
String courseId, User user, Assignment[] assignments, StatisticsPresenter.Widget widget) {
Expand All @@ -44,35 +75,44 @@ public StatisticsPresenter(HandlerManager eventBus, HTTPService service,
this.assignments = assignments;
this.user = user;
bindWidget(widget);
listenTableEvents();
}

private void listenTableEvents() {
widget.getTable().addClickHandler(new ClickHandler() {
widget.getTeamTable().addClickHandler(new TableClickHandler(widget.getTeamTable(), teamResultsInfo));
widget.getStudentTable().addClickHandler(new TableClickHandler(widget.getStudentTable(), studentResultsInfo));
}

private void loadAndShowTeamResultDetails(String assignmentId, String teamname) {
eventBus.fireEvent(new StatusChangedEvent(StatusChangedEvent.StatusType.ACTION,
constants.loadResults()));
service.getTeamResults(courseId, assignmentId, teamname, new AsyncCallback<EvaluationResult[]> () {

@Override
public void onClick(ClickEvent event) {
HTMLTable.Cell cell = widget.getTable().getCellForEvent(event);
if (cell != null) {
StudentInfo studentInfo = studentsInfo[cell.getRowIndex() - 1];
String assignmentId = assignments[cell.getCellIndex() - 1].id;
if (studentInfo.results.containsKey(assignmentId)) {
loadAndShowResultDetails(assignmentId, studentInfo.id);
}
public void onFailure(Throwable caught) {
GWT.log("StatisticsPresenter.loadAndShowTeamResultDetails()", caught);
}

@Override
public void onSuccess(EvaluationResult[] result) {
eventBus.fireEvent(new StatusChangedEvent(StatusChangedEvent.StatusType.RESET, null));
String resultsHTML = "";
for (int i = 0; i < result.length; i++) {
resultsHTML += result[i].toHTML();
}
widget.displayResultDetails(resultsHTML);
}

});
}

private void loadAndShowResultDetails(String assignmentId, String username) {
private void loadAndShowUserResultDetails(String assignmentId, String username) {
eventBus.fireEvent(new StatusChangedEvent(StatusChangedEvent.StatusType.ACTION,
constants.loadResults()));
service.getUserResults(courseId, assignmentId, username, new AsyncCallback<EvaluationResult[]> () {

@Override
public void onFailure(Throwable caught) {
GWT.log("StatisticsPresenter.loadAndShowResultDetails()", caught);
GWT.log("StatisticsPresenter.loadAndShowUserResultDetails()", caught);
}

@Override
Expand All @@ -97,23 +137,43 @@ public void clearEventHandlers() {

}

private void processResults(ResultInfo[] resultsInfo) {
ArrayList<ResultInfo> teamResults = new ArrayList<ResultInfo>();
ArrayList<ResultInfo> studentResults = new ArrayList<ResultInfo>();
for (ResultInfo result : resultsInfo) {
if (result.owner == ResultInfo.OwnerType.USER) {
studentResults.add(result);
}

if (result.owner == ResultInfo.OwnerType.TEAM) {
teamResults.add(result);
}
}

teamResultsInfo = new ResultInfo[teamResults.size()];
teamResultsInfo = teamResults.toArray(teamResultsInfo);
studentResultsInfo = new ResultInfo[studentResults.size()];
studentResultsInfo = studentResults.toArray(studentResultsInfo);
}

@Override
public void go(final HasWidgets container) {
this.container = container;
eventBus.fireEvent(new StatusChangedEvent(StatusChangedEvent.StatusType.ACTION,
constants.loadStatistics()));
service.getAllResults(courseId, new AsyncCallback<StudentInfo[]>() {
service.getAllResults(courseId, new AsyncCallback<ResultInfo[]>() {

@Override
public void onFailure(Throwable caught) {
GWT.log("StatisticsPresenter.getAllResults()", caught);
}

@Override
public void onSuccess(StudentInfo[] result) {
public void onSuccess(ResultInfo[] result) {
container.clear();
studentsInfo = result;
widget.displayInfo(user, assignments, result);
processResults(result);
listenTableEvents();
widget.displayInfo(user, assignments, teamResultsInfo, studentResultsInfo);
container.add((com.google.gwt.user.client.ui.Widget) widget);
eventBus.fireEvent(new StatusChangedEvent(StatusChangedEvent.StatusType.RESET, null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import ro.pub.cs.vmchecker.client.model.EvaluationResult;
import ro.pub.cs.vmchecker.client.model.Md5Status;
import ro.pub.cs.vmchecker.client.model.FileList;
import ro.pub.cs.vmchecker.client.model.StudentInfo;
import ro.pub.cs.vmchecker.client.model.ResultInfo;
import ro.pub.cs.vmchecker.client.service.json.AssignmentsListDecoder;
import ro.pub.cs.vmchecker.client.service.json.AuthenticationResponseDecoder;
import ro.pub.cs.vmchecker.client.service.json.CoursesListDecoder;
Expand All @@ -28,6 +28,7 @@ public class HTTPService {
public static String VMCHECKER_SERVICES_URL = computeServicesURL();
public static String GET_COURSES_URL = VMCHECKER_SERVICES_URL + "getCourses";
public static String GET_ASSIGNMENTS_URL = VMCHECKER_SERVICES_URL + "getAssignments";
public static String GET_TEAM_RESULTS_URL = VMCHECKER_SERVICES_URL + "getTeamResults";
public static String GET_USER_RESULTS_URL = VMCHECKER_SERVICES_URL + "getUserResults";
public static String GET_UPLOADED_MD5_URL = VMCHECKER_SERVICES_URL + "getUploadedMd5";
public static String GET_ALL_RESULTS_URL = VMCHECKER_SERVICES_URL + "getAllGrades";
Expand Down Expand Up @@ -117,9 +118,21 @@ public void getUserResults(String courseId, String assignmentId, String username
delegate.sendRequest(callback, new ResultDecoder(), params);
}

public void getAllResults(String courseId, final AsyncCallback<StudentInfo[]> callback) {
Delegate<StudentInfo[]> delegate =
new Delegate<StudentInfo[]>(eventBus, GET_ALL_RESULTS_URL, true, false);
public void getTeamResults(String courseId, String assignmentId, String teamname,
final AsyncCallback<EvaluationResult[]> callback) {
Delegate<EvaluationResult[]> delegate =
new Delegate<EvaluationResult[]>(eventBus, GET_TEAM_RESULTS_URL, true, true);
HashMap<String, String> params = new HashMap<String, String>();
params.put("courseId", courseId);
params.put("assignmentId", assignmentId);
params.put("teamname", teamname);
delegate.sendRequest(callback, new ResultDecoder(), params);
}


public void getAllResults(String courseId, final AsyncCallback<ResultInfo[]> callback) {
Delegate<ResultInfo[]> delegate =
new Delegate<ResultInfo[]>(eventBus, GET_ALL_RESULTS_URL, true, false);
HashMap<String, String> params = new HashMap<String, String>();
params.put("courseId", courseId);
delegate.sendRequest(callback, new StatisticsDecoder(), params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;

import ro.pub.cs.vmchecker.client.model.StudentInfo;
import ro.pub.cs.vmchecker.client.model.ResultInfo;

public final class StatisticsDecoder extends JSONDecoder<StudentInfo[]> {
public final class StatisticsDecoder extends JSONDecoder<ResultInfo[]> {

private static final String nameKey = "studentName";
private static final String idKey = "studentId";
private static final String ownerKey = "gradeOwner";
private static final String nameKey = "name";
private static final String resultsKey = "results";

@Override
protected StudentInfo[] decode(String text) {
protected ResultInfo[] decode(String text) {
JSONValue jsonValue = JSONParser.parse(text);
JSONArray jsonArray = jsonValue.isArray();
StudentInfo[] result = new StudentInfo[jsonArray.size()];
JSONArray jsonArray = jsonValue.isArray();
ResultInfo[] results = new ResultInfo[jsonArray.size()];
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject studentObj = jsonArray.get(i).isObject();
String owner = studentObj.get(ownerKey).isString().stringValue();
String name = studentObj.get(nameKey).isString().stringValue();
String id = studentObj.get(idKey).isString().stringValue();
HashMap<String, String> assignmentsResults = new HashMap<String, String>();
JSONObject resultsObj = studentObj.get(resultsKey).isObject();
HashMap<String, String> assignmentsResults = new HashMap<String, String>();
JSONObject resultsObj = studentObj.get(resultsKey).isObject();
for (String assignmentId : resultsObj.keySet()) {
assignmentsResults.put(assignmentId, resultsObj.get(assignmentId).isString().stringValue());
assignmentsResults.put(assignmentId, resultsObj.get(assignmentId).isString().stringValue());
}
result[i] = new StudentInfo(name, id, assignmentsResults);
results[i] = new ResultInfo(ResultInfo.OwnerType.valueOf(owner.toUpperCase()), name, assignmentsResults);
}
return result;

return results;
}

}
Loading

0 comments on commit 0ebec6a

Please sign in to comment.