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,109 @@
|
|
|
1
|
+
import sys, os, inspect
|
|
2
|
+
|
|
3
|
+
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
|
4
|
+
parentdir = os.path.dirname(currentdir)
|
|
5
|
+
sys.path.insert(0, parentdir)
|
|
6
|
+
|
|
7
|
+
from customeranalytics.exploratory_analysis.funnels import Funnels
|
|
8
|
+
from customeranalytics.exploratory_analysis.cohorts import Cohorts
|
|
9
|
+
from customeranalytics.exploratory_analysis.product_analytics import ProductAnalytics
|
|
10
|
+
from customeranalytics.exploratory_analysis.promotion_analytics import PromotionAnalytics
|
|
11
|
+
from customeranalytics.exploratory_analysis.rfm import RFM
|
|
12
|
+
from customeranalytics.exploratory_analysis.descriptive_statistics import Stats
|
|
13
|
+
from customeranalytics.exploratory_analysis.churn import Churn
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
ea_configs = {"date": None,
|
|
17
|
+
"funnel": {"actions": ["download", "signup"],
|
|
18
|
+
"purchase_actions": ["has_basket", "order_screen"],
|
|
19
|
+
"host": 'localhost',
|
|
20
|
+
"port": '9200',
|
|
21
|
+
'download_index': 'downloads',
|
|
22
|
+
'order_index': 'orders'},
|
|
23
|
+
"cohort": {"has_download": True, "host": 'localhost', "port": '9200',
|
|
24
|
+
'download_index': 'downloads', 'order_index': 'orders'},
|
|
25
|
+
"products": {"has_product_connection": True, "host": 'localhost', "port": '9200',
|
|
26
|
+
"download_index": 'downloads', "order_index": 'orders'},
|
|
27
|
+
"promotions": {"has_promotion_connection": True,
|
|
28
|
+
"host": 'localhost', "port": '9200',
|
|
29
|
+
"download_index": 'downloads', "order_index": 'orders'},
|
|
30
|
+
"rfm": {"host": 'localhost', "port": '9200', 'download_index': 'downloads', 'order_index': 'orders'},
|
|
31
|
+
"stats": {"host": 'localhost', "port": '9200', 'download_index': 'downloads', 'order_index': 'orders'},
|
|
32
|
+
"churn": {"host": 'localhost', "port": '9200', 'download_index': 'downloads', 'order_index': 'orders'}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
exploratory_analysis = {'funnel': Funnels,
|
|
37
|
+
'cohort': Cohorts,
|
|
38
|
+
'products': ProductAnalytics,
|
|
39
|
+
'rfm': RFM,
|
|
40
|
+
'stats': Stats,
|
|
41
|
+
'churn': Churn,
|
|
42
|
+
'promotions': PromotionAnalytics}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def create_exploratory_analyse(configs, ml):
|
|
46
|
+
ea = {a: exploratory_analysis[a](**configs[a]) for a in exploratory_analysis}
|
|
47
|
+
if ml == 'funnel':
|
|
48
|
+
print("*"*5, " Funnels ", "*"*5)
|
|
49
|
+
ea['funnel'].purchase_action_funnel(start_date=configs['date'])
|
|
50
|
+
ea['funnel'].download_signup_session_order_funnel(start_date=configs['date'])
|
|
51
|
+
ea['funnel'].overall_funnel(start_date=configs['date'])
|
|
52
|
+
del ea['funnel']
|
|
53
|
+
if ml == 'cohort':
|
|
54
|
+
print("*" * 5, " Cohorts ", "*" * 5)
|
|
55
|
+
ea['cohort'].execute_cohort(start_date=configs['date'])
|
|
56
|
+
del ea['cohort']
|
|
57
|
+
if ml == 'rfm':
|
|
58
|
+
print("*" * 5, " RFM ", "*" * 5)
|
|
59
|
+
ea['rfm'].execute_rfm(start_date=configs['date'])
|
|
60
|
+
del ea['rfm']
|
|
61
|
+
if ml == 'stats':
|
|
62
|
+
print("*" * 5, " Descriptive Statistics ", "*" * 5)
|
|
63
|
+
ea['stats'].execute_descriptive_stats(start_date=configs['date'])
|
|
64
|
+
del ea['stats']
|
|
65
|
+
if ml == 'products':
|
|
66
|
+
print("*" * 5, " Product Analytics ", "*" * 5)
|
|
67
|
+
ea['products'].execute_product_analysis(end_date=configs['date'])
|
|
68
|
+
del ea['products']
|
|
69
|
+
if ml == 'promotions':
|
|
70
|
+
print("*" * 5, " Promotion Analytics ", "*" * 5)
|
|
71
|
+
ea['promotions'].execute_promotion_analysis(end_date=configs['date'])
|
|
72
|
+
del ea['promotions']
|
|
73
|
+
if ml == 'churn':
|
|
74
|
+
print("*" * 5, " Churn ", "*" * 5)
|
|
75
|
+
ea['churn'].execute_churn(start_date=configs['date'])
|
|
76
|
+
del ea
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def create_exploratory_analysis(configs):
|
|
80
|
+
ea = {a: exploratory_analysis[a](**configs[a]) for a in exploratory_analysis}
|
|
81
|
+
print("*"*5, " Funnels ", "*"*5)
|
|
82
|
+
ea['funnel'].purchase_action_funnel(start_date=configs['date'])
|
|
83
|
+
ea['funnel'].download_signup_session_order_funnel(start_date=configs['date'])
|
|
84
|
+
ea['funnel'].overall_funnel(start_date=configs['date'])
|
|
85
|
+
del ea['funnel']
|
|
86
|
+
print("*" * 5, " Cohorts ", "*" * 5)
|
|
87
|
+
ea['cohort'].execute_cohort(start_date=configs['date'])
|
|
88
|
+
del ea['cohort']
|
|
89
|
+
print("*" * 5, " RFM ", "*" * 5)
|
|
90
|
+
ea['rfm'].execute_rfm(start_date=configs['date'])
|
|
91
|
+
del ea['rfm']
|
|
92
|
+
print("*" * 5, " Descriptive Statistics ", "*" * 5)
|
|
93
|
+
ea['stats'].execute_descriptive_stats(start_date=configs['date'])
|
|
94
|
+
del ea['stats']
|
|
95
|
+
print("*" * 5, " Product Analytics ", "*" * 5)
|
|
96
|
+
ea['products'].execute_product_analysis(end_date=configs['date'])
|
|
97
|
+
del ea['products']
|
|
98
|
+
print("*" * 5, " Promotions Analytics ", "*" * 5)
|
|
99
|
+
ea['promotions'].execute_promotion_analysis(end_date=configs['date'])
|
|
100
|
+
del ea['promotions']
|
|
101
|
+
print("*" * 5, " Churn ", "*" * 5)
|
|
102
|
+
ea['churn'].execute_churn(start_date=configs['date'])
|
|
103
|
+
del ea
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def query_exploratory_analysis(configs, queries, ea):
|
|
107
|
+
ea = exploratory_analysis[ea](**configs[ea])
|
|
108
|
+
return ea.fetch(**queries)
|
|
109
|
+
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import sys, os, inspect
|
|
4
|
+
import warnings
|
|
5
|
+
warnings.filterwarnings("ignore")
|
|
6
|
+
|
|
7
|
+
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
|
8
|
+
parentdir = os.path.dirname(currentdir)
|
|
9
|
+
sys.path.insert(0, parentdir)
|
|
10
|
+
|
|
11
|
+
from customeranalytics.configs import default_es_port, default_es_host, default_query_date, time_periods
|
|
12
|
+
from customeranalytics.utils import *
|
|
13
|
+
from customeranalytics.data_storage_configurations.query_es import QueryES
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Churn:
|
|
17
|
+
"""
|
|
18
|
+
Churn is the crucial KPI for the businesses. While they are tracking the engaged customers,
|
|
19
|
+
they also check the user who have been lost and never use the business anymore.
|
|
20
|
+
|
|
21
|
+
Here are the basic aggregated values;
|
|
22
|
+
- Overall Churn rate
|
|
23
|
+
- Weekly Churn Rate
|
|
24
|
+
- Monthly Churn Rate
|
|
25
|
+
|
|
26
|
+
!!!!
|
|
27
|
+
******* ******** *****
|
|
28
|
+
Dimensional Churn:
|
|
29
|
+
Churn Rate must be created individually for dimensions.
|
|
30
|
+
For instance, the Data set contains locations dimension.
|
|
31
|
+
In this case, each location of 'orders' and 'downloads' indexes must be created individually.
|
|
32
|
+
by using 'download_index' and 'order_index' dimension can be assigned in order to create the Churn Rate.
|
|
33
|
+
|
|
34
|
+
download_index; downloads_location1 this will be the location dimension of
|
|
35
|
+
parameters in order to query downloads indexes; 'location1'.
|
|
36
|
+
download_index; orders_location1 this will be the location dimension of
|
|
37
|
+
parameters in order to query orders indexes; 'location1'.
|
|
38
|
+
******* ******** *****
|
|
39
|
+
!!!
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def __init__(self,
|
|
43
|
+
host=None,
|
|
44
|
+
port=None,
|
|
45
|
+
download_index='downloads',
|
|
46
|
+
order_index='orders'):
|
|
47
|
+
"""
|
|
48
|
+
******* ******** *****
|
|
49
|
+
Dimensional Stats:
|
|
50
|
+
Descriptive Statistics must be created individually for dimensions.
|
|
51
|
+
For instance, the Data set contains locations dimension.
|
|
52
|
+
In this case, each location of 'orders' and 'downloads' indexes must be created individually.
|
|
53
|
+
by using 'download_index' and 'order_index' dimension can be assigned in order to create the Churn Rate.
|
|
54
|
+
|
|
55
|
+
download_index; downloads_location1 this will be the location dimension of
|
|
56
|
+
parameters in order to query downloads indexes; 'location1'.
|
|
57
|
+
download_index; orders_location1 this will be the location dimension of
|
|
58
|
+
parameters in order to query orders indexes; 'location1'.
|
|
59
|
+
******* ******** *****
|
|
60
|
+
!!!
|
|
61
|
+
|
|
62
|
+
:param host: elasticsearch host
|
|
63
|
+
:param port: elasticsearch port
|
|
64
|
+
:param download_index: elasticsearch port
|
|
65
|
+
:param order_index: elasticsearch port
|
|
66
|
+
"""
|
|
67
|
+
self.port = default_es_port if port is None else port
|
|
68
|
+
self.host = default_es_host if host is None else host
|
|
69
|
+
self.download_index = download_index
|
|
70
|
+
self.order_index = order_index
|
|
71
|
+
self.query_es = QueryES(port=port, host=host)
|
|
72
|
+
self.orders_field_data = ["id", "session_start_date", "client", "actions.purchased"]
|
|
73
|
+
self.last_week = None
|
|
74
|
+
self.time_periods = ["weekly", 'monthly']
|
|
75
|
+
self.orders = pd.DataFrame()
|
|
76
|
+
self.results = {}
|
|
77
|
+
self.average_frequency_hr = 7 * 24
|
|
78
|
+
|
|
79
|
+
def get_time_period(self, transactions, date_column):
|
|
80
|
+
"""
|
|
81
|
+
converting date column of values into the time_periods (hourly weekly, monthly,..)
|
|
82
|
+
:param transactions: total data (orders/downloads data with actions)
|
|
83
|
+
:return: data set with time periods
|
|
84
|
+
"""
|
|
85
|
+
for p in list(zip(self.time_periods,
|
|
86
|
+
[find_week_of_monday, convert_dt_to_month_str])):
|
|
87
|
+
transactions[p[0]] = transactions[date_column].apply(lambda x: p[1](x))
|
|
88
|
+
return transactions
|
|
89
|
+
|
|
90
|
+
def dimensional_query(self, boolean_query=None):
|
|
91
|
+
if dimension_decision(self.order_index):
|
|
92
|
+
if boolean_query is None:
|
|
93
|
+
boolean_query = [{"term": {"dimension": self.order_index}}]
|
|
94
|
+
else:
|
|
95
|
+
boolean_query += [{"term": {"dimension": self.order_index}}]
|
|
96
|
+
return boolean_query
|
|
97
|
+
|
|
98
|
+
def get_data(self, start_date=None):
|
|
99
|
+
"""
|
|
100
|
+
query orders index to collect the data with columns that are
|
|
101
|
+
"id", "session_start_date", "client", "payment_amount", "discount_amount", "actions.purchased".
|
|
102
|
+
:param start_date: starting date of query
|
|
103
|
+
:return: data-frame individual order transactions.
|
|
104
|
+
"""
|
|
105
|
+
start_date = default_query_date if start_date is None else start_date
|
|
106
|
+
if len(self.orders) == 0:
|
|
107
|
+
self.query_es = QueryES(port=self.port, host=self.host)
|
|
108
|
+
self.query_es.query_builder(fields=self.orders_field_data,
|
|
109
|
+
date_queries=[{"range": {"session_start_date": {"gte": start_date}}}],
|
|
110
|
+
boolean_queries=self.dimensional_query())
|
|
111
|
+
self.orders = pd.DataFrame(self.query_es.get_data_from_es())
|
|
112
|
+
self.orders['date'] = self.orders['session_start_date'].apply(lambda x: convert_to_date(x))
|
|
113
|
+
|
|
114
|
+
def frequency(self):
|
|
115
|
+
"""
|
|
116
|
+
Frequency of users;
|
|
117
|
+
- assign dates of next orders per user as a column.
|
|
118
|
+
So, each row will have a current order date and the next order date per user.
|
|
119
|
+
- Calculate the hour difference from the current order date to the next order date.
|
|
120
|
+
- Calculate the average hourly difference per user.
|
|
121
|
+
User has only 1 order will not be included in calculations.
|
|
122
|
+
"""
|
|
123
|
+
self.orders['next_order_date'] = self.orders.sort_values(
|
|
124
|
+
by=['client', 'date'], ascending=True).groupby(['client'])['date'].shift(-1)
|
|
125
|
+
self.orders['diff_hours'] = self.orders.apply(
|
|
126
|
+
lambda row: calculate_time_diff(row['date'], row['next_order_date'], 'hour'), axis=1)
|
|
127
|
+
_fequency = self.orders.query("next_order_date == next_order_date").groupby("client").agg(
|
|
128
|
+
{"diff_hours": "mean"}).reset_index().rename(columns={"diff_hours": "frequency"})
|
|
129
|
+
self.average_frequency_hr = int(np.mean(_fequency['frequency']))
|
|
130
|
+
|
|
131
|
+
def churn_rate(self):
|
|
132
|
+
"""
|
|
133
|
+
(Unique user count who have at least 1 order -
|
|
134
|
+
Unique Order who has order at least 1 order during days between last average_frequency_hr and current day)
|
|
135
|
+
/
|
|
136
|
+
(Count of Unique Client who has at least 1 order)
|
|
137
|
+
"""
|
|
138
|
+
_customer_loss_date = max(self.orders['date']) - datetime.timedelta(hours=self.average_frequency_hr)
|
|
139
|
+
_purc_orders = self.orders[self.orders['actions.purchased'] == True]
|
|
140
|
+
engaged_users = len(list(_purc_orders[_purc_orders['date'] >= _customer_loss_date]['client'].unique()))
|
|
141
|
+
all_users = len(list(_purc_orders['client'].unique()))
|
|
142
|
+
_churn = (all_users - engaged_users) / all_users
|
|
143
|
+
return pd.DataFrame([{"churn": _churn if _churn > 0 else 0}])
|
|
144
|
+
|
|
145
|
+
def churn_rate_per_time_period(self, time_period):
|
|
146
|
+
"""
|
|
147
|
+
Churn rate per week and per month
|
|
148
|
+
each week/month of unique ordered client counts are calculated and
|
|
149
|
+
divided by cumulative sum of weekly/monthly unique client count.
|
|
150
|
+
"""
|
|
151
|
+
|
|
152
|
+
_purc_clients = self.orders[self.orders['actions.purchased'] == True].groupby(time_period).agg(
|
|
153
|
+
{"client": lambda x: len(np.unique(x))}).reset_index().rename(
|
|
154
|
+
columns={"client": "client_count"}).sort_values(time_period, ascending=True)
|
|
155
|
+
_purc_clients['weekly_whole_orders'] = list(_purc_clients['client_count'].cumsum())
|
|
156
|
+
_purc_clients['churn'] = (_purc_clients['weekly_whole_orders'] - _purc_clients['client_count']) / _purc_clients[
|
|
157
|
+
'weekly_whole_orders']
|
|
158
|
+
print(_purc_clients)
|
|
159
|
+
_purc_clients['churn'] = _purc_clients['churn'].apply(lambda x: x if x > 0 else 0)
|
|
160
|
+
return _purc_clients[[time_period, 'churn']]
|
|
161
|
+
|
|
162
|
+
def execute_churn(self, start_date):
|
|
163
|
+
"""
|
|
164
|
+
1. Collect users with action.purchased column
|
|
165
|
+
2. assign weekly/monthly column
|
|
166
|
+
3. calculate overall churn rate
|
|
167
|
+
4. calculate weekly/monthly churn rate
|
|
168
|
+
"""
|
|
169
|
+
self.get_data()
|
|
170
|
+
self.orders = self.get_time_period(self.orders, 'date')
|
|
171
|
+
self.frequency()
|
|
172
|
+
self.insert_into_reports_index(self.churn_rate(), start_date, 'overall')
|
|
173
|
+
for tp in self.time_periods:
|
|
174
|
+
self.insert_into_reports_index(self.churn_rate_per_time_period(tp), start_date, tp)
|
|
175
|
+
|
|
176
|
+
def insert_into_reports_index(self, churn, start_date, churn_type, index='orders'):
|
|
177
|
+
"""
|
|
178
|
+
via query_es.py, each report can be inserted into the reports index with the given format.
|
|
179
|
+
{"id": unique report id,
|
|
180
|
+
"report_date": start_date or current date,
|
|
181
|
+
"report_name": "churn",
|
|
182
|
+
"index": "main",
|
|
183
|
+
"report_types": {
|
|
184
|
+
"type": "overall", "weekly", "monthly"
|
|
185
|
+
},
|
|
186
|
+
"data": churn (list of dictionaries)
|
|
187
|
+
}
|
|
188
|
+
:param churn: overall, weekly, monthly
|
|
189
|
+
:param start_date: datetime
|
|
190
|
+
:param churn_type: {"type": "overall" or "weekly_orders" or "daily_orders" or "monthly_orders"}
|
|
191
|
+
:param index: dimensionality of data index orders_location1 ; dimension = location1
|
|
192
|
+
"""
|
|
193
|
+
list_of_obj = [{"id": np.random.randint(200000000),
|
|
194
|
+
"report_date": current_date_to_day().isoformat() if start_date is None else start_date,
|
|
195
|
+
"report_name": "churn",
|
|
196
|
+
"index": get_index_group(index),
|
|
197
|
+
"report_types": {"type": churn_type},
|
|
198
|
+
"data": churn.to_dict('records')}]
|
|
199
|
+
self.query_es.insert_data_to_index(list_of_obj, index='reports')
|
|
200
|
+
|
|
201
|
+
def fetch(self, churn_type, start_date=None):
|
|
202
|
+
"""
|
|
203
|
+
query format;
|
|
204
|
+
queries = {"churn_type": "overall"}
|
|
205
|
+
queries = {"churn_type": "weekly"}
|
|
206
|
+
queries = {"churn_type": "monthly"}
|
|
207
|
+
weekly churn
|
|
208
|
+
0 2020-12-07T00:00:00 0.2
|
|
209
|
+
1 2020-12-14T00:00:00 0.4
|
|
210
|
+
2 2020-12-21T00:00:00 0.3
|
|
211
|
+
:param churn_type: overall, weekly, monthly
|
|
212
|
+
:param start_date:
|
|
213
|
+
:return: data-frame
|
|
214
|
+
"""
|
|
215
|
+
|
|
216
|
+
boolean_queries = [{"term": {"report_name": "stats"}},
|
|
217
|
+
{"term": {"report_types.type": churn_type}},
|
|
218
|
+
{"term": {"index": get_index_group(self.order_index)}}]
|
|
219
|
+
date_queries = []
|
|
220
|
+
if start_date is not None:
|
|
221
|
+
date_queries = [{"range": {"report_date": {"gte": convert_to_iso_format(start_date)}}}]
|
|
222
|
+
|
|
223
|
+
self.query_es = QueryES(port=self.port,
|
|
224
|
+
host=self.host)
|
|
225
|
+
self.query_es.query_builder(fields=None, _source=True,
|
|
226
|
+
boolean_queries=boolean_queries,
|
|
227
|
+
date_queries=date_queries)
|
|
228
|
+
_res = self.query_es.get_data_from_es(index="reports")
|
|
229
|
+
_data = pd.DataFrame()
|
|
230
|
+
if len(_res) != 0:
|
|
231
|
+
_data = pd.DataFrame(_res[0]['_source']['data'])
|
|
232
|
+
return _data
|