#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/2/11 19:43
# @Author  : fanhui
# @File    : GetFIinfoFromJson.py
# @Software: PyCharm

#变化率添加符号
def AddSign(factor):
    factor=factor
    if "-" in factor and"%"in factor:
        factor=factor.replace("-", "") + "↓"
    elif "%"in factor and "-"not in factor:
        factor = factor+"↑"
    # print(factor)
    return factor


def GetFIinfoFromJson(GetAllinfo):
# 获取传入的参数
    GetAllinfo = GetAllinfo
    Else_info={
        "Detection_zone": GetAllinfo.get("Detection_zone",None),
        "CreatTime": GetAllinfo.get("CreatTime",None),
        "company_name": GetAllinfo.get("company_name",None),
        "Task_Num": GetAllinfo.get("Task_Num",None)
    }

    FIinfo=GetAllinfo.get("fi",None)#如果key不存在，会返回None,因此需进行判断
    Fi_dict={}
    if FIinfo:
        Total_trade_income=FIinfo[0].get("Total_trade_income",None)
        Bq_time=''
        Sq_time=''
        if Total_trade_income:
            print(eval(Total_trade_income),type(eval(Total_trade_income)))
            keys_list = []
            Total_trade_income=eval(Total_trade_income)#str转dict,用eval
            for t_k,t_v in Total_trade_income.items():
                keys_list.append(t_k)
            Bq_time=keys_list[0]
            Sq_time=keys_list[1]
        Total_profit = eval(FIinfo[1].get("Total_profit"))
        Net_profit = eval(FIinfo[2].get("Net_profit"))
        Total_Liabilities = eval(FIinfo[3].get("Total_Liabilities"))
        Owner_rights = eval(FIinfo[4].get("Owner_rights"))
        Total_sales = eval(FIinfo[5].get("Total_sales"))
        Total_assets = eval(FIinfo[6].get("Total_assets"))
        Total_liabilities_and_Owner_rights = eval(FIinfo[7].get("Total_liabilities_and_Owner_rights"))
        sales_expense=eval(FIinfo[8].get("sales_expense"))
        Net_interest_rate = eval(FIinfo[9].get("Net_interest_rate"))
        Equity_ratio = eval(FIinfo[10].get("Equity_ratio"))
        Gearing_ratio = eval(FIinfo[11].get("Gearing_ratio"))
        sales_growth_rate = eval(FIinfo[12].get("sales_growth_rate"))
        Net_profit_growth_rate = eval(FIinfo[13].get("Net_profit_growth_rate"))
        print(type(FIinfo[14].get("total_assets_growth_rate")),FIinfo[14].get("total_assets_growth_rate"))
        total_assets_growth_rate = eval(FIinfo[14].get("total_assets_growth_rate"))
        Fi_dict["Bq_time"] = Bq_time
        Fi_dict["Sq_time"] = Sq_time
        Fi_dict["Bq_Total_trade_income"]=Total_trade_income[Bq_time]
        Fi_dict["Sq_Total_trade_income"] = Total_trade_income[Sq_time]
        Fi_dict["change_rate_1"] = AddSign(Total_trade_income["change_rate"])
        Fi_dict["Bq_Total_profit"]=Total_profit[Bq_time]
        Fi_dict["Sq_Total_profit"]=Total_profit[Sq_time]
        Fi_dict["change_rate_2"]=AddSign(Total_profit["change_rate"])
        Fi_dict["Bq_Net_profit"]=Net_profit[Bq_time]
        Fi_dict["Sq_Net_profit"]=Net_profit[Sq_time]
        Fi_dict["change_rate_3"]=AddSign(Net_profit["change_rate"])
        Fi_dict["Bq_Total_Liabilities"]=Total_Liabilities[Bq_time]
        Fi_dict["Sq_Total_Liabilities"]=Total_Liabilities[Sq_time]
        Fi_dict["change_rate_4"]=AddSign(Total_Liabilities["change_rate"])
        Fi_dict["Bq_Owner_rights"]=Owner_rights[Bq_time]
        Fi_dict["Sq_Owner_rights"]=Owner_rights[Sq_time]
        Fi_dict["change_rate_5"]=AddSign(Owner_rights["change_rate"])
        Fi_dict["Bq_Total_sales"]=Total_sales[Bq_time]
        Fi_dict["Sq_Total_sales"]=Total_sales[Sq_time]
        Fi_dict["change_rate_6"]=AddSign(Total_sales["change_rate"])
        Fi_dict["Bq_Total_assets"]=Total_assets[Bq_time]
        Fi_dict["Sq_Total_assets"]=Total_assets[Sq_time]
        Fi_dict["change_rate_7"]=AddSign(Total_assets["change_rate"])
        Fi_dict["Bq_Total_liabilities_and_Owner_rights"]=Total_liabilities_and_Owner_rights[Bq_time]
        Fi_dict["Sq_Total_liabilities_and_Owner_rights"]=Total_liabilities_and_Owner_rights[Sq_time]
        Fi_dict["Bq_sales_expense"] = sales_expense[Bq_time]
        Fi_dict["Sq_sales_expense"] = sales_expense[Sq_time]
        Fi_dict["Bq_Net_interest_rate"] = Net_interest_rate[Bq_time]
        Fi_dict["Sq_Net_interest_rate"] = Net_interest_rate[Sq_time]
        Fi_dict["Bq_Equity_ratio"] = Equity_ratio[Bq_time]
        Fi_dict["Sq_Equity_ratio"] = Equity_ratio[Sq_time]
        Fi_dict["Bq_Gearing_ratio"] = Gearing_ratio[Bq_time]
        Fi_dict["Sq_Gearing_ratio"] = Gearing_ratio[Sq_time]
        Fi_dict["Bq_sales_growth_rate"] = sales_growth_rate[Bq_time]
        Fi_dict["Sq_sales_growth_rate"] = sales_growth_rate[Sq_time]
        Fi_dict["Bq_Net_profit_growth_rate"] = Net_profit_growth_rate[Bq_time]
        Fi_dict["Sq_Net_profit_growth_rate"] = Net_profit_growth_rate[Sq_time]
        Fi_dict["Bq_total_assets_growth_rate"] = total_assets_growth_rate[Bq_time]
        Fi_dict["Sq_total_assets_growth_rate"] = total_assets_growth_rate[Sq_time]
    return Else_info,Fi_dict
