+ String islandNum = m.group(1);
+
+ URL get = new URL(PCTB_HOST_URL +
+ "upload.php?action=setisland&ocean=" + oceanNum
+ + "&island=" + islandNum
+ + "&forcereload=" + forceReload
+ + "&filename=" + filename);
+ String complete = readstreamstring(get.openStream());
+ debug_write_stringdata("pctb-final.html", complete);
+ Pattern done = Pattern.compile
+ ("Your data has been integrated into the database. Thank you!");
+ m = done.matcher(complete);
+ if(m.find()) {
+ return true;
+ } else {
+ error_html("Something was wrong with the final upload parameters!",
+ complete);
+ return false;
+ }
+ }
+
+ private InputStream post_for_yarrg(ClientHttpRequest http)
+ throws IOException {
+ if (!http.post()) {
+ String err = readstreamstring(http.resultstream());
+ error("<html><h1>Error reported by YARRG server</h1>\n" + err);
+ return null;
+ }
+ return http.resultstream();
+ }
+
+ private String getYarrgTimestamp() throws IOException {
+ ClientHttpRequest http = new ClientHttpRequest (YARRG_URL);
+ http.setParameter("clientname", YARRG_CLIENTNAME);
+ http.setParameter("clientversion", YARRG_CLIENTVERSION);
+ http.setParameter("clientfixes", YARRG_CLIENTFIXES);
+ http.setParameter("requesttimestamp", "y");
+ InputStream in = post_for_yarrg(http);
+ if (in == null) return null;
+ BufferedReader br = new BufferedReader(new InputStreamReader(in));
+ String tsresult = br.readLine();
+ return tsresult.substring(3, tsresult.length()-1);
+ }
+
+ private boolean runYarrg(String timestamp, String ocean, String island,
+ String yarrgdata) throws IOException {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ BufferedOutputStream bufos =
+ new BufferedOutputStream(new GZIPOutputStream(bos));
+ bufos.write(yarrgdata.getBytes() );
+ bufos.close();
+ 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);
+ http.setParameter("clientversion", YARRG_CLIENTVERSION);
+ http.setParameter("clientfixes", YARRG_CLIENTFIXES);
+ http.setParameter("timestamp", timestamp);
+ http.setParameter("ocean", ocean);
+ http.setParameter("island", island);
+ http.setParameter("data", "deduped.tsv.gz", file,
+ "application/octet-stream");
+ InputStream in = post_for_yarrg(http);
+ if (in == null) return false;
+ String output = readstreamstring(in);
+ if (!output.startsWith("OK")) {
+ error("<html><h1>Unexpected output from YARRG server</h1>\n" + output);
+ return false;
+ }
+ debug_write_stringdata("yarrg-result.txt", output);
+ return true;
+ }
+
+ private int calculateArbitrageCommodity(ArrayList<SortedSet<int[]>> arb_bs) {
+ // if (dtxt!=null) dtxt.println("ARBITRAGE?");
+ int profit = 0;
+ SortedSet<int[]> buys = arb_bs.get(0);
+ SortedSet<int[]> sells = arb_bs.get(1);
+ while (true) {
+ int[] buy, sell;
+ try {
+ // NB "sell" means they sell, ie we buy
+ sell = sells.last();
+ buy = buys.first();
+ } catch (NoSuchElementException e) {
+ break;
+ }
+
+ 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);
+
+ if (unitprofit <= 0)
+ break;