# Path: jd_analysis/settings.py
# BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECRET_KEY = '!=6ve76(w#_0r_b8ic#mo-*s2#xf^*&(lfn1$#c=0-u=icl(8@'
# DEBUG = True
# ALLOWED_HOSTS = []
# INSTALLED_APPS = [
#     'django.contrib.admin',
#     'django.contrib.auth',
#     'django.contrib.contenttypes',
#     'django.contrib.sessions',
#     'django.contrib.messages',
#     'django.contrib.staticfiles',
#     'django_crontab',
#     'jd',
# ]
# MIDDLEWARE = [
#     'django.middleware.security.SecurityMiddleware',
#     'django.contrib.sessions.middleware.SessionMiddleware',
#     'django.middleware.common.CommonMiddleware',
#     'django.middleware.csrf.CsrfViewMiddleware',
#     'django.contrib.auth.middleware.AuthenticationMiddleware',
#     'django.contrib.messages.middleware.MessageMiddleware',
#     'django.middleware.clickjacking.XFrameOptionsMiddleware',
# ]
# ROOT_URLCONF = 'jd_analysis.urls'
# TEMPLATES = [
#     {
#         'BACKEND': 'django.template.backends.django.DjangoTemplates',
#         'DIRS': [],
#         'APP_DIRS': True,
#         'OPTIONS': {
#             'context_processors': [
#                 'django.template.context_processors.debug',
#                 'django.template.context_processors.request',
#                 'django.contrib.auth.context_processors.auth',
#                 'django.contrib.messages.context_processors.messages',
#             ],
#         },
#     },
# ]
# WSGI_APPLICATION = 'jd_analysis.wsgi.application'
# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.mysql',
#         'NAME': 'jd_analysis',
#         'USER': 'root',
#         'PASSWORD': '123456',
#         'HOST': '',
#         'PORT': '',
#     }
# }
# AUTH_PASSWORD_VALIDATORS = [
#     {
#         'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
#     },
#     {
#         'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
#     },
#     {
#         'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
#     },
#     {
#         'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
#     },
# ]
# CRONJOBS = [
#     ('*/1 */1 * * *', 'django.core.management.call_command', ['full_analysis'], {},
#      '>> ' + BASE_DIR + '/log/full_analysis.log')
# ]
# LANGUAGE_CODE = 'en-us'
# TIME_ZONE = 'Asia/Shanghai'
# USE_I18N = True
# USE_L10N = True
# USE_TZ = True
# STATIC_URL = '/static/'
# STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
# 
# Path: cus_exception.py
# class CusException(Exception):
#     def __init__(self, name, error_msg):
#         super(CusException, self).__init__(name, error_msg)
#         self.name = name
# 
#         if type(error_msg) == CusException:
#             self.error_msg = error_msg.error_msg
#         else:
#             self.error_msg = error_msg
# 
#         self.error_time = str(datetime.datetime.now())


import matplotlib
import logging
import utils
import config
import numpy as np
import matplotlib.pyplot as plt
from wordcloud import WordCloud
from matplotlib import font_manager
from pandas import DataFrame, Series
from jd_analysis import settings
from PIL import Image
from cus_exception import CusException
            logging.exception('analysis init exception msg:%s' % e)
            raise CusException('analysis_init', 'analysis_init error:%s' % e)

    def run(self):
        table_name = '%s_%s' % (config.jd_item_table, self.product_id)
        if self.sql.is_exists(table_name) == False:
            self.record_result('出现错误。错误原因：表不存在', strong = True, color = 'red', font_size = 24)
            return self.finish()

        command = 'SELECT count(*) FROM {}'.format(table_name)
        (count,) = self.sql.query_one(command)
        if count <= 0:
            self.record_result('出现错误。错误原因：表为空，没有数据', strong = True, color = 'red', font_size = 24)
            return self.finish()

        try:
            self.analysis_item_info()
            self.analysis_comment_info()
            self.analysis_color()
            self.analysis_size()
            self.analysis_sell_time()
            self.analysis_hour()
            self.analysis_province()
            self.analysis_buy_channel()
            self.analysis_mobile()
            self.analysis_buy_days()
            self.analysis_user_level()
        except Exception, e:
            self.record_result('出现错误。错误原因:%s' % e)
            logging.exception('analysis run exception msg:%s' % e)

# Path: jd_analysis/settings.py
# BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECRET_KEY = '!=6ve76(w#_0r_b8ic#mo-*s2#xf^*&(lfn1$#c=0-u=icl(8@'
# DEBUG = True
# ALLOWED_HOSTS = []
# INSTALLED_APPS = [
#     'django.contrib.admin',
#     'django.contrib.auth',
#     'django.contrib.contenttypes',
#     'django.contrib.sessions',
#     'django.contrib.messages',
#     'django.contrib.staticfiles',
#     'django_crontab',
#     'jd',
# ]
# MIDDLEWARE = [
#     'django.middleware.security.SecurityMiddleware',
#     'django.contrib.sessions.middleware.SessionMiddleware',
#     'django.middleware.common.CommonMiddleware',
#     'django.middleware.csrf.CsrfViewMiddleware',
#     'django.contrib.auth.middleware.AuthenticationMiddleware',
#     'django.contrib.messages.middleware.MessageMiddleware',
#     'django.middleware.clickjacking.XFrameOptionsMiddleware',
# ]
# ROOT_URLCONF = 'jd_analysis.urls'
# TEMPLATES = [
#     {
#         'BACKEND': 'django.template.backends.django.DjangoTemplates',
#         'DIRS': [],
#         'APP_DIRS': True,
#         'OPTIONS': {
#             'context_processors': [
#                 'django.template.context_processors.debug',
#                 'django.template.context_processors.request',
#                 'django.contrib.auth.context_processors.auth',
#                 'django.contrib.messages.context_processors.messages',
#             ],
#         },
#     },
# ]
# WSGI_APPLICATION = 'jd_analysis.wsgi.application'
# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.mysql',
#         'NAME': 'jd_analysis',
#         'USER': 'root',
#         'PASSWORD': '123456',
#         'HOST': '',
#         'PORT': '',
#     }
# }
# AUTH_PASSWORD_VALIDATORS = [
#     {
#         'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
#     },
#     {
#         'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
#     },
#     {
#         'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
#     },
#     {
#         'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
#     },
# ]
# CRONJOBS = [
#     ('*/1 */1 * * *', 'django.core.management.call_command', ['full_analysis'], {},
#      '>> ' + BASE_DIR + '/log/full_analysis.log')
# ]
# LANGUAGE_CODE = 'en-us'
# TIME_ZONE = 'Asia/Shanghai'
# USE_I18N = True
# USE_L10N = True
# USE_TZ = True
# STATIC_URL = '/static/'
# STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
# 
# Path: cus_exception.py
# class CusException(Exception):
#     def __init__(self, name, error_msg):
#         super(CusException, self).__init__(name, error_msg)
#         self.name = name
# 
#         if type(error_msg) == CusException:
#             self.error_msg = error_msg.error_msg
#         else:
#             self.error_msg = error_msg
# 
#         self.error_time = str(datetime.datetime.now())


# Path: jd/analysis_jd_item.py
import matplotlib
import logging
import utils
import config
import numpy as np
import matplotlib.pyplot as plt
from wordcloud import WordCloud
from matplotlib import font_manager
from pandas import DataFrame, Series
from jd_analysis import settings
from PIL import Image
from cus_exception import CusException

            logging.exception('analysis init exception msg:%s' % e)
            raise CusException('analysis_init', 'analysis_init error:%s' % e)

    def run(self):
        table_name = '%s_%s' % (config.jd_item_table, self.product_id)
        if self.sql.is_exists(table_name) == False:
            self.record_result('出现错误。错误原因：表不存在', strong = True, color = 'red', font_size = 24)
            return self.finish()

        command = 'SELECT count(*) FROM {}'.format(table_name)
        (count,) = self.sql.query_one(command)
        if count <= 0:
            self.record_result('出现错误。错误原因：表为空，没有数据', strong = True, color = 'red', font_size = 24)
            return self.finish()

        try:
            self.analysis_item_info()
            self.analysis_comment_info()
            self.analysis_color()
            self.analysis_size()
            self.analysis_sell_time()
            self.analysis_hour()
            self.analysis_province()
            self.analysis_buy_channel()
            self.analysis_mobile()
            self.analysis_buy_days()
            self.analysis_user_level()
        except Exception, e:
            self.record_result('出现错误。错误原因:%s' % e)
            logging.exception('analysis run exception msg:%s' % e)

            raise CusException('analysis_run', 'analysis_run error:%s' % e)