def date_handler(request):
    start_date = request.args.get("start-date", None)
    end_date = request.args.get("end-date", None)

    if start_date is None or end_date is None:
        raise (BertException(
            "Invalid request, missing required date parameters", 400))

    if not validate_date(start_date) or not validate_date(end_date):
        raise (BertException("Invalid request, date is not valid", 400))

    return start_date, end_date
Ejemplo n.º 2
0
def number_of_records_which_has_status(records: pd.DataFrame,
                                       status: str) -> int:
    try:
        return len(records.loc[records["status"] == status])
    except Exception as err:
        raise BertException(
            f"number_of_records_which_has_status failed: {err}", 400)
Ejemplo n.º 3
0
def test_call_pattern_report_returns_error(mock_get_call_pattern_records,
                                           client):
    mock_get_call_pattern_records.side_effect = BertException(
        "Invalid date range parameters provided", 400)
    response = client.get(
        "/api/reports/call-pattern/matpal?start-date=2021-01-01&end-date=2021-01-01"
    )
    assert response.status_code == 400
    assert response.get_data(
        as_text=True) == '{"error": "Invalid date range parameters provided"}'
def get_call_history_records(interviewer_name,
                             start_date_string,
                             end_date_string,
                             survey_tla=None,
                             questionnaires=None):
    start_date, end_date = parse_dates(start_date_string, end_date_string)
    if is_invalid(start_date) or is_invalid(end_date):
        raise BertException("Invalid date range parameters provided", 400)
    records = get_datastore_records(interviewer_name, start_date, end_date,
                                    survey_tla, questionnaires)
    results = identify_webnudge_cases(records)
    return results
Ejemplo n.º 5
0
def get_valid_records(records: pd.DataFrame) -> pd.DataFrame:
    try:
        records = records.replace("", np.nan).fillna(value=np.nan)
        valid_records = records.dropna(subset=columns_to_check_for_nulls)
        if valid_records.empty:
            return pd.DataFrame()
        valid_records = valid_records.drop(
            valid_records.loc[valid_records['status'].str.contains(
                'Timed out', case=False)].index)

        return valid_records

    except Exception as err:
        raise BertException(f"get_valid_records failed: {err}", 400)
Ejemplo n.º 6
0
def calculate_hours_worked_in_seconds(records: pd.DataFrame) -> int:
    try:
        daily_call_history_by_date = records.groupby(
            [records['call_start_time'].dt.date]).agg({
                'call_start_time': min,
                'call_end_time': max
            })
        daily_call_history_by_date['hours_worked'] = (
            daily_call_history_by_date['call_end_time'] -
            daily_call_history_by_date['call_start_time'])

        return daily_call_history_by_date['hours_worked'].sum().total_seconds()
    except Exception as err:
        raise BertException(f"calculate_hours_worked_in_seconds failed: {err}",
                            400)
def survey_tla_handler(request):
    logging.debug(f"request: '{request}'")
    survey_tla = request.args.get("survey-tla", None)

    if survey_tla is None or survey_tla == "" or survey_tla == "undefined":
        logging.debug(f"survey-tla is '{survey_tla}'. Returning None...")
        return None

    if not survey_tla.isalpha() or len(survey_tla) != 3:
        logging.debug(
            f"survey-tla is '{survey_tla}'. Raising BertException...")
        raise (BertException(
            f"Invalid request, {survey_tla} is not a valid survey three letter acronym",
            400))

    return survey_tla.upper()
Ejemplo n.º 8
0
def calculate_call_time_in_seconds(records: pd.DataFrame) -> int:
    try:
        return round(records['dial_secs'].sum())
    except Exception as err:
        raise BertException(f"calculate_call_time_in_seconds failed: {err}",
                            400)