First of all, you need to set up a MongoDB server on which customer TV viewing data will be stored. The minimum supported version of MongoDB is 3.4.
Next up, in the INSTALLED_APPS section of the Smarty configuration file, you need to add the viewstats module, as well as specify the data for connecting to the raised MongoDB server:
MONGODB_HOST — MongoDB server address, data type: str;
MONGODB_PORT — MongoDB server port, data type: int;
MONGODB_NAME — Database name, data type: str;
MONGODB_USERNAME — Username for authorization, data type: str;
MONGODB_PASSWORD — Password for authorization, data type: str;
MONGODB_AUTH_METHOD — Authorization method (depending on the MongoDB version), data type: str;
And install all the missing migrations with the command:
smarty_manage migrate —settings=settings.smarty
Configuration example:
INSTALLED_APPS += (
‘viewstats’,
// …
)
MONGODB_HOST = ‘127.0.0.1’
MONGODB_PORT = 27017
MONGODB_NAME = ‘Test’
MONGODB_USERNAME = ‘Test’
MONGODB_PASSWORD = ‘Password’
MONGODB_AUTH_METHOD = ‘SCRAM-SHA-1’
In order for customer devices to start sending statistics to the server, you need to enable its sending in the administration panel on the “STB and Application Settings” page (checkbox “Enable collection of statistical data to the Smarty server”)
Setting up the customer statistics collection module
To display information inside the “Customer Dynamics” tab in the INSTALLED_APPS section in the configuration file, in addition to the viewstats module, you need to add the INSTALLED_APPS module.
After adding the modules, you need to install all the missing migrations with the command:
smarty_manage migrate —settings=settings.smarty
And configure the correct operation of the cache_max_online and save_stats management commands.
The cache_max_online command is responsible for updating information about the maximum number of customers online for statistics. You can run it as often as you like, but at least once a day.
The save_stats command is responsible for collecting and storing statistics for each client for widgets on the “Customer Dynamics” screen. You can run it as often as you like, but at least once a day.
In order to work with large amounts of data, it is recommended to configure asynchronous execution of tasks via RQ. More information about asynchronous task execution can be found in the “Scaling and fault tolerance” — “Configuring asynchronous task execution via RQ (Redis Queue)” section.
Additional commands for collecting statistics
Command for collecting additional statistics for the report on the number of users
smarty_manage collect_daily_stats —settings=settings.
This command collects information that is used in payment reports, as well as in the “Payments today” and “Customers from whom payment was received” graphs (and some other statistical data) of the “Customer Dynamics” screen. The command must be executed every day at the beginning of the day (recording time is stored in UTC+0).
Data caching command for “Customer Dynamics” graphs
smarty_manage cache_customers_dynamic —settings=settings.
It is recommended to run the command once an hour. For small databases, graphics will work quickly and correctly even without this command. When run for the first time, the command may take a long time to execute (depending on the number of accounts, transactions and tariffs) due to the fact that data will be calculated for the entire last month. When rerun, only data for the last day or hour will be calculated (data is not cached again).
Additional command parameters:
—client_id – list of client identifiers, separated by commas, for which caching should be carried out. If nothing is passed as an argument, then data for all clients is cached.
Command for creating smart channel sorting
smarty_manage create_channel_sorting_by_popularity —settings=settings.
When this command is executed, channels are sorted based on TV viewing statistics, based on the specified parameters in the command.
Required parameters to run this command:
—client_id – list of client identifiers, separated by commas, for which caching should be carried out;
—days_number — the number of days during which TV viewing should be taken into account;
—criterion — characteristic by which popularity is assessed. Possible values:
watch_time — based on the total time spent watching the channel;
watch_time — based on the number of channel turn-ons;
average_watch_time — based on the average time spent watching a channel;
median_watch_time — based on the median channel watching time.Additional command parameters:
—devices — list of devices for which TV viewing statistics should be taken into account (system device names are passed, by default — all);
—tariffs — list of tariffs for which TV viewing statistics should be taken into account (tariff identifiers are passed, by default — all);
—accounts_active — take into account statistics only from active accounts.