-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from schwalle/development
Development
- Loading branch information
Showing
11 changed files
with
85 additions
and
258 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from helper.match import Match | ||
import pkgutil | ||
import importlib | ||
import os.path | ||
|
||
class PredictorBase(): | ||
""" | ||
Predictor base class | ||
all actual predictors shall derive from this class and implement the predict method | ||
""" | ||
def predict(self, match: Match): | ||
""" | ||
predict a match by returning the number of goals as tuple (home_goals, road_goals) | ||
""" | ||
raise NotImplementedError | ||
|
||
def explore_package(): | ||
return [sub_module_name for _, sub_module_name, _ in pkgutil.iter_modules([os.path.dirname(__file__)])] | ||
|
||
def get_predictors(): | ||
""" | ||
Get all predictors from all modules in this folder | ||
return: dict{name:str, cls:class} | ||
""" | ||
for mod in explore_package(): | ||
importlib.import_module('.'+mod, __package__) | ||
return {cls.__name__: cls for cls in PredictorBase.__subclasses__()} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pytest | ||
from . import base | ||
|
||
def test_scanpreditors(): | ||
subpackages = base.explore_package() | ||
assert len(subpackages) > 0 | ||
pass | ||
|
||
def test_instanciatepreditors(): | ||
predictors = base.get_predictors() | ||
assert 'SimplePredictor' in predictors.keys() | ||
predictorobj = predictors['SimplePredictor']() | ||
assert issubclass(type(predictorobj), base.PredictorBase) | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" | ||
Simple preditor for kicktipp bet bot. | ||
""" | ||
from helper.match import Match | ||
from .base import PredictorBase | ||
import random | ||
import math | ||
|
||
|
||
class SimplePredictor(PredictorBase): | ||
DOMINATION_THRESHOLD = 6 | ||
DRAW_THRESHOLD = 1.2 | ||
|
||
def predict(self, match: Match): | ||
|
||
diff = math.fabs(match.rate_home - match.rate_road) | ||
home_wins = match.rate_home < match.rate_road | ||
|
||
if diff < self.DRAW_THRESHOLD: | ||
return (1, 1) | ||
|
||
if diff >= self.DOMINATION_THRESHOLD: | ||
result = (3, 1) | ||
elif diff >= self.DOMINATION_THRESHOLD / 2: | ||
result = (2, 1) | ||
else: | ||
result = (1, 0) | ||
|
||
return result if home_wins else tuple(reversed(result)) |
Oops, something went wrong.