This client enables obtaining statistical information from the subgraph.
Unlike other SDK clients, StatisticsClient does not require signer or provider to be provided. We just need to create a client object using relevant network data.
constructor(network: NetworkData)
Installation
npm
npm install @human-protocol/sdk
yarn
yarn install @human-protocol/sdk
Code example
import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
Constructors
new StatisticsClient()
StatisticsClient constructor
Parameters
networkData
The network information required to connect to the Statistics contract
Returns
Defined in
Properties
networkData
Defined in
subgraphUrl
subgraphUrl: string
Defined in
Methods
getEscrowStatistics()
This function returns the statistical data of escrows.
Input parameters
interface IStatisticsFilter {
from?: Date;
to?: Date;
first?: number; // (Optional) Number of transactions per page. Default is 10.
skip?: number; // (Optional) Number of transactions to skip. Default is 0.
orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
}
import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
const escrowStatistics = await statisticsClient.getEscrowStatistics();
const escrowStatisticsApril = await statisticsClient.getEscrowStatistics({
from: new Date('2021-04-01'),
to: new Date('2021-04-30'),
});
Defined in
getHMTDailyData()
This function returns the statistical data of HMToken day by day.
Input parameters
interface IStatisticsFilter {
from?: Date;
to?: Date;
first?: number; // (Optional) Number of transactions per page. Default is 10.
skip?: number; // (Optional) Number of transactions to skip. Default is 0.
orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
}
This function returns the statistical data of payments.
Input parameters
interface IStatisticsFilter {
from?: Date;
to?: Date;
first?: number; // (Optional) Number of transactions per page. Default is 10.
skip?: number; // (Optional) Number of transactions to skip. Default is 0.
orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
}
type DailyPaymentData = {
timestamp: Date;
totalAmountPaid: BigNumber;
totalCount: number;
averageAmountPerWorker: BigNumber;
};
type PaymentStatistics = {
dailyPaymentsData: DailyPaymentData[];
};
This function returns the statistical data of workers.
Input parameters
interface IStatisticsFilter {
from?: Date;
to?: Date;
first?: number; // (Optional) Number of transactions per page. Default is 10.
skip?: number; // (Optional) Number of transactions to skip. Default is 0.
orderDirection?: OrderDirection; // (Optional) Order of the results. Default is ASC.
}
type DailyWorkerData = {
timestamp: Date;
activeWorkers: number;
};
type WorkerStatistics = {
dailyWorkersData: DailyWorkerData[];
};
Parameters
filter
Statistics params with duration data
Returns
Worker statistics data.
Code example
import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
const workerStatistics = await statisticsClient.getWorkerStatistics();
const workerStatisticsApril = await statisticsClient.getWorkerStatistics({
from: new Date('2021-04-01'),
to: new Date('2021-04-30'),
});