}
}
- private void progresslog(String s) {
+ private void debuglog(String s) {
if (dtxt == null) return;
long now = new Date().getTime();
dtxt.println("progress "+(now - startTime)+"ms "+s);
uploadToPCTB=prefs.getBoolean("uploadToPCTB", true);
showArbitrage=prefs.getBoolean("showArbitrage", true);
- if (dtxt!=null) dtxt.println("main on dispatch thread: "+
- EventQueue.isDispatchThread());
+ debuglog("main on dispatch thread: "+EventQueue.isDispatchThread());
EventQueue.invokeLater(this);
}
* every top-level window, and if it
*/
public void run() {
- if (dtxt!=null) dtxt.println("MarketUploader run()...");
+ debuglog("MarketUploader run()...");
if (EventQueueMonitor.isGUIInitialized()) {
- if (dtxt!=null) dtxt.println("MarketUploader GUI already ready");
+ debuglog("MarketUploader GUI already ready");
guiInitialized();
} else {
- if (dtxt!=null) dtxt.println("MarketUploader waiting for GUI");
+ debuglog("MarketUploader waiting for GUI");
EventQueueMonitor.addGUIInitializedListener(this);
}
}
Window ws[]= EventQueueMonitor.getTopLevelWindows();
EventQueueMonitor.addTopLevelWindowListener(this);
for (int i=0; i<ws.length; i++) {
- if (dtxt!=null) dtxt.println("MarketUploader existing toplevel "+i);
+ debuglog("MarketUploader existing toplevel "+i);
topLevelWindowCreated(ws[i]);
}
}
public void topLevelWindowDestroyed(Window w) {
- if (dtxt!=null) dtxt.println("MarketUploader destroyed toplevel");
+ debuglog("MarketUploader destroyed toplevel");
}
public void topLevelWindowCreated(Window w) {
// already got it
return;
String name = w.getAccessibleContext().getAccessibleName();
- if (dtxt!=null) dtxt.println("MarketUploader new toplevel "+name);
+ debuglog("MarketUploader new toplevel "+name);
if (!name.equals("Puzzle Pirates"))
return;
- if (dtxt!=null) dtxt.println("MarketUploader found toplevel, creating gui");
+ debuglog("MarketUploader found toplevel, creating gui");
window = w;
createGUI();
frame.setVisible(true);
}
String whole_msg = "<html><h1>Error</h1>"+msg
+"<h1>PCTB Server said:</h1><blockquote>"+html+"</blockquote>";
- if (dtxt!=null) dtxt.println("###" + whole_msg + "###");
+ debuglog("###" + whole_msg + "###");
error(whole_msg);
}
int index = text.indexOf(":");
String name = text.substring(0,index);
islandName = name;
- // if (dtxt!=null) dtxt.println(islandName);
+ // debuglog(islandName);
sidePanel.removePropertyChangeListener(this);
latch.countDown();
}
public void run() {
try {
ts = getYarrgTimestamp();
- progresslog("(async) yarrg timestamp ready.");
+ debuglog("(async) yarrg timestamp ready.");
} catch(Exception e) {
error("Error getting YARRG timestamp: "+e);
}
boolean doneyarrg = false, donepctb = false;
YarrgTimestampFetcher yarrgts_thread = null;
- progresslog("starting");
+ debuglog("starting");
if (uploadToYarrg) {
- progresslog("(async) yarrg timestamp...");
+ debuglog("(async) yarrg timestamp...");
yarrgts_thread = new YarrgTimestampFetcher();
yarrgts_thread.start();
}
return null;
}
- progresslog("(async) getisland...");
+ debuglog("(async) getisland...");
getIsland();
- progresslog("getocean...");
+ debuglog("getocean...");
getOcean();
- progresslog("getocean done");
+ debuglog("getocean done");
return at;
}}.exec();
if (latch != null) {
latch.await(2, java.util.concurrent.TimeUnit.SECONDS);
}
- progresslog("(async) getisland done");
+ debuglog("(async) getisland done");
String yarrgts = null;
if (yarrgts_thread != null) {
- progresslog("(async) yarrg timestamp join...");
+ debuglog("(async) yarrg timestamp join...");
yarrgts_thread.join();
- progresslog("(async) yarrg timestamp joined.");
+ debuglog("(async) yarrg timestamp joined.");
yarrgts = yarrgts_thread.ts;
}
return;
}
- progresslog("table check...");
+ debuglog("table check...");
final ArrayList<ArrayList<String>> data =
new UIXR<ArrayList<ArrayList<String>>>
}
}
- progresslog("table read...");
+ debuglog("table read...");
return getData(accesstable);
}}.exec();
if (data == null) return;
if (showArbitrage) {
- progresslog("arbitrage...");
+ debuglog("arbitrage...");
calculateArbitrage(data);
- progresslog("arbitrage done.");
+ debuglog("arbitrage done.");
}
if (uploadToYarrg && yarrgts != null) {
- progresslog("yarrg prepare...");
+ debuglog("yarrg prepare...");
progressNote("Yarrg: Preparing data");
setProgress(10);
yarrgdata = yarrgsb.toString();
progressNote("Yarrg: Uploading");
- progresslog("yarrg upload...");
+ debuglog("yarrg upload...");
doneyarrg = runYarrg(yarrgts, oceanName, islandName, yarrgdata);
- progresslog("yarrg done.");
+ debuglog("yarrg done.");
}
if (uploadToPCTB) {
- progresslog("pctb prepare...");
+ debuglog("pctb prepare...");
progressNote("PCTB: Getting stall names");
setProgress(20);
if(isCanceled()) {
}
// get commod map
- progresslog("pctb commodmap...");
+ debuglog("pctb commodmap...");
HashMap<String,Integer> commodMap = getCommodMap();
if(commodMap == null) {
return;
}
- progresslog("pctb commodmap done.");
+ debuglog("pctb commodmap done.");
int[] offerCount = getBuySellMaps(data,buys,sells,stallMap,commodMap);
- // if (dtxt!=null) dtxt.println(sells);
- // if (dtxt!=null) dtxt.println("\n\n\n"+buys);
+ // debuglog(sells);
+ // debuglog("\n\n\n"+buys);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
setProgress(60);
dos.writeBytes(getAbbrevStallList(stallMap));
writeBuySellOffers(buys,sells,offerCount,out);
out.finish();
- progresslog("pctb send...");
+ debuglog("pctb send...");
byte[] ba = outStream.toByteArray();
debug_write_bytes("pctb-marketdata.gz", ba);
InputStream in = sendInitialData(new ByteArrayInputStream(ba));
- progresslog("pctb sent.");
+ debuglog("pctb sent.");
if (in == null) return;
setProgress(80);
if(isCanceled()) {
return;
}
progressNote("PCTB: Waiting ...");
- progresslog("pctb finish...");
+ debuglog("pctb finish...");
donepctb = finishUpload(in);
- progresslog("pctb done.");
+ debuglog("pctb done.");
}
setProgress(99);
resultSummary.setText(summary_final);
}}.exec();
- progresslog("done.");
+ debuglog("done.");
}
/**
Accessible node = descendNodes(node1,new int[] {0,1,0,0,0,0,1,0,0,1,0,0});
// commod market
// commod market: {0,1,0,0,0,0,1,0,0,1,0} {0,1,0,0,0,0,1,0,1,0,0,1,0,0})
- // if (dtxt!=null) dtxt.println(node);
+ // debuglog(node);
if (!(node instanceof JTable)) {
node = descendNodes(node1,new int[] {0,1,0,0,0,0,1,0,1,0,0,1,0,0});
// commod market
}
if (!(node instanceof JTable)) return null;
AccessibleTable table = node.getAccessibleContext().getAccessibleTable();
- // if (dtxt!=null) dtxt.println(table);
+ // debuglog(table);
return table;
}
if (parent == null) return null;
int children = parent.getAccessibleContext().getAccessibleChildrenCount();
if (childNum >= children) {
- if (dtxt!=null) dtxt.println("DESCEND "+childNum+" > "
- +children+" NOT FOUND");
+ debuglog("DESCEND "+childNum+" > "+children+" NOT FOUND");
return null;
}
Accessible child = parent.getAccessibleContext()
.getAccessibleChild(childNum);
- if (dtxt!=null) dtxt.println("DESCEND "+childNum+" "
- +child.getClass().getName()+" OK");
+ debuglog("DESCEND "+childNum+" "+child.getClass().getName()+" OK");
return child;
}
for (int i=0; i<children; i++) {
Accessible child = ac.getAccessibleChild(i);
if (child.getClass().getName() == classname) {
- if (dtxt!=null) dtxt.println("DESCEND CLASS "+classname+" OK");
+ debuglog("DESCEND CLASS "+classname+" OK");
return child;
}
}
- if (dtxt!=null) dtxt.println("DESCEND CLASS "+classname+" NOT FOUND");
+ debuglog("DESCEND CLASS "+classname+" NOT FOUND");
return null;
}
}
} catch(IllegalArgumentException e) {
unknownPCTBcommods++;
- if (dtxt!=null) dtxt.println("Error: Unsupported Commodity \""
- + offer.get(0) + "\"");
+ debuglog("Error: Unsupported Commodity \"" + offer.get(0) + "\"");
}
}
if (buySellCount[0]==0 && buySellCount[1]==0) {
}
private int calculateArbitrageCommodity(ArrayList<SortedSet<int[]>> arb_bs) {
- // if (dtxt!=null) dtxt.println("ARBITRAGE?");
+ // debuglog("ARBITRAGE?");
int profit = 0;
SortedSet<int[]> buys = arb_bs.get(0);
SortedSet<int[]> sells = arb_bs.get(1);
int unitprofit = buy[0] - sell[0];
int count = buy[1] < sell[1] ? buy[1] : sell[1];
- // if (dtxt!=null) dtxt.println(" sell @"+sell[0]+" x"+sell[1]
- // +" buy @"+buy[0]+" x"+buy[1]
- // +" => x"+count+" @"+unitprofit);
+ // debuglog(" sell @"+sell[0]+" x"+sell[1]
+ // +" buy @"+buy[0]+" x"+buy[1]
+ // +" => x"+count+" @"+unitprofit);
if (unitprofit <= 0)
break;
if (buy[1]==0) buys.remove(buy);
if (sell[1]==0) sells.remove(sell);
}
- // if (dtxt!=null) dtxt.println(" PROFIT "+profit);
+ // debuglog(" PROFIT "+profit);
return profit;
}
for (ArrayList<String> row : data) {
String thiscommod = row.get(0);
- // if (dtxt!=null) dtxt.println("ROW "+row.toString());
+ // debuglog("ROW "+row.toString());
if (lastcommod == null || !thiscommod.equals(lastcommod)) {
if (lastcommod != null)
arbitrage += calculateArbitrageCommodity(arb_bs);
- // if (dtxt!=null) dtxt.println("ROW rdy");
+ // debuglog("ROW rdy");
arb_bs = new ArrayList<SortedSet<int[]>>(2);
arb_bs.add(0, new TreeSet<int[]>(compar));
arb_bs.add(1, new TreeSet<int[]>(compar));
- // if (dtxt!=null) dtxt.println("ROW init");
+ // debuglog("ROW init");
lastcommod = thiscommod;
}
for (int bs = 0; bs < 2; bs++) {
if (pricestr == null)
continue;
int[] entry = new int[2];
- // if (dtxt!=null) dtxt.println("ROW BS "+bs);
+ // debuglog("ROW BS "+bs);
entry[0] = parseQty(pricestr);
entry[1] = parseQty(row.get(bs*2 + 3));
arb_bs.get(bs).add(entry);