diff options
-rwxr-xr-x | elo.py | 11 | ||||
-rw-r--r-- | f1elo/db.py | 8 | ||||
-rw-r--r-- | f1elo/elo.py | 6 | ||||
-rw-r--r-- | f1elo/model.py | 6 | ||||
-rw-r--r-- | import-csv.py | 7 |
5 files changed, 20 insertions, 18 deletions
@@ -1,10 +1,12 @@ #!/usr/bin/env python +import argparse +import datetime + +import dateutil.parser +import dateutil.relativedelta from f1elo.db import Session -from f1elo.model import * from f1elo.elo import Elo -import dateutil.parser, dateutil.relativedelta -import datetime -import argparse +from f1elo.model import * session = Session() elo = Elo(session) @@ -82,6 +84,7 @@ if len(rankings): if not drivers.has_key(ranking.driver): drivers[ranking.driver] = ranking.driver.get_ranking(date) + for rank in sorted(drivers.values(), key=lambda rank: rank.ranking, reverse=True): print rank else: diff --git a/f1elo/db.py b/f1elo/db.py index 49ccc3d..dc40ba1 100644 --- a/f1elo/db.py +++ b/f1elo/db.py @@ -1,16 +1,15 @@ -import __main__ +import json from os import path +import __main__ +from f1elo.model import Driver from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker -import json - config = json.load(open(path.dirname(__main__.__file__) + '/config/db.json')) engine = create_engine("mysql://{0[user]}:{0[pass]}@{0[host]}/{0[db]}?charset=utf8".format(config)) Session = sessionmaker(bind=engine) -from f1elo.model import Driver def find_driver(name, country, session): driver = session.query(Driver).filter(Driver.driver==name).first() @@ -22,4 +21,3 @@ def find_driver(name, country, session): driver.country = country session.add(driver) return driver - diff --git a/f1elo/elo.py b/f1elo/elo.py index dcf24dd..99c1fd7 100644 --- a/f1elo/elo.py +++ b/f1elo/elo.py @@ -1,10 +1,10 @@ -import __main__ +import json +from itertools import combinations from os import path +import __main__ from f1elo.model import * -import json -from itertools import combinations class Elo: def __init__(self, session): diff --git a/f1elo/model.py b/f1elo/model.py index 3133a59..7b340fa 100644 --- a/f1elo/model.py +++ b/f1elo/model.py @@ -1,7 +1,7 @@ -from sqlalchemy import Column, Table, ForeignKey -from sqlalchemy.types import Date, Float, Integer, String, Boolean -from sqlalchemy.orm import backref, relationship, sessionmaker +from sqlalchemy import Column, ForeignKey, Table from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import backref, relationship, sessionmaker +from sqlalchemy.types import Boolean, Date, Float, Integer, String Base = declarative_base() diff --git a/import-csv.py b/import-csv.py index de0eb7a..ae4b9e6 100644 --- a/import-csv.py +++ b/import-csv.py @@ -1,10 +1,11 @@ -from f1elo.db import Session, find_driver -from f1elo.model import * +import csv import sys +from f1elo.db import find_driver, Session +from f1elo.model import * + session = Session() -import csv with open(sys.argv[1]) as f: reader = csv.reader(f) for row in reader: |