コード例 #1
0
def header_error_page(category):
    wrongheaders = session['wrongheaders']
    survey = load_survey(session["survey_path"], session['save_session'])    
    survey.set_cleaning_params(session["survey_category"], 
                               session["survey_path"])
    mlist = MasterList(category)
    mlist.load_db(current_app.mongocl)
    
    correction_form = HeaderCorrectionForm()
    correction_form.headers.choices = [(c,c) for c in survey.columns]
    
    if correction_form.validate_on_submit():
        headers = correction_form.headers.data
        survey.unkmap, survey.problems = survey.gen_unkmap(mlist, headers)
        
        survey.start = 0
        probs = survey.problems
        survey.end = PER_PAGE if len(probs) >= PER_PAGE else len(probs)
        survey.save_session(current_app.mongocl)
        
        total_probs = len(survey.problems)
        return redirect(
            url_for(
                "surveycommander.cleaning",
                start=survey.start,
                end=survey.end,
                total_probs=total_probs,
                final=False if len(survey.problems) >= PER_PAGE else True
            )
        )
    else:
        return render_template("surveycommander/header_error_page.html", 
                               wrongheaders=wrongheaders, category=category,
                               form=correction_form)
コード例 #2
0
def load_masterlist(survey, db=None):
    if db:
        mlist = MasterList(survey.category, database=db)
    else:
        mlist = MasterList(survey.category)
    mlist.load_db(current_app.mongocl)
    return mlist
コード例 #3
0
def init_clean():
    """
    """
    saved_session = current_app.mongocl.synthesis.surcom_sessions.find_one(
        {"name": session["save_session"]}
    )
    name = None
    if saved_session:
        if not session["survey_path"]:
            session["survey_path"] = saved_session['surpath']
        elif session["survey_path"] != saved_session['surpath']:
            msg = "Uploaded file does not match survey saved in session '{}'"
            flash(msg.format(session["save_session"]))
            return redirect(url_for("surveycommander.suropt_select"))
    else:
        if not session["survey_path"]:
            msg = "Session '{}' not found, and no path to survey file given!"
            flash(msg.format(session["save_session"]))
            return redirect(url_for("surveycommander.suropt_select"))
        else:
            name = session["save_session"]

    survey = load_survey(session["survey_path"], name)
        
    swap_to_past_section = False
    onunseen_section = True
    if saved_session:
        swap_category = False
        oncurrent_section = session['survey_category'] == saved_session['category']
        if not oncurrent_section:
            past_sections = json.loads(saved_session['other_sections']).keys()
            swap_to_past_section = session['survey_category'] in past_sections
            if not swap_to_past_section:
                onunseen_section = True
        else:
            onunseen_section = False
        survey.load_session(current_app.mongocl, name=session["save_session"])
        swap_category = survey.category != session["survey_category"]
        if swap_category:
            survey.stash_section()
            survey.set_cleaning_params(session["survey_category"])
    else:
        survey.set_cleaning_params(session["survey_category"],
                                   session["survey_path"])

    mlist = MasterList(survey.category)
    mlist.load_db(current_app.mongocl)
    cols = mlist.map_section_name_to_col_headers(
        current_app.mongocl,
        session["rep_config"],
        survey.category
    )

    if saved_session and swap_to_past_section:
        # TODO: next line is unDRY as it is in next elif
        survey.load_section(session["survey_category"])
        survey.save_session(current_app.mongocl)
    elif not saved_session or (saved_session and onunseen_section):
        try:
            survey.unkmap, survey.problems = survey.gen_unkmap(mlist, cols)
        except KeyError as ke:
            bad_cols = [col for col in cols if not col in survey.columns]
            session['wrongheaders'] = bad_cols
            return redirect(
                url_for(
                    "surveycommander.header_error_page",
                    category=survey.category
                )
            )
        survey.start = 0
        probs = survey.problems
        survey.end = PER_PAGE if len(probs) >= PER_PAGE else len(probs)
        survey.save_session(current_app.mongocl)

    total_probs = len(survey.problems)
    return redirect(
        url_for(
            "surveycommander.cleaning",
            start=survey.start,
            end=survey.end,
            total_probs=total_probs,
            final=False if len(survey.problems) >= PER_PAGE else True
        )
    )