Changeset - 071f264dfb0c
[Not reviewed]
default
0 2 0
Laman - 7 years ago 2018-05-04 12:19:16

fix: pamatujeme si poslední jméno hráče místo prvního
2 files changed with 3 insertions and 1 deletions:
0 comments (0 inline, 0 general)
egd.py
Show inline comments
 
@@ -43,56 +43,56 @@ def loadPlayers(filename,enc="iso8859_2"
 
		if not line: continue
 

	
 
		match=regexp.match(line)
 
		if match is None:
 
			print("ignored:",line,file=sys.stderr)
 
			continue
 
		(pin,name,cc,cl,rank,tcode,wc,gc,r1,r2)=match.groups()
 
		record=dict(zip(
 
			["pin","name","countryCode","club","rank","tournamentCode","winCount","gameCount","rating1","rating2"],
 
			(int(pin),name,cc,cl,rank,tcode,int(wc),int(gc),int(r1),int(r2))
 
		))
 
		players.append(record)
 
	return players
 

	
 

	
 
def setupDB():
 
	cursor=connection.cursor()
 

	
 
	cursor.execute("""create table tournaments (code text primary key, datum text, class text, round_count integer, player_count integer, country_code text, description text)""")
 
	cursor.execute("""create table players (pin integer primary key, name text)""")
 
	cursor.execute("""create table players_performance (pin integer references players(pin), tournament_code text references tournaments(code), country_code text, club text, win_count integer, game_count integer, rating_before real, rating_after real, primary key (pin,tournament_code))""")
 

	
 
	cursor.execute("""
 
		create view players_performance_tournaments (pin,p_country_code,rating_before,rating_after,t_country_code,datum) as
 
			select pin,pp.country_code,rating_before,rating_after,ts.country_code,datum
 
				from players_performance as pp join tournaments as ts on pp.tournament_code=ts.code
 
	""")
 

	
 
	cursor.execute("""create index pp_pin on players_performance (pin)""")
 
	cursor.execute("""create index pp_tournament_code on players_performance (tournament_code)""")
 
	cursor.execute("""create index pp_country_ind on players_performance (country_code)""")
 
	cursor.execute("""create index t_datum_ind on tournaments (datum)""")
 

	
 
	connection.commit()
 

	
 

	
 
def fillDB(tournaments,players):
 
	cursor=connection.cursor()
 

	
 
	cursor.execute("""delete from players_performance""")
 
	cursor.execute("""delete from players""")
 
	cursor.execute("""delete from tournaments""")
 

	
 
	cursor.executemany(
 
		"""insert into tournaments (code,datum,class,round_count,player_count,country_code,description) values (:code,:date,:class,:roundCount,:playerCount,:countryCode,:description)""",
 
		tournaments.values()
 
	)
 

	
 
	cursor.executemany("""insert or ignore into players (pin,name) values (:pin,:name)""", players)
 
	cursor.executemany("""insert or replace into players (pin,name) values (:pin,:name)""", players)
 

	
 
	cursor.executemany(
 
		"""insert into players_performance (pin,tournament_code,country_code,club,win_count,game_count,rating_before,rating_after) values (:pin,:tournamentCode,:countryCode,:club,:winCount,:gameCount,:rating1,:rating2)""",
 
		players
 
	)
 

	
 
	connection.commit()
readme.md
Show inline comments
 
# Zpracování a dotazování dat z EGD
 

	
 
## egd.py
 
Funkce pro načtení dat vyexportovaných z veřejného rozhraní EGD a jejich konverzi do SQLite databáze.
 

	
 
## setup.py
 
Načte soubory tlist.html a all.hst (z aktivního adresáře) a vytvoří soubor egd.db s databází.
 

	
 
## queries.py
 
Uložené dotazy.
 

	
 
## Schéma databáze
 
### tournaments
 
* (text) code
 
* (text) datum
 
* (text) class
 
* (integer) round_count
 
* (integer) player_count
 
* (text) country_code
 
* (text) description
 

	
 
### players
 
* (integer) pin
 
* (text) name
 

	
 
### players_performance
 
Co se vztahuje zároveň k hráči a k turnaji. Většina položek all.hst.
 

	
 
* (integer) pin
 
* (text) tournament_code
 
* (text) country_code
 
* (text) club
 
* (integer) win_count
 
* (integer) game_count
 
* (real) rating_before
 
* (real) rating_after
 

	
 
### players_performance_tournaments
 
Pohled na tournaments a players_performance.
 

	
 
* (integer) pin
 
* (text) p_country_code - země hráče
 
* (real) rating_before
 
* (real) rating_after
 
* (text) t_country_code - lokace turnaje
 
* (text) datum
0 comments (0 inline, 0 general)