from gavel import app
from gavel.models import *
import gavel.utils as utils
from flask import Response

@app.route('/api/items.csv')
@utils.requires_auth
def item_dump():
    items = Item.query.order_by(desc(Item.mu)).all()
    data = [['Mu', 'Sigma Squared', 'Name', 'Location', 'Description', 'Active']]
    data += [[
        str(item.mu),
        str(item.sigma_sq),
        item.name,
        item.location,
        item.description,
        item.active
    ] for item in items]
    return Response(utils.data_to_csv_string(data), mimetype='text/csv')

@app.route('/api/annotators.csv')
@utils.requires_auth
def annotator_dump():
    annotators = Annotator.query.all()
    data = [['Name', 'Email', 'Description', 'Secret']]
    data += [[str(a.name), a.email, a.description, a.secret] for a in annotators]
    return Response(utils.data_to_csv_string(data), mimetype='text/csv')

from gavel import app
from gavel.models import *
import gavel.utils as utils
from flask import Response

@app.route('/api/items.csv')
@utils.requires_auth
def item_dump():
    items = Item.query.order_by(desc(Item.mu)).all()
    data = [['Mu', 'Sigma Squared', 'Name', 'Location', 'Description', 'Active']]
    data += [[
        str(item.mu),
        str(item.sigma_sq),
        item.name,
        item.location,
        item.description,
        item.active
    ] for item in items]
    return Response(utils.data_to_csv_string(data), mimetype='text/csv')

@app.route('/api/annotators.csv')
@utils.requires_auth
def annotator_dump():
    annotators = Annotator.query.all()
    data = [['Name', 'Email', 'Description', 'Secret']]
    data += [[
        str(a.name),
        a.email,
        a.description,
        a.secret
    ] for a in annotators]
    return Response(utils.data_to_csv_string(data), mimetype='text/csv')

@app.route('/api/decisions.csv')
@utils.requires_auth
def decisions_dump():
    decisions = Decision.query.all()
    data = [['Annotator ID', 'Winner ID', 'Loser ID', 'Time']]
    data += [[
        str(d.annotator.id),
        str(d.winner.id),
        str(d.loser.id),
        str(d.time)
    ] for d in decisions]
    return Response(utils.data_to_csv_string(data), mimetype='text/csv')

Add API endpoint for getting decisions
Add API endpoint for getting decisions

  from gavel import app
  from gavel.models import *
  import gavel.utils as utils
  from flask import Response
  
  @app.route('/api/items.csv')
  @utils.requires_auth
  def item_dump():
      items = Item.query.order_by(desc(Item.mu)).all()
      data = [['Mu', 'Sigma Squared', 'Name', 'Location', 'Description', 'Active']]
      data += [[
          str(item.mu),
          str(item.sigma_sq),
          item.name,
          item.location,
          item.description,
          item.active
      ] for item in items]
      return Response(utils.data_to_csv_string(data), mimetype='text/csv')
  
  @app.route('/api/annotators.csv')
  @utils.requires_auth
  def annotator_dump():
      annotators = Annotator.query.all()
      data = [['Name', 'Email', 'Description', 'Secret']]
-     data += [[str(a.name), a.email, a.description, a.secret] for a in annotators]
+     data += [[
+         str(a.name),
+         a.email,
+         a.description,
+         a.secret
+     ] for a in annotators]
      return Response(utils.data_to_csv_string(data), mimetype='text/csv')
  
+ @app.route('/api/decisions.csv')
+ @utils.requires_auth
+ def decisions_dump():
+     decisions = Decision.query.all()
+     data = [['Annotator ID', 'Winner ID', 'Loser ID', 'Time']]
+     data += [[
+         str(d.annotator.id),
+         str(d.winner.id),
+         str(d.loser.id),
+         str(d.time)
+     ] for d in decisions]
+     return Response(utils.data_to_csv_string(data), mimetype='text/csv')
+ 
Add API endpoint for getting decisions
## Code Before:
from gavel import app
from gavel.models import *
import gavel.utils as utils
from flask import Response

@app.route('/api/items.csv')
@utils.requires_auth
def item_dump():
    items = Item.query.order_by(desc(Item.mu)).all()
    data = [['Mu', 'Sigma Squared', 'Name', 'Location', 'Description', 'Active']]
    data += [[
        str(item.mu),
        str(item.sigma_sq),
        item.name,
        item.location,
        item.description,
        item.active
    ] for item in items]
    return Response(utils.data_to_csv_string(data), mimetype='text/csv')

@app.route('/api/annotators.csv')
@utils.requires_auth
def annotator_dump():
    annotators = Annotator.query.all()
    data = [['Name', 'Email', 'Description', 'Secret']]
    data += [[str(a.name), a.email, a.description, a.secret] for a in annotators]
    return Response(utils.data_to_csv_string(data), mimetype='text/csv')

## Instruction:
Add API endpoint for getting decisions
## Code After:
from gavel import app
from gavel.models import *
import gavel.utils as utils
from flask import Response

@app.route('/api/items.csv')
@utils.requires_auth
def item_dump():
    items = Item.query.order_by(desc(Item.mu)).all()
    data = [['Mu', 'Sigma Squared', 'Name', 'Location', 'Description', 'Active']]
    data += [[
        str(item.mu),
        str(item.sigma_sq),
        item.name,
        item.location,
        item.description,
        item.active
    ] for item in items]
    return Response(utils.data_to_csv_string(data), mimetype='text/csv')

@app.route('/api/annotators.csv')
@utils.requires_auth
def annotator_dump():
    annotators = Annotator.query.all()
    data = [['Name', 'Email', 'Description', 'Secret']]
    data += [[
        str(a.name),
        a.email,
        a.description,
        a.secret
    ] for a in annotators]
    return Response(utils.data_to_csv_string(data), mimetype='text/csv')

@app.route('/api/decisions.csv')
@utils.requires_auth
def decisions_dump():
    decisions = Decision.query.all()
    data = [['Annotator ID', 'Winner ID', 'Loser ID', 'Time']]
    data += [[
        str(d.annotator.id),
        str(d.winner.id),
        str(d.loser.id),
        str(d.time)
    ] for d in decisions]
    return Response(utils.data_to_csv_string(data), mimetype='text/csv')
