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

StatisticsClient

Last updated 1 year ago

/ / / StatisticsClient

Class: StatisticsClient

.StatisticsClient

Introduction

This client enables to obtain statistical information from the subgraph.

Unlikely from the other SDK clients, StatisticsClient does not require signer or provider to be provided. We just need to create client object using relevant network data.

constructor(network: NetworkData)

A Signer or a Provider should be passed depending on the use case of this module:

  • Signer: when the user wants to use this model in order to send transactions caling the contract functions.

  • Provider: when the user wants to use this model in order to get information from the contracts or subgraph.

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_MUMBAI]);

Table of contents

Constructors

Properties

Methods

Constructors

constructor

StatisticsClient constructor

Parameters

Name
Type
Description

networkData

NetworkData

The network information required to connect to the Statistics contract

Returns

Defined in

Properties

networkData

• networkData: NetworkData

Defined in

Methods

getEscrowStatistics

▸ getEscrowStatistics(params?): Promise<EscrowStatistics>

This function returns the statistical data of escrows.

Input parameters

interface IStatisticsParams {
  from?: Date;
  to?: Date;
  limit?: number;
}
type DailyEscrowsData = {
  timestamp: Date;
  escrowsTotal: number;
  escrowsPending: number;
  escrowsSolved: number;
  escrowsPaid: number;
  escrowsCancelled: number;
};

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

Parameters

Name
Type
Description

params

IStatisticsParams

Statistics params with duration data

Returns

Promise<EscrowStatistics>

Escrow statistics data.

Code example

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

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

const escrowStatistics = await statisticsClient.getEscrowStatistics();
const escrowStatisticsApril = await statisticsClient.getEscrowStatistics({
   from: new Date('2021-04-01'),
   to: new Date('2021-04-30'),
});

Defined in


getHMTStatistics

▸ getHMTStatistics(params?): Promise<HMTStatistics>

This function returns the statistical data of HMToken.

Input parameters

interface IStatisticsParams {
  from?: Date;
  to?: Date;
  limit?: number;
}
type HMTHolder = {
  address: string;
  balance: BigNumber;
}

type DailyHMTData = {
  timestamp: Date;
  totalTransactionAmount: BigNumber;
  totalTransactionCount: number;
};

type HMTStatistics = {
  totalTransferAmount: BigNumber;
  totalTransferCount: BigNumber;
  totalHolders: number;
  holders: HMTHolder[];
  dailyHMTData: DailyHMTData[];
};

Parameters

Name
Type
Description

params

IStatisticsParams

Statistics params with duration data

Returns

Promise<HMTStatistics>

HMToken statistics data.

Code example

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

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

const hmtStatistics = await statisticsClient.getHMTStatistics();

console.log('HMT statistics:', {
  ...hmtStatistics,
  totalTransferAmount: hmtStatistics.totalTransferAmount.toString(),
  holders: hmtStatistics.holders.map((h) => ({
    ...h,
    balance: h.balance.toString(),
  })),
  dailyHMTData: hmtStatistics.dailyHMTData.map((d) => ({
    ...d,
    totalTransactionAmount: d.totalTransactionAmount.toString(),
  })),
});

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,
  totalTransferAmount: hmtStatisticsRange.totalTransferAmount.toString(),
  holders: hmtStatisticsRange.holders.map((h) => ({
    ...h,
    balance: h.balance.toString(),
  })),
  dailyHMTData: hmtStatisticsRange.dailyHMTData.map((d) => ({
    ...d,
    totalTransactionAmount: d.totalTransactionAmount.toString(),
  })),
});

Defined in


getPaymentStatistics

▸ getPaymentStatistics(params?): Promise<PaymentStatistics>

This function returns the statistical data of payments.

Input parameters

interface IStatisticsParams {
  from?: Date;
  to?: Date;
  limit?: number;
}
type DailyPaymentData = {
  timestamp: Date;
  totalAmountPaid: BigNumber;
  totalCount: number;
  averageAmountPerWorker: BigNumber;
};

type PaymentStatistics = {
  dailyPaymentsData: DailyPaymentData[];
};

Parameters

Name
Type
Description

params

IStatisticsParams

Statistics params with duration data

Returns

Promise<PaymentStatistics>

Payment statistics data.

Code example

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

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

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

Defined in


getWorkerStatistics

▸ getWorkerStatistics(params?): Promise<WorkerStatistics>

This function returns the statistical data of workers.

Input parameters

interface IStatisticsParams {
  from?: Date;
  to?: Date;
  limit?: number;
}
type DailyWorkerData = {
  timestamp: Date;
  activeWorkers: number;
};

type WorkerStatistics = {
  dailyWorkersData: DailyWorkerData[];
};

Parameters

Name
Type
Description

params

IStatisticsParams

Statistics params with duration data

Returns

Promise<WorkerStatistics>

Worker statistics data.

Code example

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

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

const workerStatistics = await statisticsClient.getWorkerStatistics();
const workerStatisticsApril = await statisticsClient.getWorkerStatistics({
   from: new Date('2021-04-01'),
   to: new Date('2021-04-30'),
});

Defined in

• new StatisticsClient(networkData):

@human-protocol/sdk
Modules
statistics
statistics
StatisticsClient
StatisticsClient
statistics.ts:68
statistics.ts:61
statistics.ts:121
statistics.ts:394
statistics.ts:285
statistics.ts:196
constructor
networkData
getEscrowStatistics
getHMTStatistics
getPaymentStatistics
getWorkerStatistics