customeranalytics 0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- customeranalytics/__init__.py +319 -0
- customeranalytics/configs.py +480 -0
- customeranalytics/data_storage_configurations/__init__.py +245 -0
- customeranalytics/data_storage_configurations/data_access.py +165 -0
- customeranalytics/data_storage_configurations/data_works_pipeline.py +207 -0
- customeranalytics/data_storage_configurations/es_create_index.py +544 -0
- customeranalytics/data_storage_configurations/logger.py +36 -0
- customeranalytics/data_storage_configurations/query_es.py +157 -0
- customeranalytics/data_storage_configurations/reports.py +684 -0
- customeranalytics/data_storage_configurations/schedule_data_integration.py +355 -0
- customeranalytics/docs/queries.yaml +245 -0
- customeranalytics/docs/web_configs.yaml +2 -0
- customeranalytics/exploratory_analysis/__init__.py +109 -0
- customeranalytics/exploratory_analysis/churn.py +232 -0
- customeranalytics/exploratory_analysis/cohorts.py +535 -0
- customeranalytics/exploratory_analysis/descriptive_statistics.py +470 -0
- customeranalytics/exploratory_analysis/funnels.py +407 -0
- customeranalytics/exploratory_analysis/product_analytics.py +340 -0
- customeranalytics/exploratory_analysis/promotion_analytics.py +299 -0
- customeranalytics/exploratory_analysis/rfm.py +202 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_avg_order_count_per_promo_per_cust.csv +99 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_chart_1_search.csv +2 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_chart_2_search.csv +46 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_chart_3_search.csv +2 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_chart_4_search.csv +2 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_churn.csv +2 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_churn_weekly.csv +10 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_client_feature_predicted.csv +1590 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_client_kpis.csv +7060 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_clvrfm_anomaly.csv +561 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_clvsegments_amount.csv +8 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_customer_journey.csv +18 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_daily_clv.csv +103 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_daily_cohort_downloads.csv +68 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_daily_cohort_from_1_to_2.csv +66 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_daily_cohort_from_2_to_3.csv +64 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_daily_cohort_from_3_to_4.csv +55 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_daily_dimension_values.csv +199 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_daily_funnel.csv +36 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_daily_funnel_downloads.csv +68 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_daily_inorganic_ratio.csv +6070 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_daily_orders.csv +57 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_daily_organic_orders.csv +64 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_daily_products_of_sales.csv +12574 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_daily_promotion_discount.csv +64 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_daily_promotion_revenue.csv +6070 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_dcohort_anomaly.csv +6 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_dcohort_anomaly_2.csv +118 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_deliver.csv +47 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_deliver_kpis.csv +2 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_deliver_weekday_hour.csv +25 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_dfunnel_anomaly.csv +118 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_dimension_kpis.csv +199 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_dorders_anomaly.csv +85 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_frequency_clusters.csv +6 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_frequency_recency.csv +3740 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_hourly_funnel.csv +25 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_hourly_funnel_downloads.csv +25 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_hourly_inorganic_ratio.csv +2353 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_hourly_orders.csv +25 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_hourly_organic_orders.csv +2353 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_inorganic_orders_per_promotion_per_day.csv +6070 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_kpis.csv +2 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_monetary_clusters.csv +6 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_monetary_frequency.csv +3740 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_monthly_funnel.csv +5 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_monthly_funnel_downloads.csv +5 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_monthly_orders.csv +4 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_most_combined_products.csv +11 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_most_ordered_categories.csv +11 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_most_ordered_products.csv +11 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_order_and_payment_amount_differences.csv +91 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_prepare.csv +101 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_prepare_weekday_hour.csv +25 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_product_kpis.csv +201 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_product_usage_before_after_amount_accept.csv +11 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_product_usage_before_after_amount_reject.csv +7 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_product_usage_before_after_orders_accept.csv +11 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_product_usage_before_after_orders_reject.csv +11 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_promotion_comparison.csv +91 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_promotion_kpis.csv +99 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_promotion_number_of_customer.csv +99 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_promotion_usage_before_after_amount_accept.csv +81 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_promotion_usage_before_after_amount_reject.csv +11 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_promotion_usage_before_after_orders_accept.csv +55 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_promotion_usage_before_after_orders_reject.csv +37 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_purchase_amount_distribution.csv +22 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_recency_clusters.csv +6 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_recency_monetary.csv +3740 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_rfm.csv +2001 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_ride.csv +101 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_ride_weekday_hour.csv +25 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_segmentation.csv +11 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_segments_change_daily_before_after_amount.csv +10 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_segments_change_daily_before_after_orders.csv +9 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_segments_change_monthly_before_after_amount.csv +10 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_segments_change_monthly_before_after_orders.csv +11 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_segments_change_weekly_before_after_amount.csv +10 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_segments_change_weekly_before_after_orders.csv +10 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_user_counts_per_order_seq.csv +47 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_weekly_average_order_per_user.csv +13 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_weekly_average_payment_amount.csv +13 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_weekly_average_session_per_user.csv +13 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_weekly_cohort_downloads.csv +13 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_weekly_cohort_from_1_to_2.csv +13 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_weekly_cohort_from_2_to_3.csv +13 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_weekly_cohort_from_3_to_4.csv +12 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_weekly_funnel.csv +25 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_weekly_funnel_downloads.csv +25 -0
- customeranalytics/exploratory_analysis/sample_data/sample_data_weekly_orders.csv +10 -0
- customeranalytics/ml_process/__init__.py +64 -0
- customeranalytics/ml_process/ab_test.py +615 -0
- customeranalytics/ml_process/anomaly_detection.py +456 -0
- customeranalytics/ml_process/clv_prediction.py +301 -0
- customeranalytics/ml_process/customer_segmentation.py +354 -0
- customeranalytics/ml_process/delivery_analytics.py +754 -0
- customeranalytics/utils.py +186 -0
- customeranalytics/web/app/__init__.py +37 -0
- customeranalytics/web/app/base/__init__.py +9 -0
- customeranalytics/web/app/base/forms.py +16 -0
- customeranalytics/web/app/base/models.py +43 -0
- customeranalytics/web/app/base/routes.py +126 -0
- customeranalytics/web/app/base/static/assets/css/app.css +20 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-Black.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-Black.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-BlackItalic.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-BlackItalic.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-Bold.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-Bold.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-BoldItalic.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-BoldItalic.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-ExtraBold.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-ExtraBold.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-ExtraBoldItalic.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-ExtraBoldItalic.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-ExtraLight-BETA.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-ExtraLight-BETA.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-ExtraLightItalic-BETA.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-ExtraLightItalic-BETA.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-Italic.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-Italic.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-Light-BETA.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-Light-BETA.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-LightItalic-BETA.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-LightItalic-BETA.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-Medium.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-Medium.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-MediumItalic.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-MediumItalic.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-Regular.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-Regular.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-SemiBold.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-SemiBold.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-SemiBoldItalic.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-SemiBoldItalic.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-Thin-BETA.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-Thin-BETA.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-ThinItalic-BETA.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-ThinItalic-BETA.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-italic.var.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter-upright.var.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/Inter.var.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/fa-brands-400.eot +0 -0
- customeranalytics/web/app/base/static/assets/fonts/fa-brands-400.svg +3570 -0
- customeranalytics/web/app/base/static/assets/fonts/fa-brands-400.ttf +0 -0
- customeranalytics/web/app/base/static/assets/fonts/fa-brands-400.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/fa-brands-400.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/fa-regular-400.eot +0 -0
- customeranalytics/web/app/base/static/assets/fonts/fa-regular-400.svg +801 -0
- customeranalytics/web/app/base/static/assets/fonts/fa-regular-400.ttf +0 -0
- customeranalytics/web/app/base/static/assets/fonts/fa-regular-400.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/fa-regular-400.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/fonts/fa-solid-900.eot +0 -0
- customeranalytics/web/app/base/static/assets/fonts/fa-solid-900.svg +5028 -0
- customeranalytics/web/app/base/static/assets/fonts/fa-solid-900.ttf +0 -0
- customeranalytics/web/app/base/static/assets/fonts/fa-solid-900.woff +0 -0
- customeranalytics/web/app/base/static/assets/fonts/fa-solid-900.woff2 +0 -0
- customeranalytics/web/app/base/static/assets/img/avatars/avatar-1.png +0 -0
- customeranalytics/web/app/base/static/assets/img/avatars/avatar-2.png +0 -0
- customeranalytics/web/app/base/static/assets/img/avatars/avatar-3.png +0 -0
- customeranalytics/web/app/base/static/assets/img/avatars/avatar-4.png +0 -0
- customeranalytics/web/app/base/static/assets/img/avatars/avatar-5.png +0 -0
- customeranalytics/web/app/base/static/assets/img/avatars/info.jpeg +0 -0
- customeranalytics/web/app/base/static/assets/img/icons/customanality.png +0 -0
- customeranalytics/web/app/base/static/assets/img/icons/icon-48x48.png +0 -0
- customeranalytics/web/app/base/static/assets/js/app.js +2 -0
- customeranalytics/web/app/base/static/assets/js/app.js.LICENSE +566 -0
- customeranalytics/web/app/base/static/assets/js/app.js.LICENSE.txt +556 -0
- customeranalytics/web/app/base/static/assets/js/modules/bootstrap.js +15 -0
- customeranalytics/web/app/base/static/assets/js/modules/chartjs.js +4 -0
- customeranalytics/web/app/base/static/assets/js/modules/feather.js +8 -0
- customeranalytics/web/app/base/static/assets/js/modules/flatpickr.js +4 -0
- customeranalytics/web/app/base/static/assets/js/modules/moment.js +4 -0
- customeranalytics/web/app/base/static/assets/js/modules/sidebar.js +23 -0
- customeranalytics/web/app/base/static/assets/js/modules/theme.js +16 -0
- customeranalytics/web/app/base/templates/accounts/login.html +81 -0
- customeranalytics/web/app/base/templates/accounts/register.html +80 -0
- customeranalytics/web/app/base/templates/includes/footer.html +28 -0
- customeranalytics/web/app/base/templates/includes/navigation.html +51 -0
- customeranalytics/web/app/base/templates/includes/scripts.html +3 -0
- customeranalytics/web/app/base/templates/includes/sidebar.html +146 -0
- customeranalytics/web/app/base/templates/layouts/base-fullscreen.html +36 -0
- customeranalytics/web/app/base/templates/layouts/base.html +84 -0
- customeranalytics/web/app/base/util.py +30 -0
- customeranalytics/web/app/home/__init__.py +9 -0
- customeranalytics/web/app/home/forms.py +1039 -0
- customeranalytics/web/app/home/models.py +438 -0
- customeranalytics/web/app/home/profiles.py +310 -0
- customeranalytics/web/app/home/routes.py +386 -0
- customeranalytics/web/app/home/search.py +288 -0
- customeranalytics/web/app/home/static/assets/img/avatars/avatar-1.png +0 -0
- customeranalytics/web/app/home/static/assets/img/avatars/avatar-2.png +0 -0
- customeranalytics/web/app/home/static/assets/img/avatars/avatar-3.png +0 -0
- customeranalytics/web/app/home/static/assets/img/avatars/avatar-4.png +0 -0
- customeranalytics/web/app/home/static/assets/img/avatars/avatar-5.png +0 -0
- customeranalytics/web/app/home/static/assets/img/icons/customanality.png +0 -0
- customeranalytics/web/app/home/static/assets/img/icons/icon-48x48.png +0 -0
- customeranalytics/web/app/home/templates/abtest-product.html +280 -0
- customeranalytics/web/app/home/templates/abtest-promotion.html +362 -0
- customeranalytics/web/app/home/templates/abtest-segments.html +298 -0
- customeranalytics/web/app/home/templates/add-data-delivery.html +184 -0
- customeranalytics/web/app/home/templates/add-data-product.html +177 -0
- customeranalytics/web/app/home/templates/add-data-purchase.html +392 -0
- customeranalytics/web/app/home/templates/anomaly.html +261 -0
- customeranalytics/web/app/home/templates/clv.html +211 -0
- customeranalytics/web/app/home/templates/cohorts.html +308 -0
- customeranalytics/web/app/home/templates/customer-segmentation.html +308 -0
- customeranalytics/web/app/home/templates/data-es.html +152 -0
- customeranalytics/web/app/home/templates/data-execute.html +397 -0
- customeranalytics/web/app/home/templates/delivery.html +404 -0
- customeranalytics/web/app/home/templates/funnel-customer.html +240 -0
- customeranalytics/web/app/home/templates/funnel-session.html +236 -0
- customeranalytics/web/app/home/templates/index.html +524 -0
- customeranalytics/web/app/home/templates/index2.html +515 -0
- customeranalytics/web/app/home/templates/page-403.html +46 -0
- customeranalytics/web/app/home/templates/page-404.html +45 -0
- customeranalytics/web/app/home/templates/page-500.html +45 -0
- customeranalytics/web/app/home/templates/pages-blank.html +33 -0
- customeranalytics/web/app/home/templates/pages-sign-in.html +67 -0
- customeranalytics/web/app/home/templates/pages-sign-up.html +61 -0
- customeranalytics/web/app/home/templates/product.html +203 -0
- customeranalytics/web/app/home/templates/profile.html +1009 -0
- customeranalytics/web/app/home/templates/rfm.html +254 -0
- customeranalytics/web/app/home/templates/search.html +167 -0
- customeranalytics/web/app/home/templates/settings.html +205 -0
- customeranalytics/web/app/home/templates/stats-desc.html +230 -0
- customeranalytics/web/app/home/templates/stats-purchase.html +221 -0
- customeranalytics/web/config.py +30 -0
- customeranalytics/web/db.sqlite3 +0 -0
- customeranalytics/web/run.py +30 -0
- customeranalytics-0.1.dist-info/METADATA +1102 -0
- customeranalytics-0.1.dist-info/RECORD +254 -0
- customeranalytics-0.1.dist-info/WHEEL +4 -0
- customeranalytics-0.1.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import sys, os, inspect
|
|
4
|
+
import datetime
|
|
5
|
+
|
|
6
|
+
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
|
7
|
+
parentdir = os.path.dirname(currentdir)
|
|
8
|
+
sys.path.insert(0, parentdir)
|
|
9
|
+
|
|
10
|
+
from customeranalytics.configs import default_es_port, default_es_host, default_query_date
|
|
11
|
+
from customeranalytics.utils import convert_to_date, current_date_to_day, convert_to_iso_format, get_index_group
|
|
12
|
+
from customeranalytics.utils import calculate_time_diff, dimension_decision
|
|
13
|
+
from customeranalytics.data_storage_configurations.query_es import QueryES
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class RFM:
|
|
17
|
+
"""
|
|
18
|
+
RFM is a generally useful technique in order to classify customers according to their engagement with the business
|
|
19
|
+
Recency : Last time attraction to the business.
|
|
20
|
+
Frequency(F) : how frequently users are engaged in the business.
|
|
21
|
+
Monetary(M) : Average amount(value) per customer.
|
|
22
|
+
!!! The users, who have only 1 order will not be included in calculations !!!
|
|
23
|
+
|
|
24
|
+
!!!!
|
|
25
|
+
******* ******** *****
|
|
26
|
+
Dimensional RFM:
|
|
27
|
+
RFM values must be created individually for dimensions. For instance, the Data set contains locations dimension.
|
|
28
|
+
In this case, each location of 'orders' and 'downloads' indexes must be created individually.
|
|
29
|
+
by using 'download_index' and 'order_index' dimensions can be assigned in order to create the RFM values.
|
|
30
|
+
|
|
31
|
+
download_index; downloads_location1 this will be the location dimension of
|
|
32
|
+
parameters in order to query downloads indexes; 'location1'.
|
|
33
|
+
download_index; orders_location1 this will be the location dimension of
|
|
34
|
+
parameters in order to query orders indexes; 'location1'.
|
|
35
|
+
******* ******** *****
|
|
36
|
+
!!!
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(self,
|
|
40
|
+
host=None,
|
|
41
|
+
port=None,
|
|
42
|
+
download_index='downloads',
|
|
43
|
+
order_index='orders'):
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
!!!!
|
|
47
|
+
******* ******** *****
|
|
48
|
+
Dimensional RFM:
|
|
49
|
+
RFM values must be created individually for dimensions. For instance, the Data set contains locations dimension.
|
|
50
|
+
In this case, each location of 'orders' and 'downloads' indexes must be created individually.
|
|
51
|
+
by using 'download_index' and 'order_index' dimensions can be assigned in order to create the RFM values.
|
|
52
|
+
|
|
53
|
+
download_index; downloads_location1 this will be the location dimension of
|
|
54
|
+
parameters in order to query downloads indexes; 'location1'.
|
|
55
|
+
download_index; orders_location1 this will be the location dimension of
|
|
56
|
+
parameters in order to query orders indexes; 'location1'.
|
|
57
|
+
******* ******** *****
|
|
58
|
+
!!!
|
|
59
|
+
|
|
60
|
+
:param download_index: elasticsearch port
|
|
61
|
+
:param order_index: elasticsearch port
|
|
62
|
+
:param host: elasticsearch host
|
|
63
|
+
:param port: elasticsearch port
|
|
64
|
+
"""
|
|
65
|
+
self.port = default_es_port if port is None else port
|
|
66
|
+
self.host = default_es_host if host is None else host
|
|
67
|
+
self.download_index = download_index
|
|
68
|
+
self.order_index = order_index
|
|
69
|
+
self.query_es = QueryES(port=port, host=host)
|
|
70
|
+
self.orders_field_data = ["id", "session_start_date", "client", "payment_amount"]
|
|
71
|
+
self.orders = pd.DataFrame()
|
|
72
|
+
self.client_frequency = pd.DataFrame()
|
|
73
|
+
self.client_recency = pd.DataFrame()
|
|
74
|
+
self.client_monetary = pd.DataFrame()
|
|
75
|
+
self.rfm = pd.DataFrame()
|
|
76
|
+
self.max_order_date = datetime.datetime.now()
|
|
77
|
+
|
|
78
|
+
def dimensional_query(self, boolean_query=None):
|
|
79
|
+
if dimension_decision(self.order_index):
|
|
80
|
+
if boolean_query is None:
|
|
81
|
+
boolean_query = [{"term": {"dimension": self.order_index}}]
|
|
82
|
+
else:
|
|
83
|
+
boolean_query += [{"term": {"dimension": self.order_index}}]
|
|
84
|
+
return boolean_query
|
|
85
|
+
|
|
86
|
+
def get_data(self, start_date=None):
|
|
87
|
+
"""
|
|
88
|
+
query orders index to collect the data with columns which are "session_start_date", "client", "payment_amount".
|
|
89
|
+
:param start_date:
|
|
90
|
+
:return:
|
|
91
|
+
"""
|
|
92
|
+
start_date = default_query_date if start_date is None else start_date
|
|
93
|
+
if len(self.orders) == 0:
|
|
94
|
+
self.query_es = QueryES(port=self.port, host=self.host)
|
|
95
|
+
self.query_es.query_builder(fields=self.orders_field_data,
|
|
96
|
+
boolean_queries=self.dimensional_query([{"term": {"actions.purchased": True}}]),
|
|
97
|
+
date_queries=[{"range": {"session_start_date": {"gte": start_date}}}])
|
|
98
|
+
self.orders = pd.DataFrame(self.query_es.get_data_from_es())
|
|
99
|
+
self.orders['date'] = self.orders['session_start_date'].apply(lambda x: convert_to_date(x))
|
|
100
|
+
|
|
101
|
+
def frequency(self):
|
|
102
|
+
"""
|
|
103
|
+
Frequency of users;
|
|
104
|
+
- assign dates of next orders per user as a column.
|
|
105
|
+
So, each row will have a current order date and the next order date per user.
|
|
106
|
+
- Calculate the hour difference from the current order date to the next order date.
|
|
107
|
+
- Calculate the average hourly difference per user.
|
|
108
|
+
User has only 1 order will not be included in calculations.
|
|
109
|
+
"""
|
|
110
|
+
self.orders['next_order_date'] = self.orders.sort_values(
|
|
111
|
+
by=['client', 'date'], ascending=True).groupby(['client'])['date'].shift(-1)
|
|
112
|
+
self.orders['diff_hours'] = self.orders.apply(
|
|
113
|
+
lambda row: calculate_time_diff(row['date'], row['next_order_date'], 'hour'), axis=1)
|
|
114
|
+
self.client_frequency = self.orders.query("next_order_date == next_order_date").groupby("client").agg(
|
|
115
|
+
{"diff_hours": "mean"}).reset_index().rename(columns={"diff_hours": "frequency"})
|
|
116
|
+
|
|
117
|
+
def recency(self):
|
|
118
|
+
"""
|
|
119
|
+
The recency of users;
|
|
120
|
+
- Calculate the last transaction (purchased) date of the whole population.
|
|
121
|
+
- Find each user of maximum transaction (purchased) date.
|
|
122
|
+
- Calculate the hour difference from the maximum transaction date to each user of the maximum transaction date.
|
|
123
|
+
"""
|
|
124
|
+
self.max_order_date = max(self.orders['date'])
|
|
125
|
+
self.client_recency = self.orders.groupby("client").agg({"date": "max"}).reset_index()
|
|
126
|
+
self.client_recency['recency'] = self.client_recency.apply(
|
|
127
|
+
lambda row: calculate_time_diff(row['date'], self.max_order_date, 'hour'), axis=1)
|
|
128
|
+
self.client_recency = self.client_recency.drop('date', axis=1)
|
|
129
|
+
|
|
130
|
+
def monetary(self):
|
|
131
|
+
"""
|
|
132
|
+
Monetary of users;
|
|
133
|
+
- Calculate the average purchased amount per user
|
|
134
|
+
"""
|
|
135
|
+
self.client_monetary = self.orders.groupby("client").agg({"payment_amount": "mean"}).reset_index().rename(
|
|
136
|
+
columns={"payment_amount": "monetary"})
|
|
137
|
+
|
|
138
|
+
def execute_rfm(self, start_date):
|
|
139
|
+
"""
|
|
140
|
+
1. Execute R, F, M calculations.
|
|
141
|
+
2. Merge data-frames (R, F, M data-frames).
|
|
142
|
+
3. Insert into the reports index with report_name 'rfm'.
|
|
143
|
+
"""
|
|
144
|
+
self.get_data(start_date=start_date)
|
|
145
|
+
self.frequency()
|
|
146
|
+
self.recency()
|
|
147
|
+
self.monetary()
|
|
148
|
+
self.rfm = pd.merge(self.client_frequency, self.client_recency, on='client', how='left')
|
|
149
|
+
self.rfm = pd.merge(self.rfm, self.client_monetary, on='client', how='left')
|
|
150
|
+
self.insert_into_reports_index(self.rfm, start_date, index=self.order_index)
|
|
151
|
+
|
|
152
|
+
def insert_into_reports_index(self, rfm, start_date, index='orders'):
|
|
153
|
+
"""
|
|
154
|
+
via query_es.py, each report can be inserted into the reports index with the given format.
|
|
155
|
+
{"id": unique report id,
|
|
156
|
+
"report_date": start_date or current date,
|
|
157
|
+
"report_name": "rfm",
|
|
158
|
+
"index": "main",
|
|
159
|
+
"report_types": {},
|
|
160
|
+
"data": rfm.fillna(0.0).to_dict("records") - dataframe to list of dictionary
|
|
161
|
+
}
|
|
162
|
+
!!! null values are assigned to 0.
|
|
163
|
+
|
|
164
|
+
:param rfm: data set, data frame
|
|
165
|
+
:param start_date: data start date
|
|
166
|
+
:param index: dimensionality of data index orders_location1 ; dimension = location1
|
|
167
|
+
"""
|
|
168
|
+
|
|
169
|
+
list_of_obj = [{"id": np.random.randint(200000000),
|
|
170
|
+
"report_date": current_date_to_day().isoformat() if start_date is None else start_date,
|
|
171
|
+
"report_name": "rfm",
|
|
172
|
+
"index": get_index_group(index),
|
|
173
|
+
"report_types": {},
|
|
174
|
+
"data": rfm.fillna(0).to_dict("records")}]
|
|
175
|
+
self.query_es.insert_data_to_index(list_of_obj, index='reports')
|
|
176
|
+
|
|
177
|
+
def fetch(self, start_date=None):
|
|
178
|
+
"""
|
|
179
|
+
Collect RFM values for each user. Collecting stored RFM is useful in order to initialize Customer Segmentation.
|
|
180
|
+
:return: data-frame
|
|
181
|
+
"""
|
|
182
|
+
|
|
183
|
+
boolean_queries, date_queries = [], []
|
|
184
|
+
boolean_queries = [{"term": {"report_name": "rfm"}}, {"term": {"index": get_index_group(self.order_index)}}]
|
|
185
|
+
|
|
186
|
+
if start_date is not None:
|
|
187
|
+
date_queries = [{"range": {"report_date": {"gte": convert_to_iso_format(start_date)}}}]
|
|
188
|
+
|
|
189
|
+
self.query_es = QueryES(port=self.port,
|
|
190
|
+
host=self.host)
|
|
191
|
+
self.query_es.query_builder(fields=None, _source=True,
|
|
192
|
+
date_queries=date_queries,
|
|
193
|
+
boolean_queries=boolean_queries)
|
|
194
|
+
_res = self.query_es.get_data_from_es(index="reports")
|
|
195
|
+
_data = pd.DataFrame()
|
|
196
|
+
if len(_res) != 0:
|
|
197
|
+
_data = pd.DataFrame(_res[0]['_source']['data'])
|
|
198
|
+
return _data
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
promotion_id,average_order_count
|
|
2
|
+
promo_0,1.0411764705882354
|
|
3
|
+
promo_1,1.0467479674796747
|
|
4
|
+
promo_10,1.056969696969697
|
|
5
|
+
promo_11,1.0535917901938427
|
|
6
|
+
promo_12,1.0515826494724503
|
|
7
|
+
promo_13,1.036
|
|
8
|
+
promo_14,1.0472589792060492
|
|
9
|
+
promo_15,1.0474452554744527
|
|
10
|
+
promo_16,1.0476190476190477
|
|
11
|
+
promo_17,1.0305343511450382
|
|
12
|
+
promo_18,1.0395569620253164
|
|
13
|
+
promo_19,1.0625
|
|
14
|
+
promo_2,1.0574018126888218
|
|
15
|
+
promo_20,1.0476923076923077
|
|
16
|
+
promo_21,1.0354838709677419
|
|
17
|
+
promo_22,1.0432632880098887
|
|
18
|
+
promo_23,1.0373831775700935
|
|
19
|
+
promo_24,1.041044776119403
|
|
20
|
+
promo_25,1.048854961832061
|
|
21
|
+
promo_26,1.0447284345047922
|
|
22
|
+
promo_27,1.0296846011131726
|
|
23
|
+
promo_28,1.0359550561797752
|
|
24
|
+
promo_29,1.035031847133758
|
|
25
|
+
promo_3,1.0568047337278106
|
|
26
|
+
promo_30,1.0486425339366516
|
|
27
|
+
promo_31,1.0683453237410072
|
|
28
|
+
promo_32,1.0454545454545454
|
|
29
|
+
promo_33,1.062043795620438
|
|
30
|
+
promo_34,1.0361842105263157
|
|
31
|
+
promo_35,1.0470809792843692
|
|
32
|
+
promo_36,1.0493601462522852
|
|
33
|
+
promo_37,1.0358490566037737
|
|
34
|
+
promo_38,1.0465380249716232
|
|
35
|
+
promo_39,1.0421179302045729
|
|
36
|
+
promo_4,1.0407407407407407
|
|
37
|
+
promo_40,1.0455373406193078
|
|
38
|
+
promo_41,1.0520094562647755
|
|
39
|
+
promo_42,1.0400801603206413
|
|
40
|
+
promo_43,1.0488721804511278
|
|
41
|
+
promo_44,1.0424028268551238
|
|
42
|
+
promo_45,1.0629139072847682
|
|
43
|
+
promo_46,1.0413016270337923
|
|
44
|
+
promo_47,1.038327526132404
|
|
45
|
+
promo_48,1.0483619344773791
|
|
46
|
+
promo_49,1.0502901353965184
|
|
47
|
+
promo_5,1.0495356037151702
|
|
48
|
+
promo_50,1.0671140939597314
|
|
49
|
+
promo_51,1.057057057057057
|
|
50
|
+
promo_52,1.0461847389558232
|
|
51
|
+
promo_53,1.048689138576779
|
|
52
|
+
promo_54,1.038181818181818
|
|
53
|
+
promo_55,1.0615735461801596
|
|
54
|
+
promo_56,1.044871794871795
|
|
55
|
+
promo_57,1.0557768924302788
|
|
56
|
+
promo_58,1.0372670807453417
|
|
57
|
+
promo_59,1.04
|
|
58
|
+
promo_6,1.0363288718929253
|
|
59
|
+
promo_60,1.0388349514563107
|
|
60
|
+
promo_61,1.0595238095238095
|
|
61
|
+
promo_63,1.034013605442177
|
|
62
|
+
promo_64,1.0441988950276244
|
|
63
|
+
promo_65,1.0666666666666667
|
|
64
|
+
promo_66,1.0303030303030303
|
|
65
|
+
promo_67,1.0490367775831875
|
|
66
|
+
promo_68,1.0618932038834952
|
|
67
|
+
promo_69,1.0452830188679245
|
|
68
|
+
promo_7,1.025735294117647
|
|
69
|
+
promo_70,1.0141843971631206
|
|
70
|
+
promo_71,1.0551558752997603
|
|
71
|
+
promo_72,1.0520833333333333
|
|
72
|
+
promo_73,1.0506634499396863
|
|
73
|
+
promo_74,1.0621019108280254
|
|
74
|
+
promo_75,1.0323741007194245
|
|
75
|
+
promo_76,1.0429378531073445
|
|
76
|
+
promo_77,1.03954802259887
|
|
77
|
+
promo_78,1.0688018979833926
|
|
78
|
+
promo_79,1.0381355932203389
|
|
79
|
+
promo_8,1.0390879478827362
|
|
80
|
+
promo_80,1.0526315789473684
|
|
81
|
+
promo_81,1.044280442804428
|
|
82
|
+
promo_82,1.041522491349481
|
|
83
|
+
promo_83,1.0603948896631823
|
|
84
|
+
promo_84,1.0264550264550265
|
|
85
|
+
promo_85,1.0414691943127963
|
|
86
|
+
promo_86,1.0341614906832297
|
|
87
|
+
promo_87,1.0456140350877192
|
|
88
|
+
promo_88,1.059610705596107
|
|
89
|
+
promo_9,1.06006006006006
|
|
90
|
+
promo_90,1.0430733410942956
|
|
91
|
+
promo_91,1.0526315789473684
|
|
92
|
+
promo_92,1.048602673147023
|
|
93
|
+
promo_93,1.046218487394958
|
|
94
|
+
promo_94,1.053763440860215
|
|
95
|
+
promo_95,1.0588235294117647
|
|
96
|
+
promo_96,1.0595238095238095
|
|
97
|
+
promo_97,1.055045871559633
|
|
98
|
+
promo_98,1.0562874251497005
|
|
99
|
+
promo_99,1.037037037037037
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
daily,products,payment_amount,order_count
|
|
2
|
+
2021-06-01,p_127,2443.0200000000004,80
|
|
3
|
+
2021-06-02,p_127,2977.304999999999,100
|
|
4
|
+
2021-06-03,p_127,2321.125,83
|
|
5
|
+
2021-06-04,p_127,2604.144999999999,91
|
|
6
|
+
2021-06-05,p_127,2648.175,88
|
|
7
|
+
2021-06-06,p_127,2623.79,89
|
|
8
|
+
2021-06-07,p_127,2113.52,73
|
|
9
|
+
2021-06-08,p_127,2761.62,87
|
|
10
|
+
2021-06-09,p_127,2822.115000000001,97
|
|
11
|
+
2021-06-10,p_127,2502.4900000000007,84
|
|
12
|
+
2021-06-11,p_127,2129.9949999999994,77
|
|
13
|
+
2021-06-12,p_127,2160.69,71
|
|
14
|
+
2021-06-13,p_127,2481.3749999999995,84
|
|
15
|
+
2021-06-14,p_127,2270.1150000000007,82
|
|
16
|
+
2021-06-15,p_127,2377.2850000000008,84
|
|
17
|
+
2021-06-16,p_127,2652.715,90
|
|
18
|
+
2021-06-17,p_127,2814.22,95
|
|
19
|
+
2021-06-18,p_127,3089.0200000000013,104
|
|
20
|
+
2021-06-19,p_127,2539.245000000001,84
|
|
21
|
+
2021-06-20,p_127,2605.994999999999,83
|
|
22
|
+
2021-06-21,p_127,2836.4400000000014,95
|
|
23
|
+
2021-06-22,p_127,2874.02,95
|
|
24
|
+
2021-06-23,p_127,2083.7850000000008,71
|
|
25
|
+
2021-06-24,p_127,2325.600000000001,79
|
|
26
|
+
2021-06-25,p_127,2097.5799999999995,74
|
|
27
|
+
2021-06-26,p_127,2083.7200000000007,71
|
|
28
|
+
2021-06-27,p_127,2935.070000000001,93
|
|
29
|
+
2021-06-28,p_127,2390.0,81
|
|
30
|
+
2021-06-29,p_127,2836.7900000000004,104
|
|
31
|
+
2021-06-30,p_127,2458.58,75
|
|
32
|
+
2021-07-01,p_127,2536.115,82
|
|
33
|
+
2021-07-02,p_127,2478.3099999999995,87
|
|
34
|
+
2021-07-03,p_127,2862.2250000000013,92
|
|
35
|
+
2021-07-04,p_127,2605.034999999999,86
|
|
36
|
+
2021-07-05,p_127,2308.155,82
|
|
37
|
+
2021-07-06,p_127,1989.8450000000007,66
|
|
38
|
+
2021-07-07,p_127,2556.01,85
|
|
39
|
+
2021-07-08,p_127,2267.88,70
|
|
40
|
+
2021-07-09,p_127,2184.734999999999,84
|
|
41
|
+
2021-07-10,p_127,2292.044999999999,77
|
|
42
|
+
2021-07-11,p_127,3018.315,97
|
|
43
|
+
2021-07-12,p_127,2721.760000000001,95
|
|
44
|
+
2021-07-13,p_127,2337.795,86
|
|
45
|
+
2021-07-14,p_127,2592.885000000001,96
|
|
46
|
+
2021-07-15,p_127,2790.530000000001,86
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
weekly,churn
|
|
2
|
+
2021-04-26T00:00:00,0.0
|
|
3
|
+
2021-05-03T00:00:00,0.22315777576853527
|
|
4
|
+
2021-05-10T00:00:00,0.5375455650060753
|
|
5
|
+
2021-05-17T00:00:00,0.6788188716595183
|
|
6
|
+
2021-05-24T00:00:00,0.7658633650232147
|
|
7
|
+
2021-05-31T00:00:00,0.8036602700781805
|
|
8
|
+
2021-06-07T00:00:00,0.8307974567424794
|
|
9
|
+
2021-06-14T00:00:00,0.8633264453405916
|
|
10
|
+
2021-06-21T00:00:00,0.925724927738967
|