Пример #1
0
def start_batch(request, mongo):
    #Get fields from form
    try:
        codebook_id = request.POST["codebook_id"]
        collection_id = request.POST["collection_id"]
        pct_overlap = request.POST["pct_overlap"]

        coders = []
        for field in request.POST:
            if re.match('coder\d+', field):
                coders.append(request.POST[field])

        shuffle = "shuffle" in request.POST

    except MultiValueDictKeyError:
        return gen_json_response({"status": "failed", "msg": "Missing field."})

    #! Validate fields
    try:
        assert len(coders) > 0
    except (AssertionError, ) as e:
        return gen_json_response({
            "status": "failed",
            "msg": "You must include at least one coder."
        })

    try:
        pct_overlap = float(pct_overlap)
        assert pct_overlap >= 0
        assert pct_overlap <= 100
    except (AssertionError, ValueError) as e:
        return gen_json_response({
            "status":
            "failed",
            "msg":
            "Overlap must be a percentage between 0 and 100."
        })

    #Get a handle to the batch collection in mongo
    coll = mongo.get_collection("tb_app_batch")

    #Count existing batches
    count = coll.find().count()

    #Retrieve the codebook and collection
    codebook = mongo.get_collection("tb_app_codebook").find_one(
        {"_id": ObjectId(codebook_id)})
    collection = mongo.get_collection("tb_app_collection").find_one(
        {"_id": ObjectId(collection_id)})

    batch = models.get_new_batch_json(count, coders, pct_overlap, shuffle,
                                      codebook, collection)

    batch_id = coll.insert(batch)
    models.update_batch_progress(batch_id)

    return gen_json_response({
        "status": "success",
        "msg": "New batch created."
    })
Пример #2
0
def batch(request, mongo, id_):
    models.update_batch_progress(id_)
    models.update_batch_reliability(id_)

    batch = mongo.get_collection("tb_app_batch").find_one(
        {"_id": ObjectId(id_)},
        fields={
            "profile": 1,
            "reports": 1,
            "documents": 1
        })
    #print json.dumps(batch, cls=MongoEncoder, indent=1)

    result = {
        'batch':
        batch,
        'codebook':
        mongo.get_collection("tb_app_codebook").find_one(
            {"_id": ObjectId(batch["profile"]["codebook_id"])}, {
                "profile": 1,
                "variables": 1
            }),
        'collection':
        mongo.get_collection("tb_app_collection").find_one(
            {"_id": ObjectId(batch["profile"]["collection_id"])},
            {"profile": 1}),
        'users':
        jsonifyRecords(User.objects.all(), [
            'username', 'first_name', 'last_name', 'email', 'is_active',
            'is_superuser'
        ]),
    }
    return render_to_response('batch.html',
                              result,
                              context_instance=RequestContext(request))
Пример #3
0
def my_account(request, mongo):
    batches = list(mongo.get_collection("tb_app_batch").find(
        {"profile.coders": {"$in": [request.user.username]}},
        fields={"profile": 1, "reports.progress": 1}, sort=[('profile.created_at', 1)]
    ))

    for b in batches:
        models.update_batch_progress(b["_id"])

    result = {
        'assignments': batches,
    }

    return render_to_response('my-account.html', result, context_instance=RequestContext(request))
Пример #4
0
def start_batch(request, mongo):
    #Get fields from form
    try:
        codebook_id = request.POST["codebook_id"]
        collection_id = request.POST["collection_id"]
        pct_overlap = request.POST["pct_overlap"]

        coders = []
        for field in request.POST:
            if re.match('coder\d+', field):
                coders.append(request.POST[field])

        shuffle = "shuffle" in request.POST

    except MultiValueDictKeyError:
        return gen_json_response({"status": "failed", "msg": "Missing field."})

    #! Validate fields
    try:
        assert len(coders) > 0
    except (AssertionError,) as e:
        return gen_json_response({"status": "failed", "msg": "You must include at least one coder."})

    try:
        pct_overlap = float(pct_overlap)
        assert pct_overlap >= 0
        assert pct_overlap <= 100
    except (AssertionError, ValueError) as e:
        return gen_json_response({"status": "failed", "msg": "Overlap must be a percentage between 0 and 100."})

    #Get a handle to the batch collection in mongo
    coll = mongo.get_collection("tb_app_batch")

    #Count existing batches
    count = coll.find().count()

    #Retrieve the codebook and collection
    codebook = mongo.get_collection("tb_app_codebook").find_one({"_id": ObjectId(codebook_id)})
    collection = mongo.get_collection("tb_app_collection").find_one({"_id": ObjectId(collection_id)})

    batch = models.get_new_batch_json(count, coders, pct_overlap, shuffle, codebook, collection)

    batch_id = coll.insert(batch)
    models.update_batch_progress(batch_id)

    return gen_json_response({"status": "success", "msg": "New batch created."})
Пример #5
0
def shared_resources(request, mongo):
    codebooks = list(
        mongo.get_collection("tb_app_codebook").find(
            sort=[('profile.created_at', 1)]))
    #! This is migration code to add 'variables' objects to all codebooks
    for c in codebooks:
        c["variables"] = models.get_codebook_variables_from_questions(
            c["questions"])
        mongo.get_collection("tb_app_codebook").save(c)

    batches = list(
        mongo.get_collection("tb_app_batch").find(fields={
            "profile": 1,
            "reports": 1
        },
                                                  sort=[('profile.created_at',
                                                         1)]))

    for b in batches:
        models.update_batch_progress(b["_id"])
        models.update_batch_reliability(b["_id"])


#    print list(mongo.get_collection("tb_app_codebook").find(sort=[('created_at',1)]))
    result = {
        'codebooks':
        codebooks,
        'collections':
        list(
            mongo.get_collection("tb_app_collection").find(
                fields={"profile": 1
                        })),  #fields={"id": 1, "name": 1, "description": 1})),
        'batches':
        batches,
        'users':
        jsonifyRecords(User.objects.all(), [
            'username', 'first_name', 'last_name', 'email', 'is_active',
            'is_superuser'
        ]),
    }
    #print json.dumps(result, indent=2, cls=MongoEncoder)

    return render_to_response('shared-resources.html',
                              result,
                              context_instance=RequestContext(request))
Пример #6
0
def batch(request, mongo, id_):
    models.update_batch_progress(id_)
    models.update_batch_reliability(id_)

    batch = mongo.get_collection("tb_app_batch").find_one({"_id": ObjectId(id_)}, fields={"profile": 1, "reports": 1, "documents": 1})
    #print json.dumps(batch, cls=MongoEncoder, indent=1)


    result = {
        'batch': batch,
        'codebook': mongo.get_collection("tb_app_codebook").find_one(
            {"_id": ObjectId(batch["profile"]["codebook_id"])},
            {"profile":1, "variables":1}
        ),
        'collection': mongo.get_collection("tb_app_collection").find_one(
            {"_id": ObjectId(batch["profile"]["collection_id"])},
            {"profile":1}
        ),
        'users': jsonifyRecords(User.objects.all(), ['username', 'first_name', 'last_name', 'email', 'is_active', 'is_superuser']),
    }
    return render_to_response('batch.html', result, context_instance=RequestContext(request))
Пример #7
0
def my_account(request, mongo):
    batches = list(
        mongo.get_collection("tb_app_batch").find(
            {"profile.coders": {
                "$in": [request.user.username]
            }},
            fields={
                "profile": 1,
                "reports.progress": 1
            },
            sort=[('profile.created_at', 1)]))

    for b in batches:
        models.update_batch_progress(b["_id"])

    result = {
        'assignments': batches,
    }

    return render_to_response('my-account.html',
                              result,
                              context_instance=RequestContext(request))
Пример #8
0
def shared_resources(request, mongo):
    codebooks = list(mongo.get_collection("tb_app_codebook").find(sort=[('profile.created_at', 1)]))
    #! This is migration code to add 'variables' objects to all codebooks
    for c in codebooks:
        c["variables"] = models.get_codebook_variables_from_questions(c["questions"])
        mongo.get_collection("tb_app_codebook").save(c)

    batches = list(mongo.get_collection("tb_app_batch").find(fields={"profile": 1, "reports": 1}, sort=[('profile.created_at', 1)]))

    for b in batches:
        models.update_batch_progress(b["_id"])
        models.update_batch_reliability(b["_id"])

#    print list(mongo.get_collection("tb_app_codebook").find(sort=[('created_at',1)]))
    result = {
        'codebooks': codebooks,
        'collections': list(mongo.get_collection("tb_app_collection").find(fields={"profile":1})),#fields={"id": 1, "name": 1, "description": 1})),
        'batches': batches,
        'users': jsonifyRecords(User.objects.all(), ['username', 'first_name', 'last_name', 'email', 'is_active', 'is_superuser']),
    }
    #print json.dumps(result, indent=2, cls=MongoEncoder)

    return render_to_response('shared-resources.html', result, context_instance=RequestContext(request))