<commit_before># Log Parser for RTI Connext.
#
#   Copyright 2016 Real-Time Innovations, Inc.
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
"""Format device to show the output as Markdown.

Classes:
  + MarkdownFormatDevice: Format device for Markdown.
"""
from __future__ import absolute_import
from logparser.__init__ import __version__
from logparser.devices.formatdevice import FormatDevice


class MarkdownFormatDevice(FormatDevice):
    """Format device for Markdown.

    Functions:
      + write_header: write the header.
      + write_message: write the message.
      + write_warnings: write the warning messages.
      + write_errors: write the warning messages.
      + write_configurations: write the configuration messages.
      + write_countset: write a generic log message list.
      + write_locators: write the locators if any.
      + write_host_summary: write the host summary.
      + write_statistics_bandwidth: write the bandwidth statistics.
      + write_throughput: write the throughput information.
      + write_statistics_packets: write the packet statistics.
      + write_threads_info: write the threads information.
      + bytes_to_string: convert a byte unit value into string.
    """

    def __init__(self, state):
        """Initialize the device."""
        self.write = state['output_device'].write
        self.show_timestamp = not state['no_timestamp']
        self.show_lines = state['show_lines']

    def write_header(self, state):
        """Write the header."""
        self.write("# Log Parser for RTI Connext ~ " + __version__)
        self.write()
        self.write("## Legend:")
        self.write("* ---> or <--- for output or input packet.")
        self.write("* An asterisk in remote address if inside initial_peers")
        self.write("* Remote Address format: 'HostID AppID ObjID' or IP:Port")
        self.write("* Port format is 'Domain.Index Kind' where kind:")
        self.write("    * MeMu: Meta-traffic over Multicast")
        self.write("    * MeUn: Meta-traffic over Unicast")
        self.write("    * UsMu: User-traffic over Multicast")
        self.write("    * UsUn: User-traffic over Unicast")
        self.write("* H3.A2.P3 means 3rd participant from 2nd app of 3rd host")
        self.write("    At the end there is a summary with the assigned IP")
        self.write("* Reader and writer identifiers are: ID_TsK where:")
        self.write("    * ID: identifier number of the entity.")
        self.write("    * T: entity kind. 'W' for writers, 'R' for readers.")
        self.write("    * sK: if the entity is keyed (+K) or unkeyed (-K).")
        self.write()
        self.write()

        self.write("## Network Data Flow and Application Events")
        header = " In/Out  | Remote Address         | Local Entity   | Message"
        headln = "---------|:----------------------:|:--------------:|--------"
        if self.show_timestamp:
            header = "Timestamp".ljust(28) + "|" + header
            headln = "-".ljust(28, "-") + "|" + headln
        if self.show_lines:
            header = " Log/Parser |" + header
            headln = "------------|" + headln
        self.write(header)
        self.write(headln)

    def write_message(self, content, state):
        """Write the message."""
        # Create the standard message
        if 'inout' not in content:
            inout = "".ljust(9)
        elif content['inout'] == 'in':
            inout = "---> ".center(9)
        else:
            inout = " <---".center(9)
        description = content['description']
        if content.get('kind') in ['ERROR', 'IMPORTANT']:
            description = "**" + description + "**"
        elif content.get('kind') == 'WARNING':
            description = "*" + description + "*"
        remote = content.get('remote', '').center(24)
        entity = content.get('entity', '').center(16)
        msg = "%s|%s|%s| %s" % (inout, remote, entity, description)

        # Add the optional columns
        if self.show_timestamp:
            timestamp = content.get('timestamp', '').center(28)
            msg = timestamp + "|" + msg
        if self.show_lines:
            msg = " %05d/%04d |%s" % (content['input_line'],
                                      content['output_line'], msg)

        self.write(msg)

    def write_warnings(self, state):
        """Write the warning messages."""
        self.write_countset(state['warnings'], "Warnings")

    def write_errors(self, state):
        """Write the warning messages."""
        self.write_countset(state['errors'], "Errors")
<commit_msg>:art: Move in/out column to be between remote and local<commit_after># Log Parser for RTI Connext.
#
#   Copyright 2016 Real-Time Innovations, Inc.
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
"""Format device to show the output as Markdown.

Classes:
  + MarkdownFormatDevice: Format device for Markdown.
"""
from __future__ import absolute_import
from logparser.__init__ import __version__
from logparser.devices.formatdevice import FormatDevice


class MarkdownFormatDevice(FormatDevice):
    """Format device for Markdown.

    Functions:
      + write_header: write the header.
      + write_message: write the message.
      + write_warnings: write the warning messages.
      + write_errors: write the warning messages.
      + write_configurations: write the configuration messages.
      + write_countset: write a generic log message list.
      + write_locators: write the locators if any.
      + write_host_summary: write the host summary.
      + write_statistics_bandwidth: write the bandwidth statistics.
      + write_throughput: write the throughput information.
      + write_statistics_packets: write the packet statistics.
      + write_threads_info: write the threads information.
      + bytes_to_string: convert a byte unit value into string.
    """

    def __init__(self, state):
        """Initialize the device."""
        self.write = state['output_device'].write
        self.show_timestamp = not state['no_timestamp']
        self.show_lines = state['show_lines']

    def write_header(self, state):
        """Write the header."""
        self.write("# Log Parser for RTI Connext ~ " + __version__)
        self.write()
        self.write("## Legend:")
        self.write("* ---> or <--- for output or input packet.")
        self.write("* An asterisk in remote address if inside initial_peers")
        self.write("* Remote Address format: 'HostID AppID ObjID' or IP:Port")
        self.write("* Port format is 'Domain.Index Kind' where kind:")
        self.write("    * MeMu: Meta-traffic over Multicast")
        self.write("    * MeUn: Meta-traffic over Unicast")
        self.write("    * UsMu: User-traffic over Multicast")
        self.write("    * UsUn: User-traffic over Unicast")
        self.write("* H3.A2.P3 means 3rd participant from 2nd app of 3rd host")
        self.write("    At the end there is a summary with the assigned IP")
        self.write("* Reader and writer identifiers are: ID_TsK where:")
        self.write("    * ID: identifier number of the entity.")
        self.write("    * T: entity kind. 'W' for writers, 'R' for readers.")
        self.write("    * sK: if the entity is keyed (+K) or unkeyed (-K).")
        self.write()
        self.write()

        self.write("## Network Data Flow and Application Events")
        header = " Remote Address         | In/Out  | Local Entity   | Message"
        headln = ":----------------------:|---------|:--------------:|--------"
        if self.show_timestamp:
            header = "Timestamp".ljust(28) + "|" + header
            headln = "-".ljust(28, "-") + "|" + headln
        if self.show_lines:
            header = " Log/Parser |" + header
            headln = "------------|" + headln
        self.write(header)
        self.write(headln)

    def write_message(self, content, state):
        """Write the message."""
        # Create the standard message
        if 'inout' not in content:
            inout = "".ljust(9)
        elif content['inout'] == 'in':
            inout = "---> ".center(9)
        else:
            inout = " <---".center(9)
        description = content['description']
        if content.get('kind') in ['ERROR', 'IMPORTANT']:
            description = "**" + description + "**"
        elif content.get('kind') == 'WARNING':
            description = "*" + description + "*"
        remote = content.get('remote', '').center(24)
        entity = content.get('entity', '').center(16)
        msg = "%s|%s|%s| %s" % (remote, inout, entity, description)

        # Add the optional columns
        if self.show_timestamp:
            timestamp = content.get('timestamp', '').center(28)
            msg = timestamp + "|" + msg
        if self.show_lines:
            msg = " %05d/%04d |%s" % (content['input_line'],
                                      content['output_line'], msg)

        self.write(msg)

    def write_warnings(self, state):
        """Write the warning messages."""
        self.write_countset(state['warnings'], "Warnings")

    def write_errors(self, state):
        """Write the warning messages."""
        self.write_countset(state['errors'], "Errors")

{'fraction_non_alphanumeric': 0.13144028103044497, 'fraction_numerical': 0.006049960967993755, 'mean_word_length': 2.397083195227047, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6601289', 'n_tokens_mistral': 2865, 'n_tokens_neox': 2804, 'n_words': 925}