コード例 #1
0
ファイル: preview.py プロジェクト: pinheiroo27/ontask_b
def preview_response(
    request: http.HttpRequest,
    pk: int,
    idx: int,
    workflow: Optional[models.Workflow] = None,
    action: Optional[models.Action] = None,
) -> http.JsonResponse:
    """Preview content of action.

    HTML request and the primary key of an action to preview one of its
    instances. The request must provide and additional parameter idx to
    denote which instance to show.

    :param request: HTML request object
    :param pk: Primary key of the an action for which to do the preview
    :param idx: Index of the reponse to preview
    :param workflow: Current workflow being manipulated
    :param action: Might have been fetched already
    :return: http.JsonResponse
    """
    del pk, workflow
    # If the request has the 'action_content', update the action
    action_content = request.POST.get('action_content')
    if action_content:
        action.set_text_content(action_content)

    # Initial context to render the response page.
    context = {'action': action, 'index': idx}
    if (action.action_type == models.Action.EMAIL_REPORT
            or action.action_type == models.Action.JSON_REPORT):
        services.create_list_preview_context(action, context)
    else:
        services.create_row_preview_context(action, idx, context,
                                            request.GET.get('subject_content'))
    print(request.content_params)
    print(request.path)
    print(request.POST.items())
    print(request.POST.values())
    print(request.POST.get('action_content'))
    print(context)
    return http.JsonResponse({
        'html_form':
        render_to_string('action/includes/partial_preview.html',
                         context,
                         request=request)
    })
コード例 #2
0
ファイル: preview.py プロジェクト: pinheiroo27/ontask_b
def init_classifier(
    request: http.HttpRequest,
    pk: int,
    idx: int,
    workflow: Optional[models.Workflow] = None,
    action: Optional[models.Action] = None,
) -> http.JsonResponse:
    """Preview content of action.

    HTML request and the primary key of an action to preview one of its
    instances. The request must provide and additional parameter idx to
    denote which instance to show.

    :param request: HTML request object
    :param pk: Primary key of the an action for which to do the preview
    :param idx: Index of the reponse to preview
    :param workflow: Current workflow being manipulated
    :param action: Might have been fetched already
    :return: http.JsonResponse
    """
    del pk, workflow
    # If the request has the 'action_content', update the action
    action_content = request.POST.get('action_content')

    csv_classes = 'classes.csv'
    classes = read_classes(csv_classes)

    csv_features = 'features.csv'
    data_train, features = read_data(csv_features)

    data = {}
    for j in range(len(classes)):
        resultados = {}
        resultados.update({'ntree': []})
        resultados.update({'mtry': []})
        resultados.update({'acurácia': []})
        resultados.update({'kappa': []})
        resultados.update({'accuracy': []})
        resultados.update({'erro': []})
        resultados.update({"erro_classe_" + str(0): []})
        resultados.update({"erro_classe_" + str(1): []})

        y_train = classes[j]

        global classifiers
        resultados, classifiers[j] = cross_validation(features,
                                                      y_train,
                                                      k=10,
                                                      ntree=500,
                                                      mtry=37,
                                                      resultados=resultados)
        print(resultados)
        data['dados'] = "Ready"

    if action_content:
        action.set_text_content(data['dados'])
    print("ACTION CONTENT - PREVIEW: " + action_content)
    # Initial context to render the response page.
    context = {'action': action, 'index': idx}
    print(context)
    if (action.action_type == models.Action.EMAIL_REPORT
            or action.action_type == models.Action.JSON_REPORT):
        services.create_list_preview_context(action, context)
    else:
        services.create_row_preview_context(action, idx, context,
                                            request.GET.get('subject_content'))
    print(request.path)
    # new_url = str(request.path).replace('1/classifier/', 'edit/')
    # print(new_url)
    print(request.GET.get('subject_content'))
    # context.update({'show_values': 'yes'})
    return http.JsonResponse({
        'html_form':
        render_to_string('action/includes/partial_preview_feedback.html',
                         context,
                         request=request)
    })
コード例 #3
0
ファイル: preview.py プロジェクト: pinheiroo27/ontask_b
def preview_feedback(
    request: http.HttpRequest,
    pk: int,
    idx: int,
    workflow: Optional[models.Workflow] = None,
    action: Optional[models.Action] = None,
) -> http.JsonResponse:
    """Preview content of action.

    HTML request and the primary key of an action to preview one of its
    instances. The request must provide and additional parameter idx to
    denote which instance to show.

    :param request: HTML request object
    :param pk: Primary key of the an action for which to do the preview
    :param idx: Index of the reponse to preview
    :param workflow: Current workflow being manipulated
    :param action: Might have been fetched already
    :return: http.JsonResponse
    """
    del pk, workflow
    # If the request has the 'action_content', update the action
    action_content = request.POST.get('action_content')
    texto = str(action_content).replace("<p>", "").replace("</p>", "")
    data = {}
    data_string = ""

    sentence_clean = clean_sentence(texto)
    liwc = extract_liwc(sentence_clean)
    adds = additionals(sentence_clean)
    cohmetrix = extract_features_cohmetrix(sentence_clean)
    # cohmetrix = [1, 1, 10, 1.0, 0.0, 8.0, 0.0, 2.2, 1.398411797560202, 5.5, 2.958039891549808, 0,
    #              0, -1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0,
    #              1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
    #              0.0, 0.0, 0.0, 0.0, 0.0, 2.0, -1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0,
    #              2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 6.646578958679581, 1.8941022799930982, 6.646578958679581,
    #              383.0, 584.6666666666666, 302.0, 357.3333333333333, 386.6666666666667,
    #              -12.784999999999997, 17.029999999999998, 0]
    features = []
    for x in liwc:
        features.append(x)
    for y in cohmetrix:
        features.append(y)
    features.append(adds[0])
    features.append(adds[1])
    features.append(adds[2])

    newfeatures = []
    newfeatures.append(features)
    np_features = np.asarray(newfeatures)

    for j in range(11):
        if j == 1 or j == 3 or j == 6 or j == 9:
            y_pred = 0
        else:
            global classifiers
            y_pred = classifiers[j].predict(np_features)
        print("classe predita ", y_pred)
        data['classe' + str(j)] = y_pred[0]
        data_string += 'classe' + str(j + 1) + ": " + str(y_pred[0]) + " <br> "

    if action_content:
        action.set_text_content(action_content)
    print("ACTION CONTENT - PREVIEW: " + action_content)
    # Initial context to render the response page.
    context = {'action': action, 'index': idx}
    print(context)
    if (action.action_type == models.Action.EMAIL_REPORT
            or action.action_type == models.Action.JSON_REPORT):
        services.create_list_preview_context(action, context)
    else:
        services.create_row_preview_context(action, idx, context,
                                            request.GET.get('subject_content'))
    print(request)
    print(request.GET.get('subject_content'))
    print(context)
    # context.update({'data': data})
    # data = {}
    for i in range(0, 11):
        if i % 2 == 0:
            context.update({'classe' + str(i): data['classe' + str(i)]})
        else:
            context.update({'classe' + str(i): data['classe' + str(i)]})
    return http.JsonResponse({
        'html_form':
        render_to_string(
            'action/includes/partial_preview_feedback_result.html',
            context,
            request=request)
    })