Skip to content

Commit

Permalink
added the top 3 cheapest auctions
Browse files Browse the repository at this point in the history
and fixed a bug with the time left shown in minutes instead of seconds
  • Loading branch information
BuildTools committed Nov 17, 2019
1 parent 8132fa3 commit 81ae31a
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 10 deletions.
Binary file modified bin/main/Auction.class
Binary file not shown.
Binary file modified bin/main/Main.class
Binary file not shown.
Binary file modified bin/main/MainWindow$2.class
Binary file not shown.
Binary file modified bin/main/MainWindow$3.class
Binary file not shown.
Binary file modified bin/main/MainWindow$4.class
Binary file not shown.
Binary file modified bin/main/MainWindow$5.class
Binary file not shown.
Binary file modified bin/main/MainWindow$6.class
Binary file not shown.
Binary file modified bin/main/MainWindow.class
Binary file not shown.
14 changes: 12 additions & 2 deletions src/main/Auction.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class Auction {
private String uuid;
private String auctioneer;
private String item_name;
private long starting_bid;
private long highest_bid_amount;
Expand All @@ -10,10 +11,11 @@ public class Auction {
private long end;
private long timestamp;

public Auction(String uuid, long start, long end, long timestamp, String item_name, long highest_bid_amount,
public Auction(String uuid, String auctioneer, long start, long end, long timestamp, String item_name, long highest_bid_amount,
int item_count, long starting_bid) {
super();
this.setUuid(uuid);
this.setAuctioneer(auctioneer);
this.start = start;
this.end = end;
this.timestamp = timestamp;
Expand All @@ -24,7 +26,7 @@ public Auction(String uuid, long start, long end, long timestamp, String item_na
}

public long getSeconds_left() {
return ((end - timestamp) / 1000 / 60);
return ((end - timestamp) / 1000);
}

public long getStart() {
Expand Down Expand Up @@ -117,4 +119,12 @@ public String toString() {
+ " min ]";
}

public String getAuctioneer() {
return auctioneer;
}

public void setAuctioneer(String auctioneer) {
this.auctioneer = auctioneer;
}

}
48 changes: 41 additions & 7 deletions src/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public static void sendRequest(boolean filterCT, String CT, boolean matchCase, b

public static void filterData(boolean filterCT, String CT, boolean matchCase, boolean filterSL, int SL,
boolean filterTT, int TT, boolean filterHB, int HB) {
mw.getBtnFilterButton().setEnabled(false);
//mw.getBtnFilterButton().setEnabled(false);
if (data.isEmpty()) {
consoleOut(" [ FAILURE ] No data collected yet!\n");
mw.getBtnFilterButton().setEnabled(true);
//mw.getBtnFilterButton().setEnabled(true);
return;
}
consoleOut("Filtering collected data ...\n");
Expand All @@ -92,6 +92,7 @@ public static void filterData(boolean filterCT, String CT, boolean matchCase, bo
long sum = filterStream(data.stream(), filterCT, CT, matchCase, filterSL, SL, filterTT, TT, filterHB, HB)
.mapToLong(a -> a.getHighest_bid_amount() / a.getItem_count()).sum();
if (count > 0) {
printCheapest(3, filterCT, CT, matchCase, filterSL, SL, filterTT, TT, filterHB, HB);
consoleOut("Average: " + (sum / count) + " coins\n");
consoleOut("Maximum: "
+ (filterStream(data.stream(), filterCT, CT, matchCase, filterSL, SL, filterTT, TT, filterHB, HB)
Expand All @@ -102,6 +103,19 @@ public static void filterData(boolean filterCT, String CT, boolean matchCase, bo
updateConsoleOut();
}

private static void printCheapest(int topX, boolean filterCT, String CT, boolean matchCase, boolean filterSL,
int SL, boolean filterTT, int TT, boolean filterHB, int HB) {
long count = (filterStream(data.stream(), filterCT, CT, matchCase, filterSL, SL, filterTT, TT, filterHB,
HB).sorted(new CompHighestBidAsc())).filter(a -> a.getSeconds_left() > 5).count();
for (int i = 0; i < topX && i < count; i++) {
Auction min = (filterStream(data.stream(), filterCT, CT, matchCase, filterSL, SL, filterTT, TT, filterHB,
HB).sorted(new CompHighestBidAsc())).filter(a -> a.getSeconds_left() > 5).skip(i).findFirst().get();
String cheapestAuctioneer = getPlayerFromUUID(min.getAuctioneer());
consoleOut("Minimum " + (i + 1) + ": " + min.getHighest_bid_amount() + " coins" + " by "
+ cheapestAuctioneer + " " + min.getSeconds_left() + "sec left" + "\n");
}
}

private static Stream<Auction> filterStream(Stream<Auction> s, boolean filterCT, String CT, boolean matchCase,
boolean filterSL, int SL, boolean filterTT, int TT, boolean filterHB, int HB) {
return s.filter(a -> !filterCT || (matchCase ? a.getItem_name().equalsIgnoreCase(CT)
Expand All @@ -126,7 +140,7 @@ public void run() {
}
mw.getSp().getVerticalScrollBar().setValue(mw.getSp().getVerticalScrollBar().getMaximum());
mw.getSp().paint(mw.getSp().getGraphics());
mw.getBtnFilterButton().setEnabled(true);
//mw.getBtnFilterButton().setEnabled(true);
};
};
t.start();
Expand All @@ -149,7 +163,7 @@ private static void loadPage(int page) {
JSONObject obj = new JSONObject(out);
long timestamp = obj.getLong("lastUpdated");
max_pages = obj.getInt("totalPages");
mw.getBtnFilterButton().setEnabled(false);
//mw.getBtnFilterButton().setEnabled(false);
for (Auction a : data) {
a.setTimestamp(timestamp);
}
Expand All @@ -160,13 +174,14 @@ private static void loadPage(int page) {
String item_bytes = auction.getString("item_bytes");
int item_count = itemCountFromItemBytes(item_bytes);
String uuid = auction.getString("uuid");
String auctioneer = auction.getString("auctioneer");
long start = auction.getLong("start");
long end = auction.getLong("end");
long highest_bid_amount = auction.getLong("highest_bid_amount");
long starting_bid = auction.getLong("starting_bid");
// TODO maybe add more detail to the auction objects
Auction addition = new Auction(uuid, start, end, timestamp, item_name, highest_bid_amount, item_count,
starting_bid);
Auction addition = new Auction(uuid, auctioneer, start, end, timestamp, item_name, highest_bid_amount,
item_count, starting_bid);
int tmp = data.indexOf(addition);
if (tmp < 0)
data.add(addition);
Expand All @@ -176,7 +191,26 @@ private static void loadPage(int page) {
data.get(tmp).setHighest_bid_amount(highest_bid_amount);
}
}
mw.getBtnFilterButton().setEnabled(true);
//mw.getBtnFilterButton().setEnabled(true);
}

private static String getPlayerFromUUID(String uuid) {
URL url;
String out = "";
try {
url = new URL("https://api.hypixel.net/player?key=" + api_key + "&uuid=" + uuid);
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
out = getContent(con);
} catch (MalformedURLException e) {
consoleOut("[ FAILURE ] Some internet connection problem!\n");
e.printStackTrace();
} catch (IOException e) {
consoleOut("[ FAILURE ] Some internet connection problem!\n");
e.printStackTrace();
}
JSONObject obj = new JSONObject(out);
JSONObject player = obj.getJSONObject("player");
return player.getString("playername");
}

private static int itemCountFromItemBytes(String s) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ public void keyPressed(KeyEvent e) {
panel_1.add(checkBox_SL, "cell 5 4");

spinner_SL = new JSpinner();
spinner_SL.setModel(new SpinnerNumberModel(new Integer(10), new Integer(0), null, new Integer(1)));
spinner_SL.setModel(new SpinnerNumberModel(new Integer(1), new Integer(0), null, new Integer(1)));
panel_1.add(spinner_SL, "cell 6 4 6 1,growx");

chckbxMinutesSL = new JCheckBox("Minutes");
chckbxMinutesSL.setSelected(true);
chckbxMinutesSL.setToolTipText("");
panel_1.add(chckbxMinutesSL, "cell 12 4 5 1");

Expand Down Expand Up @@ -338,6 +339,7 @@ private void enableButtons(boolean lock) {
btn_multireq.setEnabled(lock);
chckbxKeepOldData.setEnabled(lock);
btnSendRequest.setEnabled(lock);
btnFilterButton.setEnabled(lock);
}

}

0 comments on commit 81ae31a

Please sign in to comment.