示例#1
0
def generateTestDataBySeasons():
  DIR = '/home/archer/Documents/maxent/data/basketball/leaguerank/'
  seasons = loadSeasons(DIR + 'seasons-18-Nov-2014.txt')

  for season in seasons:
    res = generateTestDataBySeason(season)
    outputFile = DIR + season + '-test.csv.knn'
    print 'INFO: ', outputFile
    saveMatrixToFile(outputFile, res)
示例#2
0
def generateTestDataByTeams():
  DIR = '/home/archer/Documents/maxent/data/basketball/leaguerank/'
  teamIds = loadTeamIds(DIR + 'teamidshortname.csv')
  teamNames = [row[1] for row in loadMatrixFromFile(DIR + 'teamidshortname.csv')]

  for teamId in teamIds:
    res = generateTestDataByTeam(teamId)
    outputFile = DIR + teamId + '-test.csv.knn'
    print 'INFO: ', outputFile
    saveMatrixToFile(outputFile, res)
def main():
  DIR = '/home/archer/Documents/maxent/data/basketball/leaguerank/'
  seasons = loadSeasons(DIR + 'seasons-18-Nov-2014.txt')
  teamIds = loadTeamIds(DIR + 'teamidshortname.csv')
  seasonTypes = ['Regular Season', 'Playoffs']
  # print seasons
  # return
  for team in teamIds:
    for season in seasons:
      #for seasonType in seasonTypes:
      seasonType = 'Regular Season'
      n = NBAStatsTeamPlayerExtractor(team, season, seasonType)
      outputFile = DIR + team + '.' + season + '.player.csv'
      print 'INFO: Processing ', outputFile
      mat = n.getStats()
      if mat == False:
        saveMatrixToFile(outputFile, [])
      else:
        saveMatrixToFile(outputFile, mat)
示例#4
0
def main():
    DIR = '/home/archer/Documents/maxent/data/basketball/leaguerank/'
    seasons = loadSeasons(DIR + 'seasons-18-Nov-2014.txt')
    teamIds = loadTeamIds(DIR + 'teamidshortname.csv')
    seasonTypes = ['Regular Season', 'Playoffs']
    # print seasons
    # return
    for team in teamIds:
        for season in seasons:
            #for seasonType in seasonTypes:
            seasonType = 'Regular Season'
            n = NBAStatsTeamPlayerExtractor(team, season, seasonType)
            outputFile = DIR + team + '.' + season + '.player.csv'
            print 'INFO: Processing ', outputFile
            mat = n.getStats()
            if mat == False:
                saveMatrixToFile(outputFile, [])
            else:
                saveMatrixToFile(outputFile, mat)
示例#5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Author: Archer
# Date: 05/Jun/2015
# File: GetTeamInfo.py
# Desc: get the team short name and teamid, will be used in InsertTeamStats.py
#
# Produced By CSRGXTU
import MySQLdb as mdb
import sys
from Utility import saveMatrixToFile

con = mdb.connect('localhost', 'root', 'root', 'NBA')
basePath = '/home/archer/Documents/Python/maxent/data/basketball/leaguerank/'

with con:
    cur = con.cursor()
    sql = "select TeamID, ShortNameEN from Team"
    cur.execute(sql)

    rows = cur.fetchall()
    res = []
    for row in rows:
        res.append([int(row[0]), row[1]])
    saveMatrixToFile(basePath + 'TeamID2TeamShortName.csv', res)
示例#6
0
#!/usr/bin/env python
# coding = utf-8
# Author: Archer Reilly
# Date: 19/Nov/2014
# File: SortByTime.py
# Desc: sort the content in original data file by time
#
# Produced By CSRGXTU
from Utility import loadMatrixFromFile, saveMatrixToFile
from os import listdir
from datetime import datetime
"""
matrix = loadMatrixFromFile('/home/archer/Documents/maxent/data/basketball/1610612766.csv')
print matrix
"""

dirs = listdir('/home/archer/Documents/Python/maxent/data/basketball/')
for f in dirs:
    if f.startswith('161'):
        print 'Process file: ' + f
        matrix = loadMatrixFromFile(
            '/home/archer/Documents/Python/maxent/data/basketball/' + f)
        matrixa = sorted(matrix,
                         key=lambda x: datetime.strptime(x[1], '%b %d:%Y'))
        saveMatrixToFile(
            '/home/archer/Documents/Python/maxent/data/basketball/' + f +
            '.sorted', matrixa)
示例#7
0
 def spider_closed(self, spider):
     # logging.info("Spider's destructor")
     # logging.info(self.ISBNS)
     # saveLstToFile(self.UID + '.csv', self.ISBNS)
     saveMatrixToFile(self.UID + '.csv', self.Books)
      if row[1] == d:
        # print '   DEBUG: ',
        # print row
        appendlst2file(row, '/home/archer/Documents/maxent/data/basketball/leaguerank/' + sortedFiles[i] + '.swp')

    # print '   DEBUG generateRow:',
    tmpMatrixb.append(generateRow(loadMatrixFromFile('/home/archer/Documents/maxent/data/basketball/leaguerank/' + sortedFiles[i] + '.swp'), sortedNames[i]))
    # appendlst2file(tmpMatrixa, '/home/archer/Documents/maxent/data/basketball/leaguerank/' + sortedFiles[i] + '.swp')
    # tmpMatrixb.append(generateRow(loadMatrixFromFile('/home/archer/Documents/maxent/data/basketball/leaguerank/' + sortedFiles[i] + '.swp'), sortedNames[i]))
    # break
  # print 'INFO: matrix for ' + d + ':'
  # print tmpMatrixb
  # print 'INFO: save ' + d + '.m  Done'
  # print '\033[1;31mINFO: save %s.m  Done\t\t\033[1;m' % d
  print '\033[1;32mINFO: save %s.m  Done\t\tON\033[1;m' % d
  saveMatrixToFile('/home/archer/Documents/maxent/data/basketball/leaguerank/' + d + '.m', tmpMatrixb)
  # break


"""
  for f in sortedFiles:
    print '   INFO: load matrix from ' + f
    tmpMatrix = loadMatrixFromFile('/home/archer/Documents/maxent/data/basketball/leaguerank/' + f)
    tmpMatrixa = []
    for row in tmpMatrix:
      if row[1] == d:
        tmpMatrixa.append(row)
        break
      else:
        tmpMatrixa.append(row)
"""
示例#9
0
#!/usr/bin/env python
# coding = utf-8
# Author: Archer Reilly
# Date: 19/Nov/2014
# File: SortByTime.py
# Desc: sort the content in original data file by time
#
# Produced By CSRGXTU
from Utility import loadMatrixFromFile, saveMatrixToFile
from os import listdir
from datetime import datetime

"""
matrix = loadMatrixFromFile('/home/archer/Documents/maxent/data/basketball/1610612766.csv')
print matrix
"""

dirs = listdir('/home/archer/Documents/Python/maxent/data/basketball/')
for f in dirs:
  if f.startswith('161'):
    print 'Process file: ' + f
    matrix = loadMatrixFromFile('/home/archer/Documents/Python/maxent/data/basketball/' + f)
    matrixa = sorted(matrix, key=lambda x: datetime.strptime(x[1], '%b %d:%Y'))
    saveMatrixToFile('/home/archer/Documents/Python/maxent/data/basketball/' + f + '.sorted', matrixa)
        Sums.append(sum)

    return Sums

if __name__ == '__main__':
    Mat = []

    for page in range(1, 2365):
        print 'Page: ', page
        res = getDatas('6w', page, 25)
        mat = processRecord(res)
        for row in mat:
            Mat.append(row)

    Mat.append(Total(Mat))
    saveMatrixToFile('./6wstatistics.csv', Mat)
    # res = getDatas('6w', 0, 5)
    # mat = processRecord(res)
    # print mat
    # Total(mat)
    # for key in res:
    #     if key == 'ISBN':
    #         print key
    #     elif key == u'\u4e66\u7c4d\u8d2d\u4e70\u6765\u6e90':
    #         print key

    # print res
    # print res.keys()
    # for key in res.keys():
    #     if key ==
    # print res