<commit_before>#!/usr/bin/env python
# coding: utf-8

import argparse
import datetime
import glob
import itertools
import json
import logging
import os
import random
import re
import steam
import subprocess
import sys

import jinja2
import xmltodict
import yaml


BREAK_LENGTH = 15
HIGH_TOLERANCE = 15
IGNORED_ROUTES = (
    'Academy',
    'TestTraK',
)
IGNORED_SCENARIO_CLASSES = (
    'eFreeRoamScenarioClass',
    'eTemplateScenarioClass',
    'eTutorialScenarioClass',
)
LOW_TOLERANCE = 15
STEAM_API_KEY = '<KEY>'
TEMPLATE_CONFIG = """
# Automatically created by Railworks Dispatcher
# See https://github.com/centralniak/railworks-dispatcher
# for instructions how to configure your Railworks Dispatcher instance

steam:
  profile: ~
  hours_two_weeks: 14
"""


class DriverInstruction(object):

    data = None
    start_datetime = None

    def __init__(self, data, start_datetime):
        self.data = data
        self.start_datetime = start_datetime

    @property
    def arrival(self):
        duration = int(float(self.data['Duration']['#text']))
        seconds_after_start = float(self.data['DueTime']['#text'])
        if not seconds_after_start or not duration:
            return
        arrival = self.start_datetime + datetime.timedelta(seconds=seconds_after_start - duration)
        return arrival

    @property
    def departure(self):
        seconds_after_start = float(self.data['DueTime']['#text'])
        if not seconds_after_start:
            return
        return self.start_datetime + datetime.timedelta(seconds=seconds_after_start)

    @property
    def extra(self):
        operation = self.data['Operation']['#text'].lower()
        if operation != 'Default':
            return getattr(self, 'operation_' + operation)

    @property
    def location(self):
        try:
            return self.data['DisplayName']['#text']
        except TypeError:
            logging.debug('Unable to fetch driver instruction location')<commit_msg>Cover a case when start_datetime is None<commit_after>#!/usr/bin/env python
# coding: utf-8

import argparse
import datetime
import glob
import itertools
import json
import logging
import os
import random
import re
import steam
import subprocess
import sys

import jinja2
import xmltodict
import yaml


BREAK_LENGTH = 15
HIGH_TOLERANCE = 15
IGNORED_ROUTES = (
    'Academy',
    'TestTraK',
)
IGNORED_SCENARIO_CLASSES = (
    'eFreeRoamScenarioClass',
    'eTemplateScenarioClass',
    'eTutorialScenarioClass',
)
LOW_TOLERANCE = 15
STEAM_API_KEY = '<KEY>'
TEMPLATE_CONFIG = """
# Automatically created by Railworks Dispatcher
# See https://github.com/centralniak/railworks-dispatcher
# for instructions how to configure your Railworks Dispatcher instance

steam:
  profile: ~
  hours_two_weeks: 14
"""


class DriverInstruction(object):

    data = None
    start_datetime = None

    def __init__(self, data, start_datetime):
        self.data = data
        self.start_datetime = start_datetime

    @property
    def arrival(self):
        duration = int(float(self.data['Duration']['#text']))
        seconds_after_start = float(self.data['DueTime']['#text'])
        if not seconds_after_start or not duration or not self.start_datetime:
            return
        arrival = self.start_datetime + datetime.timedelta(seconds=seconds_after_start - duration)
        return arrival

    @property
    def departure(self):
        seconds_after_start = float(self.data['DueTime']['#text'])
        if not seconds_after_start:
            return
        return self.start_datetime + datetime.timedelta(seconds=seconds_after_start)

    @property
    def extra(self):
        operation = self.data['Operation']['#text'].lower()
        if operation != 'Default':
            return getattr(self, 'operation_' + operation)

    @property
    def location(self):
        try:
            return self.data['DisplayName']['#text']
        except TypeError:
            logging.debug('Unable to fetch driver instruction location')
{'fraction_non_alphanumeric': 0.09534534534534535, 'fraction_numerical': 0.005005005005005005, 'mean_word_length': 3.3874862788144897, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2073537', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1153, 'n_words': 292}