parameters: (keyboard_value, stream)
docstring: Writes serialized binary of the stats for a keyboard.
  
    Args:
      keyboard_value: A dictionary from souce_id to source_value.
                      source_value is a dictionary from stats_type to
                      (cumulative_average, count).
      stream: An output stream.
docstring_summary: Writes serialized binary of the stats for a keyboard.
docstring_tokens: Writes serialized binary of the stats for a keyboard .
function: def WriteKeyboardData(keyboard_value, stream):
    """Writes serialized binary of the stats for a keyboard.
  
    Args:
      keyboard_value: A dictionary from souce_id to source_value.
                      source_value is a dictionary from stats_type to
                      (cumulative_average, count).
      stream: An output stream.
    """
  
    def GetAverage(source_value, stats_type):
      (cumulative_average, count) = source_value[stats_type]
      if count == 0:
        return 0
      # Cumulative average values are multiplied by 10^7
      # when usage stats are sent to the log server.
      # Here we get original value by dividing the average value.
      return cumulative_average / 1e7 / count
  
    # c.f. usage_stats/usage_stats_uploader.cc
    keys = ('sxa', 'sya', 'sxv', 'syv', 'dxa', 'dya', 'dxv', 'dyv')
    stream.write(struct.pack('>i', len(keyboard_value)))
    for source_id, source_value in six.iteritems(keyboard_value):
      stream.write(struct.pack('>i', source_id))
      # Note that we are calculating
      # "Average of average" and "Average of variance".
      # Such values are theoritically meaningless but we collect
      # only restricted value to avoid from privacy issue
      # so we have to use them instead.
      stream.write(struct.pack('>ffffffff',
                               *[GetAverage(source_value, key) for key in keys]))
function_tokens: def WriteKeyboardData ( keyboard_value , stream ) : def GetAverage ( source_value , stats_type ) : ( cumulative_average , count ) = source_value [ stats_type ] if count == 0 : return 0 # Cumulative average values are multiplied by 10^7 # when usage stats are sent to the log server. # Here we get original value by dividing the average value. return cumulative_average / 1e7 / count # c.f. usage_stats/usage_stats_uploader.cc keys = ( 'sxa' , 'sya' , 'sxv' , 'syv' , 'dxa' , 'dya' , 'dxv' , 'dyv' ) stream . write ( struct . pack ( '>i' , len ( keyboard_value ) ) ) for source_id , source_value in six . iteritems ( keyboard_value ) : stream . write ( struct . pack ( '>i' , source_id ) ) # Note that we are calculating # "Average of average" and "Average of variance". # Such values are theoritically meaningless but we collect # only restricted value to avoid from privacy issue # so we have to use them instead. stream . write ( struct . pack ( '>ffffffff' , * [ GetAverage ( source_value , key ) for key in keys ] ) )