Exemple #1
0
def correct_transcriptions(request):
    fi_dict = {}
    for form_image in FormImage.objects.all():
        correct_transcription = {}

        add_to_correct_transcription(
            correct_transcription,
            utils.load_json_to_pyobj(
                os.path.join(form_image.output_path, 'output.json')))

        user_dir = os.path.join(form_image.output_path, 'users')
        user_list = []
        if os.path.exists(user_dir):
            user_list = os.listdir(user_dir)
            for user in user_list:
                if user in excluded_users:
                    continue
                json_path = os.path.join(user_dir, user, 'output.json')
                pyobj = utils.load_json_to_pyobj(json_path)
                add_to_correct_transcription(correct_transcription, pyobj)
        add_ground_truth_length(correct_transcription)
        fi_dict[str(form_image)] = correct_transcription
        utils.print_pyobj_to_json(
            correct_transcription,
            os.path.join(form_image.output_path, 'corrected.json'))
    return HttpResponse("corrected", mimetype="application/json")
def gen_analysis_dict(userFilter=(lambda k: True)):
    fi_dict = {}
    for form_image in FormImage.objects.all():
        if str(form_image)[0] == "J":
            # Filter out practice forms
            continue
        ground_truth = utils.load_json_to_pyobj(os.path.join(form_image.output_path, "corrected.json"))
        user_dir = os.path.join(form_image.output_path, "users")
        user_list = []
        user_dict = {}
        if os.path.exists(user_dir):
            user_list = os.listdir(user_dir)
            for user in user_list:
                if user in excluded_users:
                    continue
                userObject = User.objects.get(username=user)
                if not userFilter(userObject):
                    continue
                json_path = os.path.join(
                    os.path.join(form_image.output_path, "users"), userObject.username, "output.json"
                )
                pyobj = utils.load_json_to_pyobj(json_path)
                kwargs = {
                    "form_image": form_image,
                    "userObject": userObject,
                    "pyobj": pyobj,
                    "ground_truth": ground_truth,
                }
                user_dict[str(form_image)] = genStats(**kwargs)
                fi_dict[user] = fi_dict.get(user, {})
                fi_dict[user].update(user_dict)
    return fi_dict
Exemple #3
0
def gen_analysis_dict(userFilter=(lambda k: True)):
    fi_dict = {}
    for form_image in FormImage.objects.all():
        if str(form_image)[0] == 'J':
            #Filter out practice forms
            continue
        ground_truth = utils.load_json_to_pyobj(
            os.path.join(form_image.output_path, 'corrected.json'))
        user_dir = os.path.join(form_image.output_path, 'users')
        user_list = []
        user_dict = {}
        if os.path.exists(user_dir):
            user_list = os.listdir(user_dir)
            for user in user_list:
                if user in excluded_users:
                    continue
                userObject = User.objects.get(username=user)
                if not userFilter(userObject):
                    continue
                json_path = os.path.join(
                    os.path.join(form_image.output_path, 'users'),
                    userObject.username, 'output.json')
                pyobj = utils.load_json_to_pyobj(json_path)
                kwargs = {
                    'form_image': form_image,
                    'userObject': userObject,
                    'pyobj': pyobj,
                    'ground_truth': ground_truth
                }
                user_dict[str(form_image)] = genStats(**kwargs)
                fi_dict[user] = fi_dict.get(user, {})
                fi_dict[user].update(user_dict)
    return fi_dict
Exemple #4
0
def analyse_target(request, userName=None, formName=None):
    if not userName or not formName:
        return HttpResponse("no user/form name", mimetype="application/json")
    form_image = FormImage.objects.get(image__contains='/photo/' + formName)
    userObject = User.objects.get(username=userName)
    ground_truth = utils.load_json_to_pyobj(
        os.path.join(form_image.output_path, 'corrected.json'))
    json_path = os.path.join(os.path.join(form_image.output_path, 'users'),
                             userObject.username, 'output.json')
    pyobj = utils.load_json_to_pyobj(json_path)
    kwargs = {
        'form_image': form_image,
        'userObject': userObject,
        'pyobj': pyobj,
        'ground_truth': ground_truth
    }
    userFormStats = genStats(**kwargs)
    filter_fields(pyobj['fields'])
    t = loader.get_template('analyseUserForm.html')
    c = RequestContext(
        request, {
            "userFormStats": userFormStats,
            "ground_truth": json.dumps(ground_truth, indent=4),
            "transciption": json.dumps(pyobj, indent=4),
        })
    return HttpResponse(t.render(c))
def generateAndroidOutput(request):
    output = ""
    # Create the output files from the log items
    view_regex = re.compile(r"^android-condition(?P<showSegs>_showSegs)?(?P<autofill>_autofill)?$")
    for form_image in FormImage.objects.all():
        if str(form_image)[0] == "J":
            # Filter out practice forms
            continue
        for user in User.objects.all():
            if user in excluded_users:
                continue
            filtered_li = LogItem.objects.filter(
                formImage=form_image, user=user, activity__in=["android-text changed", "android-answer selected"]
            )
            if len(filtered_li) > 0:
                path_to_initial_json = os.path.join(form_image.output_path, "output.json")
                initial_json = utils.load_json_to_pyobj(path_to_initial_json)
                viewParse = view_regex.search(filtered_li[0].view).groupdict()
                initial_json["autofill"] = bool(viewParse.get("autofill"))
                initial_json["showSegs"] = bool(viewParse.get("showSegs"))
                initial_json["formView"] = False
                initial_json["tableView"] = False
                initial_json["android"] = True
                for field in initial_json["fields"]:
                    ordered_field_li = filtered_li.filter(fieldName=field["name"]).order_by("-timestamp")
                    if len(ordered_field_li) > 0:
                        field["transcription"] = ordered_field_li[0].newValue
                    else:
                        pass
                user_json_path = os.path.join(form_image.output_path, "users", user.username, "output.json")
                if os.path.exists(user_json_path):
                    raise Exception("path exists: " + user_json_path)
                output += user_json_path + "\n"
                utils.print_pyobj_to_json(initial_json, user_json_path)
    return HttpResponse(output, mimetype="application/json")
def fillUserFormCondition(request):
    fi_dict = {}
    for form_image in FormImage.objects.all():
        user_dir = os.path.join(form_image.output_path, "users")
        user_list = []
        user_dict = {}
        if os.path.exists(user_dir):
            user_list = os.listdir(user_dir)
            for user in user_list:
                if user in excluded_users:
                    continue
                userObject = User.objects.get(username=user)
                # Filter by user properties here
                json_path = os.path.join(user_dir, user, "output.json")
                pyobj = utils.load_json_to_pyobj(json_path)
                try:
                    UserFormCondition.objects.create(
                        user=userObject,
                        formImage=form_image,
                        tableView=(not pyobj.get("formView", False) and not pyobj.get("android", False)),
                        formView=pyobj.get("formView", False),
                        showSegs=pyobj.get("showSegs", False),
                        autofill=pyobj.get("autofill", False),
                    ).save()
                except:
                    pass
    return HttpResponse("done", mimetype="application/json")
Exemple #7
0
def fillUserFormCondition(request):
    fi_dict = {}
    for form_image in FormImage.objects.all():
        user_dir = os.path.join(form_image.output_path, 'users')
        user_list = []
        user_dict = {}
        if os.path.exists(user_dir):
            user_list = os.listdir(user_dir)
            for user in user_list:
                if user in excluded_users:
                    continue
                userObject = User.objects.get(username=user)
                #Filter by user properties here
                json_path = os.path.join(user_dir, user, 'output.json')
                pyobj = utils.load_json_to_pyobj(json_path)
                try:
                    UserFormCondition.objects.create(
                        user=userObject,
                        formImage=form_image,
                        tableView=(not pyobj.get('formView', False)
                                   and not pyobj.get('android', False)),
                        formView=pyobj.get('formView', False),
                        showSegs=pyobj.get('showSegs', False),
                        autofill=pyobj.get('autofill', False)).save()
                except:
                    pass
    return HttpResponse("done", mimetype="application/json")
def analyse_target(request, userName=None, formName=None):
    if not userName or not formName:
        return HttpResponse("no user/form name", mimetype="application/json")
    form_image = FormImage.objects.get(image__contains="/photo/" + formName)
    userObject = User.objects.get(username=userName)
    ground_truth = utils.load_json_to_pyobj(os.path.join(form_image.output_path, "corrected.json"))
    json_path = os.path.join(os.path.join(form_image.output_path, "users"), userObject.username, "output.json")
    pyobj = utils.load_json_to_pyobj(json_path)
    kwargs = {"form_image": form_image, "userObject": userObject, "pyobj": pyobj, "ground_truth": ground_truth}
    userFormStats = genStats(**kwargs)
    filter_fields(pyobj["fields"])
    t = loader.get_template("analyseUserForm.html")
    c = RequestContext(
        request,
        {
            "userFormStats": userFormStats,
            "ground_truth": json.dumps(ground_truth, indent=4),
            "transciption": json.dumps(pyobj, indent=4),
        },
    )
    return HttpResponse(t.render(c))
def correct_transcriptions(request):
    fi_dict = {}
    for form_image in FormImage.objects.all():
        correct_transcription = {}

        add_to_correct_transcription(
            correct_transcription, utils.load_json_to_pyobj(os.path.join(form_image.output_path, "output.json"))
        )

        user_dir = os.path.join(form_image.output_path, "users")
        user_list = []
        if os.path.exists(user_dir):
            user_list = os.listdir(user_dir)
            for user in user_list:
                if user in excluded_users:
                    continue
                json_path = os.path.join(user_dir, user, "output.json")
                pyobj = utils.load_json_to_pyobj(json_path)
                add_to_correct_transcription(correct_transcription, pyobj)
        add_ground_truth_length(correct_transcription)
        fi_dict[str(form_image)] = correct_transcription
        utils.print_pyobj_to_json(correct_transcription, os.path.join(form_image.output_path, "corrected.json"))
    return HttpResponse("corrected", mimetype="application/json")
Exemple #10
0
def generateAndroidOutput(request):
    output = ''
    #Create the output files from the log items
    view_regex = re.compile(
        r"^android-condition(?P<showSegs>_showSegs)?(?P<autofill>_autofill)?$")
    for form_image in FormImage.objects.all():
        if str(form_image)[0] == 'J':
            #Filter out practice forms
            continue
        for user in User.objects.all():
            if user in excluded_users:
                continue
            filtered_li = LogItem.objects.filter(formImage=form_image,
                                                 user=user,
                                                 activity__in=[
                                                     'android-text changed',
                                                     'android-answer selected'
                                                 ])
            if len(filtered_li) > 0:
                path_to_initial_json = os.path.join(form_image.output_path,
                                                    'output.json')
                initial_json = utils.load_json_to_pyobj(path_to_initial_json)
                viewParse = view_regex.search(filtered_li[0].view).groupdict()
                initial_json['autofill'] = bool(viewParse.get('autofill'))
                initial_json['showSegs'] = bool(viewParse.get('showSegs'))
                initial_json['formView'] = False
                initial_json['tableView'] = False
                initial_json['android'] = True
                for field in initial_json['fields']:
                    ordered_field_li = filtered_li.filter(
                        fieldName=field['name']).order_by('-timestamp')
                    if len(ordered_field_li) > 0:
                        field['transcription'] = ordered_field_li[0].newValue
                    else:
                        pass
                user_json_path = os.path.join(form_image.output_path, 'users',
                                              user.username, 'output.json')
                if os.path.exists(user_json_path):
                    raise Exception('path exists: ' + user_json_path)
                output += user_json_path + '\n'
                utils.print_pyobj_to_json(initial_json, user_json_path)
    return HttpResponse(output, mimetype="application/json")