countChange: calculatePercentChange()

in src/commands/analytics/events/show.ts [145:220]


        countChange: calculatePercentChange(event.count, event.previousCount),
        users: event.deviceCount,
        userChange: calculatePercentChange(event.deviceCount, event.previousDeviceCount),
        perUser: event.countPerDevice,
        perSession: event.countPerSession,
      }));
    } catch (error) {
      debug(`Failed to get events statistics - ${inspect(error)}`);
      throw failure(ErrorCodes.Exception, "failed to get events statistics");
    }

    if (loadProperties) {
      const limit = pLimit(ShowCommand.numberOfParallelRequests);
      const propertiesPromises = eventsStatistics.map((eventStats) =>
        this.getProperties(client, app, eventStats.name, startDate, endDate, appVersions, limit)
      );

      (await Promise.all(propertiesPromises)).forEach((properties, index) => (eventsStatistics[index].properties = properties));
    }

    return eventsStatistics;
  }

  private async getProperties(
    client: AppCenterClient,
    app: DefaultApp,
    eventName: string,
    startDate: Date,
    endDate: Date,
    appVersions: string[] | undefined,
    limit: any
  ): Promise<IPropertyStatistics[]> {
    let propertiesNames: string[];
    try {
      const httpContent = await (limit(() =>
        clientRequest<models.EventProperties>((cb) =>
          client.analytics.eventPropertiesMethod(eventName, app.ownerName, app.appName, cb)
        )
      ) as Promise<ClientResponse<models.EventProperties>>);

      propertiesNames = httpContent.result.eventProperties;
    } catch (error) {
      debug(`Failed to get event properties of event ${eventName} - ${inspect(error)}`);
      throw failure(ErrorCodes.Exception, `failed to get event properties of event ${eventName}`);
    }

    const valuesStatsPromises = propertiesNames.map((propertyName) =>
      this.getPropertyValueStatistics(client, app, eventName, propertyName, startDate, endDate, appVersions, limit)
    );

    return (await Promise.all(valuesStatsPromises)).map((valueStats, index) => ({
      name: propertiesNames[index],
      valuesStatistics: valueStats,
    }));
  }

  private async getPropertyValueStatistics(
    client: AppCenterClient,
    app: DefaultApp,
    eventName: string,
    eventPropertyName: string,
    startDate: Date,
    endDate: Date,
    appVersions: string[] | undefined,
    limit: any
  ): Promise<IPropertyValueStatistics[]> {
    try {
      const httpContent = await (limit(() =>
        clientRequest<models.EventPropertyValues>((cb) =>
          client.analytics.eventPropertyCounts(
            eventName,
            eventPropertyName,
            startDate,
            app.ownerName,
            app.appName,
            {