Skip to content

Commit cfd3dc7

Browse files
authored
Merge pull request #3 from StenAL/dev
Dev
2 parents 9714682 + 8b35f63 commit cfd3dc7

6 files changed

Lines changed: 63 additions & 18 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
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.
44

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

77
## Getting Started
88

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

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>Laane.Sten</groupId>
88
<artifactId>StockTracker</artifactId>
9-
<version>1.4.0</version>
9+
<version>1.4.1</version>
1010
<properties>
1111
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1212
</properties>
@@ -18,7 +18,7 @@
1818
</repository>
1919
<repository>
2020
<id>0002</id>
21-
<name>mulesoft (for xmlparser</name>
21+
<name>mulesoft (for xmlparser)</name>
2222
<url>https://repository.mulesoft.org/nexus/content/repositories/public/</url>
2323
</repository>
2424
</repositories>

src/main/java/stocktracker/StockTracker.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
import java.util.ArrayList;
1313
import java.util.List;
1414

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

20-
public static final String VERSION = "1.3.0";
18+
public static final String VERSION = "1.4.1";
2119
public static final int MAX_STOCKS = 5;
2220
public static final String PATH;
2321

src/main/java/stocktracker/StockTrackerGUI.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import javafx.scene.Scene;
77
import javafx.scene.chart.*;
88
import javafx.scene.control.*;
9+
import javafx.scene.input.KeyCode;
910
import javafx.scene.paint.Color;
1011
import javafx.scene.image.Image;
1112
import javafx.scene.layout.*;
1213
import javafx.scene.paint.ImagePattern;
14+
import javafx.scene.text.TextAlignment;
1315
import javafx.stage.Screen;
1416
import javafx.stage.Stage;
1517
import jfxtras.styles.jmetro8.JMetro;
@@ -20,7 +22,7 @@
2022
import java.util.*;
2123

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

2527
public class StockTrackerGUI extends Application {
2628
private Stage primaryStage;
@@ -175,21 +177,57 @@ public void updateItem(LocalDate date, boolean empty) {
175177
ExtendableTextField tickerCurrencyTextField = new ExtendableTextField(inputDataBox);
176178
tickerCurrencyTextField.setMaxWidth(200);
177179
tickerCurrencyTextField.setPromptText("ticker");
178-
180+
tickerCurrencyTextField.amountField.setOnKeyPressed(e -> {
181+
if (e.getCode().equals(KeyCode.ENTER)) {
182+
plotNewData(startDate.getValue());
183+
}
184+
});
179185

180186
inputDataBox.setAlignment(Pos.CENTER);
187+
Label errorLabel = new Label();
188+
errorLabel.setTextFill(Color.RED);
189+
errorLabel.setTextAlignment(TextAlignment.LEFT);
190+
errorLabel.setPrefWidth(270);
181191

182192
Button goButton = new Button("Go!");
183-
goButton.setOnAction(e -> plotNewData(startDate.getValue()));
193+
goButton.setOnAction(e -> {
194+
if (checkValidInput() && startDate.getValue() != null) {
195+
plotNewData(startDate.getValue());
196+
}
197+
else {
198+
errorLabel.setText("");
199+
if (!checkValidInput()) {
200+
errorLabel.setText("Input a stock ticker and a corresponding amount\n");
201+
}
202+
if (startDate.getValue() == null) {
203+
errorLabel.setText(errorLabel.getText() + "Pick a date");
204+
}
184205

185-
VBox contentPane = new VBox(startDateBox, inputDataBox, goButton);
206+
}
207+
});
208+
209+
VBox contentPane = new VBox(startDateBox, inputDataBox, errorLabel, goButton);
186210
contentPane.setSpacing(30);
187211
contentPane.setAlignment(Pos.CENTER);
188212
root.getChildren().add(contentPane);
189213

190214
createScene(root);
191215
}
192216

217+
private boolean checkValidInput() {
218+
boolean valid = true;
219+
for (ExtendableTextField field: stocksTracked) {
220+
if (field.getText().equals("") && !field.amountField.getText().equals("") ||
221+
!field.getText().equals("") && field.amountField.getText().equals("")) {
222+
valid = false;
223+
}
224+
}
225+
if (stocksTracked.get(0).getText().equals("") || stocksTracked.get(0).amountField.getText().equals("")) {
226+
valid = false;
227+
}
228+
return valid;
229+
}
230+
193231
private void plotNewData(LocalDate startDate) {
194232
ArrayList<String> dataList = new ArrayList<>();
195233
ArrayList<Number> amounts = new ArrayList<>();

src/test/java/stocktracker/DataAggregatorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ void testSingleAggregation() {
5151
assertEquals(3, line.split(",").length);
5252
assertDoesNotThrow(() -> LocalDate.parse(line.split(",")[0]));
5353
}
54+
5455
@Nested
5556
@DisplayName("compoundAggregation")
5657
class compoundAggregate {

src/test/java/stocktracker/StockTrackerTest.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
import org.junit.jupiter.api.AfterAll;
44
import org.junit.jupiter.api.BeforeAll;
5+
import org.junit.jupiter.api.Order;
56
import org.junit.jupiter.api.Test;
67

78
import java.io.File;
8-
import java.io.IOException;
99
import java.time.LocalDate;
1010
import java.util.ArrayList;
11+
import java.util.List;
1112

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

14-
//TODO: These tests are bad. Fix it
1515
class StockTrackerTest {
1616

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

31+
@Order(1)
3132
@Test
32-
void runNewTest()
33-
{
33+
void runNewTest() throws InterruptedException {
3434
StockTracker.createConfig(testList, testAmounts);
3535
StockTracker.writeData("IVV", LocalDate.now().minusDays(139));
3636
StockTracker.writeData("QQQ", LocalDate.now().minusDays(139));
@@ -39,15 +39,23 @@ void runNewTest()
3939
System.out.println("$$$");
4040
StockTracker.calculateMoney(testList, testAmounts);
4141
StockTracker.createSave();
42-
StockTracker.deleteTempFiles();
4342
System.out.println("Files aggregated, money calculated");
4443
System.out.println("Done");
4544
assertTrue(new File(PATH + "save_data.csv").exists());
4645
assertTrue(new File(PATH + "save_config.csv").exists());
4746
assertFalse(StockTracker.updateSave());
47+
Thread.sleep(30000);
4848
}
4949

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

5260
@AfterAll
5361
static void teardown() {

0 commit comments

Comments
 (0)