-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredicta.rb
More file actions
executable file
·60 lines (46 loc) · 1.34 KB
/
predicta.rb
File metadata and controls
executable file
·60 lines (46 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env ruby
require_relative './cricinfo/cricinfo.rb'
require "thor"
class PredictaCLI < Thor
desc "fetch", "Scraps data from Cricinfo and saves"
def fetch
Cricinfo.sync
end
desc "predict [TEAM1] [TEAM2]", "Predicts the outcome of a match"
def predict(home,away)
ratings = Cricinfo.calculateRatings
result = Cricinfo.prediction(ratings,home,away)
puts "#{home} has a #{result[:home]}% chance of winning"
puts "#{away} has a #{result[:away]}% chance of winning"
end
desc "list" , "Lists teams in CWC2019"
def list
teams = Cricinfo.list_teams
ratings = Cricinfo.calculateRatings
results = []
teams.each_with_index do |team,index|
results.push({team: team, rating: ratings[index].rating})
end
results = results.sort_by{|result| result[:rating]}.reverse
results.each do |result|
puts "#{result[:team]} -- #{result[:rating]}"
end
end
desc "fetchFixtures", "Scraps fixture data"
def fetchFixtures
Cricinfo.fetchFixtures
end
desc "fetchTodaysFixture", "Scraps fixture data"
def fetchTodaysFixture
fixtures = Cricinfo.fetchTodaysFixture
puts fixtures
end
desc "todaysPrediction", "Predicts results for today's match/matches"
def todaysPrediction
fixtures = Cricinfo.fetchTodaysFixture
fixtures.each do |fixture|
predict(fixture[:home],fixture[:away])
end
end
end
PredictaCLI.start(ARGV)