Skip to content

Commit

Permalink
Merge remote-tracking branch 'CS2103-AY-1819S1-W12-2/master' into Bella
Browse files Browse the repository at this point in the history
  • Loading branch information
Bellaaarh committed Oct 16, 2018
2 parents ed90f59 + 75d1f58 commit 0ed30dd
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public ComponentManager() {

public ComponentManager(EventsCenter eventsCenter) {
this.eventsCenter = eventsCenter;
//this to refer to the object itself which is anything that extends componentmanager
eventsCenter.registerHandler(this);
}

Expand Down
14 changes: 12 additions & 2 deletions src/main/java/seedu/address/logic/commands/AnalyticsCommand.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* @@author xiaoyeong */
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
Expand All @@ -17,20 +18,29 @@ public class AnalyticsCommand extends Command {
public static final String COMMAND_ALIAS = "an";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Analyse the your financial status and generate \n"
+ "your expected income for the following week.\n";
+ "your financial status to view.\n";

public static final String MESSAGE_SUCCESS = "Financial status : $ ";



@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
int amount;
amount = 0;
requireNonNull(model);

//List<Person> personList = model.getFilteredPersonList();
List<Transaction> transactionList = model.getFilteredTransactionList();

for (int i = 0; i < transactionList.size(); i++) {
//amount += transactionList.ownesMoney();
Transaction t = transactionList.get(i);

if (t.getType().toString().compareTo("Debt") == 0) {
amount += t.getAmount().getVal();
} else {
amount -= t.getAmount().getVal();
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import seedu.address.Mode;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.AddTransactionCommand;
import seedu.address.logic.commands.AnalyticsCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.DeleteCommand;
Expand Down Expand Up @@ -60,7 +62,17 @@ public Command parseCommand(String userInput) throws ParseException {

case AddCommand.COMMAND_WORD:
case AddCommand.COMMAND_ALIAS:
return new AddCommandParser().parse(arguments);

if (MainApp.m == Mode.PersonMode) {
return new AddCommandParser().parse(arguments);
} else {
return new AddTransactionCommandParser().parse(arguments);
}

case AnalyticsCommand.COMMAND_WORD:
case AnalyticsCommand.COMMAND_ALIAS:
return new AnalyticsCommand();

case EditCommand.COMMAND_WORD:
case EditCommand.COMMAND_ALIAS:
return new EditCommandParser().parse(arguments);
Expand Down
168 changes: 168 additions & 0 deletions src/main/java/seedu/address/model/person/Photo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package seedu.address.model.person;
import seedu.address.commons.exceptions.IllegalValueException;

import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static java.util.Objects.requireNonNull;


public class Photo {

public static final String DEFAULT_MESSAGE_PHOTO = "Filepath be less than 10MB and FilePath must be valid ";
public static final String DEFAULT_PHOTO = "images/default_person.png";
private static final String FOLDER = getOperatingPath();
//cannot be blank space
//double space equals to one in java
private static final String PHOTO_INTITAL_REGEX_ = "[^\\s].*";
private static final int tenMB = 1048576;

private String photoPath;


public Photo(){
this.photoPath = DEFAULT_PHOTO;
}

public Photo(String path){

requireNonNull(path);

if(checkPath(path)){
this.photoPath = path;
} else{
this.photoPath = DEFAULT_PHOTO;
}

}


public Photo(String filePath, String newPhoto) throws IllegalValueException {
requireNonNull(filePath);

if (checkPath(filePath)) {
throw new IllegalValueException(DEFAULT_MESSAGE_PHOTO);
}
//link to the path
this.photoPath = FOLDER + "//" + newPhoto;

makePhoto( filePath, newPhoto);
}

private void makePhoto(String filePath, String newPhoto) {

makePhotoFolder();


//get image from source
File getImage = new File(filePath);

//create file object
File pictureFinal = new File(FOLDER + "//" + newPhoto);


//if cannot get file object create an empty object


if (!pictureFinal.exists() ) {

try {
pictureFinal.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}

}

try {

Files.copy(getImage.toPath(), pictureFinal.toPath(), REPLACE_EXISTING);
this.photoPath =pictureFinal.toPath().toString();
} catch (IOException e){
e.printStackTrace();

}

}


public void makePhotoFolder(){

File locationFolder = new File(FOLDER);

if ( !locationFolder.exists()) {
locationFolder.mkdir();
}

}




private static String getOperatingPath(){
String oSystem = System.getProperty("os.name");

//mac
if (oSystem.contains("mac")){
return System.getProperty("user.home") +"/Documents/cs2103/debt-tracker/PhotoFolder";
}
//windows
else{
return System.getenv("APPDATA")+"/PhotoFolder";
}
}

private static String getOsName(){
return System.getProperty("os.name");
}


public String getPicturePath(){
return this.photoPath;
}

public static boolean checkPath(String path){

if(path.equals(DEFAULT_PHOTO)){
return true;
}

if( path.matches(PHOTO_INTITAL_REGEX_) ){
return checkPicture(path);
}

return false;

}

public static boolean checkPicture(String path){


File pictureNew = new File(path);

try{
if (ImageIO.read(pictureNew) == null)
return false;

} catch (IOException error){
return false;
}

if (pictureNew.length() > tenMB){
return false;
}

return true;



}





}

0 comments on commit 0ed30dd

Please sign in to comment.