예제 #1
0
def analyze_sales_by_year():
    _json = request.json
    year = int(_json.get('year'))
    if not year:
        return jsonify(return_unsuccess('无法获取总销售额信息'))
    types = DataAnalysisDao().query_type_from_goods()
    dict_keys = []
    for m in range(1, 13):
        for typeOfGoods in types:
            if m < 10:
                month = "0" + str(m)
            else:
                month = str(m)
            temp_key = month + str(typeOfGoods[0])
            dict_keys.append(temp_key)
    dict_of_year_month_type_and_total_sales = {key: 0 for key in dict_keys}
    for i in range(1, 13):
        if i < 10:
            month = "0" + str(i)
        else:
            month = str(i)
        info = DataAnalysisDao().query_sales_sum_proportions_by_year_and_type(
            year, month)
        for tu in info:
            if i < 10:
                month = "0" + str(i)
            else:
                month = str(i)
            dict_of_year_month_type_and_total_sales[month +
                                                    str(tu[0])] = float(tu[1])
    if not dict_of_year_month_type_and_total_sales:
        return jsonify(return_unsuccess('无法获取总销售额信息'))
    return jsonify(return_success(dict_of_year_month_type_and_total_sales))
예제 #2
0
def analyze_net_profit_rate():
    net_profits = DataAnalysisDao().query_net_profit()
    operating_incomes = DataAnalysisDao().query_operating_income()
    dict_of_year_and_net_profit_rate = {
        i + 2010: 100 * float(
            float(net_profits[0][i + 1]) / float(operating_incomes[0][i + 1]))
        for i in range(0, 10)
    }
    if not dict_of_year_and_net_profit_rate:
        return jsonify(return_unsuccess('无法获取净利率信息'))
    return jsonify(return_success(dict_of_year_and_net_profit_rate))
예제 #3
0
def analyze_cash_ratio():
    total_diets = DataAnalysisDao().query_total_diets()
    total_cash = DataAnalysisDao().query_cash()
    dict_of_year_and_total_assets = {
        i + 2010:
        100 * float(total_cash[0][i + 1]) / float(total_diets[0][i + 1])
        for i in range(0, 10)
    }
    if not dict_of_year_and_total_assets:
        return jsonify(return_unsuccess('无法获取现金比率信息'))
    return jsonify(return_success(dict_of_year_and_total_assets))
예제 #4
0
def analyze_turnover_rate():
    operating_incomes = DataAnalysisDao().query_operating_income()
    total_assets = DataAnalysisDao().query_total_assets()
    dict_of_year_and_total_assets = {
        i + 2010: 100 * float(
            float(operating_incomes[0][i + 1]) / float(total_assets[0][i + 1]))
        for i in range(0, 10)
    }
    if not dict_of_year_and_total_assets:
        return jsonify(return_unsuccess('无法获取资产周转率信息'))
    return jsonify(return_success(dict_of_year_and_total_assets))
예제 #5
0
def analyze_liquid_ratio_rate():
    total_diets = DataAnalysisDao().query_total_diets()
    total_assets = DataAnalysisDao().query_total_assets()
    total_fixed_assets = DataAnalysisDao().query_fiexed_assets()
    dict_of_year_and_total_assets = {
        i + 2010: 100 * float(
            float(total_assets[0][i + 1]) -
            float(total_fixed_assets[0][i + 1])) / float(total_diets[0][i + 1])
        for i in range(0, 9)
    }
    if not dict_of_year_and_total_assets:
        return jsonify(return_unsuccess('无法获取流动比率信息'))
    return jsonify(return_success(dict_of_year_and_total_assets))
예제 #6
0
def analyze_operating_expenditures_by_year():
    _json = request.json
    year = int(_json.get('year'))
    types = ['食品类', '日用品类', '童装类', '营养品类', '玩具类', '其他类']
    dict_keys = []
    info = DataAnalysisDao().query_operating_expenditure_by_year_with_types(
        str(year))
    for m in range(1, 13):
        for typeOfGoods in types:
            if m < 10:
                month = "0" + str(m)
            else:
                month = str(m)
            temp_key = month + str(typeOfGoods)
            dict_keys.append(temp_key)
    dict_of_day_type_and_operating_expenditures = {key: 0 for key in dict_keys}
    for tu in info:
        if int(str(tu[0])) < 10:
            dict_of_day_type_and_operating_expenditures["0" + str(tu[0]) +
                                                        str(tu[1])] = float(
                                                            tu[2])
        else:
            dict_of_day_type_and_operating_expenditures[str(tu[0]) +
                                                        str(tu[1])] = float(
                                                            tu[2])
    if not dict_of_day_type_and_operating_expenditures:
        return jsonify(return_unsuccess('无法获取当月营收信息'))
    return jsonify(return_success(dict_of_day_type_and_operating_expenditures))
예제 #7
0
def analyze_operating_expenditures_by_year_and_month():
    _json = request.json
    year = int(_json.get('year'))
    month = int(_json.get('month'))
    info = DataAnalysisDao().query_operating_expenditure_by_year_and_month(
        year, month)
    dict_of_day_type_and_operating_expenditure = {}
    days = list(range(1, 32))
    for i in range(len(days)):
        if days[i] < 10:
            days[i] = '0' + str(days[i])
        else:
            days[i] = str(days[i])
    for d in days:
        for t in ['食品类', '日用品类', '童装类', '营养品类', '玩具类', '其他类']:
            dict_of_day_type_and_operating_expenditure[d + t] = 0
    for tu in info:
        if int(tu[0]) < 10:
            dict_of_day_type_and_operating_expenditure['0' + str(tu[0]) +
                                                       str(tu[1])] = float(
                                                           tu[2])
        else:
            dict_of_day_type_and_operating_expenditure[str(tu[0]) +
                                                       str(tu[1])] = float(
                                                           tu[2])
    if not dict_of_day_type_and_operating_expenditure:
        return jsonify(return_unsuccess('无法获取当月营收信息'))
    return jsonify(return_success(dict_of_day_type_and_operating_expenditure))
예제 #8
0
def analyze_net_profit():
    info = DataAnalysisDao().query_net_profit()
    dict_of_year_and_net_profit = {
        i + 2010: info[0][i + 1]
        for i in range(0, 10)
    }
    if not dict_of_year_and_net_profit:
        return jsonify(return_unsuccess('无法获取净利润信息'))
    return jsonify(return_success(dict_of_year_and_net_profit))
예제 #9
0
def analyze_total_profits():
    info = DataAnalysisDao().query_total_profits()
    dict_of_year_and_operating_profits = {
        i + 2010: info[0][i + 1]
        for i in range(0, 10)
    }
    if not dict_of_year_and_operating_profits:
        return jsonify(return_unsuccess('无法获取利润总额信息'))
    return jsonify(return_success(dict_of_year_and_operating_profits))
예제 #10
0
def get_earnings_per_share():
    info = DataAnalysisDao().query_main_indicators()
    for i in range(len(info)):
        if info[i][0] == '每股收益(元)':
            dict_of_years_and_rates = {
                x + 2008: info[i][x]
                for x in range(1, 11)
            }
            return jsonify(return_success(dict_of_years_and_rates))
        return jsonify(return_unsuccess('无法获取相关每股收益信息'))
예제 #11
0
def get_asset_growth_rate_per_year():
    info = DataAnalysisDao().query_main_indicators()
    for i in range(len(info)):
        if info[i][0] == '净利润增长率(%)':
            dict_of_years_and_rates = {
                x + 2008: info[i][x]
                for x in range(1, 11)
            }
            return jsonify(return_success(dict_of_years_and_rates))
    return jsonify(return_unsuccess('无法获取相关净利润增长率信息'))
예제 #12
0
def analyze_goods_ratio():
    info = DataAnalysisDao().query_goods_in_warehouse()
    dict_of_type_and_ratio = {
        t: float(0)
        for t in ['食品类', '日用品类', '童装类', '营养品类', '玩具类', '其他类']
    }
    for tu in info:
        dict_of_type_and_ratio[str(tu[0])] = float(tu[1])
    if not dict_of_type_and_ratio:
        return jsonify(return_unsuccess('无法获取仓库信息'))
    return jsonify(return_success(dict_of_type_and_ratio))
예제 #13
0
def analyze_total_operating_income():
    info = DataAnalysisDao().query_total_operating_income()
    dict_of_type_and_total_operating_income = {
        t: float(0)
        for t in ['食品类', '日用品类', '童装类', '营养品类', '玩具类', '其他类']
    }
    for tu in info:
        dict_of_type_and_total_operating_income[str(tu[0])] = float(tu[1])
    if not dict_of_type_and_total_operating_income:
        return jsonify(return_unsuccess('无法获取总营收信息'))
    return jsonify(return_success(dict_of_type_and_total_operating_income))
예제 #14
0
def analyze_purchase_detail_by_category():
    _json = request.json
    category = str(_json.get('category'))
    info = DataAnalysisDao().query_purchase_info_by_category(category)
    detail = []
    for tu in info:
        print(detail)
        detail.append((str(tu[0]), str(tu[1]), str(tu[2]), str(tu[3]),
                       str(tu[4]), str(tu[5]), str(tu[6]), str(tu[7])))
    dict_of_index_and_detail = {i: detail[i] for i in range(len(detail))}
    if not dict_of_index_and_detail:
        return jsonify(return_unsuccess('无法获取采购信息'))
    return jsonify(return_success(dict_of_index_and_detail))
예제 #15
0
def analyze_sales_detail_by_category():
    _json = request.json
    category = str(_json.get('category'))
    info = DataAnalysisDao().query_sales_info_by_category(category)
    print(info)
    detail = []
    for tu in info:
        detail.append((str(tu[6]), str(tu[5]), str(round(tu[6] / tu[3], 2)),
                       str(tu[3]), str(tu[0]), str(tu[1])))
    print(detail)
    dict_of_index_and_detail = {i: detail[i] for i in range(len(detail))}
    if not dict_of_index_and_detail:
        return jsonify(return_unsuccess('无法获取销售信息'))
    return jsonify(return_success(dict_of_index_and_detail))
예제 #16
0
def analyze_sales_detail_by_month():
    _json = request.json
    year = int(_json.get('year'))
    month = int(_json.get('month'))
    info = DataAnalysisDao().query_sales_info_by_year_and_month(year, month)
    detail = []
    for tu in info:
        detail.append(
            str(tu[2]) + ' ' + str(tu[0]) + '向' + str(tu[1]) + '购买了' +
            str(tu[3]) + str(tu[4]) + str(tu[5]) + ',共计' + str(tu[6]) + '元。')
    dict_of_index_and_detail = {i: detail[i] for i in range(len(detail))}
    if not dict_of_index_and_detail:
        return jsonify(return_unsuccess('无法获取销售信息'))
    return jsonify(return_success(dict_of_index_and_detail))
예제 #17
0
def analyze_BackorderGoods():
    _method = request.method
    if _method == 'GET':
        _data = request.args
    else:
        _data = request.json
    page = int(_data.get('page'))
    offset = num_one_page * page
    rows = data_analysis_dao.query_backorder_goods(limit=num_one_page,
                                                   offset=offset)
    if rows:
        return json.dumps(return_success(
            DataAnalysisDao.goods_store_desc_to_dict(rows)),
                          cls=DecimalEncoder)
    else:
        return jsonify(return_unsuccess('无更多低库存商品信息'))
예제 #18
0
def analyze_sales_by_year_and_month(year, month):
    info = DataAnalysisDao().query_sales_sum_proportions_by_year_and_month(
        year, month)
    total_num = 0
    try:
        for i in range(len(info)):
            total_num += info[i][1]
    except ():
        Exception('sql failed!')
    info = tuple(
        map(lambda tu: tuple([tu[0],
                              round(int(tu[1]) / total_num, 4), tu[2]]), info))
    sum_proportions = 0
    for i in range(len(info)):
        sum_proportions += info[i][1]
    if sum_proportions != 1:
        info = tuple(
            map(
                lambda tu: tuple(
                    [tu[0], tu[1] + (1 - sum_proportions) / len(info), tu[2]]),
                info))
    return info
예제 #19
0
def analyze_sales():
    info = DataAnalysisDao().query_sales_proportions()
    total_num = 0
    for i in range(len(info)):
        total_num += info[i][1]
    info = tuple(
        map(
            lambda tu: tuple(
                [tu[0], round(int(tu[1]) / total_num, 4),
                 float(tu[2])]), info))
    sum_proportions = 0
    for i in range(len(info)):
        sum_proportions += info[i][1]
    if sum_proportions != 1:
        info = tuple(
            map(
                lambda tu: tuple(
                    [tu[0], tu[1] + (1 - sum_proportions) / len(info), tu[2]]),
                info))
    sales_dict = {t[0]: t[2] for t in info}
    if not sales_dict:
        return jsonify(return_unsuccess('无法获取相关销售比例信息'))
    return jsonify(return_success(sales_dict))
예제 #20
0
def analyze_SellWellGoods():
    _method = request.method
    if _method == 'GET':
        _data = request.args
    else:
        _data = request.json
    # 获取参数中的页数和近期多少天参数,并检查参数格式
    try:
        page = int(_data.get('page'))
        days = int(_data.get('days'))
    except Exception as e:
        print(e)
        return jsonify(return_unsuccess('参数格式有误'))
    if page < 0 or days <= 0:
        return jsonify(return_unsuccess('参数值有误'))
    # 当前日期作为时间区间上界
    high = datetime.datetime.now()
    if not days:
        # 默认查看一周以内的畅销商品
        days = 7
    # 根据近期天数计算时间区间
    delta = datetime.timedelta(days=int(days))
    # 上界减去长度后得到下界
    low = high - delta
    # 查询数据
    offset = page * num_one_page
    rows = data_analysis_dao.query_sell_well_goods(low=low,
                                                   high=high,
                                                   limit=num_one_page,
                                                   offset=offset)
    if rows:
        return json.dumps(return_success(
            DataAnalysisDao.goods_store_desc_to_dict(rows)),
                          cls=DecimalEncoder)
    else:
        return jsonify(return_unsuccess("无更多畅销商品信息"))
예제 #21
0
from flask import Blueprint, render_template, request
from app.dao.DataAnalysisDao import DataAnalysisDao
from app.utils.auth import check_token
from app.utils.json_util import *
from flask import Blueprint, render_template, request, session, jsonify
from app.utils.json_util import *
from app.utils.crawler import *
import uuid
import urllib
import re

# 都是对于利润表/负债表/主要指标表/现金流量表的分析操作
# 因为我们的数据,所以时间均是09-18 / 10-19

analysis_results = Blueprint('analysis_results', __name__)
data_analysis_dao = DataAnalysisDao()


@analysis_results.before_request
@check_token
def res():
    pass


# 0 时间(年份tuple)
@analysis_results.route("/data/time0918", methods=["GET", "POST"])
def get09_18_tuple():
    res = {x: x + 2009 for x in range(0, 10)}
    return jsonify(return_success(res))