Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ connection.py
logs/*
output/*

# Python / Tox
.tox
.cache
.coverage

# Windows image file caches
Thumbs.db
ehthumbs.db
Expand Down
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name":"lamont",
"scripts":{},
"env":{},
"addons":[]
}
5 changes: 5 additions & 0 deletions lamont/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-


class UnsupportedFormat(Exception):
pass
56 changes: 56 additions & 0 deletions lamont/player.py
Original file line number Diff line number Diff line change
@@ -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")
31 changes: 31 additions & 0 deletions lamont/team.py
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions lamont/test-player.py
Original file line number Diff line number Diff line change
@@ -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!')
20 changes: 20 additions & 0 deletions lamont/test-team.py
Original file line number Diff line number Diff line change
@@ -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!')
Empty file added requirements.txt
Empty file.
Empty file added tests/__init__.py
Empty file.
9 changes: 9 additions & 0 deletions tests/test_log.py
Original file line number Diff line number Diff line change
@@ -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'
27 changes: 27 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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