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,319 @@
|
|
|
1
|
+
import sys, os, inspect
|
|
2
|
+
from os.path import join
|
|
3
|
+
import subprocess
|
|
4
|
+
import pandas as pd
|
|
5
|
+
import urllib
|
|
6
|
+
import time
|
|
7
|
+
from sqlalchemy import create_engine, MetaData
|
|
8
|
+
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
|
9
|
+
parentdir = os.path.dirname(currentdir)
|
|
10
|
+
sys.path.insert(0, parentdir)
|
|
11
|
+
|
|
12
|
+
try: from utils import abspath_for_sample_data
|
|
13
|
+
except: from .utils import abspath_for_sample_data
|
|
14
|
+
|
|
15
|
+
try: from web.app.home.models import RouterRequest
|
|
16
|
+
except: from customeranalytics.web.app.home.models import RouterRequest
|
|
17
|
+
|
|
18
|
+
try: from web.app.home.forms import RealData, SampleData
|
|
19
|
+
except: from customeranalytics.web.app.home.forms import RealData, SampleData
|
|
20
|
+
|
|
21
|
+
from customeranalytics.web.config import config_dict
|
|
22
|
+
|
|
23
|
+
try: from web.config import web_configs
|
|
24
|
+
except: from customeranalytics.web.config import web_configs
|
|
25
|
+
|
|
26
|
+
try: from data_storage_configurations import get_data_connection_arguments, \
|
|
27
|
+
decision_for_product_conn, decision_for_promotion_conn, get_ea_and_ml_config, check_elasticsearch
|
|
28
|
+
except: from customeranalytics.data_storage_configurations import get_data_connection_arguments, \
|
|
29
|
+
decision_for_product_conn, decision_for_promotion_conn, get_ea_and_ml_config, check_elasticsearch
|
|
30
|
+
|
|
31
|
+
try: from .exploratory_analysis import ea_configs
|
|
32
|
+
except: from customeranalytics.exploratory_analysis import ea_configs
|
|
33
|
+
|
|
34
|
+
try: from .exploratory_analysis import ml_configs
|
|
35
|
+
except: from customeranalytics.ml_process import ml_configs
|
|
36
|
+
|
|
37
|
+
try: from .configs import none_types, session_columns, customer_columns
|
|
38
|
+
except: from customeranalytics.configs import none_types, session_columns, customer_columns
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
engine = create_engine('sqlite://///' + join(abspath_for_sample_data(), "web", 'db.sqlite3'), connect_args={'check_same_thread': False})
|
|
42
|
+
metadata = MetaData()
|
|
43
|
+
con = engine.connect()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
r = RouterRequest()
|
|
47
|
+
reports = RealData()
|
|
48
|
+
sample_reports = SampleData()
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def url_string(value, res=False):
|
|
52
|
+
if value is not None:
|
|
53
|
+
if res:
|
|
54
|
+
return value.replace("\r", " ").replace("\n", " ").replace(" ", "+")
|
|
55
|
+
else:
|
|
56
|
+
return value.replace("+", " ")
|
|
57
|
+
else:
|
|
58
|
+
return None
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def request_url(url):
|
|
62
|
+
try:
|
|
63
|
+
res = urllib.request.urlopen(url)
|
|
64
|
+
except Exception as e:
|
|
65
|
+
print(e)
|
|
66
|
+
time.sleep(2)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def create_user_interface():
|
|
70
|
+
"""
|
|
71
|
+
This process triggers web interface
|
|
72
|
+
port: port is stored at web_interface.yaml
|
|
73
|
+
host: host is stored at web_interface.yaml
|
|
74
|
+
"""
|
|
75
|
+
path = join(abspath_for_sample_data(), "web", "run.py")
|
|
76
|
+
cmd = "python " + path
|
|
77
|
+
print('http://' + str(web_configs['host']) + ':' + str(web_configs['port']))
|
|
78
|
+
_p = subprocess.Popen(cmd, shell=True)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def kill_user_interface():
|
|
82
|
+
"""
|
|
83
|
+
This process kills the thread for web interface
|
|
84
|
+
"""
|
|
85
|
+
print('http://' + str(web_configs['host']) + ':' + str(web_configs['port']) + '/shutdown')
|
|
86
|
+
request_url(url='http://' + str(web_configs['host']) + ':' + str(web_configs['port']) + '/shutdown')
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def collect_data_source():
|
|
90
|
+
"""
|
|
91
|
+
_ds = {'data_source': connection[index + '_data_source_type'],
|
|
92
|
+
'date': date,
|
|
93
|
+
'data_query_path': sqlite_string_converter(connection[index + '_data_query_path'], back_to_normal=True),
|
|
94
|
+
'test': test,
|
|
95
|
+
'config': {'host': connection[index + '_host'],
|
|
96
|
+
'port': connection[index + '_port'],
|
|
97
|
+
'password': connection[index + '_password'],
|
|
98
|
+
'user': connection[index + '_user'], 'db': connection[index + '_db']}}
|
|
99
|
+
"""
|
|
100
|
+
columns, data_configs = get_data_connection_arguments()[1:]
|
|
101
|
+
has_product_connection = decision_for_product_conn(data_configs)
|
|
102
|
+
has_promotion_connection = decision_for_promotion_conn(columns)
|
|
103
|
+
_ea_configs, _ml_configs, _actions = get_ea_and_ml_config(ea_configs, ml_configs,
|
|
104
|
+
has_product_connection, has_promotion_connection)
|
|
105
|
+
|
|
106
|
+
for ds in data_configs:
|
|
107
|
+
for c in data_configs[ds]['config']:
|
|
108
|
+
if c == 'password':
|
|
109
|
+
data_configs[ds]['config']['password'] = "*****"
|
|
110
|
+
|
|
111
|
+
return data_configs
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def create_ElasticSearch_connection(port, host, temporary_path):
|
|
115
|
+
"""
|
|
116
|
+
ElasticSearch configurations with host and port.
|
|
117
|
+
Another requirement which is temporary path is for importing files such as CLV Prediction model files and
|
|
118
|
+
.csv format files with build_in_reports folder.
|
|
119
|
+
|
|
120
|
+
:param port: elasticsearch port
|
|
121
|
+
:param host: elasticsearch host
|
|
122
|
+
:param temporary_path: folder path for importing data into the given directory in .csv format.
|
|
123
|
+
"""
|
|
124
|
+
request = {'tag': 'es_con',
|
|
125
|
+
'url': "http://{host}:{port}/".format(**{'host': str(host), 'port': str(port)}),
|
|
126
|
+
"port": str(port), 'host': str(host), 'directory': temporary_path, "connect": 'True'}
|
|
127
|
+
r.manage_data_integration(r.check_for_request(request))
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def create_connections(customers_connection,
|
|
131
|
+
sessions_connection,
|
|
132
|
+
products_connection=None,
|
|
133
|
+
deliveries_connection=None,
|
|
134
|
+
sessions_fields={},
|
|
135
|
+
customer_fields={},
|
|
136
|
+
product_fields={},
|
|
137
|
+
delivery_fields={},
|
|
138
|
+
actions_sessions='None',
|
|
139
|
+
actions_customers='None',
|
|
140
|
+
promotion_id='None',
|
|
141
|
+
dimension_sessions=None):
|
|
142
|
+
"""
|
|
143
|
+
This process is for the connecting data sources which are SESSIONS, CUSTOMERS PRODUCTS.
|
|
144
|
+
Each data source has on its own unique form to connect.
|
|
145
|
+
This process checks the connection failure, before store the connection information to the sqlite DB.
|
|
146
|
+
There are 3 main updating processes for the store process;
|
|
147
|
+
1. db connection; These process included data_source_name, data_source_type, DB_name, DB_user, DB_name,
|
|
148
|
+
data_source_path/query, etc.
|
|
149
|
+
2. actions; This is for actions both for Sessions and Customer Data Source.
|
|
150
|
+
Example of actions; "has_basket, order_screen". Actions are split with ',' and string format.
|
|
151
|
+
3. column names; data source columns must be matched with ElasticSearch fields
|
|
152
|
+
for each data source (Session, Customers, products) individually. column maes must be string format.
|
|
153
|
+
Example of columns;
|
|
154
|
+
*** SESSION COLUMNS ***
|
|
155
|
+
sessions_fields = {'order_id': unique ID for each session (purchased/non-purchased sessions),
|
|
156
|
+
'client': ID for client this column can connect with client ID (client_2) ar customer_fields,
|
|
157
|
+
'session_start_date': eligible date format (yyyy-mm-dd hh:mm),
|
|
158
|
+
'date': eligible date format (yyyy-mm-dd hh:mm), ,
|
|
159
|
+
'payment_amount': value of purchase (float/int). If it not purchased, please assign None, Null '-',
|
|
160
|
+
'discount_amount': discount of purchase (float/int). If it not purchased, please assign None, Null '-',
|
|
161
|
+
'has_purchased':
|
|
162
|
+
True/False. If it is True, session ends with purchased.
|
|
163
|
+
If it is False, session ends with non-purchased.
|
|
164
|
+
** optional columns; date, discount_amount
|
|
165
|
+
|
|
166
|
+
*** CUSTOMERS COLUMNS ***
|
|
167
|
+
customer_fields = {'client_2': unique ID for client this column can connect with client ID (client) ar session_fields,
|
|
168
|
+
'download_date': eligible date format (yyyy-mm-dd hh:mm).
|
|
169
|
+
This date can be any date wich customers first appear at the business.
|
|
170
|
+
'signup_date': eligible date format (yyyy-mm-dd hh:mm).
|
|
171
|
+
First event of timestamp after the download_Date per customer
|
|
172
|
+
}
|
|
173
|
+
** optional columns; signup_date
|
|
174
|
+
|
|
175
|
+
*** PRODUCT COLUMNS ***
|
|
176
|
+
product_fields = {'order_id': Order ID for each session which has the created basket,
|
|
177
|
+
This column is eligible to merge with Order Id column at session fields.
|
|
178
|
+
'product': product Id or name. Make sure it is easy to read from charts
|
|
179
|
+
'price': price per each product,
|
|
180
|
+
'category': product of category
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
Products and sessions data sets are stored into the orders Index at ElasticSearch.
|
|
185
|
+
Customer data sets are stored into the customers Index at ElasticSearch.
|
|
186
|
+
4. promotions; ** optional ** Each order might have promotion ID which is an indicator of the organic/inorganic order.
|
|
187
|
+
It would be more efficient, if both promotion ID and discount amount is assigned at the same data set.
|
|
188
|
+
|
|
189
|
+
5. dimension; ** optional ** While you need to split the data set you need to assign dimensional column to the session data set.
|
|
190
|
+
This process will be directly added to ElasticSearch orders (sessions) index and
|
|
191
|
+
you may choose dimension filter in the dashboards.
|
|
192
|
+
|
|
193
|
+
:param customers_connection: dictionary with data_source, data_query_path, host, port, password, user, db
|
|
194
|
+
:param sessions_connection: dictionary with data_source, data_query_path, host, port, password, user, db
|
|
195
|
+
:param products_connection: dictionary with data_source, data_query_path, host, port, password, user, db
|
|
196
|
+
:param sessions_fields: dictionary with order_id, client, session_start_date, date, payment_amount, discount_amount, has_purchased
|
|
197
|
+
:param customer_fields: client_2, download_date, signup_date
|
|
198
|
+
:param product_fields: order_id, product, price, category
|
|
199
|
+
:param actions_sessions: string with comma separated for sessions
|
|
200
|
+
:param actions_customers: string with comma separated for customers
|
|
201
|
+
:param promotion_id: string column name for promotions
|
|
202
|
+
:param dimension_sessions: string column name for dimensions
|
|
203
|
+
"""
|
|
204
|
+
|
|
205
|
+
args = {"sessions": [sessions_fields, "orders", sessions_connection, dimension_sessions, actions_sessions],
|
|
206
|
+
"products": [product_fields, "products", products_connection],
|
|
207
|
+
"customers": [customer_fields, "downloads", customers_connection, "", actions_customers],
|
|
208
|
+
"deliveries": [delivery_fields, "deliveries", deliveries_connection]}
|
|
209
|
+
|
|
210
|
+
# check it is eligible to insert data source
|
|
211
|
+
ready_for_insert = True
|
|
212
|
+
return_message = ""
|
|
213
|
+
session_column_need = session_columns - set(args['sessions'][0].keys())
|
|
214
|
+
customer_column_need = customer_columns - set(args['customers'][0].keys())
|
|
215
|
+
|
|
216
|
+
# check data sources (sessions/customers) have data_source_type and data_source_type
|
|
217
|
+
if args['sessions'][2].get('data_source_type', None) in none_types or \
|
|
218
|
+
args['customers'][2].get('data_query_path', None) in none_types or \
|
|
219
|
+
args['sessions'][2].get('data_source_type', None) in none_types or \
|
|
220
|
+
args['customers'][2].get('data_query_path', None) in none_types:
|
|
221
|
+
ready_for_insert = False
|
|
222
|
+
return_message += """
|
|
223
|
+
- Please make sure customers and sessions connections have both data_source_type and data_source_type. \n
|
|
224
|
+
"""
|
|
225
|
+
# check sessions data source has matched data columns
|
|
226
|
+
if len(session_column_need) != 0:
|
|
227
|
+
ready_for_insert = False
|
|
228
|
+
return_message += """
|
|
229
|
+
- Please make sure all session columns are assigned to the sessions_fields parameter. Here are the forgotten ones;
|
|
230
|
+
""" + ", ".join(session_column_need) + " \n "
|
|
231
|
+
# check sessions data source has matched data columns
|
|
232
|
+
if len(customer_column_need) != 0:
|
|
233
|
+
ready_for_insert = False
|
|
234
|
+
return_message += """
|
|
235
|
+
- Please make sure all customer columns are assigned to the customer_fields parameter. Here are the forgotten ones;
|
|
236
|
+
""" + ", ".join(customer_column_need) + " \n "
|
|
237
|
+
|
|
238
|
+
try:
|
|
239
|
+
es_con = pd.read_sql(""" SELECT * FROM es_connection """, con).to_dict('records')[0]
|
|
240
|
+
connection, message = check_elasticsearch(es_con['port'], es_con['host'], es_con['directory'])
|
|
241
|
+
except:
|
|
242
|
+
connection, message = False, """
|
|
243
|
+
ElasticSearch Connection Failed Check ES port/host or temporary path or Add new ElasticSearch connection
|
|
244
|
+
"""
|
|
245
|
+
|
|
246
|
+
if not connection:
|
|
247
|
+
ready_for_insert = False
|
|
248
|
+
return_message += message + " \n "
|
|
249
|
+
|
|
250
|
+
if ready_for_insert:
|
|
251
|
+
for i in args:
|
|
252
|
+
# _fields = args[i][0].split("*")
|
|
253
|
+
if i in ['sessions', 'customers']:
|
|
254
|
+
_req = {"connect": args[i][1],
|
|
255
|
+
args[i][1] + "_data_source_tag": i + "_data_source",
|
|
256
|
+
"dimension": args[i][3], "actions": args[i][4]}
|
|
257
|
+
else:
|
|
258
|
+
_req = {"connect": args[i][1], args[i][1] + "_data_source_tag": i + "_data_source"}
|
|
259
|
+
|
|
260
|
+
if i == 'sessions':
|
|
261
|
+
_req["promotion_id"] = promotion_id
|
|
262
|
+
|
|
263
|
+
if i in ['sessions', 'customers']:
|
|
264
|
+
_req["actions"] = args[i][4]
|
|
265
|
+
|
|
266
|
+
for col in args[i][0]:
|
|
267
|
+
_req[col] = args[i][0][col]
|
|
268
|
+
|
|
269
|
+
if args[i][2] is not None:
|
|
270
|
+
for col in args[i][2]:
|
|
271
|
+
_req[args[i][1] + '_' + col] = args[i][2][col]
|
|
272
|
+
r.data_connections(r.check_for_request(_req))
|
|
273
|
+
print(i, " : ", r.message['data_source_con_check'])
|
|
274
|
+
else: print(return_message)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def create_schedule(time_period):
|
|
278
|
+
"""
|
|
279
|
+
There are 3 options for scheduling;
|
|
280
|
+
- Once; it is started for only once that triggers all processes but it is never triggered again.
|
|
281
|
+
- Daily; Every day at 00:00, it is started for all processes includes exploratory analyisis, Ml Processes,
|
|
282
|
+
Data Transferring to the ElasticSearch.
|
|
283
|
+
- 12 Hours; Every 12 hours data transferring is going to be started. And every 24 hours all processes includes
|
|
284
|
+
exploratory analysis, Ml Processes, Data Transferring to the ElasticSearch are triggered together.
|
|
285
|
+
|
|
286
|
+
"""
|
|
287
|
+
delete_schedule()
|
|
288
|
+
es_tag = list(pd.read_sql("select tag from es_connection", con)['tag'])[0]
|
|
289
|
+
request = {'schedule': 'True', 'time_period': time_period, "es_tag": es_tag}
|
|
290
|
+
r.data_execute(request)
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def delete_schedule():
|
|
294
|
+
"""
|
|
295
|
+
In order to stop schedule, you need to delete schedule process.
|
|
296
|
+
Schedule with time_period='once', can only stop with ending running process.
|
|
297
|
+
"""
|
|
298
|
+
try:
|
|
299
|
+
con.execute("delete from schedule_data where id = 1")
|
|
300
|
+
except Exception as e:
|
|
301
|
+
print(e)
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def collect_report(report_name, date=None, dimension='main'):
|
|
305
|
+
"""
|
|
306
|
+
If there is a report need as .csv format.
|
|
307
|
+
"""
|
|
308
|
+
report = reports.fetch_report(report_name, index=dimension, date=date)
|
|
309
|
+
if report is False:
|
|
310
|
+
print("reports is not created")
|
|
311
|
+
return None
|
|
312
|
+
else: return report
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
def report_names():
|
|
316
|
+
"""
|
|
317
|
+
Collect all possible report names. These report names are .csv files at sample_data folder.
|
|
318
|
+
"""
|
|
319
|
+
return list(sample_reports.kpis.keys())
|