Word Association Tool - warwickfoster/qurantools GitHub Wiki

File: app/library/admin/statistics.php

Purpose

The Statistics abstract class provides a framework for generating statistical reports. It defines common properties and methods used by concrete statistics classes, such as CustomerStatistics and UserStatistics.

Key Features

  • Period Types The class supports two period types: six months and four weeks.
  • Statistic Types It supports only one statistic type for now: logins.
  • Output Formats Data can be output in JSON or CSV format.
  • Caching Periods and statistics are cached for efficiency.
  • DataTables Integration Methods are provided for generating HTML tables and JSON data suitable for DataTables.

Abstract Methods

  • get_statistics(): Returns an array of statistics.
  • get_statistics_header(): Returns an array of column headings.
  • get_statistics_data(): Returns an array of data rows.

Constructor

  • Takes period_type and statistic_type as parameters, defaulting to six months and logins, respectively.

Getters

  • get_period_type(): Returns the period type.
  • get_statistic_type(): Returns the statistic type.

Periods Calculation

  • The get_periods() method calculates the start and end dates for each period based on the specified period type.

Output

  • The output() method provides JSON output, while output_json() is a helper method for JSON encoding.

Usage

  • Concrete statistics classes extend this class and implement the abstract methods.
  • The output() method can be used to generate statistical data in the desired format.

Example

// Create a CustomerStatistics object
$customerStats = new CustomerStatistics();

// Output statistics in JSON format
$jsonStats = $customerStats->output();

// Display the JSON data
echo $jsonStats;

Conclusion

The Statistics abstract class provides a solid foundation for generating statistical reports. Its caching mechanism, DataTables integration, and abstract methods make it a versatile tool for data visualization and analysis.