use of com.remswork.project.alice.model.Activity in project classify-system by anverliedoit.
the class ActivityResource method getActivityById.
@GET
@Path("{activityId}")
public Response getActivityById(@PathParam("activityId") long id) {
try {
ActivityResourceLinks resourceLinks = new ActivityResourceLinks(uriInfo);
ClassResourceLinks classResourceLinks = new ClassResourceLinks(uriInfo);
Activity activity = activityService.getActivityById(id);
activity.addLink(resourceLinks.self(id));
if (activity.get_class() != null)
activity.get_class().addLink(classResourceLinks.self(activity.get_class().getId()));
return Response.status(Response.Status.OK).entity(activity).build();
} catch (GradingFactorException e) {
e.printStackTrace();
Message message = new Message(404, "Not Found", e.getMessage());
return Response.status(Response.Status.NOT_FOUND).entity(message).build();
}
}
use of com.remswork.project.alice.model.Activity in project classify-system by anverliedoit.
the class ActivityResource method updateActivityById.
@PUT
@Path("{activityId}")
public Response updateActivityById(@PathParam("activityId") long id, Activity newActivity) {
try {
ActivityResourceLinks resourceLinks = new ActivityResourceLinks(uriInfo);
ClassResourceLinks classResourceLinks = new ClassResourceLinks(uriInfo);
Activity activity;
if (termId > 0)
activity = activityService.updateActivityById(id, newActivity, classId, termId);
else
activity = activityService.updateActivityById(id, newActivity, classId);
activity.addLink(resourceLinks.self(activity.getId()));
if (activity.get_class() != null)
activity.get_class().addLink(classResourceLinks.self(activity.get_class().getId()));
return Response.status(Response.Status.OK).entity(activity).build();
} catch (GradingFactorException e) {
e.printStackTrace();
Message message = new Message(400, "Bad Request", e.getMessage());
return Response.status(Response.Status.BAD_REQUEST).entity(message).build();
}
}
use of com.remswork.project.alice.model.Activity in project classify-system by anverliedoit.
the class ActivityServiceImpl method getActivityListByClassId.
@Override
public List<Activity> getActivityListByClassId(final long classId) throws GradingFactorException {
final List<Activity> activityList = new ArrayList<>();
try {
return new AsyncTask<String, List<Activity>, List<Activity>>() {
@Override
protected List<Activity> doInBackground(String... args) {
try {
String link = "".concat(domain).concat("/").concat(baseUri).concat("/").concat(payload).concat("?classId=").concat(String.valueOf(classId));
URL url = new URL(link);
Gson gson = new Gson();
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("GET");
httpURLConnection.setRequestProperty("Content-Type", "application/json");
httpURLConnection.setRequestProperty("Accept", "application/json");
httpURLConnection.connect();
if (httpURLConnection.getResponseCode() == 200) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
JSONArray jsonArray = new JSONArray(jsonData);
for (int ctr = 0; ctr < jsonArray.length(); ctr++) {
activityList.add(gson.fromJson(jsonArray.get(ctr).toString(), Activity.class));
}
return activityList;
} else if (httpURLConnection.getResponseCode() == 404) {
InputStream inputStream = httpURLConnection.getInputStream();
String jsonData = "";
int data;
while ((data = inputStream.read()) != -1) {
jsonData += (char) data;
}
Message message = gson.fromJson(jsonData, Message.class);
Log.i("ServiceTAG", "Service : Activity");
Log.i("ServiceTAG", "Status : " + message.getStatus());
Log.i("ServiceTAG", "Type : " + message.getType());
Log.i("ServiceTAG", "Message : " + message.getMessage());
return activityList;
} else
throw new GradingFactorException("Server Error");
} catch (GradingFactorException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
}.execute((String) null).get();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
} catch (ExecutionException e) {
e.printStackTrace();
return null;
}
}
use of com.remswork.project.alice.model.Activity in project classify-system by anverliedoit.
the class ActivityInputActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_z_input_activity);
init();
buttonSubmit.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
final long classId = getIntent().getExtras().getLong("classId");
try {
Activity activity = new Activity();
activity.setTitle(!editTextName.getText().toString().trim().isEmpty() ? editTextName.getText().toString().trim() : "Activity");
activity.setDate(textViewDate.getText().toString());
if (editTextTotal.getText().toString().equals("")) {
toggleButtonhideandshow.setChecked(false);
getDialogEmptyTotal.setVisibility(View.VISIBLE);
recyclerViewStudentInput.setVisibility(View.GONE);
return;
} else {
activity.setItemTotal(Integer.parseInt(editTextTotal.getText().toString()));
}
studentAdapter.setTotalItem(activity.getItemTotal());
studentAdapter.onValidate(true);
if (studentAdapter.isNoError()) {
// Add then compute the grade
activity = activityService.addActivity(activity, classId, 1L);
// List of student
for (int i = 0; i < studentList.size(); i++) {
// Student id
final long studentId = studentList.get(i).getId();
//
int score = studentAdapter.getScore(i);
Student student = studentList.get(i);
activityService.addActivityResult(score, activity.getId(), student.getId());
// Adding Grade for activity
new Thread(new Runnable() {
@Override
public void run() {
try {
final List<Activity> activityList = activityService.getActivityListByClassId(classId);
final double[] fActivity = new double[activityList.size()];
final long sId = studentId;
double tempTotal = 0;
try {
List<Grade> tempList = gradeService.getGradeListByClass(classId, sId, 1L);
grade = (tempList.size() > 0 ? tempList.get(0) : null);
} catch (GradingFactorException e) {
e.printStackTrace();
grade = null;
}
if (grade == null) {
Grade _grade = new Grade();
grade = gradeService.addGrade(_grade, classId, studentId, 1L);
}
final Grade lGrade = grade;
final long gradeId = grade.getId();
for (int i = 0; i < fActivity.length; i++) {
final double total = activityList.get(i).getItemTotal();
final double score = activityService.getActivityResultByActivityAndStudentId(activityList.get(i).getId(), sId).getScore();
fActivity[i] = (score / total) * 100;
}
for (int i = 0; i < fActivity.length; i++) tempTotal += fActivity[i];
// after looping
if (fActivity.length > 0)
tempTotal /= fActivity.length;
else
tempTotal = 0;
lGrade.setActivityScore(tempTotal);
lGrade.setTotalScore(lGrade.getTotalScore() + tempTotal);
gradeService.updateGradeById(gradeId, lGrade);
} catch (GradingFactorException e) {
e.printStackTrace();
}
}
}).start();
final List<Activity> activityList = activityService.getActivityListByClassId(classId);
try {
// list always return 0 or 1 result
List<Grade> tempList = gradeService.getGradeListByClass(classId, student.getId(), 1L);
grade = (tempList.size() > 0 ? tempList.get(0) : null);
} catch (GradingFactorException e) {
e.printStackTrace();
grade = null;
}
if (grade == null) {
Grade _grade = new Grade();
grade = gradeService.addGrade(_grade, classId, studentId, 1L);
}
ActivityGradeManager gradeManager = new ActivityGradeManager(student, grade, activityList);
// gradeManager.compute();
new Thread(gradeManager).start();
// GradingFactory gradingFactory = new GradingFactory(gradeManager);
}
dialogSucces.setVisibility(View.VISIBLE);
Toast.makeText(ActivityInputActivity.this, "Success", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(ActivityInputActivity.this, "Failed", Toast.LENGTH_LONG).show();
dialogFailed.setVisibility(View.VISIBLE);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
use of com.remswork.project.alice.model.Activity in project classify-system by anverliedoit.
the class ActivityInputActivity2 method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_z_input_activity);
init();
buttonSubmit.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
final long classId = getIntent().getExtras().getLong("classId");
try {
Activity activity = new Activity();
activity.setTitle(!editTextName.getText().toString().trim().isEmpty() ? editTextName.getText().toString().trim() : "Activity");
activity.setDate(textViewDate.getText().toString());
if (editTextTotal.getText().toString().equals("")) {
toggleButtonhideandshow.setChecked(false);
getDialogEmptyTotal.setVisibility(View.VISIBLE);
recyclerViewStudentInput.setVisibility(View.GONE);
return;
} else {
activity.setItemTotal(Integer.parseInt(editTextTotal.getText().toString()));
}
studentAdapter.setTotalItem(activity.getItemTotal());
studentAdapter.onValidate(true);
if (studentAdapter.isNoError()) {
// Add then compute the grade
activity = activityService.addActivity(activity, classId, 1L);
// List of student
for (int i = 0; i < studentList.size(); i++) {
// Student id
final long studentId = studentList.get(i).getId();
//
int score = studentAdapter.getScore(i);
Student student = studentList.get(i);
activityService.addActivityResult(score, activity.getId(), student.getId());
// Adding Grade for activity
new Thread(new Runnable() {
@Override
public void run() {
try {
// list of activity of specific class
final List<Activity> activityList = activityService.getActivityListByClassId(classId);
// grade of each activity
final double[] fActivity = new double[activityList.size()];
// current student id
final long sId = studentId;
// total grade
double tempTotal = 0;
try {
// list always return 0 or 1 result
List<Grade> tempList = gradeService.getGradeListByClass(classId, sId, 1L);
grade = (tempList.size() > 0 ? tempList.get(0) : null);
} catch (GradingFactorException e) {
e.printStackTrace();
grade = null;
}
if (grade == null) {
Grade _grade = new Grade();
grade = gradeService.addGrade(_grade, classId, studentId, 1L);
}
final Grade lGrade = grade;
final long gradeId = grade.getId();
Log.i("STUDENT ID :", sId + "");
Log.i("Grade ID :", gradeId + "");
for (int i = 0; i < fActivity.length; i++) {
final double total = activityList.get(i).getItemTotal();
final double score = activityService.getActivityResultByActivityAndStudentId(activityList.get(i).getId(), sId).getScore();
fActivity[i] = (score / total) * 100;
Log.i("Activity[" + i + "] :", fActivity[i] + "");
}
for (int i = 0; i < fActivity.length; i++) tempTotal += fActivity[i];
// after looping
if (fActivity.length > 0)
tempTotal /= fActivity.length;
else
tempTotal = 0;
DecimalFormat formatter = new DecimalFormat("#.##");
formatter.setRoundingMode(RoundingMode.FLOOR);
formatter.format(tempTotal);
lGrade.setActivityScore(tempTotal);
lGrade.setTotalScore(lGrade.getTotalScore() + tempTotal);
gradeService.updateGradeById(gradeId, lGrade);
} catch (GradingFactorException e) {
e.printStackTrace();
}
}
}).start();
}
dialogSucces.setVisibility(View.VISIBLE);
Toast.makeText(ActivityInputActivity2.this, "Success", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(ActivityInputActivity2.this, "Failed", Toast.LENGTH_LONG).show();
dialogFailed.setVisibility(View.VISIBLE);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
Aggregations