diff --git a/.gitignore b/.gitignore index bf42452..5d0312f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,11 @@ connection.py logs/* output/* +# Python / Tox +.tox +.cache +.coverage + # Windows image file caches Thumbs.db ehthumbs.db diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..abfebb9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,13 @@ +sudo: false +notifications: + email: false +language: python +env: + - TOX_ENV=py27 + - TOX_ENV=py33 + - TOX_ENV=py34 + - TOX_ENV=coveralls +install: + - pip install tox +script: + - tox -e $TOX_ENV diff --git a/README.md b/README.md new file mode 100644 index 0000000..78fbdbf --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# python-scouting + +[![Build Status](https://travis-ci.org/matt-bernhardt/python-scouting.svg)](https://travis-ci.org/matt-bernhardt/python-scouting) + +A set of data curation scripts for the soccer database behind Massive Report Data \ No newline at end of file diff --git a/app.json b/app.json new file mode 100644 index 0000000..b9eb7c5 --- /dev/null +++ b/app.json @@ -0,0 +1,6 @@ +{ + "name":"lamont", + "scripts":{}, + "env":{}, + "addons":[] +} \ No newline at end of file diff --git a/lamont/__init__.py b/lamont/__init__.py new file mode 100644 index 0000000..3bd8d30 --- /dev/null +++ b/lamont/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + + +class UnsupportedFormat(Exception): + pass diff --git a/lamont/player.py b/lamont/player.py new file mode 100644 index 0000000..715ae0d --- /dev/null +++ b/lamont/player.py @@ -0,0 +1,56 @@ +from database import Database + + +class Player(): + + def __init__(self): + self.data = {} + self.db = Database() + self.db.connect() + + def loadID(self, tid): + # This looks up a player record by ID + sql = ('SELECT ID, FirstName, LastName ' + 'FROM tbl_players p ' + 'WHERE p.ID = %s') + rs = self.db.query(sql, (tid, )) + + if (rs.with_rows): + records = rs.fetchall() + + for index, item in enumerate(records): + self.data["ID"] = item[0] + self.data["First"] = item[1] + self.data["Last"] = item[2] + + return self + + def lookup(self, needle): + # This takes a dictionary 'needle' and uses it to look up player information + print("Looking up...") + for item in needle: + print(str(item)) + output = {} + print("\n") + return output + + def lookupName(self, name): + sql = ('SELECT ID, FirstName, LastName ' + 'FROM tbl_players p ' + 'WHERE TRIM(CONCAT(FirstName," ",LastName)) LIKE %s ' + 'ORDER BY LastName ASC, FirstName') + rs = self.db.query(sql, (name, )) + + if (rs.with_rows): + records = rs.fetchall() + + for index, item in enumerate(records): + self.data.index = self.data.item[index] + + return self + + def dumpToTerminal(self): + print("Dumping...") + for item in self.data: + print(str(item) + ": " + str(self.data[item])) + print("...Done\n") diff --git a/lamont/team.py b/lamont/team.py new file mode 100644 index 0000000..17b0760 --- /dev/null +++ b/lamont/team.py @@ -0,0 +1,31 @@ +from database import Database + + +class Team(): + + def __init__(self): + self.data = [] + self.db = Database() + self.db.connect() + + def load(self, tid): + sql = ('SELECT * ' + 'FROM tbl_teams t ' + 'WHERE t.ID = %s') + print('Query defined') + + rs = self.db.query(sql, (tid, )) + print('Query executed') + + if (rs.with_rows): + records = rs.fetchall() + print('Data retrieved') + + for index, item in enumerate(records): + print(str(index)) + print(str(type(item))) + for key, value in enumerate(item): + print(str(value)) + # self.data.index = self.data.item[index] + + return self.data diff --git a/lamont/test-player.py b/lamont/test-player.py new file mode 100644 index 0000000..2c4d55e --- /dev/null +++ b/lamont/test-player.py @@ -0,0 +1,37 @@ +# This script implements the three main methods of the Log object. +# This will eventually need to be unit tests, but...one thing at a time +from log import Log +from player import Player + +logfile = Log('../logs/test-player.log') +output = Log('../output/test-player.txt') + +print('First player test') +output.message('First player test') +# First player test +p1 = Player() +output.message(str(p1.data)) +p1.loadID(1565) +p1.dumpToTerminal() +output.message(str(p1)) + +output.message("") + +print('Second player test') +output.message('Second player test') +# Second player test +p2 = Player() +p2.lookupName('Brian') +output.message(str(p2)) + +output.message(str(type(p2))) +output.message(str(type(p2.data))) + +for index, item in enumerate(p2.data): + output.message(p2.data.index) + output.message(p2.data.item[index]) + +logfile.end() +output.end() + +print('Finished!') diff --git a/lamont/test-team.py b/lamont/test-team.py new file mode 100644 index 0000000..ce1bec5 --- /dev/null +++ b/lamont/test-team.py @@ -0,0 +1,20 @@ +# This script implements the three main methods of the Log object. +# This will eventually need to be unit tests, but...one thing at a time +from log import Log +from team import Team + +logfile = Log('../logs/test-team.log') +output = Log('../output/test-team.txt') + +t = Team() + +logfile.message(str(t.data)) + +t.load(11) + +output.message(str(t)) + +logfile.end() +output.end() + +print('Finished!') \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_log.py b/tests/test_log.py new file mode 100644 index 0000000..594b488 --- /dev/null +++ b/tests/test_log.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import + +from lamont.log import Log + + +def test_log_filename(): + l = Log('test.log') + assert l.name == 'test.log' diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..65b88c0 --- /dev/null +++ b/tox.ini @@ -0,0 +1,27 @@ +[tox] +envlist = py27,py33,py34,clean,coverage +skipsdist = True + +[testenv] +commands = py.test {posargs:--tb=short} +deps = + pytest + +[testenv:clean] +commands = coverage erase +deps = coverage + +[testenv:coverage] +deps = + pytest-cov + {[testenv]deps} +commands = py.test --cov=lamont {posargs} + +[testenv:coveralls] +passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH +deps = + coveralls + {[testenv:coverage]deps} +commands = + py.test --cov=lamont + coveralls