Example #1
0
def make_matrix(is_positive=True):
  timestamp =  time.time()

  # addresses ids count from 1
  # to make everyone happy, there'll be a 0 entry who says nothing

  M = make_empty_matrix()
  size = M.get_shape()[0]

  respect_category = Statement.get_category_by_name('RESPECT')
  filters =  { 'active' : True,
              'timestamp__lte' : timestamp,
              'category' : respect_category,
              'author__id__lt' : size,
              'subject__id__lt' : size}

  if is_positive:
    filters['value__gt'] = 0.0
  else:
    filters['value__lt'] = 0.0

  for s in Statement.objects.\
      filter(**filters).\
      order_by('subject'):
      M[s.author.id, s.subject.id] = s.value

  return M
Example #2
0
def make_matrix(is_positive=True):
    timestamp = time.time()

    # addresses ids count from 1
    # to make everyone happy, there'll be a 0 entry who says nothing

    M = make_empty_matrix()
    size = M.get_shape()[0]

    respect_category = Statement.get_category_by_name('RESPECT')
    filters = {
        'active': True,
        'timestamp__lte': timestamp,
        'category': respect_category,
        'author__id__lt': size,
        'subject__id__lt': size
    }

    if is_positive:
        filters['value__gt'] = 0.0
    else:
        filters['value__lt'] = 0.0

    for s in Statement.objects.\
        filter(**filters).\
        order_by('subject'):
        M[s.author.id, s.subject.id] = s.value

    return M