效果:by部门展示人均建议数
views.py
# 将所有模型都查出来
suggestion_all = suggestion.objects.all()
dept_review_all = dept_review.objects.all()
headcount_all = headcount.objects.all()
User_all = User.objects.all()
# main24参数提取(by各部门人均建议提出条数)
# 读取编制的数值(需要每个月都维护编制,否则可能报错)(headcount_item不存在则需要追认这一年最后一笔编制)
headcount_item = headcount_all.filter(Q(headcount_datetime__range=(start_date3, end_date3))).order_by('headcount_datetime').last()
print('headcount_item',headcount_item)
if headcount_item:
pass
else:
headcount_item = headcount_all.filter(Q(headcount_datetime__range=(this_year_start, this_year_end))).order_by('headcount_datetime').last()
headcount_ttl_count = headcount_item.headcount_ttl
print('headcount_item',headcount_item)
headcount_dict = {'总体':headcount_item.headcount_ttl,
'生产部':headcount_item.headcount_shengchanbu,
'物流部':headcount_item.headcount_wuliubu,
'人事综合管理部':headcount_item.headcount_renshizonghebu,
'工艺质量部':headcount_item.headcount_gongyizhiliangbu,
'项目部':headcount_item.headcount_xiangmubu,
'总经办':headcount_item.headcount_zongjingban,
'财务部':headcount_item.headcount_caiwubu,
'研发部':headcount_item.headcount_yanfabu,
}
person_average_suggestion = suggestion_count/headcount_ttl_count
# 计算平均数
suggestion_count = suggestion_all.filter(Q(suggestion_date__range=(start_date3, end_date3))).count()
# 人均建议条数
#print('headcount_datetime',headcount_all.filter(Q(headcount_datetime__range=(start_date3, end_date3))).order_by('headcount_datetime').last().headcount_datetime)
list_of_suggestion_dept_count = []
dict_of_sum_suggestion_dept_count = {'总体':round(suggestion_count/headcount_ttl_count,1),
'生产部':0,
'物流部':0,
'人事综合管理部':0,
'工艺质量部':0,
'项目部':0,
'总经办':0,
'财务部':0,
'研发部':0,
}
for su in suggestion_all:
list_of_suggestion_dept_count.append(su.suggestion_employee_dept)
for suggestion_employee_dept in list_of_suggestion_dept_count:
dept_sum = suggestion_all.filter(Q(suggestion_employee_dept=suggestion_employee_dept) & Q(suggestion_date__range=(start_date1, end_date1))).aggregate(suggestion_employee_dept=Count('suggestion_employee_id'))
process_dict = {suggestion_employee_dept : round(dept_sum['suggestion_employee_dept']/headcount_dict[suggestion_employee_dept],1)}
dict_of_sum_suggestion_dept_count.update(process_dict)
#print('dict_of_sum_suggestion_dept_count',dict_of_sum_suggestion_dept_count)
value24A = []
value24B = []
for key,value in dict_of_sum_suggestion_dept_count.items():
value24A.append(key)
value24B.append(value)
dashboard.html