Skip to content

Commit

Permalink
Fixed staking data and country names
Browse files Browse the repository at this point in the history
  • Loading branch information
dylancm4 committed Aug 25, 2023
1 parent 9b2816b commit 6301072
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 21 deletions.
6 changes: 3 additions & 3 deletions web/src/Components/DfinityEarth/DfinityEarth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file DfinityEarth
* @copyright Copyright (c) 2018-2022 Dylan Miller and icpexplorer contributors
* @copyright Copyright (c) 2018-2023 Dylan Miller and icpexplorer contributors
* @license MIT License
*/

Expand Down Expand Up @@ -236,9 +236,9 @@ class DfinityEarth extends Component {

// Create a random set of unique subnets.
// It would be preferable to use the real number of subnets and number of nodes in each
// subnet, but that would result in too high of a CPU load.
// subnet, but that would result in too high of a CPU load and too much visual noise.
const nodesPerSubnet = 7;
const numberOfSubnets = 8;
const numberOfSubnets = 16;
const subnets = new Set();
let i = 0;
while (subnets.size !== numberOfSubnets) {
Expand Down
14 changes: 8 additions & 6 deletions web/src/Components/IcpMetricsTable/IcpMetricsTable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file IcpMetricsTable
* @copyright Copyright (c) 2018-2022 Dylan Miller and icpexplorer contributors
* @copyright Copyright (c) 2018-2023 Dylan Miller and icpexplorer contributors
* @license MIT License
*/

Expand All @@ -9,6 +9,7 @@ import PropTypes from 'prop-types';
import axios from 'axios';
import InfoTable, { InfoTableTextColor } from '../InfoTable/InfoTable';
import Constants from '../../constants';
import getApiStakingSubnetSum from '../../utils/getApiStakingSubnetSum';

/**
* This component displays a table with ICP-related info.
Expand Down Expand Up @@ -161,21 +162,22 @@ class IcpMetricsTable extends Component {
* @private
*/
getNnsMetrics() {
const url = 'https://ic-api.internetcomputer.org/api/v3/staking-metrics';
const url = 'https://ic-api.internetcomputer.org/api/v3/governance-metrics';
axios.get(url)
.then(res => {
// Dissolving Neurons ICP
const dissolvingNeuronsE8s = res.data.metrics.find(element => {
return element.name === 'governance_dissolving_neurons_e8s_count'
return element.name === 'governance_dissolving_neurons_e8s'
});
const dissolvingNeuronsIcp = parseInt(dissolvingNeuronsE8s.samples[0].value) / 100000000;
const dissolvingNeuronsIcp =
getApiStakingSubnetSum(dissolvingNeuronsE8s.subsets) / 100000000;

// Not Dissolving Neurons ICP
const notDissolvingNeuronsE8s = res.data.metrics.find(element => {
return element.name === 'governance_not_dissolving_neurons_e8s_count'
return element.name === 'governance_not_dissolving_neurons_e8s'
});
const notDissolvingNeuronsIcp =
parseInt(notDissolvingNeuronsE8s.samples[0].value) / 100000000;
getApiStakingSubnetSum(notDissolvingNeuronsE8s.subsets) / 100000000;

const totalStakedIcp = {
value: dissolvingNeuronsIcp + notDissolvingNeuronsIcp,
Expand Down
8 changes: 4 additions & 4 deletions web/src/Components/NetworkMetricsTable/NetworkMetricsTable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file NetworkMetricsTable
* @copyright Copyright (c) 2018-2022 Dylan Miller and icpexplorer contributors
* @copyright Copyright (c) 2018-2023 Dylan Miller and icpexplorer contributors
* @license MIT License
*/

Expand Down Expand Up @@ -163,23 +163,23 @@ class NetworkMetricsTable extends Component {
* @private
*/
getNnsMetrics() {
const url = 'https://ic-api.internetcomputer.org/api/v3/staking-metrics';
const url = 'https://ic-api.internetcomputer.org/api/v3/governance-metrics';
axios.get(url)
.then(res => {
// Total Voting Power
const totalVotingPowerE8s = res.data.metrics.find(element => {
return element.name === 'governance_voting_power_total'
});
const totalVotingPower = {
value: parseInt(totalVotingPowerE8s.samples[0].value) / 100000000,
value: Number(totalVotingPowerE8s.subsets[0].value[1]) / 100000000,
error: 0
};

// Daily Voting Rewards Maturity
const lastRewardEventE8s = res.data.metrics.find(element => {
return element.name === 'governance_last_rewards_event_e8s'
});
const lastRewardEvent = parseInt(lastRewardEventE8s.samples[0].value) / 100000000;
const lastRewardEvent = Number(lastRewardEventE8s.subsets[0].value[1]) / 100000000;
const dailyVotingRewards = {
value: lastRewardEvent,
error: 0
Expand Down
16 changes: 9 additions & 7 deletions web/src/Components/StakedChart/StakedChart.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/**
* @file StakedChart
* @copyright Copyright (c) 2018-2022 Dylan Miller and icpexplorer contributors
* @copyright Copyright (c) 2018-2023 Dylan Miller and icpexplorer contributors
* @license MIT License
*/

import PropTypes from 'prop-types';
import { withTheme } from 'styled-components';
import axios from 'axios';
import PieChart from '../PieChart/PieChart';
import getApiStakingSubnetSum from '../../utils/getApiStakingSubnetSum';

/**
* This component displays a pie chart showing Staked ICP by neuron state.
Expand Down Expand Up @@ -106,21 +107,22 @@ class StakedChart extends PieChart {
* @private
*/
getNnsMetrics() {
const url = 'https://ic-api.internetcomputer.org/api/v3/staking-metrics';
const url = 'https://ic-api.internetcomputer.org/api/v3/governance-metrics';
axios.get(url)
.then(res => {
// Dissolving Neurons ICP
const dissolvingNeuronsE8s = res.data.metrics.find(element => {
return element.name === 'governance_dissolving_neurons_e8s_count'
return element.name === 'governance_dissolving_neurons_e8s'
});
const dissolvingNeuronsIcp = parseInt(dissolvingNeuronsE8s.samples[0].value) / 100000000;
const dissolvingNeuronsIcp =
getApiStakingSubnetSum(dissolvingNeuronsE8s.subsets) / 100000000;

// Not Dissolving Neurons ICP
const notDissolvingNeuronsE8s = res.data.metrics.find(element => {
return element.name === 'governance_not_dissolving_neurons_e8s_count'
return element.name === 'governance_not_dissolving_neurons_e8s'
});
const notDissolvingNeuronsIcp =
parseInt(notDissolvingNeuronsE8s.samples[0].value) / 100000000;
getApiStakingSubnetSum(notDissolvingNeuronsE8s.subsets) / 100000000;

this.setState({
error: 0,
Expand All @@ -133,7 +135,7 @@ class StakedChart extends PieChart {
error: prevState.error + 1
}));
});
}
}
}

// Use the withTheme HOC so that we can use the current theme outside styled components.
Expand Down
16 changes: 16 additions & 0 deletions web/src/utils/getApiStakingSubnetSum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @file getApiStakingSubnetSum
* @copyright Copyright (c) 2018-2023 Dylan Miller and icpexplorer contributors
* @license MIT License
*/

/**
* Return the sum of values from an array of subset objects in the ic-api.internetcomputer.org/api
* response of a staking-related endpoint.
* @param {Array} subsets An array of subset objects in the API response of a staking-related
* endpoint.
* @returns {number} The sum of values from all subsets.
*/
export default function getApiStakingSubnetSum(subsets) {
return subsets.reduce((acc, subset) => acc + Number(subset.value[1]), 0);
}
20 changes: 19 additions & 1 deletion web/src/utils/getLocationsByCountry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file getLocationsByCountry
* @copyright Copyright (c) 2018-2022 Dylan Miller and icpexplorer contributors
* @copyright Copyright (c) 2018-2023 Dylan Miller and icpexplorer contributors
* @license MIT License
*/

Expand All @@ -15,36 +15,54 @@ export default async function getLocationsByCountry() {
// Future enhancement: Get the country name by latitude/longitude using an API such as:
// http://geodb-cities-api.wirefreethought.com/docs/api/find-near-location
const cityToCountryMap = new Map();
cityToCountryMap.set('Alabma', 'USA'); // sic
cityToCountryMap.set('Allentown', 'USA');
cityToCountryMap.set('Antwerp', 'Belgium');
cityToCountryMap.set('Atlanta', 'USA');
cityToCountryMap.set('Boston', 'USA');
cityToCountryMap.set('Brussels', 'Belgium');
cityToCountryMap.set('Bucharest', 'Romania');
cityToCountryMap.set('California', 'USA');
cityToCountryMap.set('Chicago', 'USA');
cityToCountryMap.set('Colombo', 'Sri Lanka');
cityToCountryMap.set('Dallas', 'USA');
cityToCountryMap.set('Frankfurt', 'Germany');
cityToCountryMap.set('Fremont', 'USA');
cityToCountryMap.set('Gauteng', 'South Africa');
cityToCountryMap.set('Geneva', 'Switzerland');
cityToCountryMap.set('HongKong', 'China'); // sic
cityToCountryMap.set('Houston', 'USA');
cityToCountryMap.set('Jacksonville', 'USA');
cityToCountryMap.set('Las Vegas', 'USA');
cityToCountryMap.set('Ljubljana', 'Slovenia');
cityToCountryMap.set('Maribor', 'Slovenia');
cityToCountryMap.set('Marseille', 'France');
cityToCountryMap.set('Melbourne', 'Australia');
cityToCountryMap.set('Miami', 'USA');
cityToCountryMap.set('Munich', 'Germany');
cityToCountryMap.set('Navi Mumbai', 'India');
cityToCountryMap.set('New Delhi', 'India');
cityToCountryMap.set('New York', 'USA');
cityToCountryMap.set('Normandie', 'France');
cityToCountryMap.set('Orlando', 'USA');
cityToCountryMap.set('Paris', 'France');
cityToCountryMap.set('Phoenix', 'USA');
cityToCountryMap.set('Portland', 'USA');
cityToCountryMap.set('Quebec', 'Canada');
cityToCountryMap.set('Quebec l', 'Canada'); // sic
cityToCountryMap.set('Queensland', 'Australia');
cityToCountryMap.set('San Jose', 'USA');
cityToCountryMap.set('Singapore', 'Singapore');
cityToCountryMap.set('Sterling', 'USA');
cityToCountryMap.set('South Moravian Region', 'Czech Republic');
cityToCountryMap.set('Stockholm', 'Sweden');
cityToCountryMap.set('Tampa', 'USA');
cityToCountryMap.set('Tbilisi', 'Georgia');
cityToCountryMap.set('Tokyo', 'Japan');
cityToCountryMap.set('Toronto', 'Canada');
cityToCountryMap.set('Vancouver', 'Canada');
cityToCountryMap.set('Vancouver', 'Canada');
cityToCountryMap.set('Vilnius', 'Lithuania');
cityToCountryMap.set('Zurich', 'Switzerland');

try {
Expand Down

0 comments on commit 6301072

Please sign in to comment.