# HG changeset patch # User Laman # Date 2018-04-01 13:32:52 # Node ID 6048d5c40c9b31f40750ab4b5e7f5b2d4b4e97b7 # Parent 4ebd2c7c365734961f962c725375c7a3d503b626 populationStrength rozšířeno na rozsah let, yearByCountry nahrazeno yearsByCountry diff --git a/queries.py b/queries.py --- a/queries.py +++ b/queries.py @@ -4,8 +4,6 @@ from egd import connection cursor=connection.cursor() -year1=2001 -year2=2018 def yearStart(year): @@ -43,23 +41,15 @@ def _yearByCountry(year): group by p_country_code order by p_country_code asc """ - res=cursor.execute(query,(date1,date2)) - return res + return cursor.execute(query,(date1,date2)) -def yearByCountry(year): - print("kód země\tpočet aktivních hráčů") - for rec in _yearByCountry(year): - print("\t".join([str(x) for x in rec])) - - -def yearsByCountry(): +def yearsByCountry(year1,year2): res=dict() for year in range(year1,year2): records=_yearByCountry(year) - for rec in records: - (countryCode,playerCount)=rec + for (countryCode,playerCount) in records: if countryCode not in res: res[countryCode]=dict() res[countryCode][year]=playerCount @@ -92,7 +82,7 @@ def timeRank(year,country): print("\t".join([str(x) for x in rec])) -def populationStrength(year,country): +def _populationStrength(year,country): """Rozdělení populace země v daném roce podle ratingu (po stovkách). Uvažují se pouze aktivní hráči.""" date1=yearStart(year) date2=yearStart(year+1) @@ -104,10 +94,26 @@ def populationStrength(year,country): order by rating desc """ - res=cursor.execute(query,(date1,date2,country)) - print("rating\tpočet hráčů s takovým a vyšším ratingem") - for rec in res: - print("\t".join([str(x) for x in rec])) + return cursor.execute(query,(date1,date2,country)) + + +def populationStrength(year1,year2,country): + res=dict() + + for year in range(year1,year2): + records=_populationStrength(year,country) + for (rating,playerCount) in records: + if rating not in res: + res[rating]=dict() + res[rating][year]=playerCount + print("\r",year,end="",file=sys.stderr) + print("\r",end="",file=sys.stderr) + + print("Počty aktivních hráčů v {0} s uvedeným vyšším ratingem".format(country)) + print("rating\t"+"\t".join(str(y) for y in range(year1,year2))) + for rating in sorted(res.keys()): + print(rating,end="\t") + print("\t".join(str(res[rating].get(y,0)) for y in range(year1,year2))) def populationAge(year,country): @@ -150,4 +156,5 @@ def tournamentAttendance(year): # populationStrength(2017,"CZ") # populationAge(2017,"CZ") # tournamentAttendance(2010) -yearsByCountry() +# yearsByCountry(2001,2018) +# populationStrength(2017,2018,"CZ")