From 47efdd4f84cc9a29738fe16d631eb33ee716db61 Mon Sep 17 00:00:00 2001 From: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> Date: Sun, 27 Mar 2022 19:12:44 +0200 Subject: New wiki in wiki renderer (#97) * partly working and pushing cuz jani * way better rendering stuff but still not perfect * finish most of wiki renderer for new wiki * JANI MY FRIEND PLEASE TEST * Windows time :sad: * fix wiki renderer * Some things I forgor * changelog * Better corrupted file handling in graph and added check for crash that I have no idea how it happened. --- .../notenoughupdates/miscgui/GuiPriceGraph.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java index 3955b35f..63a08d41 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java @@ -117,12 +117,11 @@ public class GuiPriceGraph extends GuiScreen { Utils.drawStringCentered("Loading...", Minecraft.getMinecraft().fontRendererObj, guiLeft + 166, guiTop + 116, false, 0xffffff00 ); - else if (dataPoints == null || dataPoints.get() == null || dataPoints.get().size() <= 1) + else if (dataPoints == null || dataPoints.get() == null || dataPoints.get().size() <= 1 || lowestValue == null) Utils.drawStringCentered("No data found.", Minecraft.getMinecraft().fontRendererObj, guiLeft + 166, guiTop + 116, false, 0xffff0000 ); else { - int graphColor = SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.ahGraph.graphColor); int graphColor2 = SpecialColour.specialToChromaRGB(NotEnoughUpdates.INSTANCE.config.ahGraph.graphColor2); Integer lowestDist = null; @@ -399,15 +398,17 @@ public class GuiPriceGraph extends GuiScreen { if (!file.getName().endsWith(".gz")) continue; if (file.lastModified() < System.currentTimeMillis() - NotEnoughUpdates.INSTANCE.config.ahGraph.dataRetention * 86400000L) + //noinspection ResultOfMethodCallIgnored file.delete(); } Date date = new Date(); Long epochSecond = date.toInstant().getEpochSecond(); File file = new File(dir, "prices_" + format.format(date) + ".gz"); HashMap prices = new HashMap<>(); - if (file.exists()) - prices = load(file); - if (prices == null) return; + if (file.exists()) { + HashMap tempPrices = load(file); + if (tempPrices != null) prices = tempPrices; + } for (Map.Entry item : items.entrySet()) { if (prices.containsKey(item.getKey())) { if (bazaar && item.getValue().getAsJsonObject().has("curr_buy") && item.getValue().getAsJsonObject().has( @@ -493,7 +494,10 @@ public class GuiPriceGraph extends GuiScreen { )) ) { return GSON.fromJson(reader, type); - } catch (Exception ignored) { + } catch (Exception e) { + System.out.println("Deleting " + file.getName() + " because it is probably corrupted."); + //noinspection ResultOfMethodCallIgnored + file.delete(); } } return null; -- cgit From 5bb02db85994ea0c017894fb49950c67a6db552e Mon Sep 17 00:00:00 2001 From: CraftyOldMiner <85420839+CraftyOldMiner@users.noreply.github.com> Date: Sun, 27 Mar 2022 12:16:54 -0500 Subject: Lowest BIN related fixes & optimizations (#101) * Lowest BIN related fixes & optimizations - Fix double-call of updateLowestBin due to a race condition where lastLowestBinUpdate is not updated by the async thread until after the following tick. - Change the parsing of item prices to avoid using getAsInt on a decimal string that throws two exceptions per value parsed. I replaced it with the code that getAsInt ends up falling back to. - Delete corrupted prices_*.gz file so that it can be re-downloaded. - Make the Bazaar update retry after 60 seconds instead of 5 minutes to be consistent with auction average data. * Remove corrupt file deletion code to avoid conflict with other PR --- .../io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java index 63a08d41..66014b1f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java @@ -418,7 +418,7 @@ public class GuiPriceGraph extends GuiScreen { item.getValue().getAsJsonObject().get("curr_sell").getAsFloat() )); else if (!bazaar) - prices.get(item.getKey()).ah.put(epochSecond, item.getValue().getAsInt()); + prices.get(item.getKey()).ah.put(epochSecond, item.getValue().getAsBigDecimal().intValue()); } else { TreeMap mapData = new TreeMap<>(); if (bazaar && item.getValue().getAsJsonObject().has("curr_buy") && item.getValue().getAsJsonObject().has( -- cgit From 0418460b5ff12af5bc0b4078ec43210489d6ae99 Mon Sep 17 00:00:00 2001 From: CraftyOldMiner <85420839+CraftyOldMiner@users.noreply.github.com> Date: Sat, 30 Apr 2022 09:17:14 -0500 Subject: Crash & perf fixes (#121) - Fix crash in profile viewer when name not found - Parse numbers using exception-free methods in hot code paths - Update price graph to handle items transitioning from the bz to ah --- .../notenoughupdates/miscgui/GuiPriceGraph.java | 175 ++++++++++++--------- 1 file changed, 102 insertions(+), 73 deletions(-) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java index 66014b1f..e2381503 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java @@ -36,7 +36,7 @@ public class GuiPriceGraph extends GuiScreen { private final ResourceLocation TEXTURE; private static final int X_SIZE = 364; private static final int Y_SIZE = 215; - private Data dataPoints; + private ItemData itemData; private float highestValue; private long firstTime; private long lastTime; @@ -117,7 +117,8 @@ public class GuiPriceGraph extends GuiScreen { Utils.drawStringCentered("Loading...", Minecraft.getMinecraft().fontRendererObj, guiLeft + 166, guiTop + 116, false, 0xffffff00 ); - else if (dataPoints == null || dataPoints.get() == null || dataPoints.get().size() <= 1 || lowestValue == null) + else if ( + itemData == null || itemData.get() == null || itemData.get().size() <= 1 || lowestValue == null) Utils.drawStringCentered("No data found.", Minecraft.getMinecraft().fontRendererObj, guiLeft + 166, guiTop + 116, false, 0xffff0000 ); @@ -127,16 +128,16 @@ public class GuiPriceGraph extends GuiScreen { Integer lowestDist = null; Long lowestDistTime = null; HashMap secondLineData = new HashMap<>(); - for (int i = (dataPoints.isBz() ? 1 : 0); i >= 0; i--) { + for (int i = (itemData.isBz() ? 1 : 0); i >= 0; i--) { Utils.drawGradientRect(0, guiLeft + 17, guiTop + 35, guiLeft + 315, guiTop + 198, changeAlpha(i == 0 ? graphColor : graphColor2, 120), changeAlpha(i == 0 ? graphColor : graphColor2, 10) ); Integer prevX = null; Integer prevY = null; - for (Long time : dataPoints.get().keySet()) { - float price = dataPoints.isBz() - ? i == 0 ? dataPoints.bz.get(time).b : dataPoints.bz.get(time).s - : dataPoints.ah.get(time); + for (Long time : itemData.get().keySet()) { + float price = itemData.isBz() + ? i == 0 ? itemData.bz.get(time).b : itemData.bz.get(time).s + : itemData.ah.get(time); int xPos = (int) map(time, firstTime, lastTime, guiLeft + 17, guiLeft + 315); int yPos = (int) map(price, highestValue + 10d, lowestValue - 10d, guiTop + 35, guiTop + 198); if (prevX != null) { @@ -159,7 +160,7 @@ public class GuiPriceGraph extends GuiScreen { ); if (i == 0) { Utils.drawLine(prevX, prevY + 0.5f, xPos, yPos + 0.5f, 2, graphColor); - if (dataPoints.isBz()) + if (itemData.isBz()) Utils.drawLine( prevX, secondLineData.get(prevX) + 0.5f, @@ -218,8 +219,8 @@ public class GuiPriceGraph extends GuiScreen { Utils.drawDottedLine(customStart, guiTop + 197, customEnd, guiTop + 197, 2, 10, 0xFFc6c6c6); } if (lowestDist != null && !customSelecting) { - float price = dataPoints.isBz() ? dataPoints.bz.get(lowestDistTime).b : dataPoints.ah.get(lowestDistTime); - Float price2 = dataPoints.isBz() ? dataPoints.bz.get(lowestDistTime).s : null; + float price = itemData.isBz() ? itemData.bz.get(lowestDistTime).b : itemData.ah.get(lowestDistTime); + Float price2 = itemData.isBz() ? itemData.bz.get(lowestDistTime).s : null; int xPos = (int) map(lowestDistTime, firstTime, lastTime, guiLeft + 17, guiLeft + 315); int yPos = (int) map(price, highestValue + 10d, lowestValue - 10d, guiTop + 35, guiTop + 198); int yPos2 = price2 != null @@ -243,7 +244,7 @@ public class GuiPriceGraph extends GuiScreen { NumberFormat nf = NumberFormat.getInstance(); ArrayList text = new ArrayList<>(); text.add(displayFormat.format(date)); - if (dataPoints.isBz()) { + if (itemData.isBz()) { text.add(EnumChatFormatting.YELLOW + "" + EnumChatFormatting.BOLD + "Bazaar Insta-Buy: " + EnumChatFormatting.GOLD + EnumChatFormatting.BOLD + nf.format(price)); text.add(EnumChatFormatting.YELLOW + "" + EnumChatFormatting.BOLD + "Bazaar Insta-Sell: " + @@ -320,7 +321,7 @@ public class GuiPriceGraph extends GuiScreen { } private void loadData() { - dataPoints = null; + itemData = null; loaded = false; new Thread(() -> { File dir = new File("config/notenoughupdates/prices"); @@ -329,46 +330,46 @@ public class GuiPriceGraph extends GuiScreen { return; } File[] files = dir.listFiles(); - Data data = new Data(); + ItemData itemData = new ItemData(); if (files == null) return; for (File file : files) { if (!file.getName().endsWith(".gz")) continue; - HashMap data2 = load(file); + HashMap data2 = load(file); if (data2 == null || !data2.containsKey(itemId)) continue; if (data2.get(itemId).isBz()) { - if (data.bz == null) data.bz = data2.get(itemId).bz; - else data.bz.putAll(data2.get(itemId).bz); - } else if (data.ah == null) data.ah = data2.get(itemId).ah; - else data.ah.putAll(data2.get(itemId).ah); + if (itemData.bz == null) itemData.bz = data2.get(itemId).bz; + else itemData.bz.putAll(data2.get(itemId).bz); + } else if (itemData.ah == null) itemData.ah = data2.get(itemId).ah; + else itemData.ah.putAll(data2.get(itemId).ah); } - if (data.get() != null && !data.get().isEmpty()) { + if (itemData.get() != null && !itemData.get().isEmpty()) { if (mode < 3) - data = new Data( - new TreeMap<>(data.get().entrySet().stream() - .filter(e -> e.getKey() > System.currentTimeMillis() / 1000 - + itemData = new ItemData( + new TreeMap<>(itemData.get().entrySet().stream() + .filter(e -> e.getKey() > System.currentTimeMillis() / 1000 - (mode == 0 ? 3600 : mode == 1 ? 86400 : 604800)) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))), - data.isBz() + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))), + itemData.isBz() ); else if (mode == 4) - data = new Data( - new TreeMap<>(data.get().entrySet().stream() - .filter(e -> e.getKey() >= customStart && e.getKey() <= customEnd) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))), - data.isBz() + itemData = new ItemData( + new TreeMap<>(itemData.get().entrySet().stream() + .filter(e -> e.getKey() >= customStart && e.getKey() <= customEnd) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))), + itemData.isBz() ); - if (data.get() == null || data.get().isEmpty()) { + if (itemData.get() == null || itemData.get().isEmpty()) { loaded = true; return; } - dataPoints = trimData(data); - firstTime = dataPoints.get().firstKey(); - lastTime = dataPoints.get().lastKey(); + this.itemData = trimData(itemData); + firstTime = this.itemData.get().firstKey(); + lastTime = this.itemData.get().lastKey(); highestValue = 0; lowestValue = null; - for (long key : dataPoints.get().keySet()) { - float value1 = dataPoints.isBz() ? dataPoints.bz.get(key).b : dataPoints.ah.get(key); - Float value2 = dataPoints.isBz() ? dataPoints.bz.get(key).s : null; + for (long key : this.itemData.get().keySet()) { + float value1 = this.itemData.isBz() ? this.itemData.bz.get(key).b : this.itemData.ah.get(key); + Float value2 = this.itemData.isBz() ? this.itemData.bz.get(key).s : null; if (value1 > highestValue) { highestValue = value1; } @@ -404,33 +405,13 @@ public class GuiPriceGraph extends GuiScreen { Date date = new Date(); Long epochSecond = date.toInstant().getEpochSecond(); File file = new File(dir, "prices_" + format.format(date) + ".gz"); - HashMap prices = new HashMap<>(); + HashMap prices = new HashMap<>(); if (file.exists()) { - HashMap tempPrices = load(file); + HashMap tempPrices = load(file); if (tempPrices != null) prices = tempPrices; } for (Map.Entry item : items.entrySet()) { - if (prices.containsKey(item.getKey())) { - if (bazaar && item.getValue().getAsJsonObject().has("curr_buy") && item.getValue().getAsJsonObject().has( - "curr_sell")) - prices.get(item.getKey()).bz.put(epochSecond, new BzData( - item.getValue().getAsJsonObject().get("curr_buy").getAsFloat(), - item.getValue().getAsJsonObject().get("curr_sell").getAsFloat() - )); - else if (!bazaar) - prices.get(item.getKey()).ah.put(epochSecond, item.getValue().getAsBigDecimal().intValue()); - } else { - TreeMap mapData = new TreeMap<>(); - if (bazaar && item.getValue().getAsJsonObject().has("curr_buy") && item.getValue().getAsJsonObject().has( - "curr_sell")) - mapData.put(epochSecond, new BzData( - item.getValue().getAsJsonObject().get("curr_buy").getAsFloat(), - item.getValue().getAsJsonObject().get("curr_sell").getAsFloat() - )); - else if (!bazaar) - mapData.put(epochSecond, item.getValue().getAsLong()); - prices.put(item.getKey(), new Data(mapData, bazaar)); - } + addOrUpdateItemPriceInfo(item, prices, epochSecond, bazaar); } //noinspection ResultOfMethodCallIgnored file.createNewFile(); @@ -447,16 +428,64 @@ public class GuiPriceGraph extends GuiScreen { } } - private Data trimData(Data data) { - long first = data.get().firstKey(); - long last = data.get().lastKey(); - Data trimmed = new Data(); - if (data.isBz()) + private static void addOrUpdateItemPriceInfo(Map.Entry item, HashMap prices, long timestamp, boolean bazaar) { + String itemName = item.getKey(); + ItemData existingItemData = null; + if (prices.containsKey(itemName)) { + existingItemData = prices.get(itemName); + } + + // Handle transitions from ah to bz (the other direction typically doesn't happen) + if (existingItemData != null) { + if (existingItemData.isBz() && !bazaar) { + return; + } + + if (!existingItemData.isBz() && bazaar) { + prices.remove(itemName); + existingItemData = null; + } + } + + if (bazaar) { + if (!item.getValue().getAsJsonObject().has("curr_buy") || + !item.getValue().getAsJsonObject().has("curr_sell") + ) { + return; + } + + BzData bzData = new BzData( + item.getValue().getAsJsonObject().get("curr_buy").getAsFloat(), + item.getValue().getAsJsonObject().get("curr_sell").getAsFloat()); + + if (existingItemData != null) { + existingItemData.bz.put(timestamp, bzData); + } else { + TreeMap mapData = new TreeMap<>(); + mapData.put(timestamp, bzData); + prices.put(item.getKey(), new ItemData(mapData, true)); + } + } else { + if (existingItemData != null) { + prices.get(item.getKey()).ah.put(timestamp, item.getValue().getAsBigDecimal().intValue()); + } else { + TreeMap mapData = new TreeMap<>(); + mapData.put(timestamp, item.getValue().getAsLong()); + prices.put(item.getKey(), new ItemData(mapData, false)); + } + } + } + + private ItemData trimData(ItemData itemData) { + long first = itemData.get().firstKey(); + long last = itemData.get().lastKey(); + ItemData trimmed = new ItemData(); + if (itemData.isBz()) trimmed.bz = new TreeMap<>(); else trimmed.ah = new TreeMap<>(); int zones = NotEnoughUpdates.INSTANCE.config.ahGraph.graphZones; - Long[] dataArray = !data.isBz() ? data.ah.keySet().toArray(new Long[0]) : data.bz.keySet().toArray(new Long[0]); + Long[] dataArray = !itemData.isBz() ? itemData.ah.keySet().toArray(new Long[0]) : itemData.bz.keySet().toArray(new Long[0]); int prev = 0; for (int i = 0; i < zones; i++) { long lowest = (long) map(i, 0, zones, first, last); @@ -467,14 +496,14 @@ public class GuiPriceGraph extends GuiScreen { for (int l = prev; l < dataArray.length; l++) { if (dataArray[l] >= lowest && dataArray[l] <= highest) { amount++; - sumBuy += data.isBz() ? data.bz.get(dataArray[l]).b : data.ah.get(dataArray[l]); - if (data.isBz()) sumSell += data.bz.get(dataArray[l]).s; + sumBuy += itemData.isBz() ? itemData.bz.get(dataArray[l]).b : itemData.ah.get(dataArray[l]); + if (itemData.isBz()) sumSell += itemData.bz.get(dataArray[l]).s; prev = l + 1; } else if (dataArray[l] > highest) break; } if (amount > 0) { - if (data.isBz()) + if (itemData.isBz()) trimmed.bz.put(lowest, new BzData((float) (sumBuy / amount), (float) (sumSell / amount))); else trimmed.ah.put(lowest, (int) (sumBuy / amount)); @@ -483,8 +512,8 @@ public class GuiPriceGraph extends GuiScreen { return trimmed; } - private static HashMap load(File file) { - Type type = new TypeToken>() { + private static HashMap load(File file) { + Type type = new TypeToken>() { }.getType(); if (file.exists()) { try ( @@ -525,14 +554,14 @@ public class GuiPriceGraph extends GuiScreen { } } -class Data { +class ItemData { public TreeMap ah = null; public TreeMap bz = null; - public Data() { + public ItemData() { } - public Data(TreeMap map, boolean bz) { + public ItemData(TreeMap map, boolean bz) { if (bz) this.bz = (TreeMap) map; else -- cgit From 50dc2122462642a0c3a00b3a3ae6389825dc04df Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Thu, 9 Jun 2022 18:04:22 -0400 Subject: Re-license project as LGPL (#157) * add licence files & a few misc chores * add license notices & run auto formatter --- .../notenoughupdates/miscgui/GuiPriceGraph.java | 50 +++++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java index e2381503..ed8d5d92 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java @@ -1,3 +1,22 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see . + */ + package io.github.moulberry.notenoughupdates.miscgui; import com.google.common.reflect.TypeToken; @@ -17,14 +36,26 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; -import java.io.*; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; import java.text.DecimalFormat; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.time.Instant; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.TreeMap; import java.util.stream.Collectors; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; @@ -347,7 +378,7 @@ public class GuiPriceGraph extends GuiScreen { itemData = new ItemData( new TreeMap<>(itemData.get().entrySet().stream() .filter(e -> e.getKey() > System.currentTimeMillis() / 1000 - - (mode == 0 ? 3600 : mode == 1 ? 86400 : 604800)) + (mode == 0 ? 3600 : mode == 1 ? 86400 : 604800)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))), itemData.isBz() ); @@ -428,7 +459,12 @@ public class GuiPriceGraph extends GuiScreen { } } - private static void addOrUpdateItemPriceInfo(Map.Entry item, HashMap prices, long timestamp, boolean bazaar) { + private static void addOrUpdateItemPriceInfo( + Map.Entry item, + HashMap prices, + long timestamp, + boolean bazaar + ) { String itemName = item.getKey(); ItemData existingItemData = null; if (prices.containsKey(itemName)) { @@ -456,7 +492,8 @@ public class GuiPriceGraph extends GuiScreen { BzData bzData = new BzData( item.getValue().getAsJsonObject().get("curr_buy").getAsFloat(), - item.getValue().getAsJsonObject().get("curr_sell").getAsFloat()); + item.getValue().getAsJsonObject().get("curr_sell").getAsFloat() + ); if (existingItemData != null) { existingItemData.bz.put(timestamp, bzData); @@ -485,7 +522,8 @@ public class GuiPriceGraph extends GuiScreen { else trimmed.ah = new TreeMap<>(); int zones = NotEnoughUpdates.INSTANCE.config.ahGraph.graphZones; - Long[] dataArray = !itemData.isBz() ? itemData.ah.keySet().toArray(new Long[0]) : itemData.bz.keySet().toArray(new Long[0]); + Long[] dataArray = + !itemData.isBz() ? itemData.ah.keySet().toArray(new Long[0]) : itemData.bz.keySet().toArray(new Long[0]); int prev = 0; for (int i = 0; i < zones; i++) { long lowest = (long) map(i, 0, zones, first, last); -- cgit From 872c522def2a301ac09c0e784dc640ba023c26a1 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 30 Jul 2022 16:47:31 +0200 Subject: changed float to double and int to long in GuiPriceGraph (#198) --- .../notenoughupdates/miscgui/GuiPriceGraph.java | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java index ed8d5d92..71a23ffb 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java @@ -68,10 +68,10 @@ public class GuiPriceGraph extends GuiScreen { private static final int X_SIZE = 364; private static final int Y_SIZE = 215; private ItemData itemData; - private float highestValue; + private double highestValue; private long firstTime; private long lastTime; - private Float lowestValue = null; + private Double lowestValue = null; private String itemName; private final String itemId; private int guiLeft; @@ -166,7 +166,7 @@ public class GuiPriceGraph extends GuiScreen { Integer prevX = null; Integer prevY = null; for (Long time : itemData.get().keySet()) { - float price = itemData.isBz() + double price = itemData.isBz() ? i == 0 ? itemData.bz.get(time).b : itemData.bz.get(time).s : itemData.ah.get(time); int xPos = (int) map(time, firstTime, lastTime, guiLeft + 17, guiLeft + 315); @@ -250,7 +250,7 @@ public class GuiPriceGraph extends GuiScreen { Utils.drawDottedLine(customStart, guiTop + 197, customEnd, guiTop + 197, 2, 10, 0xFFc6c6c6); } if (lowestDist != null && !customSelecting) { - float price = itemData.isBz() ? itemData.bz.get(lowestDistTime).b : itemData.ah.get(lowestDistTime); + double price = itemData.isBz() ? itemData.bz.get(lowestDistTime).b : itemData.ah.get(lowestDistTime); Float price2 = itemData.isBz() ? itemData.bz.get(lowestDistTime).s : null; int xPos = (int) map(lowestDistTime, firstTime, lastTime, guiLeft + 17, guiLeft + 315); int yPos = (int) map(price, highestValue + 10d, lowestValue - 10d, guiTop + 35, guiTop + 198); @@ -399,7 +399,7 @@ public class GuiPriceGraph extends GuiScreen { highestValue = 0; lowestValue = null; for (long key : this.itemData.get().keySet()) { - float value1 = this.itemData.isBz() ? this.itemData.bz.get(key).b : this.itemData.ah.get(key); + double value1 = this.itemData.isBz() ? this.itemData.bz.get(key).b : this.itemData.ah.get(key); Float value2 = this.itemData.isBz() ? this.itemData.bz.get(key).s : null; if (value1 > highestValue) { highestValue = value1; @@ -411,7 +411,7 @@ public class GuiPriceGraph extends GuiScreen { lowestValue = value1; } if (value2 != null && value2 < lowestValue) { - lowestValue = value2; + lowestValue = Double.valueOf(value2); } } } @@ -504,7 +504,7 @@ public class GuiPriceGraph extends GuiScreen { } } else { if (existingItemData != null) { - prices.get(item.getKey()).ah.put(timestamp, item.getValue().getAsBigDecimal().intValue()); + prices.get(item.getKey()).ah.put(timestamp, item.getValue().getAsBigDecimal().longValue()); } else { TreeMap mapData = new TreeMap<>(); mapData.put(timestamp, item.getValue().getAsLong()); @@ -544,7 +544,7 @@ public class GuiPriceGraph extends GuiScreen { if (itemData.isBz()) trimmed.bz.put(lowest, new BzData((float) (sumBuy / amount), (float) (sumSell / amount))); else - trimmed.ah.put(lowest, (int) (sumBuy / amount)); + trimmed.ah.put(lowest, (long) (sumBuy / amount)); } } return trimmed; @@ -593,7 +593,7 @@ public class GuiPriceGraph extends GuiScreen { } class ItemData { - public TreeMap ah = null; + public TreeMap ah = null; public TreeMap bz = null; public ItemData() { @@ -603,7 +603,7 @@ class ItemData { if (bz) this.bz = (TreeMap) map; else - this.ah = (TreeMap) map; + this.ah = (TreeMap) map; } public TreeMap get() { -- cgit