-
Notifications
You must be signed in to change notification settings - Fork 89
/
get_pairwise_data.py
80 lines (69 loc) · 3.4 KB
/
get_pairwise_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import csv, csv_hack, json
from receipts import write_receipt
auctions = {}
bidsdict = csv.DictReader(open('data/auctions.csv'))
for bid in bidsdict:
auction_num = bid['auction_id']
if not auction_num in auctions:
auctions[auction_num] = []
auctions[auction_num].append(bid)
self_price_deltas = {}
pairwise_price_deltas = {}
pairwise_price_percent_deltas = {}
self_price_percent_deltas = {}
self_time_deltas = {}
pairwise_time_deltas = {}
pairs = {}
auctions_participated = {}
for auction_num in auctions:
last_bid = None
last_bids_by_id = {}
for bid in auctions[auction_num]:
sender = bid['sender']
if not sender in auctions_participated:
auctions_participated[sender] = set()
auctions_participated[sender].add(auction_num)
bid['gas_price'] = int(bid['gas_price'])
bid['time_seen'] = int(bid['time_seen'])
if last_bid is not None and last_bid['gas_price'] != 0:
counterbidder = last_bid['sender']
price_delta = bid['gas_price'] - last_bid['gas_price']
price_percent_delta = (price_delta / (float(bid['gas_price'] + last_bid['gas_price'])/2)) * 100
time_delta = (bid['time_seen'] - last_bid['time_seen']) / (10 ** 9)
price_delta /=(10 ** 9)
if price_delta < 0:
continue # ignore bids that aren't raises; TODO check effects
bidder_pairs = str(sender) + "-" + str(counterbidder)
if not bidder_pairs in pairwise_price_deltas:
pairwise_price_deltas[bidder_pairs] = []
pairwise_price_percent_deltas[bidder_pairs] = []
pairwise_time_deltas[bidder_pairs] = []
pairs[sender] = set()
pairwise_time_deltas[bidder_pairs].append(time_delta)
pairwise_price_deltas[bidder_pairs].append(price_delta)
pairwise_price_percent_deltas[bidder_pairs].append(price_percent_delta)
pairs[sender].add(bidder_pairs)
if sender in last_bids_by_id and last_bids_by_id[sender]['gas_price'] != 0:
last_self_bid = last_bids_by_id[sender]
price_delta = bid['gas_price'] - last_self_bid['gas_price']
time_delta = (bid['time_seen'] - last_self_bid['time_seen']) / (10 ** 9)
price_percent_delta = (price_delta / ((bid['gas_price'] + last_self_bid['gas_price'])/2)) * 100
price_delta /=(10 ** 9)
if not sender in self_price_deltas:
self_time_deltas[sender] = []
self_price_deltas[sender] = []
self_price_percent_deltas[sender] = []
self_time_deltas[sender].append(time_delta)
self_price_deltas[sender].append(price_delta)
self_price_percent_deltas[sender].append(price_percent_delta)
last_bid = bid
last_bids_by_id[sender] = bid
# convert sets to lists for json reasons
for pair in pairs:
pairs[pair] = list(pairs[pair])
for sender in auctions_participated:
auctions_participated[sender] = list(auctions_participated[sender])
print(pairs)
data = {"pairwise_time": pairwise_time_deltas, "pairwise_price": pairwise_price_deltas,"pairwise_price_percent": pairwise_price_percent_deltas,"self_time": self_time_deltas,"self_price": self_price_deltas, "self_price_percent": self_price_deltas, "pairs": pairs, "auctions": auctions_participated}
f = open('data/pairwise_self.csv', 'w')
f.write(json.dumps(data))