Changeset - 8732ad224e56
[Not reviewed]
default
0 1 0
Laman - 7 years ago 2018-05-04 12:34:57

dotaz fetchByRating
1 file changed with 12 insertions and 0 deletions:
0 comments (0 inline, 0 general)
queries.py
Show inline comments
 
@@ -135,54 +135,66 @@ def _populationAge(year,country):
 

	
 

	
 
def populationAge(year1,year2,country):
 
	res=dict()
 

	
 
	for year in range(year1,year2):
 
		records=_populationAge(year,country)
 
		for (age,playerCount) in records:
 
			if age not in res:
 
				res[age]=dict()
 
			res[age][year]=playerCount
 
		print("\r",year,end="",file=sys.stderr)
 
	print("\r",end="",file=sys.stderr)
 

	
 
	print("Počty aktivních hráčů v {0} hrajících tolik a více let".format(country))
 
	print("roky hraní\t"+"\t".join(str(y) for y in range(year1,year2)))
 
	for age in sorted(res.keys()):
 
		print(age,end="\t")
 
		print("\t".join(str(res[age].get(y,0)) for y in range(year1,year2)))
 

	
 

	
 
def _tournamentAttendance(year):
 
	"""Návštěvnosti turnajů za daný rok, dělené podle země konání."""
 
	date1=yearStart(year)
 
	date2=yearStart(year+1)
 
	query="""select country_code,sum(player_count) from tournaments where datum>=date(?) and datum<date(?) group by country_code"""
 

	
 
	return cursor.execute(query,(date1,date2))
 

	
 

	
 
def tournamentAttendance(year1,year2):
 
	res=dict()
 

	
 
	for year in range(year1,year2):
 
		records=_tournamentAttendance(year)
 
		for (country,attendance) in records:
 
			if country not in res:
 
				res[country]=dict()
 
			res[country][year]=attendance
 
		print("\r",year,end="",file=sys.stderr)
 
	print("\r",end="",file=sys.stderr)
 

	
 
	print("Návštěvnosti (počty hráčů) na turnajích podle let")
 
	print("kód země\t"+"\t".join(str(y) for y in range(year1,year2)))
 
	for country in sorted(res.keys()):
 
		print(country,end="\t")
 
		print("\t".join(str(res[country].get(y,0)) for y in range(year1,year2)))
 

	
 

	
 
def fetchByRating(strongerThan,country=""):
 
	"""Hráči, kteří dosáhli rating strongerThan nebo vyšší, nepovinně filtrovaní podle země, seřazení od nejlepšího dosaženého ratingu."""
 
	query="""select pin,name,max(rating_after) as max_rating from players_performance natural join players where rating_after>=? and (?='' or country_code=?) group by pin order by max_rating desc"""
 

	
 
	res=cursor.execute(query,(strongerThan,country,country))
 
	print("pin\tjméno\tmax rating")
 
	for rec in res:
 
		print("\t".join([str(x) for x in rec]))
 

	
 

	
 
# playerYear("Kotowski Jaroslav",2017)
 
# timeRank(2017,"CZ")
 
# yearsByCountry(2001,2018)
 
# populationStrength(2001,2018,"RU")
 
# populationAge(2001,2018,"RU")
 
# tournamentAttendance(2001,2018)
 
# fetchByRating(2600,"CZ")
0 comments (0 inline, 0 general)