Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Added distance between stations
Browse files Browse the repository at this point in the history
Added distances table to database
Added Bug-Report button
Updated number formats
  • Loading branch information
Felix Pechtl committed Jun 8, 2021
1 parent 4e0e4d3 commit 88b8aca
Show file tree
Hide file tree
Showing 25 changed files with 262 additions and 1,208 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ assignees: Fi0x
A clear and concise description of what the bug is.

**To Reproduce**
Version: '...'
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.fi0x.edct</groupId>
<artifactId>EliteDangerousCarrierTrader</artifactId>
<!-- //TODO: update version -->
<version>1.0.1.2</version>
<version>1.0.2.2</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Expand Down Expand Up @@ -107,8 +107,8 @@
<mainClass>com.fi0x.edct.Main</mainClass>
</classPath>
<jre>
<path>jre</path>
<!-- <minVersion>13.0.1</minVersion>-->
<!-- <path>jre</path>-->
<minVersion>13.0.1</minVersion>
</jre>
<versionInfo>
<fileVersion>${project.version}</fileVersion>
Expand Down
2 changes: 1 addition & 1 deletion setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

; TODO: Update Version info
#define MyAppName "Elite Dangerous Carrier Trader"
#define MyAppVersion "1.0.1.2"
#define MyAppVersion "1.0.2.2"
#define MyAppPublisher "Fi0x"
#define MyAppURL "https://github.com/Fi0x/EDCT"
#define MyAppExeName "EDCT.exe"
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/fi0x/edct/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Main
public static File errors;
public static File settings;
//TODO: Update version information
public static final String version = "1.0.1.2";//All.GUI.Logic.Hotfix
public static final String version = "1.0.2.2";//All.GUI.Logic.Hotfix

public static void main(String[] args)
{
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/com/fi0x/edct/controller/Commodity.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.fi0x.edct.controller;

import com.fi0x.edct.util.NumberConverter;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;

import java.text.DecimalFormat;

public class Commodity
{
private Results resultsController;
Expand All @@ -16,6 +19,8 @@ public class Commodity
private Label lblCommodity;
@FXML
private Label lblProfit;
@FXML
private Label lblDistance;

@FXML
private void nextCommodity()
Expand All @@ -28,10 +33,14 @@ private void previousCommodity()
resultsController.previousCommodity();
}

public void updateDisplay(boolean hasPrev, boolean hasNext)
public void updateDisplay(boolean hasPrev, boolean hasNext, double distance)
{
lblCommodity.setText(resultsController.getCurrentTrade().NAME);
lblProfit.setText(resultsController.getCurrentTrade().profit + " credits");
String profit = NumberConverter.convertToString(resultsController.getCurrentTrade().profit, " ");
lblProfit.setText(profit + " credits");
DecimalFormat df = new DecimalFormat();
df.setMaximumFractionDigits(2);
lblDistance.setText("Distance: " + (distance == 0 ? "Unknown" : df.format(distance) + "Ly"));

btnPrevComm.setDisable(!hasPrev);
btnNextComm.setDisable(!hasNext);
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/fi0x/edct/controller/ProgramInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.fi0x.edct.controller;

import com.fi0x.edct.Main;
import com.fi0x.edct.data.webconnection.GitHub;
import com.fi0x.edct.data.websites.GitHub;
import com.fi0x.edct.util.Logger;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
Expand All @@ -25,6 +25,8 @@ public class ProgramInfo implements Initializable
@FXML
private Label lblVersion;
@FXML
private Button btnBugReport;
@FXML
private Button btnUpdate;

@Override
Expand All @@ -40,6 +42,11 @@ private void openErrorPage()
lblError.setVisible(false);
}
@FXML
private void reportBug()
{
openWebsite("https://github.com/Fi0x/EDCT/issues");
}
@FXML
private void updateVersion()
{
openWebsite(updateUrl);
Expand All @@ -59,6 +66,7 @@ public void checkForUpdates()
{
updateUrl = url;
btnUpdate.setVisible(true);
btnBugReport.setVisible(false);
}
}

Expand Down
17 changes: 14 additions & 3 deletions src/main/java/com/fi0x/edct/controller/Results.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fi0x.edct.data.structures.COMMODITY;
import com.fi0x.edct.data.structures.STATION;
import com.fi0x.edct.data.websites.Hozbase;
import com.fi0x.edct.util.Logger;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
Expand Down Expand Up @@ -138,26 +139,36 @@ public void displayResults()
}

int profit = 0;
STATION sellStation = null;
STATION buyStation = null;

if(trades.get(currentCommodity).BUY_PRICES != null && trades.get(currentCommodity).BUY_PRICES.size() > currentBuyStation)
{
STATION sellStation = trades.get(currentCommodity).BUY_PRICES.get(currentBuyStation);
sellStation = trades.get(currentCommodity).BUY_PRICES.get(currentBuyStation);
sellController.setStation(sellStation, currentBuyStation > 0, currentBuyStation < trades.get(currentCommodity).BUY_PRICES.size() - 1);

profit -= sellStation.PRICE;
}

if(trades.get(currentCommodity).SELL_PRICES != null && trades.get(currentCommodity).SELL_PRICES.size() > currentSellStation)
{
STATION buyStation = trades.get(currentCommodity).SELL_PRICES.get(currentSellStation);
buyStation = trades.get(currentCommodity).SELL_PRICES.get(currentSellStation);
buyController.setStation(buyStation, currentSellStation > 0, currentSellStation < trades.get(currentCommodity).SELL_PRICES.size() - 1);

if(profit < 0) profit += buyStation.PRICE;
}

trades.get(currentCommodity).profit = profit;
double distance = 0;
try
{
if(sellStation == null || buyStation == null) distance = 0;
else distance = Hozbase.getStarDistance(sellStation.SYSTEM, buyStation.SYSTEM);
} catch(InterruptedException ignored)
{
}

commodityController.updateDisplay(currentCommodity > 0, currentCommodity < trades.size() - 1);
commodityController.updateDisplay(currentCommodity > 0, currentCommodity < trades.size() - 1, distance);

vbResults.setVisible(true);
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/fi0x/edct/controller/Station.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.fi0x.edct.controller;

import com.fi0x.edct.data.structures.STATION;
import com.fi0x.edct.util.NumberConverter;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
Expand Down Expand Up @@ -66,8 +67,8 @@ public void setStation(STATION station, boolean hasPrev, boolean hasNext)
lblStationName.setText("Station: " + station.NAME);
lblType.setText("Type: " + station.TYPE);
lblPad.setText("Pad: " + station.PAD);
lblPrice.setText("Price: " + station.PRICE + " credits");
lblAmount.setText((isBuying ? "Demand: " : "Supply: ") + station.QUANTITY + " tons");
lblPrice.setText("Price: " + NumberConverter.convertToString(station.PRICE, " ") + " credits");
lblAmount.setText((isBuying ? "Demand: " : "Supply: ") + NumberConverter.convertToString(station.QUANTITY, " ") + " tons");
lblAge.setText("Data age: " + station.getUpdateAge());

btnPrevStation.setDisable(!hasPrev);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.fi0x.edct.data.webconnection;
package com.fi0x.edct.data;

import com.fi0x.edct.MainWindow;
import com.fi0x.edct.data.cleanup.HTMLCleanup;
Expand All @@ -7,6 +7,7 @@
import com.fi0x.edct.data.structures.PADSIZE;
import com.fi0x.edct.data.structures.STATION;
import com.fi0x.edct.data.structures.STATIONTYPE;
import com.fi0x.edct.data.websites.InaraStation;
import com.fi0x.edct.util.Logger;
import javafx.application.Platform;
import org.json.simple.JSONObject;
Expand All @@ -15,7 +16,6 @@
import org.zeromq.ZContext;
import org.zeromq.ZMQ;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.zip.DataFormatException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.fi0x.edct.data.webconnection;
package com.fi0x.edct.data;

import com.fi0x.edct.Main;
import com.fi0x.edct.util.Logger;

import javax.annotation.Nullable;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -37,7 +38,7 @@ public static String sendHTTPRequest(String endpoint, String requestType, Map<St
if(!canRequest(ignore429)) return null;

endpoint += getParamsString(parameters);
URL url = new URL(endpoint);
URL url = cleanUpUrl(endpoint);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod(requestType);

Expand Down Expand Up @@ -93,15 +94,14 @@ private static boolean canRequest(boolean ignore429) throws IOException, Interru
Logger.WARNING("HTTP request could not be sent because of a 429 response");
return false;
}
}
else if(error.contains("[995]"))
} else if(error.contains("[995]"))
{
String[] logEntry = error.split("]");
String errorTimeString = logEntry[0].replace("[", "");

Date errorDate = getDateFromString(errorTimeString);
if(errorDate == null) return true;

if(System.currentTimeMillis() <= errorDate.getTime() + 1000 * 10)
{
Thread.sleep(1000 * 10);
Expand Down Expand Up @@ -140,4 +140,15 @@ private static Date getDateFromString(String input)
return null;
}
}

private static URL cleanUpUrl(String endpoint) throws MalformedURLException
{
URL url = new URL(endpoint
.replace(" ", "%20")
.replace("'", "%27")
.replace("`", "%60")
);

return url;
}
}
3 changes: 1 addition & 2 deletions src/main/java/com/fi0x/edct/data/Updater.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import com.fi0x.edct.MainWindow;
import com.fi0x.edct.data.localstorage.DBHandler;
import com.fi0x.edct.data.localstorage.TradeReloader;
import com.fi0x.edct.data.webconnection.EDDN;
import com.fi0x.edct.data.webconnection.InaraCommodity;
import com.fi0x.edct.data.websites.InaraCommodity;
import com.fi0x.edct.util.Logger;
import javafx.application.Platform;

Expand Down
44 changes: 41 additions & 3 deletions src/main/java/com/fi0x/edct/data/cleanup/HTMLCleanup.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fi0x.edct.data.structures.PADSIZE;
import com.fi0x.edct.data.structures.STATION;
import com.fi0x.edct.data.structures.STATIONTYPE;
import com.fi0x.edct.util.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
Expand All @@ -12,7 +11,6 @@
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public class HTMLCleanup
Expand Down Expand Up @@ -108,6 +106,46 @@ public static ArrayList<STATION> getCommodityPrices(String inputHTML)
return stations;
}

public static double getSystemDistance(String inputHTML)
{
Document doc = Jsoup.parse(inputHTML);

Elements bodies = doc.getElementsByClass("body-outer");
if(bodies.size() == 0) return 0;

Elements containers = bodies.first().getElementsByClass("container body-content");
if(containers.size() == 0) return 0;

Elements panels = containers.first().getElementsByClass("panel panel-primary panel-success");
if(panels.size() == 0) return 0;

Elements tables = panels.first().getElementsByClass("table-responsive");
if(tables.size() == 0) return 0;

Elements innerTables = tables.first().getElementsByClass("table table-condensed table-striped table-bordered");
if(innerTables.size() == 0) return 0;

Elements rows = innerTables.first().getElementsByTag("tr");
if(rows.size() == 0) return 0;

for(Element row : rows)
{
if(!row.toString().contains("td")) continue;

Elements rowEntries = row.getElementsByTag("td");
for(Element entry : rowEntries)
{
if(entry.ownText().contains("-")) continue;
if(entry.ownText().length() == 0) continue;
if(entry.toString().contains("<td>")) continue;

return Double.parseDouble(entry.ownText());
}
}

return 0;
}

@Nullable
public static String getStationID(String inputHTML, String stationName, String systemName)
{
Expand Down Expand Up @@ -198,7 +236,7 @@ private static Element getStationDetails(String inputHTML)
{
String blockText = block.toString().toLowerCase();
if(blockText.contains("class=\"mainblock\"") && (blockText.contains("landing pad") || blockText.contains("station type") || blockText.contains("href=\"/station/")))
return block;
return block;

}
return null;
Expand Down
Loading

0 comments on commit 88b8aca

Please sign in to comment.