<commit_before>/* Copyright 2013 <NAME>.
 * See the LICENSE file at the top-level directory of this distribution and at
 * https://github.com/bliksemlabs/rrrr/
 */

#include "tdata_validation.h"
#include "tdata.h"

#include <stdio.h>

/* Validate that the first journey_pattern_point have won't alighting set and
 * the last journey_pattern_point won't allow boarding.
 */
int tdata_validation_boarding_alighting(tdata_t *tdata) {
    int32_t ret_invalid = 0;
    uint32_t i_jp;

    for (i_jp = 0; i_jp < tdata->n_journey_patterns; ++i_jp) {
        journey_pattern_t *jp = &(tdata->journey_patterns[i_jp]);
        uint8_t *rsa = tdata->journey_pattern_point_attributes +
                       jp->journey_pattern_point_offset;

        if ((rsa[0] & rsa_alighting) == rsa_alighting ||
            (rsa[jp->n_stops - 1] & rsa_boarding) == rsa_boarding) {
            fprintf(stderr, "journey_pattern index %d %s %s %s has:\n%s%s", i_jp,
                    tdata_agency_name_for_journey_pattern(tdata, i_jp),
                    tdata_shortname_for_journey_pattern(tdata, i_jp),
                    tdata_headsign_for_journey_pattern(tdata, i_jp),
              ((rsa[0] & rsa_alighting) == rsa_alighting ?
                "  alighting on the first stop\n" : ""),

              ((rsa[jp->n_stops - 1] & rsa_boarding) == rsa_boarding ?
                "  boarding on the last stop\n" : ""));

            ret_invalid--;
        }

        if (ret_invalid < -10) {
            fprintf(stderr, "Too many boarding/alighting problems.\n");
            break;
        }
    }

    return ret_invalid;
}

/* Check that all lat/lon look like valid coordinates.
 * If validation fails the number of invalid coordinates are return
 * as negative value.
 */
int tdata_validation_coordinates(tdata_t *tdata) {

    /* farther south than Ushuaia, Argentina */
    float min_lat = -55.0f;

    /* farther north than Tromsø and Murmansk */
    float max_lat = +70.0f;
    float min_lon = -180.0f;
    float max_lon = +180.0f;

    int32_t ret_invalid = 0;

    uint32_t stop_index;
    for (stop_index = 0; stop_index < tdata->n_stops; ++stop_index) {
        latlon_t ll = tdata->stop_coords[stop_index];
        if (ll.lat < min_lat || ll.lat > max_lat ||
            ll.lon < min_lon || ll.lon > max_lon) {
            fprintf (stderr, "stop lat/lon out of range: lat=%f, lon=%f \n",
                                                ll.lat, ll.lon);
            ret_invalid--;
        }
    }

    return ret_invalid;
}

/* Check that all timedemand types start at 0 and consist of
 * monotonically increasing times.
 */
int tdata_validation_increasing_times(tdata_t *tdata) {

    uint32_t jp_index, stop_index, trip_index;
    #ifdef RRRR_DEBUG
    /* statistics on errors, instead of early bail out */
    int ret_nonincreasing = 0;
    #endif

    for (jp_index = 0; jp_index < tdata->n_journey_patterns; ++jp_index) {
        journey_pattern_t jp = tdata->journey_patterns[jp_index];
        trip_t *trips = tdata->trips + jp.trip_ids_offset;
        int n_nonincreasing_trips = 0;<commit_msg>Comment on early bail out and statistics<commit_after>/* Copyright 2013 Bliksem Labs.
 * See the LICENSE file at the top-level directory of this distribution and at
 * https://github.com/bliksemlabs/rrrr/
 */

#include "tdata_validation.h"
#include "tdata.h"

#include <stdio.h>

/* Validate that the first journey_pattern_point have won't alighting set and
 * the last journey_pattern_point won't allow boarding.
 */
int tdata_validation_boarding_alighting(tdata_t *tdata) {
    int32_t ret_invalid = 0;
    uint32_t i_jp;

    for (i_jp = 0; i_jp < tdata->n_journey_patterns; ++i_jp) {
        journey_pattern_t *jp = &(tdata->journey_patterns[i_jp]);
        uint8_t *rsa = tdata->journey_pattern_point_attributes +
                       jp->journey_pattern_point_offset;

        if ((rsa[0] & rsa_alighting) == rsa_alighting ||
            (rsa[jp->n_stops - 1] & rsa_boarding) == rsa_boarding) {
            fprintf(stderr, "journey_pattern index %d %s %s %s has:\n%s%s", i_jp,
                    tdata_agency_name_for_journey_pattern(tdata, i_jp),
                    tdata_shortname_for_journey_pattern(tdata, i_jp),
                    tdata_headsign_for_journey_pattern(tdata, i_jp),
              ((rsa[0] & rsa_alighting) == rsa_alighting ?
                "  alighting on the first stop\n" : ""),

              ((rsa[jp->n_stops - 1] & rsa_boarding) == rsa_boarding ?
                "  boarding on the last stop\n" : ""));

            ret_invalid--;
        }

        if (ret_invalid < -10) {
            fprintf(stderr, "Too many boarding/alighting problems.\n");
            break;
        }
    }

    return ret_invalid;
}

/* Check that all lat/lon look like valid coordinates.
 * If validation fails the number of invalid coordinates are return
 * as negative value.
 */
int tdata_validation_coordinates(tdata_t *tdata) {

    /* farther south than Ushuaia, Argentina */
    float min_lat = -55.0f;

    /* farther north than Tromsø and Murmansk */
    float max_lat = +70.0f;
    float min_lon = -180.0f;
    float max_lon = +180.0f;

    int32_t ret_invalid = 0;

    uint32_t stop_index;
    for (stop_index = 0; stop_index < tdata->n_stops; ++stop_index) {
        latlon_t ll = tdata->stop_coords[stop_index];
        if (ll.lat < min_lat || ll.lat > max_lat ||
            ll.lon < min_lon || ll.lon > max_lon) {
            fprintf (stderr, "stop lat/lon out of range: lat=%f, lon=%f \n",
                                                ll.lat, ll.lon);
            ret_invalid--;
        }
    }

    return ret_invalid;
}

/* Check that all timedemand types start at 0 and consist of
 * monotonically increasing times.
 */
int tdata_validation_increasing_times(tdata_t *tdata) {

    uint32_t jp_index, stop_index, trip_index;
    int ret_nonincreasing = 0;

    for (jp_index = 0; jp_index < tdata->n_journey_patterns; ++jp_index) {
        journey_pattern_t jp = tdata->journey_patterns[jp_index];
        trip_t *trips = tdata->trips + jp.trip_ids_offset;

        #ifdef RRRR_DEBUG
        /* statistics on errors, instead of early bail out */
        int n_nonincreasing_trips = 0;
        #endif

{'fraction_non_alphanumeric': 0.10666666666666667, 'fraction_numerical': 0.013815261044176706, 'mean_word_length': 2.4133771929824563, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 32, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2597171', 'n_tokens_mistral': 2240, 'n_tokens_neox': 2070, 'n_words': 504}