chiark / gitweb /
debug write out deduped.tsv.gz not deduped.tsv
[jarrg-ian.git] / src / com / tedpearson / ypp / market / MarketUploader.java
index f8437f94d85758511f7f1067076cba4f3c56238f..90a920a44442f321f0bcec4ec63a61e2d3eae2d7 100644 (file)
@@ -40,6 +40,7 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
        private JButton findMarket = null;
        private JLabel resultSummary = null;
        private JLabel arbitrageResult = null;
+        private int unknownPCTBcommods = 0;
         private long startTime = 0;
 
        private final static String PCTB_LIVE_HOST_URL = "http://pctb.crabdance.com/";
@@ -104,6 +105,13 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
            strm.close();
        }
 
+        private void debug_write_bytes(String what, byte[] data) throws FileNotFoundException,IOException {
+           if (dtxt==null) return;
+           FileOutputStream strm = new FileOutputStream(new File("jarrg-debug-"+what));
+           strm.write(data);
+           strm.close();
+       }
+
         private void progressNote(ProgressMonitor pm, String s) {
            String arb = null;
            if (arbitrageResult != null)
@@ -297,6 +305,7 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
                                                startTime = new Date().getTime();
                                                resultSummary.setText("");
                                                arbitrageResult.setText("");
+                                               unknownPCTBcommods = 0;
                                                try {
                                                        runUpload();
                                                } catch(Exception e) {
@@ -535,8 +544,6 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
                        progressNote(pm, "Yarrg: Uploading");
                        progresslog("yarrg upload...");
 
-                       debug_write_stringdata("yarrg-deduped.tsv", yarrgdata);
-
                        doneyarrg = runYarrg(yarrgts, oceanName, islandName, yarrgdata);
                        progresslog("yarrg done.");
                }
@@ -584,11 +591,7 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
                    progresslog("pctb send...");
 
                    byte[] ba = outStream.toByteArray();
-                   if (dtxt!=null) {
-                       FileOutputStream dbgdata = new FileOutputStream(new File("jarrg-debug-pctb-marketdata.gz"));
-                       dbgdata.write(ba);
-                       dbgdata.close();
-                   }
+                   debug_write_bytes("pctb-marketdata.gz", ba);
 
                    InputStream in = sendInitialData(new ByteArrayInputStream(ba));
                    progresslog("pctb sent.");
@@ -607,6 +610,8 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
                if ((uploadToPCTB && !donepctb) ||
                    (uploadToYarrg && !doneyarrg)) {
                        resultSummary.setText("trouble");
+               } else if (unknownPCTBcommods != 0) {
+                       resultSummary.setText("PCTB lacks "+unknownPCTBcommods+" commod");
                } else if (donepctb || doneyarrg) {
                        resultSummary.setText("Done " + islandName);
                } else {
@@ -810,6 +815,7 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
                                        buySellCount[1]++;
                                }
                        } catch(IllegalArgumentException e) {
+                               unknownPCTBcommods++;
                                if (dtxt!=null) dtxt.println("Error: Unsupported Commodity \"" + offer.get(0) + "\"");
                        }
                }
@@ -1050,7 +1056,9 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
        BufferedOutputStream bufos = new BufferedOutputStream(new GZIPOutputStream(bos));
        bufos.write(yarrgdata.getBytes() );
        bufos.close();
-       ByteArrayInputStream file = new ByteArrayInputStream(bos.toByteArray());
+       byte[] compressed = bos.toByteArray();
+       debug_write_bytes("yarrg-deduped.tsv.gz", compressed);
+       ByteArrayInputStream file = new ByteArrayInputStream(compressed);
 
        ClientHttpRequest http = new ClientHttpRequest (YARRG_URL);
        http.setParameter("clientname", YARRG_CLIENTNAME);