Bitcoin Forum
November 08, 2024, 06:24:01 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Lucky Bit Bet Analysis Tool [SOURCE]  (Read 1153 times)
stingleword (OP)
Legendary
*
Offline Offline

Activity: 1008
Merit: 1001

Out of crypto entirely and don't miss it


View Profile
October 05, 2014, 08:32:48 PM
 #1

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!

Code:
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<Bet> bets = new LinkedList<Bet>();
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();
}
}

Crypto is dead, its community is a series of bad jokes.
stingleword (OP)
Legendary
*
Offline Offline

Activity: 1008
Merit: 1001

Out of crypto entirely and don't miss it


View Profile
October 05, 2014, 08:34:50 PM
 #2

Sample output:

Code:
Fetching data... Please wait!

Bet analysis for [1WayStGErPLgjrGpK7Ro36ZA2eeraoaMi]
Total bet 3.038 BTC - Total won 2.993 BTC - Net P/L -0.045 BTC
Biggest win was 0.003 on yellow, hitting x12 for 0.036 BTC
Best win was 0.001 on red, hitting x24 for 0.024 BTC
        Green Yellow    Red  Total
Mid +0     29    128     15    172 19.09%
Mid +1     36    259     19    314 34.85%
Mid +2     26    166     30    222 24.64%
Mid +3     19     83      7    109 12.10%
Mid +4     10     46      7     63 6.99%
Mid +5      0     13      2     15 1.66%
Mid +6      1      4      1      6 0.67%
Mid +7      0      0      0      0 0.00%
Mid +8      0      0      0      0 0.00%
 Total    121    699     81    901

Crypto is dead, its community is a series of bad jokes.
seoincorporation
Legendary
*
Offline Offline

Activity: 3332
Merit: 3116



View Profile
October 05, 2014, 10:17:07 PM
 #3

Sample output:

Code:
Fetching data... Please wait!

Bet analysis for [1WayStGErPLgjrGpK7Ro36ZA2eeraoaMi]
Total bet 3.038 BTC - Total won 2.993 BTC - Net P/L -0.045 BTC
Biggest win was 0.003 on yellow, hitting x12 for 0.036 BTC
Best win was 0.001 on red, hitting x24 for 0.024 BTC
        Green Yellow    Red  Total
Mid +0     29    128     15    172 19.09%
Mid +1     36    259     19    314 34.85%
Mid +2     26    166     30    222 24.64%
Mid +3     19     83      7    109 12.10%
Mid +4     10     46      7     63 6.99%
Mid +5      0     13      2     15 1.66%
Mid +6      1      4      1      6 0.67%
Mid +7      0      0      0      0 0.00%
Mid +8      0      0      0      0 0.00%
 Total    121    699     81    901

Nice code  Smiley i like that output:

Quote
Biggest win was 0.003 on yellow, hitting x12 for 0.036 BTC
Best win was 0.001 on red, hitting x24 for 0.024 BTC

Luckybit in the statistics with graphs dont show the best bets of the addy, that can be in the next update, is just an idea  Wink

▄▄███████▄▄
▄██████████████▄
▄██████████████████▄
▄████▀▀▀▀███▀▀▀▀█████▄
▄█████████████▄█▀████▄
███████████▄███████████
██████████▄█▀███████████
██████████▀████████████
▀█████▄█▀█████████████▀
▀████▄▄▄▄███▄▄▄▄████▀
▀██████████████████▀
▀███████████████▀
▀▀███████▀▀
.
 MΞTAWIN  THE FIRST WEB3 CASINO   
.
.. PLAY NOW ..
LuckyBitSupport
Hero Member
*****
Offline Offline

Activity: 706
Merit: 519


Official LuckyBit Support


View Profile WWW
October 06, 2014, 05:34:21 PM
 #4

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!

Code:
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<Bet> bets = new LinkedList<Bet>();
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();
}
}

Nice!


[...]

Luckybit in the statistics with graphs dont show the best bets of the addy, that can be in the next update, is just an idea  Wink

Indeed, good idea.

                         ▄▄▄▄▄▄
             ▄▄█████▄▄███████████▄▄
     ▄▄    ▄████▀▀█████▀▀▀  ▄███████▄
  ▄█████  ████    ███▀     ███▀▀▀████▌
 ▐██▀    ████    ▐██▀  ▄  ▐███    ███▌
 ▐██▄   █████  ▄▄███  ███ ███▌   ▄███
  ▀█████████████████▄███ ▐█████████▀
    ▀▀▀▀████▀▀  ▀▀████▀  ██████████
       ▐███▌            ▐███    ▀███▄
       ████             ███▌     ████
    ▄▄█████       ▄██▄ ▐███     ▄███▀
 ▄███████████▄▄▄█████▀ █████▄▄▄████▀
█████▀▀▀▀██████████▀ ▐███████████▀
▀▀          ▀▀▀▀▀     ▀▀▀▀  ▀▀▀













██████████████████
████████████████████████
████████████████████████████
███████████████████████▀▀    ███
████████████████████▀▀   ▄▄██  ███
██████████████████▀▀   ▄▄██████  █████
██
████████████▀▀   ▄▄██████████  █████
███
████████▀▀   ▄▄██████████████  ██████
██
█████▀▀   ▄▄██████████████████  ██████
██
██▀   ▄▄██████████████████████  ██████
██
██
▄▄██████████████████████████  ██████
██
██
████████████████████████████  ██████
███
██
███████████████████████████  ██████
██
███
█████████████████████████  █████
████
██
█████████████████████████  █████
███
██
████████████████████████████
███
████
██████████████████████████
████
█████
███████████████████
██████
██████████████████
██████████████████












● Great Prizes
● Trophies
● The Original Plinko
● Great Community
● Chat Lotto
● Low House Edge
stingleword (OP)
Legendary
*
Offline Offline

Activity: 1008
Merit: 1001

Out of crypto entirely and don't miss it


View Profile
October 07, 2014, 11:20:35 PM
 #5

I've completed the independent Lucky Bit API for Java. Head on over here:

https://bitcointalk.org/index.php?topic=815560

Crypto is dead, its community is a series of bad jokes.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!