一个小程序:计算绩效的方案

因为强制要求考核绩效,为了大家雨露均沾,考虑制定平均的绩效方案

比较挫的用了穷举,跑起来很慢啊...

# -*- coding:utf-8 -*-

'''
用来计算指定季度,指定绩效评分类型,平均绩效方案
'''

class check_list:
    def __init__(self,season=4):
        self.get_list=set()
        self.season=season
        self.target=None
        self.count=0

    def job(self,list_a,result=()):
        '''
        计算所有可能的绩效排列方案,结果存储在self.get_list中,去重
        '''
        if(len(list_a)==1):
            result += (list_a[0],)
            self.get_list.add(result)
        else:
            for i in range(len(list_a)):
                a_bak=list_a[:]
                del a_bak[i]
                self.job(a_bak,result+(list_a[i],))
    
    def count_score(self,list_a):
        '''
        用来计算绩效方案的方差值
        计算方法:
        分别计算每个人所有季度的绩效分数总和,然后计算每个人总和的方差
        '''
        i_total=len(list_a)
        j_total=len(list_a[0])
        person_score=[]
        for j in range(j_total):
            temp=0
            for i in range(i_total):
                temp+=list_a[i][j]
            person_score.append(temp)
        avg=sum(person_score)/j_total
        sdsq=sum([(i-avg)**2 for i in person_score])
        stdev=(sdsq/(j_total-1)**0.5)
        #print(stdev)
        return stdev
    
    def get_total_list(self,list_src,result_list=[]):
        '''
        穷举所有的排列情形,找出方差最小的绩效方案
        '''
        if(len(result_list)==self.season):
            self.count+=1
            stdev=self.count_score(result_list)
            if(self.target==None):
                self.target=[]
                self.target.append(result_list)
                self.target.append(stdev)
            else:
                if(stdev<self.target[-1]):
                    self.target=[]
                    self.target.append(result_list)
                    self.target.append(stdev)
                    #print(self.target)
        else:
            for i in list_src:
                if(len(result_list)>0):
                    # 不能连续两个季度同一个人拿-1
                    if(i.index(-1)!=result_list[-1].index(-1)):
                        temp=result_list[:]
                        temp.append(i)
                        self.get_total_list(list_src,temp)
                else:
                    temp=result_list[:]
                    temp.append(i)
                    self.get_total_list(list_src,temp)

# 绩效类型
score=[2,2,1,1,1,-1]
# 绩效时长
season=4

c=check_list(season)
c.job(score)
c.get_total_list(c.get_list)
print('共比较 %d 种情况' % c.count)
print(c.target)

猜你喜欢

转载自blog.csdn.net/sofeien/article/details/83088633