示例#1
0
class dao_test(unittest.TestCase):
    def setUp(self):
        #testing reference http://www.zerozero.pt/edition.php?jornada_in=19&id_edicao=86785&fase=81592
        self.dao = DAO(country="england", season="15-16", cols="sport_cols")

    def test_get_data(self):
        #each team plays 19 time as HomeTeam
        self.assertEqual(20 * 19, len(self.dao.get_data()))

    def test_half_league_data(self):
        half1 = self.dao.half_league_data(half=1)

        self.assertEqual(max(half1["Date"]),
                         to_datetime("30/12/2015", dayfirst=True))
        self.assertEqual(min(half1["Date"]),
                         to_datetime("08/08/2015", dayfirst=True))

    def test_search_percentil_date(self):
        p05 = self.dao.search_percentil_date(percentile=0.5)
        self.assertEqual(p05, to_datetime("30/12/2015", dayfirst=True))

        p0316 = self.dao.search_percentil_date(percentile=0.316)
        self.assertEqual(p0316, to_datetime("08/11/2015", dayfirst=True))

        p06316 = self.dao.search_percentil_date(percentile=0.6316)
        self.assertEqual(p06316, to_datetime("03/02/2016", dayfirst=True))
示例#2
0
 def create_tables () :
     tables = ["installations.csv", "equipements.csv", "activites.csv"] #get CSV files
     for table in tables :
         list = CSV_read(table)
         list_attribute = DB.get_list_attribute(table) #link with tables attributes lists
         name = DB.remove_dot_CSV(table) #removing .csv
         DAO.create_table(name, list, list_attribute)
示例#3
0
    def setUp(self):
        #testing reference http://www.zerozero.pt/edition.php?jornada_in=19&id_edicao=86785&fase=81592
        eng_dao_15_16 = DAO(country="england",
                            season="15-16",
                            cols="sport_cols")
        self.league = League(eng_dao_15_16)

        spa_dao_15_16 = DAO(country="spain", season="15-16", cols="sport_cols")
        self.league_spa = League(spa_dao_15_16)
示例#4
0
    def setUp(self):
        if os.path.exists('stock.db'):
            os.remove('stock.db')

        self.dao = DAO()
        self.dao.connect()
        self.dao.create_db()

        self.ds = SinaDS()
示例#5
0
    def select_from_installations(activity_code) :
        #get equipement table
        resultEqu = DAO.select_from_equipements(activity_code)

        #get instal_number (num_install in db) from equipement table to get the installation
        tmp = str(resultEqu[1]).split(",")
        instal_number = tmp[5]
        instal_number = str(instal_number)[:-2]

        resultIns = DAO.select_from_installations(instal_number)
        return DB.get_JSON(resultIns)
示例#6
0
 def get_by_id(card_id):
     result = DAO.select(
         "SELECT * FROM cards WHERE id = {}".format(card_id))
     if len(result) == 0:
         raise FanIDCardNotFoundError(
             "Fan ID Card {} does not exist".format(card_id))
     return result[0]
示例#7
0
 def get_card_by_username(username):
     result = DAO.select(
         "SELECT * FROM cards WHERE username = '******'".format(username))
     if len(result) == 0:
         raise UsernameNotFoundError(
             "Username {} was not found in the system".format(username))
     return result[0]
示例#8
0
	def test_paired_points(self):
		eng_dao_16_17 = DAO(country="england", season="16-17", cols="sport_cols")
		eng_league = League(eng_dao_16_17)
		eng_league_anl = LeagueAnalysis(league=eng_league)

		n_round = 18

		five_dates = [eng_league.date_by_round(round_n) for round_n in range(n_round - 4, n_round + 1)]
		
		date1 = five_dates[0]
		date2 = five_dates[-1]
		
		df1 = eng_league.table(to_date=date1)
		df2 = eng_league.table(to_date=date2)

        # Chelsea		34 46	Chelsea
        # Arsenal		31 40	Liverpool
        # Liverpool		30 39	Man City
        # Man City		30 37	Arsenal
        # Tottenham		27 36	Tottenham

		points1, points2 = eng_league_anl.paired_points(df1, df2, n_head=5)

		self.assertEqual(points1.tolist(), [34, 31, 30, 30, 27])
		self.assertEqual(points2.tolist(), [46, 37, 40, 39, 36])
示例#9
0
文件: app_test.py 项目: B-Rich/dealer
 def setUp(self):
     if os.path.exists('stock.db'):
         os.remove('stock.db')
         
     self.dao = DAO()
     self.dao.connect()
     self.dao.create_db()
     
     self.ds = SinaDS()
示例#10
0
def create_dao(db: str) -> BaseDAO:
    if db == 'mongo':
        config = json.load(open(relative(__file__,
                                         "config/mongoconfig.json")), )
        return MongoDAO(
            host=config["host"],
            port=config["port"],
            db_name=config["dbName"],
        )
    elif db == 'mysql':
        return DAO()
示例#11
0
class Test(unittest.TestCase):
    def setUp(self):
        if os.path.exists('stock.db'):
            os.remove('stock.db')

        self.dao = DAO()
        self.dao.connect()
        self.dao.create_db()

        self.ds = SinaDS()

    def tearDown(self):
        self.dao.commit()

    def testExtract(self):
        for item in self.ds.get_reference():
            self.dao.insert_instrument(item)

        for record in self.ds.get_trade_history('600000'):
            print['600000'] + record
            self.dao.insert_trade(tuple(['600000'] + record))
示例#12
0
    def get_name_activity() :
        resultEqu = DAO.get_name_activity()

        res = {}
        #replacing underscores by space for a better displaying
        id1 = str(resultEqu[0][0]).replace("_", " ")

        #fill the list with db datas
        for row in resultEqu[1]:
            dict = {id1:row[0]}
            res[len(res)] = dict

        return (res)
示例#13
0
文件: app_test.py 项目: B-Rich/dealer
class Test(unittest.TestCase):

    def setUp(self):
        if os.path.exists('stock.db'):
            os.remove('stock.db')
            
        self.dao = DAO()
        self.dao.connect()
        self.dao.create_db()
        
        self.ds = SinaDS()

    def tearDown(self):
        self.dao.commit()

    def testExtract(self):
        for item in self.ds.get_reference():
            self.dao.insert_instrument(item)
        
        for record in self.ds.get_trade_history('600000'):
            print ['600000'] + record
            self.dao.insert_trade(tuple(['600000'] + record))
示例#14
0
	def test_range_points_spread(self):
		spain_dao = DAO(country="spain", season="16-17", cols="sport_cols")
		league = League(spain_dao)
		league_anl = LeagueAnalysis(league=league)
		
		dates = ['2016/11/28', '2016/12/05', '2016/12/12', '2016/12/19', '2017/01/09', '2017/01/16', '2017/01/22']

		# for date in dates:
		# 	print()
		# 	print(league.table(to_date=date))

		range_points_spread = league_anl.range_points_spread(dates=dates, top_n_clubs=6)

		self.assertEqual([11, 11, 12, 9, 11, 9, 12], range_points_spread)
示例#15
0
	def test_points_corr(self):
		eng_dao_16_17 = DAO(country="england", season="16-17", cols="sport_cols")
		eng_league = League(eng_dao_16_17)
		eng_league_anl = LeagueAnalysis(league=eng_league)
		n_round = 18

		date1 = "2016-12-28"
		table_df1 = eng_league.table(to_date=date1)

		corr1 = eng_league_anl.points_corr(df_tables=[table_df1, table_df1], method="spearman", n_head=10)
		self.assertLess(0.98, corr1[0])

		date2 = "2016-12-05"
		table_df2 = eng_league.table(to_date=date2)

		corr2 = eng_league_anl.points_corr(df_tables=[table_df1, table_df2], method="spearman", n_head=5)
		self.assertLess(0.665, corr2[0])
		self.assertGreater(0.669, corr2[0])
示例#16
0
 def insert(card):
     DAO.insert(
         "INSERT INTO cards (username, expiration_date, balance, is_blocked) VALUES ('{}', '{}', {}, '{}')"
         .format(card.username, card.expiration_date, card.balance,
                 card.is_blocked))
示例#17
0
 def does_exist(card_id):
     result = DAO.select(
         "SELECT * FROM cards WHERE id = {}".format(card_id))
     return len(result) > 0
示例#18
0
 def increase_balance(card_id, value):
     DAO.update(
         "UPDATE cards SET balance = balance + {} WHERE id = {}".format(
             value, card_id))
import pandas as pd
from dao.dao import DAO
from table import Table

data = DAO().get_data("spain", "15-16", cols="sport_cols")
print(data.head())

table = Table(data)
table.league_progress_by_date("15/01/2016")
table.matches_played("15/01/2016")
示例#20
0
 def create_table (table) :
     list = CSV_read(table)
     list_attribute = DB.get_list_attribute(table) #link with table attributes list
     name = DB.remove_dot_CSV(table) #removing .csv
     DAO.create_table(name, list, list_attribute)
示例#21
0
 def select_from_activites(name_commune, number_equipment, activitie, practice, special) :
     result = DAO.select_from_activites(name_commune, number_equipment, activitie, practice, special)
     return DB.get_JSON7(result)
示例#22
0
 def does_exist(username):
     result = DAO.select(
         "SELECT * FROM person WHERE username = '******'".format(username))
     return len(result) > 0
示例#23
0
 def get_by_id(username):
     result = DAO.select(
         "SELECT * FROM person WHERE username = '******'".format(username))
     if len(result) == 0:
         raise UsernameNotFoundError("Username was not found")
     return result[0]
示例#24
0
 def is_password_correct(username, password):
     encrypted_password = PersonDAO.encrypt_password(password)
     result = DAO.select(
         "SELECT * FROM person WHERE username = '******' and password = '******'".
         format(username, encrypted_password))
     return len(result) != 0
示例#25
0
 def register(person, creator="NULL"):
     DAO.insert(
         "INSERT INTO person (username, first_name, last_name, age, role, password, creator) VALUES ('{}', '{}', '{}', {}, '{}', '{}', '{}')"
         .format(person.username, person.first_name, person.last_name,
                 person.age, person.role,
                 PersonDAO.encrypt_password(person.password), creator))
示例#26
0
 def select_all_table(db_table):
     result = DAO.select_all(db_table)
     return DB.get_JSON(result)
示例#27
0
 def update(card):
     DAO.update(
         "UPDATE cards SET username = '******', expiration_date = '{}', balance = {}, is_blocked = '{}' WHERE id = {}"
         .format(card.username, card.expiration_date, card.balance,
                 card.is_blocked, card.id))
示例#28
0
 def get_role_by_username(username):
     result = DAO.select(
         "SELECT role FROM person WHERE username = '******'".format(username))
     return result[0][0]
示例#29
0
 def get_max_card_id():
     max_card_id = DAO.select("SELECT MAX(id) FROM cards")[0][0]
     return max_card_id
示例#30
0
	def setUp(self):
		#testing reference http://www.zerozero.pt/edition.php?jornada_in=19&id_edicao=86785&fase=81592
		dao = DAO(country="england", season="15-16", cols="sport_cols")
		self.grouped_stats = GroupedStats(dao)
示例#31
0
 def __init__(self):
     DAO.__init__(self)
示例#32
0
 def select_from_equipements(activity_code) :
     #get the equipment thanks to the activity_code given by activites table
     resultEqu = DAO.select_from_equipements(activity_code)
     return DB.get_JSON(resultEqu)