-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add NP rewards with dashboard logs (#978)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
565dfd7
commit 28f424b
Showing
14 changed files
with
263 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,51 @@ | ||
import csv | ||
import json | ||
import subprocess | ||
|
||
import time | ||
# Define the file paths and constants | ||
csv_file_path = "node_info_api.csv" | ||
did_file_path = "rs/dre-canisters/trustworthy-node-metrics/src/trustworthy-node-metrics/trustworthy-node-metrics.did" | ||
network = "ic" | ||
canister_name = "trustworthy-node-metrics" | ||
|
||
# Function to generate the dfx command for node_metadata | ||
def generate_dfx_command(node_mappings): | ||
nodes = [ | ||
f'record {{ node_id = principal "{row["node_id"]}"; node_provider_id = principal "{row["node_provider_id"]}"; node_provider_name = "{row["node_provider_name"]}"; }}' | ||
for row in node_mappings | ||
] | ||
# Prepare the argument for the canister call | ||
node_metadata_args = f"vec {{ {'; '.join(nodes)} ; }}" | ||
|
||
# Function to generate the dfx command for a single node | ||
def generate_dfx_command(node_data): | ||
command = [ | ||
"dfx", "canister", "call", canister_name, "node_metadata", | ||
f'({node_metadata_args})', | ||
"dfx", "canister", "call", canister_name, "np_rewardable_backfill", | ||
f'(record {{ node_provider_id = principal "{node_data["node_provider_id"]}"; region = "{node_data["region"]}"; node_type = "{node_data["node_type"]}"; count = {node_data["count"]}; }})', | ||
"--candid", did_file_path, | ||
"--network", network | ||
] | ||
|
||
return command | ||
|
||
# Read the CSV file and filter out missing providers | ||
def read_csv(csv_file_path): | ||
node_mappings = [] | ||
with open(csv_file_path, mode='r') as file: | ||
csv_reader = csv.DictReader(file) | ||
for row in csv_reader: | ||
if row['node_provider_id'] != "missing": # Ignore missing providers | ||
node_mappings.append({ | ||
"node_id": row["node_id"], | ||
"node_provider_id": row["node_provider_id"], | ||
"node_provider_name": row["node_provider_name"] | ||
}) | ||
# Read the .json file and extract node information | ||
def read_json(json_file_path): | ||
with open(json_file_path, mode='r') as file: | ||
# Each line is a separate JSON object, so we use a list to store them | ||
node_mappings = [json.loads(line) for line in file] | ||
return node_mappings | ||
|
||
# Execute the dfx command for each node | ||
def execute_dfx_command(command): | ||
try: | ||
result = subprocess.run(command, capture_output=True, text=True) | ||
print("Command executed successfully:", result.stdout) | ||
if result.stderr: | ||
print("Error:", result.stderr) | ||
except Exception as e: | ||
print("Failed to execute the dfx command:", str(e)) | ||
|
||
# Main execution | ||
if __name__ == "__main__": | ||
# Read the CSV and get node mappings | ||
node_mappings = read_csv(csv_file_path) | ||
# Read the JSON file and get node mappings | ||
node_mappings = read_json(json_file_path) | ||
|
||
if node_mappings: | ||
# Generate the dfx command | ||
dfx_command = generate_dfx_command(node_mappings) | ||
|
||
# Execute the dfx command | ||
try: | ||
result = subprocess.run(dfx_command, capture_output=True, text=True) | ||
print(result.stdout) | ||
if result.stderr: | ||
print("Error:", result.stderr) | ||
except Exception as e: | ||
print("Failed to execute the dfx command:", str(e)) | ||
# Loop through each node and execute a separate command | ||
for node in node_mappings: | ||
# Generate the dfx command for the current node | ||
dfx_command = generate_dfx_command(node) | ||
|
||
# Execute the dfx command for the current node | ||
execute_dfx_command(dfx_command) | ||
else: | ||
print("No valid node mappings found.") | ||
print("No valid node mappings found.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.