parameters: (self,data_set_key, raw_service_data)
return_statement: return optimized_dic
docstring: calculate out ava,max,min,mid value from raw service data set
          :param data_set_key: where the optimized data needed to save to in redis db
          :param raw_service_data: raw service data data list
          :return:
docstring_summary: calculate out ava,max,min,mid value from raw service data set
          :param data_set_key: where the optimized data needed to save to in redis db
          :param raw_service_data: raw service data data list
          :return:
docstring_tokens: calculate out ava max min mid value from raw service data set : param data_set_key : where the optimized data needed to save to in redis db : param raw_service_data : raw service data data list : return :
function: def get_optimized_data(self,data_set_key, raw_service_data):
          '''
          calculate out ava,max,min,mid value from raw service data set
          :param data_set_key: where the optimized data needed to save to in redis db
          :param raw_service_data: raw service data data list
          :return:
          '''
          #index_init =[avg,max,min,mid]
          print("get_optimized_data:",raw_service_data[0] )
          service_data_keys = raw_service_data[0][0].keys() #[iowait, idle,system...]
          first_service_data_point = raw_service_data[0][0] # use this to build up a new empty dic
          #print("--->",service_data_keys)
          optimized_dic = {} #set a empty dic, will save optimized data later
          if 'data' not  in service_data_keys: #means this dic has  no subdic, works for service like cpu,memory
              for key in service_data_keys:
                  optimized_dic[key] = []
              #optimized_dic = optimized_dic.fromkeys(first_service_data_point,[])
              tmp_data_dic = copy.deepcopy(optimized_dic)  #为了临时存最近n分钟的数据 ,把它们按照每个指标 都 搞成一个一个列表 ,来存最近N分钟的数据
              print("tmp data dic:",tmp_data_dic)
              for service_data_item,last_save_time in raw_service_data: #loop 最近n分钟的数据
                  #print(service_data_item)
                  for service_index,v in service_data_item.items(): #loop 每个数据点的指标
                      #print(service_index,v)
                      try:
                          tmp_data_dic[service_index].append(round(float(v),2)) #把这个点的当前这个指标 的值 添加到临时dict中
                      except ValueError as e:
                          pass
                  #print(service_data_item,last_save_time)
              for service_k,v_list in tmp_data_dic.items():
                  print(service_k, v_list)
                  avg_res = self.get_average(v_list)
                  max_res = self.get_max(v_list)
                  min_res = self.get_min(v_list)
                  mid_res = self.get_mid(v_list)
                  optimized_dic[service_k]= [avg_res,max_res,min_res,mid_res]
                  print(service_k, optimized_dic[service_k])
  
          else: # has sub dic inside key 'data', works for a service has multiple independent items, like many ethernet,disks...
              #print("**************>>>",first_service_data_point )
              for service_item_key,v_dic in first_service_data_point['data'].items():
                  #service_item_key 相当于lo,eth0,... , v_dic ={ t_in:333,t_out:3353}
                  optimized_dic[service_item_key] = {}
                  for k2,v2 in v_dic.items():
                      optimized_dic[service_item_key][k2] = [] #{etho0:{t_in:[],t_out:[]}}
  
              tmp_data_dic = copy.deepcopy(optimized_dic)
              if tmp_data_dic: #some times this tmp_data_dic might be empty due to client report err
                  print('tmp data dic:', tmp_data_dic)
                  for service_data_item,last_save_time in raw_service_data:#loop最近n分钟数据
                      for service_index,val_dic in service_data_item['data'].items():
                          #print(service_index,val_dic)
                          #service_index这个值 相当于eth0,eth1...
                          for service_item_sub_key, val in val_dic.items():
                              #上面这个service_item_sub_key相当于t_in,t_out
                              #if service_index == 'lo':
                              #print(service_index,service_item_sub_key,val)
                              tmp_data_dic[service_index][service_item_sub_key].append(round(float(val),2))
                              #上面的service_index变量相当于 eth0...
                  for service_k,v_dic in tmp_data_dic.items():
                      for service_sub_k,v_list in v_dic.items():
                          print(service_k, service_sub_k, v_list)
                          avg_res = self.get_average(v_list)
                          max_res = self.get_max(v_list)
                          min_res = self.get_min(v_list)
                          mid_res = self.get_mid(v_list)
                          optimized_dic[service_k][service_sub_k] = [avg_res,max_res,min_res,mid_res]
                          print(service_k, service_sub_k, optimized_dic[service_k][service_sub_k])
  
              else:
                  print("\033[41;1mMust be sth wrong with client report data\033[0m")
          print("optimized empty dic:", optimized_dic)
  
          return optimized_dic
function_tokens: def get_optimized_data ( self , data_set_key , raw_service_data ) : #index_init =[avg,max,min,mid] print ( "get_optimized_data:" , raw_service_data [ 0 ] ) service_data_keys = raw_service_data [ 0 ] [ 0 ] . keys ( ) #[iowait, idle,system...] first_service_data_point = raw_service_data [ 0 ] [ 0 ] # use this to build up a new empty dic #print("--->",service_data_keys) optimized_dic = { } #set a empty dic, will save optimized data later if 'data' not in service_data_keys : #means this dic has  no subdic, works for service like cpu,memory for key in service_data_keys : optimized_dic [ key ] = [ ] #optimized_dic = optimized_dic.fromkeys(first_service_data_point,[]) tmp_data_dic = copy . deepcopy ( optimized_dic ) #为了临时存最近n分钟的数据 ,把它们按照每个指标 都 搞成一个一个列表 ,来存最近N分钟的数据 print ( "tmp data dic:" , tmp_data_dic ) for service_data_item , last_save_time in raw_service_data : #loop 最近n分钟的数据 #print(service_data_item) for service_index , v in service_data_item . items ( ) : #loop 每个数据点的指标 #print(service_index,v) try : tmp_data_dic [ service_index ] . append ( round ( float ( v ) , 2 ) ) #把这个点的当前这个指标 的值 添加到临时dict中 except ValueError as e : pass #print(service_data_item,last_save_time) for service_k , v_list in tmp_data_dic . items ( ) : print ( service_k , v_list ) avg_res = self . get_average ( v_list ) max_res = self . get_max ( v_list ) min_res = self . get_min ( v_list ) mid_res = self . get_mid ( v_list ) optimized_dic [ service_k ] = [ avg_res , max_res , min_res , mid_res ] print ( service_k , optimized_dic [ service_k ] ) else : # has sub dic inside key 'data', works for a service has multiple independent items, like many ethernet,disks... #print("**************>>>",first_service_data_point ) for service_item_key , v_dic in first_service_data_point [ 'data' ] . items ( ) : #service_item_key 相当于lo,eth0,... , v_dic ={ t_in:333,t_out:3353} optimized_dic [ service_item_key ] = { } for k2 , v2 in v_dic . items ( ) : optimized_dic [ service_item_key ] [ k2 ] = [ ] #{etho0:{t_in:[],t_out:[]}} tmp_data_dic = copy . deepcopy ( optimized_dic ) if tmp_data_dic : #some times this tmp_data_dic might be empty due to client report err print ( 'tmp data dic:' , tmp_data_dic ) for service_data_item , last_save_time in raw_service_data : #loop最近n分钟数据 for service_index , val_dic in service_data_item [ 'data' ] . items ( ) : #print(service_index,val_dic) #service_index这个值 相当于eth0,eth1... for service_item_sub_key , val in val_dic . items ( ) : #上面这个service_item_sub_key相当于t_in,t_out #if service_index == 'lo': #print(service_index,service_item_sub_key,val) tmp_data_dic [ service_index ] [ service_item_sub_key ] . append ( round ( float ( val ) , 2 ) ) #上面的service_index变量相当于 eth0... for service_k , v_dic in tmp_data_dic . items ( ) : for service_sub_k , v_list in v_dic . items ( ) : print ( service_k , service_sub_k , v_list ) avg_res = self . get_average ( v_list ) max_res = self . get_max ( v_list ) min_res = self . get_min ( v_list ) mid_res = self . get_mid ( v_list ) optimized_dic [ service_k ] [ service_sub_k ] = [ avg_res , max_res , min_res , mid_res ] print ( service_k , service_sub_k , optimized_dic [ service_k ] [ service_sub_k ] ) else : print ( "\033[41;1mMust be sth wrong with client report data\033[0m" ) print ( "optimized empty dic:" , optimized_dic ) return optimized_dic