Skip to content

Commit

Permalink
Merge pull request #3 from StenAL/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
StenAL authored Mar 29, 2019
2 parents 9714682 + 8b35f63 commit cfd3dc7
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Calls various APIs to get data on stock prices and currency rates, which it then uses to convert user input in the form of stock and amount owned to total value of portfolio in euros over time. The value of the portfolio is graphed using a JavaFX GUI.

![Graph showing 1 AAPL stock owned from March 1st to Match 25th 2019](example.png)
![Example of graph made by StockTracker](example.png)

## Getting Started

Expand All @@ -15,7 +15,7 @@ For functional usage navigate to "Help -> Getting Started" from the menu bar of
* [Java 8](https://www.oracle.com/technetwork/java/javase/overview/java8-2100321.html) - The programming language used
* [Maven](https://maven.apache.org/) - Dependency Management, project building and deployment
* [Alpha Vantage API](https://www.alphavantage.co/) - API for fetching stock price data
* [Quotes API for Yahoo Finance] (https://financequotes-api.com/) - API for fetching additional stock data
* [Quotes API for Yahoo Finance](https://financequotes-api.com/) - API for fetching additional stock data
* [ECB SDMX 2.1 RESTful web service](https://sdw-wsrest.ecb.europa.eu/help/) - API for fetching currency data
* [JavaFX](https://openjfx.io/), [JUnit 5](https://junit.org/junit5/)

Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>Laane.Sten</groupId>
<artifactId>StockTracker</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Expand All @@ -18,7 +18,7 @@
</repository>
<repository>
<id>0002</id>
<name>mulesoft (for xmlparser</name>
<name>mulesoft (for xmlparser)</name>
<url>https://repository.mulesoft.org/nexus/content/repositories/public/</url>
</repository>
</repositories>
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/stocktracker/StockTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
import java.util.ArrayList;
import java.util.List;

//TODO: Add more/better jUnit testing
//TODO: Account for dividends using AlphaVantage + add boolean for reinvesting dividends
//TODO: Add enum for constants
//TODO: Add enum for constants (version, path, max_stocks)
public class StockTracker {

public static final String VERSION = "1.3.0";
public static final String VERSION = "1.4.1";
public static final int MAX_STOCKS = 5;
public static final String PATH;

Expand Down
46 changes: 42 additions & 4 deletions src/main/java/stocktracker/StockTrackerGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import javafx.scene.Scene;
import javafx.scene.chart.*;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.paint.Color;
import javafx.scene.image.Image;
import javafx.scene.layout.*;
import javafx.scene.paint.ImagePattern;
import javafx.scene.text.TextAlignment;
import javafx.stage.Screen;
import javafx.stage.Stage;
import jfxtras.styles.jmetro8.JMetro;
Expand All @@ -20,7 +22,7 @@
import java.util.*;

//TODO: Add progress bars/loading indication
//TODO: Add listener for pressing enter in "new tracker" scene as shortcut to go button
//TODO: Add more styling to make GUI look better

public class StockTrackerGUI extends Application {
private Stage primaryStage;
Expand Down Expand Up @@ -175,21 +177,57 @@ public void updateItem(LocalDate date, boolean empty) {
ExtendableTextField tickerCurrencyTextField = new ExtendableTextField(inputDataBox);
tickerCurrencyTextField.setMaxWidth(200);
tickerCurrencyTextField.setPromptText("ticker");

tickerCurrencyTextField.amountField.setOnKeyPressed(e -> {
if (e.getCode().equals(KeyCode.ENTER)) {
plotNewData(startDate.getValue());
}
});

inputDataBox.setAlignment(Pos.CENTER);
Label errorLabel = new Label();
errorLabel.setTextFill(Color.RED);
errorLabel.setTextAlignment(TextAlignment.LEFT);
errorLabel.setPrefWidth(270);

Button goButton = new Button("Go!");
goButton.setOnAction(e -> plotNewData(startDate.getValue()));
goButton.setOnAction(e -> {
if (checkValidInput() && startDate.getValue() != null) {
plotNewData(startDate.getValue());
}
else {
errorLabel.setText("");
if (!checkValidInput()) {
errorLabel.setText("Input a stock ticker and a corresponding amount\n");
}
if (startDate.getValue() == null) {
errorLabel.setText(errorLabel.getText() + "Pick a date");
}

VBox contentPane = new VBox(startDateBox, inputDataBox, goButton);
}
});

VBox contentPane = new VBox(startDateBox, inputDataBox, errorLabel, goButton);
contentPane.setSpacing(30);
contentPane.setAlignment(Pos.CENTER);
root.getChildren().add(contentPane);

createScene(root);
}

private boolean checkValidInput() {
boolean valid = true;
for (ExtendableTextField field: stocksTracked) {
if (field.getText().equals("") && !field.amountField.getText().equals("") ||
!field.getText().equals("") && field.amountField.getText().equals("")) {
valid = false;
}
}
if (stocksTracked.get(0).getText().equals("") || stocksTracked.get(0).amountField.getText().equals("")) {
valid = false;
}
return valid;
}

private void plotNewData(LocalDate startDate) {
ArrayList<String> dataList = new ArrayList<>();
ArrayList<Number> amounts = new ArrayList<>();
Expand Down
1 change: 1 addition & 0 deletions src/test/java/stocktracker/DataAggregatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void testSingleAggregation() {
assertEquals(3, line.split(",").length);
assertDoesNotThrow(() -> LocalDate.parse(line.split(",")[0]));
}

@Nested
@DisplayName("compoundAggregation")
class compoundAggregate {
Expand Down
20 changes: 14 additions & 6 deletions src/test/java/stocktracker/StockTrackerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

//TODO: These tests are bad. Fix it
class StockTrackerTest {

private static ArrayList<String> testList;
Expand All @@ -28,9 +28,9 @@ static void setup() {
testAmounts.add(10);
}

@Order(1)
@Test
void runNewTest()
{
void runNewTest() throws InterruptedException {
StockTracker.createConfig(testList, testAmounts);
StockTracker.writeData("IVV", LocalDate.now().minusDays(139));
StockTracker.writeData("QQQ", LocalDate.now().minusDays(139));
Expand All @@ -39,15 +39,23 @@ void runNewTest()
System.out.println("$$$");
StockTracker.calculateMoney(testList, testAmounts);
StockTracker.createSave();
StockTracker.deleteTempFiles();
System.out.println("Files aggregated, money calculated");
System.out.println("Done");
assertTrue(new File(PATH + "save_data.csv").exists());
assertTrue(new File(PATH + "save_config.csv").exists());
assertFalse(StockTracker.updateSave());
Thread.sleep(30000);
}

//TODO: test actually updating the save
@Order(2)
@Test
void testUpdate() {
List<String> originalData = FileManager.readLines(PATH + "save_data.csv");
List<String> data = originalData.subList(0, originalData.size()-10);
FileManager.writeList(PATH + "save_data.csv", data);
assertTrue(StockTracker.updateSave());
assertEquals(FileManager.readLines(PATH + "save_data.csv"), originalData);
}

@AfterAll
static void teardown() {
Expand Down

0 comments on commit cfd3dc7

Please sign in to comment.