summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKapil Viren Ahuja <kvahuja@users.noreply.github.com>2017-02-16 22:18:04 +0530
committerschneefux <schneefux+github@schneefux.xyz>2017-02-16 17:48:04 +0100
commit07f17264500c388cb039eb33cdd89bc4f54d9505 (patch)
tree3820fe6620ab170242fca870311798d5246c4d3d
parent5a932151539247fef874c9bcb8e49b8483c529cd (diff)
downloadprocessor-07f17264500c388cb039eb33cdd89bc4f54d9505.tar.gz
processor-07f17264500c388cb039eb33cdd89bc4f54d9505.zip
1. using the right table names in SQL. 2. also put in some exception handling which spits out the error and moves on instead of exiting (#11)
* 1. using the right table names in SQL. 2. also put in some exception handling which spits out the error and moves on instead of exiting * ID in participant table is participant ID. we need a mapping for player ID in Web to get a player's matches.
-rw-r--r--api.py17
-rw-r--r--queries/match.sql2
-rw-r--r--queries/match_participation.sql5
-rw-r--r--queries/match_results.sql2
-rw-r--r--queries/player.sql2
5 files changed, 19 insertions, 9 deletions
diff --git a/api.py b/api.py
index ac004d2..d42c2aa 100644
--- a/api.py
+++ b/api.py
@@ -53,12 +53,17 @@ class Processor(object):
async with self._srcpool.acquire() as srccon:
async with self._destpool.acquire() as destcon:
for table, query in self._queries.items():
+ logging.info("running query for '%s'", table)
stop_after -= 1 # TODO for debugging, don't process whole table
- logging.info("processing table %s", table)
async with srccon.transaction():
async with destcon.transaction():
- async for rec in srccon.cursor(query):
- await self.into(destcon, rec, table)
+ rec_o = ""
+ try:
+ async for rec in srccon.cursor(query):
+ rec_o = rec
+ await self.into(destcon, rec, table)
+ except:
+ logging.error("rec: %s", rec_o)
async def into(self, conn, data, table):
"""Insert a named tuple into a table."""
@@ -67,7 +72,11 @@ class Processor(object):
placeholders = ["${}".format(i) for i, _ in enumerate(values, 1)]
query = "INSERT INTO {} (\"{}\") VALUES ({})".format(
table, "\", \"".join(keys), ", ".join(placeholders))
- await conn.execute(query, (*data))
+ try:
+ await conn.execute(query, (*data))
+ except:
+ logging.error("Query: '%s'", query)
+ logging.error("Data: '%s'", data)
async def main():
diff --git a/queries/match.sql b/queries/match.sql
index 970412b..0ff0c62 100644
--- a/queries/match.sql
+++ b/queries/match.sql
@@ -15,4 +15,4 @@ false AS "anyAFK",
0 AS "jungleMinionsSlayed",
0 AS "heroDeaths"
-FROM apidata WHERE type='match'
+FROM match
diff --git a/queries/match_participation.sql b/queries/match_participation.sql
index 0fed84b..d37983f 100644
--- a/queries/match_participation.sql
+++ b/queries/match_participation.sql
@@ -1,6 +1,7 @@
SELECT
-id AS "player_id",
+id AS "participant_id",
+relationships->'player'-> 'data' ->> 'id' AS player_id,
0 AS "rosterId",
0 AS "fk_player_id",
0 AS "fk_match_results_id",
@@ -20,4 +21,4 @@ attributes->>'actor' AS "hero",
(attributes->'stats'->>'wentAfk')::bool::int AS "wentAfk",
FALSE AS "perfectGame"
-FROM apidata WHERE type='participant'
+FROM participant
diff --git a/queries/match_results.sql b/queries/match_results.sql
index b1e750b..c493d5c 100644
--- a/queries/match_results.sql
+++ b/queries/match_results.sql
@@ -19,4 +19,4 @@ FALSE AS "surrender",
0 AS "afkCount",
0 AS "afkTime"
-FROM apidata WHERE type='roster'
+FROM roster
diff --git a/queries/player.sql b/queries/player.sql
index cf71d20..4f37018 100644
--- a/queries/player.sql
+++ b/queries/player.sql
@@ -18,4 +18,4 @@ attributes->'stats'->>'lifetimeGold' AS "lifeTimeGold",
0 AS "lifeTimeKD",
0 AS "lifeTimeKDA"
-FROM apidata WHERE type='player'
+FROM player