<commit_before>package org.mtransit.parser.ca_guelph_transit_bus;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.mtransit.commons.CharUtils;
import org.mtransit.commons.CleanUtils;
import org.mtransit.commons.StringUtils;
import org.mtransit.parser.DefaultAgencyTools;
import org.mtransit.parser.MTLog;
import org.mtransit.parser.gtfs.data.GRoute;
import org.mtransit.parser.gtfs.data.GStop;
import org.mtransit.parser.mt.data.MAgency;
import org.mtransit.parser.mt.data.MTrip;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.mtransit.commons.StringUtils.EMPTY;

// http://data.open.guelph.ca/
// http://data.open.guelph.ca/dataset/guelph-transit-gtfs-data
// http://data.open.guelph.ca/datafiles/guelph-transit/guelph_transit_gtfs.zip
// OTHER: http://guelph.ca/uploads/google/google_transit.zip
public class GuelphTransitBusAgencyTools extends DefaultAgencyTools {

	public static void main(@Nullable String[] args) {
		new GuelphTransitBusAgencyTools().start(args);
	}

	@Override
	public boolean defaultExcludeEnabled() {
		return true;
	}

	@NotNull
	@Override
	public String getAgencyName() {
		return "Guelph Transit";
	}

	@NotNull
	@Override
	public Integer getAgencyRouteType() {
		return MAgency.ROUTE_TYPE_BUS;
	}

	private static final Pattern DIGITS = Pattern.compile("[\\d]+");

	private static final String COMMUNITY_BUS_RSN = "Com";
	private static final long COMMUNITY_BUS_RID = 9_998L;

	private static final String U = "U";

	private static final long RID_ENDS_WITH_U = 21_000L;

	@Override
	public long getRouteId(@NotNull GRoute gRoute) {
		if (COMMUNITY_BUS_RSN.equals(gRoute.getRouteShortName())) {
			return COMMUNITY_BUS_RID;
		}
		final String routeShortName = gRoute.getRouteShortName();
		if (routeShortName.length() > 0 && CharUtils.isDigitsOnly(routeShortName)) {
			return Long.parseLong(routeShortName); // using route short name as route ID
		}
		final Matcher matcher = DIGITS.matcher(routeShortName);
		if (matcher.find()) {
			int digits = Integer.parseInt(matcher.group());
			if (routeShortName.endsWith(U)) {
				return RID_ENDS_WITH_U + digits;
			}
		}
		throw new MTLog.Fatal("Can't find route ID for '%s' (%s)!", routeShortName, gRoute);
	}

	private static final Pattern ALL_WHITESPACES = Pattern.compile("\\s+", Pattern.CASE_INSENSITIVE);

	@Nullable
	@Override
	public String getRouteShortName(@NotNull GRoute gRoute) {
		return cleanRouteShortName(gRoute.getRouteShortName());
	}

	@SuppressWarnings("WeakerAccess")
	@NotNull
	public String cleanRouteShortName(@NotNull String routeShortName) {
		routeShortName = ALL_WHITESPACES.matcher(routeShortName).replaceAll(EMPTY);
		return routeShortName;
	}

	private static final Pattern STARTS_WITH_ROUTE_RSN = Pattern.compile("(route[\\d]*[A-Z]*[\\-]?[\\s]*)", Pattern.CASE_INSENSITIVE);

	@NotNull
	@Override
	public String cleanRouteLongName(@NotNull String routeLongName) {
		routeLongName = STARTS_WITH_ROUTE_RSN.matcher(routeLongName).replaceAll(EMPTY);
		if (StringUtils.isEmpty(routeLongName)) {
			throw new MTLog.Fatal("getRouteLongName() > Unexpected route long name name '%s'!", routeLongName);
		}
		return CleanUtils.cleanLabel(routeLongName);
	}

	private static final String AGENCY_COLOR = "00A6E5"; // BLUE

	@NotNull
	@Override
	public String getAgencyColor() {
		return AGENCY_COLOR;
	}

	@SuppressWarnings("DuplicateBranchesInSwitch")
	@Nullable
	@Override
	public String getRouteColor(@NotNull GRoute gRoute) {
		if (StringUtils.isEmpty(gRoute.getRouteShortName())) {
			if (COMMUNITY_BUS_RSN.equals(gRoute.getRouteShortName())) {
				return "D14625";
			}
			if (gRoute.getRouteShortName().startsWith("Zone ") //
					|| gRoute.getRouteShortName().startsWith("NYE ")) {
				return "ED1C24";
			}
			final Matcher matcher = DIGITS.matcher(gRoute.getRouteShortName());
			if (matcher.find()) {
				final int rsn = Integer.parseInt(matcher.group());
				switch (rsn) {
				// @formatter:off
				case 1: return "EC008C";
				case 2: return "EC008C";
				case 3: return "91469B";
				case 4: return "1988B7";
				case 5: return "921B1E";
				case 6: return "ED1C24";
				case 7: return "682C91";
				case 8: return "0082B1";
				case 9: return "5C7AAE";
				case 10: return "A54686";
				case 11: return "5C7AAE";
				case 12: return "008290";
				case 13: return "811167";
				case 14: return "485E88";
				case 15: return "8F7140";
				case 16: return "29712A";
				case 17: return "CB640A";
				case 18: return "CB640A";
				case 20: return "556940";
				case 40: return "005689";
				case 41: return "405D18";
				case 50: return "A54686"; // 50 U
				case 51: return "405D18"; // 51 U
				case 52: return "485E88"; // 52 U
				case 56: return "ED1C24"; // 56 U
				case 57: return "5C7AAE"; // 57 U
				case 58: return "91469b"; // 58 U
				case 99: return "4F832E ";
				// @formatter:on
				}
			}
			throw new MTLog.Fatal("getRouteColor() > Unexpected route color for '%s'!", gRoute);
		}
		return super.getRouteColor(gRoute);
	}

	@Override
	public boolean directionFinderEnabled() {
		return true;
	}

	private static final Pattern STARTS_WITH_RSN = Pattern.compile("(^[\\d]+ )", Pattern.CASE_INSENSITIVE);

	private static final Pattern STARTS_W_COMMUNITY_BUS_ = Pattern.compile("(^community bus (?=(.{3,})))", Pattern.CASE_INSENSITIVE);<commit_msg>April 16 update<commit_after>package org.mtransit.parser.ca_guelph_transit_bus;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.mtransit.commons.CharUtils;
import org.mtransit.commons.CleanUtils;
import org.mtransit.commons.StringUtils;
import org.mtransit.parser.DefaultAgencyTools;
import org.mtransit.parser.MTLog;
import org.mtransit.parser.gtfs.data.GRoute;
import org.mtransit.parser.gtfs.data.GStop;
import org.mtransit.parser.mt.data.MAgency;
import org.mtransit.parser.mt.data.MTrip;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.mtransit.commons.StringUtils.EMPTY;

// http://data.open.guelph.ca/
// http://data.open.guelph.ca/dataset/guelph-transit-gtfs-data
// http://data.open.guelph.ca/datafiles/guelph-transit/guelph_transit_gtfs.zip
// OTHER: http://guelph.ca/uploads/google/google_transit.zip
public class GuelphTransitBusAgencyTools extends DefaultAgencyTools {

	public static void main(@Nullable String[] args) {
		new GuelphTransitBusAgencyTools().start(args);
	}

	@Override
	public boolean defaultExcludeEnabled() {
		return true;
	}

	@NotNull
	@Override
	public String getAgencyName() {
		return "Guelph Transit";
	}

	@NotNull
	@Override
	public Integer getAgencyRouteType() {
		return MAgency.ROUTE_TYPE_BUS;
	}

	private static final Pattern DIGITS = Pattern.compile("[\\d]+");

	private static final String COMMUNITY_BUS_RSN = "Com";
	private static final long COMMUNITY_BUS_RID = 9_998L;

	private static final String U = "U";

	private static final long RID_ENDS_WITH_U = 21_000L;

	@Override
	public long getRouteId(@NotNull GRoute gRoute) {
		if (COMMUNITY_BUS_RSN.equals(gRoute.getRouteShortName())) {
			return COMMUNITY_BUS_RID;
		}
		final String routeShortName = gRoute.getRouteShortName();
		if (routeShortName.length() > 0 && CharUtils.isDigitsOnly(routeShortName)) {
			return Long.parseLong(routeShortName); // using route short name as route ID
		}
		final Matcher matcher = DIGITS.matcher(routeShortName);
		if (matcher.find()) {
			final int digits = Integer.parseInt(matcher.group());
			if (routeShortName.endsWith(U)) {
				return RID_ENDS_WITH_U + digits;
			}
		}
		throw new MTLog.Fatal("Can't find route ID for '%s' (%s)!", routeShortName, gRoute);
	}

	private static final Pattern ALL_WHITESPACES = Pattern.compile("\\s+", Pattern.CASE_INSENSITIVE);

	@Nullable
	@Override
	public String getRouteShortName(@NotNull GRoute gRoute) {
		return cleanRouteShortName(gRoute.getRouteShortName());
	}

	@SuppressWarnings("WeakerAccess")
	@NotNull
	public String cleanRouteShortName(@NotNull String routeShortName) {
		routeShortName = ALL_WHITESPACES.matcher(routeShortName).replaceAll(EMPTY);
		return routeShortName;
	}

	private static final Pattern STARTS_WITH_ROUTE_RSN = Pattern.compile("(route[\\d]*[A-Z]*[\\-]?[\\s]*)", Pattern.CASE_INSENSITIVE);

	@NotNull
	@Override
	public String cleanRouteLongName(@NotNull String routeLongName) {
		routeLongName = STARTS_WITH_ROUTE_RSN.matcher(routeLongName).replaceAll(EMPTY);
		if (StringUtils.isEmpty(routeLongName)) {
			throw new MTLog.Fatal("getRouteLongName() > Unexpected route long name name '%s'!", routeLongName);
		}
		return CleanUtils.cleanLabel(routeLongName);
	}

	private static final String AGENCY_COLOR = "00A6E5"; // BLUE

	@NotNull
	@Override
	public String getAgencyColor() {
		return AGENCY_COLOR;
	}

	@SuppressWarnings("DuplicateBranchesInSwitch")
	@Nullable
	@Override
	public String getRouteColor(@NotNull GRoute gRoute) {
		if (StringUtils.isEmpty(gRoute.getRouteShortName())) {
			if (COMMUNITY_BUS_RSN.equals(gRoute.getRouteShortName())) {
				return "D14625";
			}
			if (gRoute.getRouteShortName().startsWith("Zone ") //
					|| gRoute.getRouteShortName().startsWith("NYE ")) {
				return "ED1C24";
			}
			final Matcher matcher = DIGITS.matcher(gRoute.getRouteShortName());
			if (matcher.find()) {
				final int rsn = Integer.parseInt(matcher.group());
				switch (rsn) {
				// @formatter:off
				case 1: return "EC008C";
				case 2: return "EC008C";
				case 3: return "91469B";
				case 4: return "1988B7";
				case 5: return "921B1E";
				case 6: return "ED1C24";
				case 7: return "682C91";
				case 8: return "0082B1";
				case 9: return "5C7AAE";
				case 10: return "A54686";
				case 11: return "5C7AAE";
				case 12: return "008290";
				case 13: return "811167";
				case 14: return "485E88";
				case 15: return "8F7140";
				case 16: return "29712A";
				case 17: return "CB640A";
				case 18: return "CB640A";
				case 20: return "556940";
				case 40: return "005689";
				case 41: return "405D18";
				case 50: return "A54686"; // 50 U
				case 51: return "405D18"; // 51 U
				case 52: return "485E88"; // 52 U
				case 56: return "ED1C24"; // 56 U
				case 57: return "5C7AAE"; // 57 U
				case 58: return "91469b"; // 58 U
				case 99: return "4F832E ";
				// @formatter:on
				}
			}
			throw new MTLog.Fatal("getRouteColor() > Unexpected route color for '%s'!", gRoute);
		}
		return super.getRouteColor(gRoute);
	}

	@Override
	public boolean directionFinderEnabled() {
		return true;
	}

	private static final Pattern STARTS_WITH_RSN = Pattern.compile("(^[\\d]+ )", Pattern.CASE_INSENSITIVE);

	private static final Pattern STARTS_W_COMMUNITY_BUS_ = Pattern.compile("(^(community bus|mainline) (?=(.{3,})))", Pattern.CASE_INSENSITIVE);
{'fraction_non_alphanumeric': 0.12664243779703663, 'fraction_numerical': 0.038020687727145654, 'mean_word_length': 4.409274193548387, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6276806', 'n_tokens_mistral': 4384, 'n_tokens_neox': 3723, 'n_words': 828}