Hey there, Lucky Bit fans! I've taken a moment to put together a useful tool that expands on the power of the
Lucky Bit Bet Browser. This small Java app will analyze your betting history and provide a breakdown of your results. You can see what color you've been lucky (or unlucky!) on, how many times you've hit the rare wins, and the app also discovers your largest win and best result.
It's 160+ lines of source code, and since I don't think it's a good idea to be casually tossing around JAR files I've decided to not provide a pre-compiled version at this time. Once the code is a little more polished I may do this but for now I'd like to release this code to the public. So yeah - the source code provided in this post is offered with no claim of ownership and no instruction manual. It also has no comments. Enjoy!
package it.luckyb.demo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import org.json.JSONObject;
public class LuckyStatsApp {
public final static String API = "http://luckyb.it/api";
protected enum Color { GREEN, YELLOW, RED };
protected class Bet {
protected double amount, result, payout;
protected Color color;
protected boolean isValid;
private String binary;
public Bet(JSONObject txo) {
if (!txo.getString("type").equals("VALID_BET")) {
isValid = false;
return;
}
isValid = true;
binary = txo.getString("binary_string");
amount = txo.getDouble("bet_amount");
result = txo.getDouble("multiplier_obtained");
payout = txo.getDouble("payout_amount");
color = Color.valueOf(txo.getString("game_name").toUpperCase(Locale.US));
}
public String mult() {
return String.format((result < 2 && result != 1.0) ? "%-1.1f" : "%-1.0f", result);
}
public int slot() {
int r = 0;
for (char c : binary.toCharArray())
if (c == '0') r -= 1; else r += 1;
r/=2;
return r<0?r*-1:r;
}
}
private String address;
private LuckyStatsApp(String address) { this.address = address; }
private JSONObject getData() throws IOException {
StringBuilder sb = new StringBuilder();
HttpURLConnection conn = (HttpURLConnection)(new URL(API + "/getbetsbyaddress/" + address).openConnection());
conn.connect();
InputStream is = conn.getInputStream();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line = null;
while ((line = reader.readLine()) != null) sb.append(line+"\n");
} catch (IOException e) {
is.close();
conn.disconnect();
throw e;
}
is.close();
conn.disconnect();
return new JSONObject(sb.toString());
}
private void go() {
List bets = new LinkedList();
try {
System.out.println("Fetching data... Please wait!");
JSONObject o = getData();
System.out.println();
for (String txkey : o.keySet())
bets.add(new Bet(o.getJSONObject(txkey)));
} catch (IOException e) {
System.out.println("Data retrieval failed. Is the Lucky Bit API down?");
System.out.println("The actual error encountered was:");
System.out.println(e.getLocalizedMessage());
return;
}
if (bets.size() == 0) {
System.out.println("No results received.");
System.out.println("Either [" + address + "] has never played a bet,");
System.out.println("or that isn't a valid bitcoin address.");
return;
}
double betT, betG = 0, betY = 0, betR = 0;
double wonT, wonG = 0, wonY = 0, wonR = 0;
Bet topWin = null, topHit = null;
int plays, playsG = 0, playsY = 0, playsR = 0;
int slots[] = {0,0,0,0,0,0,0,0,0};
int slotsG[] = {0,0,0,0,0,0,0,0,0};
int slotsY[] = {0,0,0,0,0,0,0,0,0};
int slotsR[] = {0,0,0,0,0,0,0,0,0};
double slotsP[] = {0,0,0,0,0,0,0,0,0};
for (Bet bet : bets) {
if (bet.isValid) {
switch (bet.color) {
case GREEN:
betG += bet.amount;
wonG += bet.payout;
playsG += 1;
slotsG[bet.slot()] += 1;
break;
case YELLOW:
betY += bet.amount;
wonY += bet.payout;
playsY += 1;
slotsY[bet.slot()] += 1;
break;
case RED:
betR += bet.amount;
wonR += bet.payout;
playsR += 1;
slotsR[bet.slot()] += 1;
break;
default:
break;
}
if (topWin == null || topWin.payout < bet.payout) topWin = bet;
if (topHit == null || topHit.result < bet.result || (topHit.result == bet.result && topHit.payout < bet.payout)) topHit = bet;
}
}
betT = betG + betY + betR;
wonT = wonG + wonY + wonR;
plays = playsG + playsY + playsR;
for (int i = 0; i < 9; i++) {
slots[i] += slotsG[i];
slots[i] += slotsY[i];
slots[i] += slotsR[i];
slotsP[i] = slots[i]*100.0/plays;
}
System.out.println("Bet analysis for [" + address + "]");
System.out.println(String.format(
"Total bet %-1.3f BTC - Total won %-1.3f BTC - Net P/L %-1.3f BTC", betT, wonT, wonT - betT));
System.out.println(String.format(
"Biggest win was %-1.3f on %s, hitting x%s for %-1.3f BTC", topWin.amount, topWin.color.toString().toLowerCase(), topWin.mult(), topWin.payout));
System.out.println(String.format(
"Best win was %-1.3f on %s, hitting x%s for %-1.3f BTC", topHit.amount, topHit.color.toString().toLowerCase(), topHit.mult(), topHit.payout));
System.out.println(String.format(
"%6s %6s %6s %6s %6s",
"", "Green", "Yellow", "Red", "Total"));
for (int i = 0; i < 9; i++)
System.out.println(String.format(
"Mid +%1d %6d %6d %6d %6d %-2.2f%%",
i, slotsG[i], slotsY[i], slotsR[i], slots[i], slotsP[i]));
System.out.println(String.format(
"%6s %6d %6d %6d %6d",
"Total", playsG, playsY, playsR, plays));
}
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("Specify your address, please.");
return;
}
LuckyStatsApp theApp = new LuckyStatsApp(args[0]);
theApp.go();
}
}