Exemplo n.º 1
0
def admin_flags():
  flags = Flag.query.order_by(Flag.id).all()
  flag_count = len(flags)

  flags_dumped = []

  for fl in flags:
    flag_dumped = fl.to_dict()
    flag_dumped.update({
      'item_name': fl.item.name,
      'item_location': fl.item.location,
      'annotator_name': fl.annotator.name
      })
    flags_dumped.append(flag_dumped)

  dump_data = {
    "flags": flags_dumped,
    "flag_count": flag_count
  }

  response = app.response_class(
    response=json.dumps(dump_data),
    status=200,
    mimetype='application/json'
  )

  return response
Exemplo n.º 2
0
def admin_annotators():
    annotators = Annotator.query.order_by(Annotator.id).all()
    decisions = Decision.query.all()

    counts = {}

    for d in decisions:
        a = d.annotator_id
        w = d.winner_id
        l = d.loser_id
        counts[a] = counts.get(a, 0) + 1

    dump_data = {
        "annotators":
        [an.to_dict() if an else {
            'null': 'null'
        } for an in annotators],
        "counts":
        counts
    }

    response = app.response_class(response=json.dumps(dump_data),
                                  status=200,
                                  mimetype='application/json')

    return response
Exemplo n.º 3
0
def admin_annotators():
    annotators = Annotator.query.order_by(Annotator.id).all()
    decisions = Decision.query.all()
    annotator_count = len(annotators)

    annotator_schema = AnnotatorSchema()

    counts = {}

    for d in decisions:
        a = d.annotator_id
        w = d.winner_id
        l = d.loser_id
        counts[a] = counts.get(a, 0) + 1

    annotators_dumped = []

    for an in annotators:
        try:
            annotator_dumped = annotator_schema.dump(an)
            annotator_dumped.update({'votes': counts.get(an.id, 0)})
            annotators_dumped.append(annotator_dumped)
        except:
            annotators_dumped.append({'null': 'null'})
    dump_data = {
        "annotators": annotators_dumped,
        "anotator_count": annotator_count
    }

    response = app.response_class(response=json.dumps(dump_data),
                                  status=200,
                                  mimetype='application/json')

    return response
Exemplo n.º 4
0
def admin_items():
    items = Item.query.order_by(Item.id).all()
    annotators = Annotator.query.order_by(Annotator.id).all()
    decisions = Decision.query.all()

    item_schema = ItemSchema()

    viewed = {}
    for i in items:
        viewed_holder = []
        for a in i.viewed:
            viewed_holder.append(a.id)
        viewed[i.id] = viewed_holder

    skipped = {}
    for a in annotators:
        skipped_holder = []
        for i in a.ignore:
            if a.id not in viewed[i.id]:
                skipped_holder.append(a.id)
        skipped[i.id] = skipped_holder

    item_count = len(items)

    item_counts = {}

    for d in decisions:
        a = d.annotator_id
        w = d.winner_id
        l = d.loser_id
        item_counts[w] = item_counts.get(w, 0) + 1
        item_counts[l] = item_counts.get(l, 0) + 1

    items_dumped = []

    for it in items:
        try:
            item_dumped = item_schema.dump(it)
            item_dumped.update({
                'votes': item_counts.get(it.id, 0),
                'skipped': list(set(skipped.get(it.id, [])))
            })
            items_dumped.append(item_dumped)
        except Exception as e:
            print(str(e))
            items_dumped.append({'null': 'null'})

    dump_data = {"items": items_dumped, "item_count": item_count}

    response = app.response_class(response=json.dumps(dump_data),
                                  status=200,
                                  mimetype='application/json')

    return response
Exemplo n.º 5
0
def admin_live():
  annotators = Annotator.query.order_by(Annotator.id).all()
  items = Item.query.order_by(Item.id).all()
  flags = Flag.query.order_by(Flag.id).all()
  decisions = Decision.query.all()

  # settings
  setting_closed = Setting.value_of(SETTING_CLOSED) == SETTING_TRUE
  setting_stop_queue = Setting.value_of(SETTING_STOP_QUEUE) == SETTING_TRUE

  item_count = len(items)
  votes = len(decisions)
  flag_count = len(flags)

  # Calculate average sigma
  holder = 0.0
  for it in items:
    holder += it.sigma_sq
  try:
    average_sigma = holder / len(items)
  except:
    average_sigma = 0.0

  # Calculate average seen
  holder = 0
  for an in annotators:
    seen = Item.query.filter(Item.viewed.contains(an)).all()
    holder += len(seen)
  try:
    average_seen = holder / len(annotators)
  except:
    average_seen = 0

  dump_data = {
    "votes": votes,
    "setting_closed": setting_closed,
    "setting_stop_queue": setting_stop_queue,
    "flag_count": flag_count,
    "item_count": item_count,
    "average_sigma": average_sigma,
    "average_seen": average_seen
  }

  response = app.response_class(
    response=json.dumps(dump_data),
    status=200,
    mimetype='application/json'
  )

  return response
Exemplo n.º 6
0
def admin_items():
  items = Item.query.order_by(Item.id).all()
  annotators = Annotator.query.order_by(Annotator.id).all()
  decisions = Decision.query.all()

  viewed = {}
  for i in items:
    viewed_holder = []
    for a in i.viewed:
      viewed_holder.append(a.id)
    viewed[i.id] = viewed_holder

  skipped = {}
  for a in annotators:
    for i in a.ignore:
      if a.id not in viewed[i.id]:
        skipped[i.id] = skipped.get(i.id, 0) + 1

  item_count = len(items)

  item_counts = {}

  for d in decisions:
    a = d.annotator_id
    w = d.winner_id
    l = d.loser_id
    item_counts[w] = item_counts.get(w, 0) + 1
    item_counts[l] = item_counts.get(l, 0) + 1

  dump_data = {
    "items": [it.to_dict() if it else {'null': 'null'} for it in items],
    "viewed": viewed,
    "skipped": skipped,
    "item_count": item_count,
    "item_counts": item_counts
  }

  response = app.response_class(
    response=json.dumps(dump_data),
    status=200,
    mimetype='application/json'
  )

  return response