Human Protocol SDK
v4.1.0
v4.1.0
  • Typescript SDK
    • Encryption
      • Encryption
      • EncryptionUtils
    • Escrow
      • EscrowClient
      • EscrowUtils
    • KVStore
      • KVStoreClient
      • KVStoreUtils
    • Staking
      • StakingClient
    • Operator
      • OperatorUtils
    • Storage
      • StorageClient
    • Statistics
      • StatisticsClient
    • Transaction
      • TransactionUtils
  • Python SDK
    • agreement
      • bootstrap
      • measures
      • utils
    • encryption
      • encryption
      • legacy_encryption
      • encryption_utils
    • escrow
      • escrow_client
      • escrow_utils
    • kvstore
      • kvstore_client
      • kvstore_utils
    • staking
      • staking_client
      • staking_utils
    • operator
      • operator_utils
    • statistics
      • statistics_client
    • storage
      • storage_client
      • storage_utils
    • transaction
      • transaction_utils
    • constants
    • filter
    • utils
  • CHANGELOG
Powered by GitBook
On this page
  • Class: StatisticsClient
  • Introduction
  • Installation
  • Code example
  • Constructors
  • Properties
  • Methods
  1. Typescript SDK
  2. Statistics

StatisticsClient

Last updated 3 days ago


/ / StatisticsClient

Class: StatisticsClient

Defined in:

Introduction

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

Properties

networkData


subgraphUrl

subgraphUrl: string

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.
}
type DailyEscrowsData = {
  timestamp: Date;
  escrowsTotal: number;
  escrowsPending: number;
  escrowsSolved: number;
  escrowsPaid: number;
  escrowsCancelled: number;
};

type EscrowStatistics = {
  totalEscrows: number;
  dailyEscrowsData: DailyEscrowsData[];
};

Parameters

filter

Statistics params with duration data

Returns

Escrow statistics data.

Code example

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'),
});

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.
}
type DailyHMTData = {
  timestamp: Date;
  totalTransactionAmount: bigint;
  totalTransactionCount: number;
  dailyUniqueSenders: number;
  dailyUniqueReceivers: number;
}

Parameters

filter

Statistics params with duration data

Returns

Daily HMToken statistics data.

Code example

import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';

const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);

const dailyHMTStats = await statisticsClient.getHMTStatistics();

console.log('Daily HMT statistics:', dailyHMTStats);

const hmtStatisticsRange = await statisticsClient.getHMTStatistics({
  from: new Date(2023, 4, 8),
  to: new Date(2023, 5, 8),
});

console.log('HMT statistics from 5/8 - 6/8:', hmtStatisticsRange);

getHMTHolders()

This function returns the holders of the HMToken with optional filters and ordering.

Input parameters

Parameters

params

HMT Holders params with filters and ordering

Returns

List of HMToken holders.

Code example

import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';

const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);

const hmtHolders = await statisticsClient.getHMTHolders({
  orderDirection: 'asc',
});

console.log('HMT holders:', hmtHolders.map((h) => ({
  ...h,
  balance: h.balance.toString(),
})));

getHMTStatistics()

This function returns the statistical data of HMToken.

type HMTStatistics = {
  totalTransferAmount: BigNumber;
  totalTransferCount: BigNumber;
  totalHolders: number;
};

Returns

HMToken statistics data.

Code example

import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';

const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);

const hmtStatistics = await statisticsClient.getHMTStatistics();

console.log('HMT statistics:', {
  ...hmtStatistics,
  totalTransferAmount: hmtStatistics.totalTransferAmount.toString(),
});

getPaymentStatistics()

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[];
};

Parameters

filter

Statistics params with duration data

Returns

Payment statistics data.

Code example

import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';

const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);

console.log(
  'Payment statistics:',
  (await statisticsClient.getPaymentStatistics()).dailyPaymentsData.map(
    (p) => ({
      ...p,
      totalAmountPaid: p.totalAmountPaid.toString(),
      averageAmountPerJob: p.averageAmountPerJob.toString(),
      averageAmountPerWorker: p.averageAmountPerWorker.toString(),
    })
  )
);

console.log(
  'Payment statistics from 5/8 - 6/8:',
  (
    await statisticsClient.getPaymentStatistics({
      from: new Date(2023, 4, 8),
      to: new Date(2023, 5, 8),
    })
  ).dailyPaymentsData.map((p) => ({
    ...p,
    totalAmountPaid: p.totalAmountPaid.toString(),
    averageAmountPerJob: p.averageAmountPerJob.toString(),
    averageAmountPerWorker: p.averageAmountPerWorker.toString(),
  }))
);

getWorkerStatistics()

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'),
});

new StatisticsClient(networkData):

Defined in:

networkData:

Defined in:

Defined in:

getEscrowStatistics(filter): Promise<>

Defined in:

= {}

Promise<>

getHMTDailyData(filter): Promise<[]>

Defined in:

= {}

Promise<[]>

getHMTHolders(params): Promise<[]>

Defined in:

= {}

Promise<[]>

getHMTStatistics(): Promise<>

Defined in:

Promise<>

getPaymentStatistics(filter): Promise<>

Defined in:

= {}

Promise<>

getWorkerStatistics(filter): Promise<>

Defined in:

= {}

Promise<>

@human-protocol/sdk
@human-protocol/sdk
statistics
statistics.ts:58
StatisticsClient
statistics.ts:67
NetworkData
StatisticsClient
NetworkData
statistics.ts:59
statistics.ts:60
EscrowStatistics
statistics.ts:120
IStatisticsFilter
EscrowStatistics
DailyHMTData
statistics.ts:478
IStatisticsFilter
DailyHMTData
HMTHolder
statistics.ts:407
IHMTHoldersParams
HMTHolder
HMTStatistics
statistics.ts:364
HMTStatistics
PaymentStatistics
statistics.ts:300
IStatisticsFilter
PaymentStatistics
WorkerStatistics
statistics.ts:204
IStatisticsFilter
WorkerStatistics