Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 208 project submissions scoring ui #218

Open
wants to merge 5 commits into
base: issue-208-project-submissions-scoring-ui
Choose a base branch
from
Open

Issue 208 project submissions scoring ui #218

wants to merge 5 commits into from

Conversation

susham
Copy link

@susham susham commented Aug 30, 2017

For retrieving the student Id and Project Name, I think method I have written checks for the string CS410. I think, this should be changed. As the summer term had both CS410 and CS510.

susham added 4 commits July 29, 2017 09:59
…s-scoring-ui

Issue 208 project submissions scoring ui
…s-scoring-ui

Get upstream changes from Dave
…s-scoring-ui

Get latest changes from DavidWhitlock's issue 208 branch
Copy link
Collaborator

@DavidWhitlock DavidWhitlock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making these changes, @susham. Overall, they are very good. I have some suggestions that I think would improve the code. After we discuss those some more, I'd be happy to merge this code into my repository.

@@ -17,6 +17,13 @@
private Double score;
private String studentName;
private Date submissionTime;
private Date gradedTime;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. Good call. Thank you for adding this.


public ProjectSubmissionOutputFileParser(Reader source) {
if(source != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If source is null, it's probably better to throw a NullPointerException.

}

private BufferedReader bufferedReader=null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please declare field at the beginning of the class before the constructor and methods.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, since bufferedReader is always initialized in the constructor and is never modified, you can make the field final.

}

private BufferedReader bufferedReader=null;
private ProjectSubmission projectSubmission=null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to initial this field to null. That is the default value it will receive.

}

} catch (IOException e) {
e.printStackTrace();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't "swallow" this exception. Instead, declare that this method throws an IOException and let the calling code deal with it.

projectSubmission = new ProjectSubmission();
String fileContents=null;

try {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to be sure to close the BufferedReader when your done with it. I recommend using the "enhanced try/catch" syntax described here:

https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html

try {
while((fileContents= bufferedReader.readLine()) !=null) {
fileContents=fileContents.trim();
if(fileContents.contains("CS410J")){ // fileContents has the student Id and Project Name.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, my grading scripts don't differentiate between the undergraduate and graduate sections of the course. So, it is fine to have this hard-coded "magic string" of "CS410J".

fileContents=fileContents.trim();
if(fileContents.contains("CS410J")){ // fileContents has the student Id and Project Name.
String[] splitContent=fileContents.split(Pattern.quote("."));
projectSubmission.setProjectName(splitContent[splitContent.length -1]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the output file being parsed is bogus, we'll end up with ArrayIndexOutOfBoundsExceptions, but I don't know what we could do about it. Maybe an answer will be become apparent later as we build more of the class..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, bogus output file is always going to be an issue. probably I can write a test case to handle the bogus output file.

As of the first iteration, handling this scenario should help to move on. But, we need to find out a better way or use a different type.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.


}

if(fileContents.contains("Submitted by")){ //fileContents has StudentName
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend that you move "Submitted by" into a constant (a private static final field whose name is ALL_CAPS) so that this "magic" string doesn't appear twice.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think, its better to create final fields whose names are ALL_CAPS, so that the magic string doesn't appear twice?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That way, if the "magic" string ever changes in the output file, we only need to change one place in the code.

projectSubmission.setGradedTime(parseGradingTime(splitContent[splitContent.length -1].trim()));
}
if(fileContents.contains("out of")){ //fileContents has Total Points and Awarded Points
String [] splitContent=fileContents.split("out of");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but you might also want to consider using two "capturing groups" in a regular expression:

https://alvinalexander.com/blog/post/java/how-extract-multiple-groups-patterns-string-regex

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to create a regexp to get the left and right side of the matched string? Right now, I am able to get both the left and right sub string of the matched string using a separate Regexp

@susham
Copy link
Author

susham commented Sep 1, 2017

@DavidWhitlock

I have made changes as per the code review. Do I have to raise another pull request, to reflect my changes?

Copy link
Collaborator

@DavidWhitlock DavidWhitlock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for addressing my earlier feedback. I had some questions about the most recent changes, though.

* Created by sushamkumar on 9/1/17.
*/
public class InvalidFileContentException extends Exception {
public InvalidFileContentException() { super("Out file is corrupted"); }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this constructor ever called? If not, let's delete it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this constructor is never called for now. But, I have kept this so that If there isn't any message to provide then we could use this constructor. I will remove this, so that custom message makes more sense.


if(fileContents.contains("out of")){ //fileContents has Total Points and Awarded Points

Pattern rightpattern = Pattern.compile("(?<=out of).*");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought there was a way to go this with a single regular expression. But maybe not.


private void convertOutFileToXml(File outFile) {

File xmlFile = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the only change that you made to this method is to move this variable declaration to the top? If so, I'm not sure if that's necessary. This isn't C where you need to declare all variables at the beginning of a function. In Java, it's preferred to declare variables close to where they are used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to move the variable declaration to the top, because the variable scope wasn't sufficient. That was because of the try, catch block. I think, I have to refactor the code to make the unit test cases pass.


} catch (FileNotFoundException e) {
logger.error("Could not file file " + outFile, e);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked having this specific error message when the file could not be found.

@@ -185,7 +183,10 @@ public void parseCompilerTestWithNoOutput() {
file.line();
file.line("***** Test 1: No arguments");

ProjectSubmission submission = parse(file);
ProjectSubmission submission = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think that splitting the declaration and assignment make the code easier to read? I'm not so sure.

projectSubmission= parser.parse();

parser.parse();
} catch (ParseException e) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might as well have the parse() method declare that it should throw the ParseException.

parser.parse();
} catch (ParseException e) {
e.printStackTrace();
} catch (IOException e) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that this is what you want to do. Yes, the stack trace will be printed, but null will be returned from the method. That will probably cause the test to fail, but perhaps not in the way that anyone would expect.

@DavidWhitlock
Copy link
Collaborator

Also, @susham, I noticed that the Travis build failed. It looks like there was a problem with the grader application. The Travis output wasn't very helpful, but when I made a local checkout of your branch, I saw these unit tests fail:

Tests run: 11, Failures: 0, Errors: 2, Skipped: 3, Time elapsed: 0.023 sec <<< FAILURE! - in edu.pdx.cs410J.grader.scoring.ProjectSubmissionOutputFileParserTest
parseEmptyGrade(edu.pdx.cs410J.grader.scoring.ProjectSubmissionOutputFileParserTest)  Time elapsed: 0.016 sec  <<< ERROR!
java.lang.NumberFormatException: empty String
	at edu.pdx.cs410J.grader.scoring.ProjectSubmissionOutputFileParserTest.parse(ProjectSubmissionOutputFileParserTest.java:242)
	at edu.pdx.cs410J.grader.scoring.ProjectSubmissionOutputFileParserTest.parseEmptyGrade(ProjectSubmissionOutputFileParserTest.java:116)

parseTotalPoints(edu.pdx.cs410J.grader.scoring.ProjectSubmissionOutputFileParserTest)  Time elapsed: 0.001 sec  <<< ERROR!
java.lang.NumberFormatException: empty String
	at edu.pdx.cs410J.grader.scoring.ProjectSubmissionOutputFileParserTest.parse(ProjectSubmissionOutputFileParserTest.java:242)
	at edu.pdx.cs410J.grader.scoring.ProjectSubmissionOutputFileParserTest.parseTotalPoints(ProjectSubmissionOutputFileParserTest.java:100)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants