summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2014-10-29 15:48:36 +0100
committeremkael <emkael@tlen.pl>2014-10-29 15:48:36 +0100
commitf271f4971aa3f2ea8718c6df353fadf7aa688cf0 (patch)
treea90a59127d4f44bb6a1712b46644c31c47fe3916
parenta6e982ee9e229badc5357aad542b36f354a02471 (diff)
* useful queries re-formatted
-rw-r--r--doc/sql.txt43
-rwxr-xr-xelo.py2
2 files changed, 38 insertions, 7 deletions
diff --git a/doc/sql.txt b/doc/sql.txt
index 16373b3..3a67dd3 100644
--- a/doc/sql.txt
+++ b/doc/sql.txt
@@ -1,17 +1,48 @@
Useful queries:
-SELECT * FROM `rankings` JOIN drivers ON rankings._driver = drivers.id WHERE ranking >= (SELECT MAX(r.ranking) FROM rankings r WHERE r.rank_date <= rankings.rank_date) ORDER BY rank_date ASC
-
- selects top rating progression
-SELECT drivers.driver, rankings.ranking, rankings.rank_date FROM rankings INNER JOIN (SELECT MAX(ranking) ranking, _driver FROM rankings GROUP BY _driver) r ON r.ranking=rankings.ranking AND r._driver=rankings._driver JOIN drivers ON rankings._driver = drivers.id ORDER BY rankings.ranking DESC
+SELECT * FROM rankings
+JOIN drivers ON rankings._driver = drivers.id
+WHERE ranking >= (
+ SELECT MAX(r.ranking) FROM rankings r
+ WHERE r.rank_date <= rankings.rank_date
+) ORDER BY rank_date ASC
- overall top peak ratings
-
-SELECT drivers.driver, rankings.ranking, rankings.rank_date FROM rankings INNER JOIN (SELECT MAX(rank_date) rank_date, _driver FROM rankings GROUP BY _driver) r ON r.rank_date=rankings.rank_date AND r._driver=rankings._driver JOIN drivers ON rankings._driver = drivers.id ORDER BY rankings.ranking DESC
+
+SELECT drivers.driver,
+ rankings.ranking,
+ rankings.rank_date
+FROM rankings
+INNER JOIN (
+ SELECT MAX(ranking) ranking, _driver FROM rankings
+ GROUP BY _driver
+) r ON r.ranking=rankings.ranking AND r._driver=rankings._driver
+JOIN drivers ON rankings._driver = drivers.id
+ORDER BY rankings.ranking DESC
- highest exit ratings
-SELECT MAX(ranking), AVG(ranking), YEAR(rank_date) FROM rankings GROUP BY YEAR(rank_date) ORDER BY YEAR(rank_date) ASC
+SELECT drivers.driver,
+ rankings.ranking,
+ rankings.rank_date
+FROM rankings
+INNER JOIN (
+ SELECT MAX(rank_date) rank_date, _driver FROM rankings GROUP BY _driver
+) r ON r.rank_date=rankings.rank_date AND r._driver=rankings._driver
+JOIN drivers ON rankings._driver = drivers.id
+WHERE rankings.rank_date < CONCAT(YEAR(CURDATE()),'-01-01')
+ORDER BY rankings.ranking DESC
- year-by-year rating inflation
+
+SELECT YEAR(rank_date),
+ MAX(ranking),
+ MIN(ranking),
+ AVG(ranking),
+ AVG(ranking)+STDDEV(ranking),
+ AVG(ranking)-STDDEV(ranking)
+FROM rankings
+GROUP BY YEAR(rank_date)
+ORDER BY YEAR(rank_date) ASC
diff --git a/elo.py b/elo.py
index 8aacfc8..743ee4e 100755
--- a/elo.py
+++ b/elo.py
@@ -7,7 +7,7 @@ from f1elo.interface import Interface
parser = argparse.ArgumentParser(
description='Ranks Formula One drivers using Elo rating',
- formatter_class=argparse.RawTextHelpFormatter)
+ formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('command', metavar='COMMAND', nargs='?',
help="Action to execute against the database:\n"
"print - prints the rankings for all drivers ranked in 12 months,\n"