-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindexer.php
More file actions
60 lines (51 loc) · 2.62 KB
/
indexer.php
File metadata and controls
60 lines (51 loc) · 2.62 KB
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
<?php
$roundInformation = json_decode(file_get_contents('data/all_rounds.json'), true);
$programFilter = 'GG18';
$contributors = array();
$amounts = array(); // Array to keep track of aggregated amounts
$voteCounts = array(); // Array to keep track of vote counts
foreach ($roundInformation as $roundInfo) {
if ($roundInfo['program'] == $programFilter) {
// check if round exists in local folder
if (!file_exists('data/' . $roundInfo['chain_id'] . '/rounds/' . $roundInfo['round_id'] . '/contributors.json')) {
// if not, download it
// https://indexer-production.fly.dev/data/280/rounds/0xc75348afb1fa5C5151564d8a7398cD62632BA207.json
$roundURL = 'https://indexer-production.fly.dev/data/' . $roundInfo['chain_id'] . '/rounds/' . $roundInfo['round_id'] . '.json';
if (!file_exists('data/' . $roundInfo['chain_id'] . '/rounds/' . $roundInfo['round_id'])) {
mkdir('data/' . $roundInfo['chain_id'] . '/rounds/' . $roundInfo['round_id'], 0777, true);
}
copy('https://indexer-production.fly.dev/data/' . $roundInfo['chain_id'] . '/rounds/' . $roundInfo['round_id'] . '/contributors.json', 'data/' . $roundInfo['chain_id'] . '/rounds/' . $roundInfo['round_id'] . '/contributors.json');
}
$roundContributorsURL = 'data/' . $roundInfo['chain_id'] . '/rounds/' . $roundInfo['round_id'] . '/contributors.json';
if (file_exists($roundContributorsURL)) {
$roundContributors = json_decode(file_get_contents($roundContributorsURL), true);
foreach ($roundContributors as $contributor) {
$id = $contributor['id'];
$amountUSD = $contributor['amountUSD'];
$votes = $contributor['votes'];
// Check if this contributor ID already exists in the amounts and voteCounts arrays
if (isset($amounts[$id])) {
// Update the amountUSD and votes in the contributors array
foreach ($contributors as &$existingContributor) {
if ($existingContributor['id'] === $id) {
$existingContributor['amountUSD'] += $amountUSD;
$existingContributor['votes'] += $votes;
break;
}
}
// Update the aggregated amount and vote count
$amounts[$id] += $amountUSD;
$voteCounts[$id] += $votes;
} else {
// Add this contributor to the contributors array and track the amount and votes
$contributors[] = $contributor;
$amounts[$id] = $amountUSD;
$voteCounts[$id] = $votes;
}
}
}
}
}
// write to file
file_put_contents('data/' . $programFilter . '.json', json_encode($contributors));
echo json_encode($contributors);