statistics_func.py 1.9 KB
# -*- coding:utf-8 -*-
#@Time : 2021/2/5 10:32
#@File : statistics_func.py
#@Auth : bianxinhua
from datetime import date, timedelta
import datetime

###获取季度
def quarters1() :
    today = datetime.date.today()
    quarter = (today.month-1) // 3
    return  quarter

def get_quarters(key,*args_v):
    quarters = args_v[0][quarters1() - 1][key]
    return quarters

def get_statistics(*args_v):
    value = []
    statistics = []
    for i in range(len(args_v)-1):
        value.append(args_v[i])
    for v in value:
        statistics.append(args_v[-1][v])
    return sum(statistics)
#统计应收/已收/未收

def statistics_func(keys,*args_v):
    # print("====================args_v===============================")
    # print(args_v)
    value = []
    num = 0
    for i in range(len(args_v)):
        if args_v[i] == []:
            value.append(0)
        else:
            for j in range(len(args_v[i])):
                value.append((args_v[i][j][keys]))
    for v in value:
        if type(v) == str:
            v = float(v)
        num = num + v
    # print("===========================================================")
    # print('num=',num)
    return num

#统计订单金额
def statistics_actual_func(keys,*args_v):
    # print("====================args_v===============================")
    # print(args_v)
    value = []
    for i in range(len(args_v)):
        for j in range(len(args_v[i])):
            if args_v[i][j]['partnerCategory'] == keys:
                value.append(args_v[i][j]['orderPrice'])
    # print("===========================================================")
    # print('value=',value)
    return sum(value)

#统计个数
def statistics_num_func(keys,*args_v):
    value = []
    num = 0
    for i in range(len(args_v)):
        for j in range(len(args_v[i])):
            value.append(args_v[i][j][keys])
    for v in range(len(value)):
        if float(value[v]) > 0 :
            num = num +1
    # print(num)
    return num