bet 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +21 -0
- data/Rakefile +2 -0
- data/bet.gemspec +22 -0
- data/lib/bet.rb +5 -0
- data/lib/bet/bet_calculations/combinatorial.rb +57 -0
- data/lib/bet/bet_calculations/convenience.rb +6 -0
- data/lib/bet/bet_calculations/core.rb +27 -0
- data/lib/bet/calc.rb +45 -0
- data/lib/bet/version.rb +3 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 52e7c97a52bb4e4ba5a5dcb2a98f6467225a6718
|
4
|
+
data.tar.gz: 9b38ee0ad8f170b0bbc0189c4d7f8a2ebefd0141
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 200218acceb2434ecd5c1618e5ad14a12725ed38188855cfae3b20a28b1dde7cb2a7d28547a49cf4a9d04aea574c5e2d394d9251d928c135f1e368bd4ef56596
|
7
|
+
data.tar.gz: bf770179e639fbe4aa05007f478ac36d150cd83c38a88cea5e422af439dd5dabbcf87430754f7bb01d66e5a9e967a5239ef3d3486d06ad9e21cd17b16a283ddd
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Mike Campbell
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Bet
|
2
|
+
|
3
|
+
Want to prototype a new betting strategy? Can't be arsed to work out all the annoying maths involved in calculating bets? This is the gem for you ..
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install bet
|
8
|
+
|
9
|
+
## Todo
|
10
|
+
|
11
|
+
1. Make it actually work
|
12
|
+
2. Add dutching and shit like that
|
13
|
+
3. Test
|
14
|
+
|
15
|
+
## Contributing
|
16
|
+
|
17
|
+
1. Fork it ( https://github.com/mikecmpbll/bet/fork )
|
18
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
19
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
20
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
21
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bet.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bet/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bet"
|
8
|
+
spec.version = Bet::VERSION
|
9
|
+
spec.authors = ["Mike Campbell"]
|
10
|
+
spec.email = ["mike@wordofmike.net"]
|
11
|
+
spec.summary = %q{An awesome bet calculator}
|
12
|
+
spec.homepage = "https://github.com/mikecmpbll/bet"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
end
|
data/lib/bet.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Bet
|
2
|
+
module BetCalculations
|
3
|
+
module Combinatorial
|
4
|
+
{
|
5
|
+
trixie: 3,
|
6
|
+
yankee: 4,
|
7
|
+
canadian: 5,
|
8
|
+
heinz: 6,
|
9
|
+
super_heinz: 7,
|
10
|
+
goliath: 8,
|
11
|
+
block: 9
|
12
|
+
}.each do |ord, n|
|
13
|
+
define_method(ord) do |opts|
|
14
|
+
prices = extract_prices(opts)
|
15
|
+
raise ArgumentError, "Wrong number of prices (#{prices.size} for #{n})" if prices.size != n
|
16
|
+
opts[:min_size] = 2
|
17
|
+
full_cover(opts)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
{
|
22
|
+
patent: 3,
|
23
|
+
lucky15: 4,
|
24
|
+
lucky31: 5,
|
25
|
+
lucky63: 6,
|
26
|
+
super_heinz_with_singles: 7,
|
27
|
+
goliath_with_singles: 8,
|
28
|
+
block_with_singles: 9
|
29
|
+
}.each do |ord, n|
|
30
|
+
define_method(ord) do |opts|
|
31
|
+
prices = extract_prices(opts)
|
32
|
+
raise ArgumentError, "Wrong number of prices (#{prices.size} for #{n})" if prices.size != n
|
33
|
+
full_cover(opts)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def full_cover(opts)
|
38
|
+
prices = extract_prices(opts)
|
39
|
+
opts = parse_opts(opts)
|
40
|
+
opts = { min_size: 1 }.merge(opts)
|
41
|
+
|
42
|
+
num_bets = 0
|
43
|
+
returns = (opts[:min_size]..opts[:prices].length).to_a.map do |n|
|
44
|
+
win_prices.combination(n).map do |multis|
|
45
|
+
num_bets += 1
|
46
|
+
acca(stake: opts[:stake], prices: multis)
|
47
|
+
end.reduce(:+)
|
48
|
+
end.reduce(:+)
|
49
|
+
|
50
|
+
total_stake = num_bets * stake
|
51
|
+
profit = returns - total_stake
|
52
|
+
|
53
|
+
[returns, profit, total_stake]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Bet
|
2
|
+
module BetCalculations
|
3
|
+
module Core
|
4
|
+
{ single: 1, double: 2, treble: 3 }.each do |ord, n|
|
5
|
+
define_method(ord) do |opts|
|
6
|
+
prices = extract_prices(opts)
|
7
|
+
raise ArgumentError, "Wrong number of prices (#{prices.size} for #{n})" if prices.size != n
|
8
|
+
acca(opts)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def accumulator(opts)
|
13
|
+
prices = extract_prices(opts)
|
14
|
+
opts = parse_opts(opts)
|
15
|
+
|
16
|
+
return send("ew_#{__method__}") if opts[:ew]
|
17
|
+
|
18
|
+
returns = c(opts[:stake], opts[:prices].reduce(:*))
|
19
|
+
profit = returns - opts[:stake]
|
20
|
+
|
21
|
+
[returns, profit, opts[:stake]]
|
22
|
+
end
|
23
|
+
alias :acca, :accumulator
|
24
|
+
alias :parlay, :accumulator
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/bet/calc.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'bet/bet_calculations/core'
|
2
|
+
require 'bet/bet_calculations/combinatorial'
|
3
|
+
require 'bet/bet_calculations/convenience'
|
4
|
+
# require 'bet/each_way'
|
5
|
+
|
6
|
+
module Bet
|
7
|
+
class Calc
|
8
|
+
extend BetCalculations::Core
|
9
|
+
extend BetCalculations::Combinatorial
|
10
|
+
extend BetCalculations::Convenience
|
11
|
+
|
12
|
+
DEFAULT_OPTS = { stake: 1, ew: false }
|
13
|
+
WIN_PLACE_LOSS_INTEGER = { -1 => :loss, 0 => :place, 1 => :win }
|
14
|
+
|
15
|
+
attr_accessor :returns, :profit
|
16
|
+
|
17
|
+
def initialize(bet_type, opts)
|
18
|
+
@returns, @profit, @stake = send(bet_type, opts)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def win_place_lose?(v)
|
23
|
+
v.is_a?(Fixnum) ? WIN_PLACE_LOSS_INTEGER[v] : v
|
24
|
+
end
|
25
|
+
|
26
|
+
def c(stake, price)
|
27
|
+
stake * price
|
28
|
+
end
|
29
|
+
|
30
|
+
def extract_prices(opts_or_prices)
|
31
|
+
case opts_or_prices
|
32
|
+
when Hash
|
33
|
+
opts_or_prices[:prices]
|
34
|
+
when Numeric
|
35
|
+
[opts_or_prices]
|
36
|
+
else
|
37
|
+
opts_or_prices
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def parse_opts(opts_or_prices)
|
42
|
+
opts_or_prices.is_a?(Hash) ? DEFAULT_OPTS.merge(opts_or_prices) : DEFAULT_OPTS
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/bet/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Campbell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- mike@wordofmike.net
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bet.gemspec
|
54
|
+
- lib/bet.rb
|
55
|
+
- lib/bet/bet_calculations/combinatorial.rb
|
56
|
+
- lib/bet/bet_calculations/convenience.rb
|
57
|
+
- lib/bet/bet_calculations/core.rb
|
58
|
+
- lib/bet/calc.rb
|
59
|
+
- lib/bet/version.rb
|
60
|
+
homepage: https://github.com/mikecmpbll/bet
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.2.2
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: An awesome bet calculator
|
84
|
+
test_files: []
|