示例#1
0
    def summing(cls, measure_staff_qs):
        new_number_sum_list = []
        exhale_number_sum_list = []
        call_number_sum_list = []
        wechat_number_sum_list = []

        sum_data = DictWrapper({})

        for measure_staff in measure_staff_qs:
            new_number_sum_list.append(measure_staff.new_number)
            exhale_number_sum_list.append(measure_staff.exhale_number)
            call_number_sum_list.append(measure_staff.call_number)
            wechat_number_sum_list.append(measure_staff.wechat_number)

        sum_data.new_number = sum(new_number_sum_list)
        sum_data.exhale_number = sum(exhale_number_sum_list)
        sum_data.call_number = sum(call_number_sum_list)
        sum_data.wechat_number = sum(wechat_number_sum_list)
        sum_data.call_rate = "0%"

        if sum_data.exhale_number > 0:
            sum_data.call_rate = "{rate}%".format(rate=str(
                round((sum_data.call_number / sum_data.exhale_number *
                       100), 2)))
        return sum_data
示例#2
0
    def Statistics(cls, search_time=None):
        if isinstance(search_time, dict):
            search_time_in = search_time['search_time']
            user_pro = search_time['cur_user']
        if search_time_in is None:
            current_time = datetime.datetime.now()
        else:
            current_time = search_time_in
        cur_date_first = datetime.date(current_time.year, current_time.month,
                                       1)
        cur_date_last = datetime.date(current_time.year, current_time.month +
                                      1, 1) - datetime.timedelta(1)
        if user_pro:

            measure_staff_list = MeasureStaffHelper.search_qs(
                begin_time=cur_date_first,
                end_time=cur_date_last,
                cur_user=user_pro)
        else:
            measure_staff_list = MeasureStaffHelper.search_qs(
                begin_time=cur_date_first, end_time=cur_date_last)
        measure_staff_mapping = {}
        cal_time = cur_date_last
        while (cal_time >= cur_date_first):
            temp_calc = DictWrapper({})

            temp_calc.new_number = 0
            temp_calc.exhale_number = 0
            temp_calc.call_number = 0
            temp_calc.call_rate = '0%'
            temp_calc.wechat_number = 0
            temp_calc.volume = 0
            temp_calc.conversion_rate = '0%'
            temp_calc.open_number = 0
            temp_calc.open_rate = '0%'
            temp_calc.activation_number = 0
            temp_calc.activation_rate = '0%'

            temp_calc_day = {}
            time_str = cal_time.strftime('%Y-%m-%d')
            measure_staff_mapping[time_str] = temp_calc
            cal_time = cal_time - datetime.timedelta(1)
        for measure_staff in measure_staff_list:
            report_date_str = str(measure_staff.report_date)
            temp_item = measure_staff_mapping[report_date_str]
            temp_item["new_number"] += measure_staff.new_number
            temp_item["exhale_number"] += measure_staff.exhale_number
            temp_item["call_number"] += measure_staff.call_number
            temp_item["wechat_number"] += measure_staff.wechat_number
        return measure_staff_mapping