Package: reports
Generated from api/packages/reports
Source: api/packages/reports · imported version 0.1.49. The sections after the README are extracted from the code on every docs build.
README
Section titled “README”Package for statistics & reports
Purpose
Section titled “Purpose”This package contains web API for retrieving statistical data about other LMS components (or event any arbitrary non-LMS Models for which Metrics and/or Reports are registered).
Installation
Section titled “Installation”composer require ulams/reportsphp artisan migratephp artisan db:seed --class="Ulams\Reports\Database\Seeders\ReportsPermissionSeeder"- optional:
php artisan vendor:publish --tag=reportsto publish config file
Dependencies
Section titled “Dependencies”Ulams\Coursesfor all Courses related stats and metricsUlams\Cartfor all metrics related to calculating amounts of money spent
Configuration
Section titled “Configuration”By editing published config reports.php you can:
- Change which metrics are available in API (by editing
metrics) - Change settings for each Metric (by editing
metric_configuration)limitdefines how many data points will be calculated by default (if you don’t pass limit as query parameter); for example:TutorsPopularityMetricwithlimitset to 10 will return popularity of 10 most popular Tutorshistoryis a boolean that defines if this metric should be automatically calculated and stored in databasecronis cron config which determines how often automatic calculation of metrics happens
- Change which stats are available in API (by editing
stats) and to which Model they are mapped
Stats are used for calculating some statistical data about given single Model (for example Course or Topic). No historical data is stored, only current data is available.
Available stats
Section titled “Available stats”Ulams\Reports\Stats\Course\AverageTime- average time spent on Course by users subscribed to itUlams\Reports\Stats\Course\AverageTimePerTopic- average time spent on Course by users subscribed to it, grouped by topicUlams\Reports\Stats\Course\MoneyEarned- sum of money earned by given CourseUlams\Reports\Stats\Course\PeopleBought- count of users that bought given CourseUlams\Reports\Stats\Course\PeopleFinished- count of how many users finished given CourseUlams\Reports\Stats\Course\PeopleStarted- count of how many users started learning given CourseUlams\Reports\Stats\Topic\AverageTime- average time spent on Topic by users subscribed to Course which this topic is part of
Creating your own stat
Section titled “Creating your own stat”To create your own Stat, you need to create class implementing Ulams\Reports\Stats\StatContract.
After creating a Stat you need to register it by adding it to stats array in config file.
Metrics
Section titled “Metrics”Metrics are used for reporting data accumulated over time. Historical data is stored for each day using scheduled job, and requesting a metric returns that historical data (that is, metric values stored at given date).
Available metrics
Section titled “Available metrics”Ulams\Reports\Metrics\CoursesMoneySpentMetric- calculates total money spent for every Course (historical data represents total money spent up to given date)Ulams\Reports\Metrics\CoursesPopularityMetric- calculates how many users were subscribed to every CourseUlams\Reports\Metrics\CoursesSecondsSpentMetric- calculates how much times users spent learning every CourseUlams\Reports\Metrics\TutorsPopularityMetric- calculates how many users were subscribed to courses created by given Tutor
Creating your own metric
Section titled “Creating your own metric”To create your own Metric, you need to create class implementing Ulams\Reports\Metrics\Contracts\MetricContract. You can extend Ulams\Reports\Metrics\AbstractMetric to use default implementations of most of the methods declared in this interface.
After creating a Metric you need to register it by adding it to metrics array in config file.
Endpoints
Section titled “Endpoints”All the endpoints are defined in .
Metrics endpoints
Section titled “Metrics endpoints”GET /api/admin/reports/metricsreturns list ofmetricsconfigured inreports.phpconfig fileGET /api/admin/reports/reportcalculates data for chosen metric; you can pass following query parameters to this endpoint:metric={classname}is required;classnameis one of themetricsreturned in/api/admin/reports/metricsendpoitlimit={int}is optional; determines the maximum number of data points that will be returneddate={date}is optional; will try to load historical report data for given date or return404if there is no data available; without this param, endpoint will return today’s data
Stats endpoints
Section titled “Stats endpoints”GET /api/admin/stats/availablereturns list ofstatsconfigured inreports.phpconfig file- `GET /api/admin/stats/
Run ./vendor/bin/phpunit --filter='Ulams\\Reports\\Tests' to run tests.
Events
Section titled “Events”No Events are defined in this package.
Listeners
Section titled “Listeners”No Listeners are defined in this package.
How to use this package on Frontend
Section titled “How to use this package on Frontend”Admin Panel
Section titled “Admin Panel”Reports dashboard
Section titled “Reports dashboard”
Course Stats
Section titled “Course Stats”
Permissions
Section titled “Permissions”Permissions are defined in Enum and seeded in Seeder.
Roadmap. Todo. Troubleshooting
Section titled “Roadmap. Todo. Troubleshooting”- ???
More documentation in the package
Section titled “More documentation in the package”- api/packages/reports/ADMIN.md
- api/packages/reports/docs/course.png
- api/packages/reports/docs/reports.png
API endpoints
Section titled “API endpoints”| Method | Path | Auth | Action |
|---|---|---|---|
GET |
/api/admin/reports/metrics |
yes | ReportsController@metrics |
GET |
/api/admin/reports/report |
yes | ReportsController@report |
GET |
/api/admin/reports/available-for-user |
yes | ReportsController@availableForUser |
GET |
/api/admin/stats/available |
yes | StatsController@available |
GET |
/api/admin/stats/course/{course_id} |
yes | StatsController@course |
GET |
/api/admin/stats/course/{course_id}/export |
yes | StatsController@courseExport |
POST |
/api/admin/stats/course/{course_id}/import |
yes | StatsController@courseImport |
GET |
/api/admin/stats/cart |
yes | StatsController@cart |
GET |
/api/admin/stats/date-range |
yes | StatsController@dateRange |
GET |
/api/admin/stats/topic/{topic_id} |
yes | StatsController@topic |
GET |
/api/admin/stats/topic/{topic_id}/export |
yes | StatsController@topicExport |
Permissions
Section titled “Permissions”| Permission | Seeded for roles | Constant |
|---|---|---|
report_list |
admin | ReportsPermissionsEnum::DISPLAY_REPORTS |
Settings
Section titled “Settings”Registered with AdministrableConfig::registerConfig (editable in the admin panel under Configuration → Settings).
None.
Events
Section titled “Events”None.
Artisan commands
Section titled “Artisan commands”None.
Scheduled jobs
Section titled “Scheduled jobs”| Kind | Target | Frequency |
|---|---|---|
| call | fn () => $this->calculateAndStore() |
cron($this->cronExpression()) |
Environment variables read
Section titled “Environment variables read”None.