Skip to content

Commit 8fd062d

Browse files
committed
Adjust analysis scripts to new database schema
1 parent 517d0bd commit 8fd062d

File tree

8 files changed

+70
-21
lines changed

8 files changed

+70
-21
lines changed

analysis/mixed/lib/node_agent.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,35 @@
11
# get_agent_version gets the agent version info of given peers.
2-
# It takes an sql connection, the peer ids as arguments, and
2+
# It takes an sql connection, the peer **database** ids as arguments, and
33
# returns the agent version info of these peer ids.
44
def get_agent_version(conn, peer_ids):
55
cur = conn.cursor()
66
res = dict()
77
cur.execute(
88
"""
9-
SELECT id, agent_version
10-
FROM peers
11-
WHERE id IN (%s)
9+
SELECT p.id, agent_version
10+
FROM peers p
11+
INNER JOIN agent_versions av on av.id = p.agent_version_id
12+
WHERE p.id IN (%s)
13+
""" % ','.join(['%s'] * len(peer_ids)),
14+
tuple(peer_ids)
15+
)
16+
for id, agent in cur.fetchall():
17+
res[id] = agent
18+
return res
19+
20+
21+
# get_agent_version_multi_hash gets the agent version info of given peers.
22+
# It takes an sql connection, the peer ID multi hashes as arguments, and
23+
# returns the agent version info of these peer ids.
24+
def get_agent_version_multi_hash(conn, peer_ids):
25+
cur = conn.cursor()
26+
res = dict()
27+
cur.execute(
28+
"""
29+
SELECT p.id, agent_version
30+
FROM peers p
31+
INNER JOIN agent_versions av on av.id = p.agent_version_id
32+
WHERE p.multi_hash IN (%s)
1233
""" % ','.join(['%s'] * len(peer_ids)),
1334
tuple(peer_ids)
1435
)

analysis/mixed/lib/node_classification.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def get_on_nodes(conn, start, end):
3333
WHERE (created_at < %s AND updated_at > %s AND first_successful_dial != last_successful_dial) OR (created_at < %s AND finished = false) AND peer_id NOT IN (
3434
SELECT peer_id
3535
FROM sessions
36-
WHERE updated_at > %s AND updated_At < %s AND finished = true
36+
WHERE updated_at > %s AND updated_at < %s AND finished = true
3737
)
3838
""",
3939
[end, end, end, start, end]
@@ -55,7 +55,7 @@ def get_off_nodes(conn, start, end):
5555
WHERE created_at < %s AND updated_at > %s AND first_successful_dial = last_successful_dial AND finished = true AND peer_id NOT IN (
5656
SELECT peer_id
5757
FROM sessions
58-
WHERE updated_at > %s AND updated_At < %s AND first_successful_dial != last_successful_dial AND finished = true
58+
WHERE updated_at > %s AND updated_at < %s AND first_successful_dial != last_successful_dial AND finished = true
5959
)
6060
""",
6161
[end, start, start, end]

analysis/mixed/lib/node_cloud.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66

77

88
# get_cloud gets the cloud info of given peers.
9-
# It takes an sql connection, the peer ids as arguments, and
9+
# It takes an sql connection, the peer **database** ids as arguments, and
1010
# returns the cloud info of these peer ids.
1111
def get_cloud(conn, peer_ids):
1212
cur = conn.cursor()
1313
res = dict()
1414
cur.execute(
1515
"""
16-
SELECT id, multi_addresses
17-
FROM peers
18-
WHERE id IN (%s)
16+
SELECT p.id, ma.maddr
17+
FROM peers p
18+
INNER JOIN peers_x_multi_addresses pxma on p.id = pxma.peer_id
19+
INNER JOIN multi_addresses ma on pxma.multi_address_id = ma.id
20+
WHERE p.id IN (%s)
1921
""" % ','.join(['%s'] * len(peer_ids)),
2022
tuple(peer_ids)
2123
)
@@ -31,7 +33,7 @@ def get_cloud(conn, peer_ids):
3133
page = requests.get(azure_url)
3234
tree = html.fromstring(page.content)
3335
download_url = tree.xpath("//a[contains(@class, 'failoverLink') and "
34-
"contains(@href,'download.microsoft.com/download/')]/@href")[0]
36+
"contains(@href,'download.microsoft.com/download/')]/@href")[0]
3537
azure_ips = requests.get(download_url, allow_redirects=True).json()
3638
azure_prefixes = set()
3739
for item in azure_ips["values"]:

analysis/mixed/lib/node_geolocation.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ def get_geolocation(conn, peer_ids):
1111
res = dict()
1212
cur.execute(
1313
"""
14-
SELECT id, multi_addresses
15-
FROM peers
16-
WHERE id IN (%s)
14+
SELECT p.id, ma.maddr
15+
FROM peers p
16+
INNER JOIN peers_x_multi_addresses pxma on p.id = pxma.peer_id
17+
INNER JOIN multi_addresses ma on pxma.multi_address_id = ma.id
18+
WHERE p.id IN (%s)
1719
""" % ','.join(['%s'] * len(peer_ids)),
1820
tuple(peer_ids)
1921
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# get_multi_addresses gets the multi addresses of the given peers.
2+
# It takes an sql connection, the peer **database** ids as arguments, and
3+
# returns the agent version info of these peer ids.
4+
def get_multi_addresses(conn, peer_ids):
5+
cur = conn.cursor()
6+
res = dict()
7+
cur.execute(
8+
"""
9+
SELECT p.id, ma.maddr
10+
FROM peers p
11+
INNER JOIN peers_x_multi_addresses pxma on p.id = pxma.peer_id
12+
INNER JOIN multi_addresses ma on pxma.multi_address_id = ma.id
13+
WHERE p.id IN (%s)
14+
""" % ','.join(['%s'] * len(peer_ids)),
15+
tuple(peer_ids)
16+
)
17+
for id, maddr in cur.fetchall():
18+
res[id] = maddr
19+
return res

analysis/mixed/lib/node_ping.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ async def check_node_ping_async(conn, peer_ids):
1111
res = dict()
1212
cur.execute(
1313
"""
14-
SELECT id, multi_addresses
15-
FROM peers
16-
WHERE id IN (%s)
14+
SELECT p.id, ma.maddr
15+
FROM peers p
16+
INNER JOIN peers_x_multi_addresses pxma on p.id = pxma.peer_id
17+
INNER JOIN multi_addresses ma on pxma.multi_address_id = ma.id
18+
WHERE p.id IN (%s)
1719
""" % ','.join(['%s'] * len(peer_ids)),
1820
tuple(peer_ids)
1921
)

analysis/mixed/lib/node_protocol.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ def get_agent_protocol(conn, peer_ids):
66
res = dict()
77
cur.execute(
88
"""
9-
SELECT id, protocol
10-
FROM peers
11-
WHERE id IN (%s)
9+
SELECT sq.id, array_agg(prot.protocol)
10+
FROM protocols prot INNER JOIN (
11+
SELECT p.id, unnest(ps.protocol_ids) protocol_id
12+
FROM peers p INNER JOIN protocols_sets ps ON ps.id = p.protocols_set_id
13+
WHERE p.id IN (%s)
14+
) AS sq ON sq.protocol_id = prot.id GROUP BY 1
1215
""" % ','.join(['%s'] * len(peer_ids)),
1316
tuple(peer_ids)
1417
)

analysis/mixed/plot_nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
labels=["off nodes %d" % len(off), "on nodes %d" % len(on), "dangling nodes %d" % len(dangle)],
2424
autopct="%.1f%%")
2525
plt.title("Node classification from %s to %s" % (start.replace(microsecond=0), end.replace(microsecond=0)))
26-
plt.show()
26+
plt.show()

0 commit comments

Comments
 (0)