Skip to content

Commit 5d78c30

Browse files
authored
Merge pull request #674 from net-zero-project/main
Update O&G data loader
2 parents 5f75092 + 7d749e2 commit 5d78c30

35 files changed

+3726
-305
lines changed

.env.SAMPLE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ LEDGER_FIRST_BLOCK="0"
4545
#LEDGER_ETH_JSON_RPC_URL="https://goerli.infura.io/v3/<your-infura-project-id>"
4646
#LEDGER_ETH_WS_URL="wss://goerli.infura.io/ws/v3/<your-infura-project-id>"
4747
#LEDGER_ETH_NETWORK="goerli"
48-
#LEDGER_EMISSION_TOKEN_CONTRACT_ADDRESS="0xE8854ec567b3762046d8f773547f373e6A1A620A"
48+
#LEDGER_EMISSION_TOKEN_CONTRACT_ADDRESS="0x118938E52100df8FfE8793f8ec231f56d85e8E72"
4949
#LEDGER_FIRST_BLOCK="7385471"
50-
#LEDGER_CARBON_TRACKER_ADDRESS="0xDb80143bCf04B53Ed586b7f806C25ff275b5Cc5b"
50+
#LEDGER_CARBON_TRACKER_ADDRESS="0x039EF5c92CC8249D2cb3785B68bc4F79dC8a7625"
5151

5252
# it should be 2048 for Avalanche testnet and could be 5000 for bsc testnet. 2048 seems to work for Goerli
5353
LEDGER_EVENTS_BLOCK_INTERVAL="2048"

app/api-server/controller/synchronizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ const getNumOfProductTokens = async (opts: OPTS_TYPE): Promise<number> => {
305305
return result;
306306
} catch (err) {
307307
console.error(err)
308-
throw new Error('Error in _numOfProducts: ' + err)
308+
throw new Error('Error in getNumOfProductTokens: ' + err)
309309
}
310310
}
311311

app/api-server/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const assertEnv = (key: string): string => {
2626
return process.env[key] || '';
2727
}
2828
const contract_address = assertEnv('LEDGER_EMISSION_TOKEN_CONTRACT_ADDRESS')
29-
const tracker_address = process.env['LEDGER_CARBON_TRACKER_ADDRESS']
29+
const tracker_address = assertEnv('LEDGER_CARBON_TRACKER_ADDRESS')
3030
const network_name = assertEnv('LEDGER_ETH_NETWORK')
3131
const network_rpc_url = assertEnv('LEDGER_ETH_JSON_RPC_URL')
3232
const network_ws_url = process.env['LEDGER_ETH_WS_URL']

app/frontend/contracts/src/addresses.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ const networksAndAddresses = {
2121
}
2222
},
2323

24+
hedera_testnet: {
25+
network: "Hedera Testnet",
26+
tokenNetwork: {
27+
address: "0x00000000000000000000000000000000003be83f",
28+
},
29+
carbonTracker: {
30+
address: "0x00000000000000000000000000000000003c0064",
31+
},
32+
dao: {
33+
governor: {
34+
address: "",
35+
},
36+
daoToken: {
37+
address: "",
38+
}
39+
}
40+
},
41+
2442
goerli: {
2543
network: "Goerli Testnet",
2644
tokenNetwork: {
@@ -34,10 +52,10 @@ const networksAndAddresses = {
3452
},
3553
dao: {
3654
governor: {
37-
address: "0x9F4590684d1DD950dF65Dc71D39f782bc3af317A",
55+
address: "0x6875735ee7864673B211eC2ec2a534179F863DAD",
3856
},
3957
daoToken: {
40-
address: "0x67E5b82809f28aA321818b90bF5c603D954f87C8",
58+
address: "0x08AA8Ae1E7A087b591a5a1234fBE20e592c5c417",
4159
}
4260
}
4361
},
@@ -152,6 +170,6 @@ const networksAndAddresses = {
152170
}
153171

154172
// change this to the network you want
155-
const addresses = networksAndAddresses.hardhat;
173+
const addresses = networksAndAddresses.hedera_testnet;
156174

157175
export default addresses;

app/frontend/react-app/src/components/tracker-info-modal.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,11 @@ const TrackerInfoModal:FC<TrackerInfoModalProps> = ({provider,show,tracker,onHid
107107
: null)}
108108
<tr>
109109
<td>From date</td>
110-
{/*TO-DO infer fromDate/thruDate from Net Emission tokens*/}
111-
<td><DisplayDate date={tracker.fromDate}/></td>
110+
<td><DisplayDate date={Math.min.apply(Math,tracker?.tokens?.map(e=>{return e?.token?.thruDate!}) as number[])}/></td>
112111
</tr>
113112
<tr>
114113
<td>Thru date</td>
115-
<td><DisplayDate date={tracker.thruDate}/></td>
114+
<td><DisplayDate date={Math.min.apply(Math,tracker?.tokens?.map(e=>{return e?.token?.thruDate!}) as number[])}/></td>
116115
</tr>
117116
<tr>
118117
<td>Description</td>

app/methane/client/src/components/static-data.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Field } from "@blockchain-carbon-accounting/react-app/src/components/static-data"
22
export type Asset = {
33
name?: string
4+
operator?: string
45
latitude: number
56
longitude: number
67
division_type?: string
@@ -77,6 +78,12 @@ export const ASSET_FIELDS: Field[] = [
7778
type: 'string',
7879
ops: ['eq']
7980
},
81+
{
82+
alias: 'Operator',
83+
name: 'operator',
84+
type: 'string',
85+
ops: ['like']
86+
},
8087
]
8188

8289
export const PRODUCT_FIELDS: Field[] = [

app/methane/client/src/pages/assets.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ const RegisteredOperator: ForwardRefRenderFunction<AssetsHandle, AssetProps> = (
182182
<div className="mt-4">
183183
<h2 style={{display: 'inline'}}>
184184
Operator: {operator?.name}&nbsp;
185-
{assetCount} Assets&nbsp;
185+
{operator?.assetsCount} ({assetCount}) Assets &nbsp;
186186
</h2>
187187
&nbsp;
188188
<Button className="mb-3" onClick={switchQueryBuilder} variant={(showQueryBuilder) ? 'dark' : 'outline-dark'}><BsFunnel /></Button>
@@ -197,6 +197,7 @@ const RegisteredOperator: ForwardRefRenderFunction<AssetsHandle, AssetProps> = (
197197
<thead>
198198
<tr>
199199
<th>Name</th>
200+
<th>Operator</th>
200201
<th>State</th>
201202
<th>Status</th>
202203
<th></th>
@@ -206,7 +207,8 @@ const RegisteredOperator: ForwardRefRenderFunction<AssetsHandle, AssetProps> = (
206207
{!!selectedAssets &&
207208
selectedAssets.map((asset,index) => (
208209
<tr key={[asset?.name,index].join('_')} onClick={() => handleOpenOperatorInfoModal(asset)} onMouseOver={pointerHover}>
209-
<td> {asset.name}</td>
210+
<td>{asset.name}</td>
211+
<td>{asset?.operator}</td>
210212
<td>{asset?.division_name}</td>
211213
<td>{asset?.status}</td>
212214
<td>

data/loadOGdata.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
npm run dataLoader load_og_assets "./oil_and_gas/files/Oil_and_Natural_Gas_Wells.geojson" -- --format US_asset_data --source "https://hifld-geoplatform.opendata.arcgis.com/datasets/geoplatform::oil-and-natural-gas-wells/explore"
1+
#npm run dataLoader load_og_assets "./oil_and_gas/files/Oil_and_Natural_Gas_Wells.geojson" -- --format US_asset_data --source "https://hifld-geoplatform.opendata.arcgis.com/datasets/geoplatform::oil-and-natural-gas-wells/explore"
2+
#npm run dataLoader set_asset_operators
3+
24
npm run dataLoader load_product_data "./oil_and_gas/files/2022-og-benchmarking-report-data.xlsx" "Company_basin" -- --format Benchmark --source "https://www.sustainability.com/globalassets/sustainability.com/thinking/pdfs/2022/2022-og-benchmarking-report-data.xlsx" --skip_rows 7
35

46
npm run dataLoader load_product_data "./oil_and_gas/files/VIIRS_Global_flaring_d.7_slope_0.029353_2021_web.xlsx" "flare upstream" -- --format VIIRS --year 2021 --source "https://eogdata.mines.edu/global_flare_data/VIIRS_Global_flaring_d.7_slope_0.029353_2021_web.xlsx"

data/oil_and_gas/README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,24 @@ Or you can download the data
99
sh download.sh
1010
```
1111

12-
Once you have the data, load them into postgres db (blockchain-carbon-accounting) by running the following from `/data`:
12+
### Oil & gas asset and operator data.
13+
14+
The oil & gas asset data includes >1.5 million assets.
15+
To avoid reloading the data into postres `download.sh` returns 3 binary files that can be used to restore the following postrgres tables (after initializing the DB with `npm run pg:init`)
16+
17+
1. oil_and_gas_asset
18+
2. operator
19+
3. asset_operator
20+
21+
Otherwise the tables can be loaded using the following commands from `\data`.
22+
23+
``` npm run dataLoader load_og_assets "./oil_and_gas/files/Oil_and_Natural_Gas_Wells.geojson" -- --format US_asset_data --source "https://hifld-geoplatform.opendata.arcgis.com/datasets/geoplatform::oil-and-natural-gas-wells/explore"```
24+
25+
```npm run dataLoader set_asset_operators```
26+
27+
### Oil & gas product & emissions data
28+
29+
Load the product data into postgres db by running the following from `/data` directorty:
1330
```
1431
sh loadOGdata.sh
1532
```

data/oil_and_gas/download.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ curl -L -c cookies.txt 'https://docs.google.com/uc?export=download&id='$fileId \
99
curl -L -b cookies.txt -o $fileName \
1010
'https://docs.google.com/uc?export=download&id='$fileId'&confirm='$(<confirm.txt)
1111
rm -f confirm.txt cookies.txt
12+
echo "Downloading postgres table backup..."
13+
curl \
14+
-L -o 'asset_operator' 'https://docs.google.com/uc?export=download&id=1ME0XIz065OEMReqfvsVOl7oW5ye2BmUl' \
15+
-L -o 'operator' 'https://docs.google.com/uc?export=download&id=1MHKrkMvq9FZCw_RYsiIrXi1rRmfLmSD7' \
16+
-L -o 'oil_and_gas_asset' 'https://docs.google.com/uc?export=download&id=1VPYAKasx3SJ9l3wuW99CMMFHEGU-4Dfr'
1217

1318
echo "Downloading oil and gas product data from google drive..."
1419
echo "VIIRS flaring data..."

0 commit comments

Comments
 (0)