<commit_before>__author__ = 'nietaki'

import math
import warnings
from TrackPiece import TrackPiece, straight_line_radius


class Track(object):
    def __init__(self, track):
        self.track = track
        self.track_id = self.track['id']
        self.track_pieces_deprecated = self.track['pieces']
        self.lanes = self.track['lanes']
        self.track_pieces = map(lambda pc: TrackPiece(pc, self.lanes), self.track_pieces_deprecated)
        self.track_piece_count = len(self.track_pieces_deprecated)
        # piece id -> macro piece id
        self.macro_piece_map = dict()
        # macro_id -> first normal id
        self.reverse_macro_map = dict()
        self.compute_macro_pieces()

    def compute_macro_pieces(self):
        self.macro_piece_map[0] = 0
        self.reverse_macro_map[0] = 0
        last_macro_index = 0
        for index in range(1, self.track_piece_count):
            if not self.track_pieces[index].same_as(self.track_pieces[index - 1]):
                last_macro_index += 1
                self.reverse_macro_map[last_macro_index] = index
            self.macro_piece_map[index] = last_macro_index
        print(self.macro_piece_map)

    def radius(self, piece_index):
        return self.track_pieces[piece_index].radius

    def next_index(self, input_track_piece_index):
        return (input_track_piece_index + 1) % self.track_piece_count

    def next_piece(self, input_track_piece_index):
        return self.track_pieces[self.next_index(input_track_piece_index)]

    def piece_straight(self, piece_index):
        return self.track_pieces[piece_index].is_straight

    def bend_direction(self, piece_index):
        return self.track_pieces[piece_index].bend_direction

    def true_radius(self, piece_index, lane):
        return self.track_pieces[piece_index].true_radius(lane)

    def true_piece_length(self, piece_index, lane):
        return self.track_pieces[piece_index].true_length(lane)
<commit_msg>longest straight detection added<commit_after>__author__ = 'nietaki'

import math
import warnings
from TrackPiece import TrackPiece, straight_line_radius


class Track(object):
    def __init__(self, track):
        self.track = track
        self.track_id = self.track['id']
        self.track_pieces_deprecated = self.track['pieces']
        self.lanes = self.track['lanes']
        self.track_pieces = map(lambda pc: TrackPiece(pc, self.lanes), self.track_pieces_deprecated)
        self.track_piece_count = len(self.track_pieces_deprecated)

        self.index_of_the_beginning_of_the_longest_straight_piece = None  # yes, exactly. Because I can

        # piece id -> macro piece id
        self.macro_piece_map = dict()
        # macro_id -> first normal id
        self.reverse_macro_map = dict()
        self.compute_macro_pieces()
        self.compute_longest_straight()

    def compute_macro_pieces(self):
        self.macro_piece_map[0] = 0
        self.reverse_macro_map[0] = 0
        last_macro_index = 0
        for index in range(1, self.track_piece_count):
            if not self.track_pieces[index].same_as(self.track_pieces[index - 1]):
                last_macro_index += 1
                self.reverse_macro_map[last_macro_index] = index
            self.macro_piece_map[index] = last_macro_index
        print(self.macro_piece_map)

    def compute_longest_straight(self):
        origin_id = 0

        # I want to start with a bend
        while self.track_pieces[origin_id].is_straight:
            origin_id += 1

        cur_id = (origin_id + 1) % self.track_piece_count
        best_id = None
        best_length = 0.0

        current_starting_id = None
        current_length = 0.0
        while cur_id != origin_id:
            cur_piece = self.track_pieces[cur_id]
            if not cur_piece.is_straight:
                current_starting_id = None
                current_length = 0.0
            else:
                # it's a straight
                if current_starting_id is None:
                    current_starting_id = cur_id
                current_length += cur_piece.length

                if current_length > best_length:
                    best_length = current_length
                    best_id = current_starting_id

            cur_id = (cur_id + 1) % self.track_piece_count

        self.index_of_the_beginning_of_the_longest_straight_piece = best_id
        print("the longest straight begins on piece {0}!".format(best_id))
        return best_id





    def radius(self, piece_index):
        return self.track_pieces[piece_index].radius

    def next_index(self, input_track_piece_index):
        return (input_track_piece_index + 1) % self.track_piece_count

    def next_piece(self, input_track_piece_index):
        return self.track_pieces[self.next_index(input_track_piece_index)]

    def piece_straight(self, piece_index):
        return self.track_pieces[piece_index].is_straight

    def bend_direction(self, piece_index):
        return self.track_pieces[piece_index].bend_direction

    def true_radius(self, piece_index, lane):
        return self.track_pieces[piece_index].true_radius(lane)

    def true_piece_length(self, piece_index, lane):
        return self.track_pieces[piece_index].true_length(lane)

{'fraction_non_alphanumeric': 0.08120472741136103, 'fraction_numerical': 0.005528021349599695, 'mean_word_length': 2.7802593659942363, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '297781', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1569, 'n_words': 302}