<commit_before>﻿import re

from PySide import QtCore, QtGui
from ui.window import Ui_MainWindow

import ChatListener
import LevelListModel

class LevelsBotWindow(Ui_MainWindow, QtGui.QMainWindow):
    """The QMainWindow class for the Mario Maker Levels Bot, 
    containing all the UI logic."""

    
    def __init__(self):
        super().__init__(None)
        self.setupUi(self)

        self.level_list_model = LevelListModel.LevelListModel()
        self.levels_tableView.setModel(self.level_list_model)
        self.levels_tableView.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)

        self.chat_listener = None
        self.find_codes_checkbox.stateChanged.connect(self.toggle_check_codes)

    def toggle_check_codes(self, checked):
        """Slot receiving information about if chat should be parsed or not.
        """
        if(checked):
            
            if(self.chat_listener is None):
                self.chat_listener = ChatListener.ChatListener(
                    self.twitch_name_lineedit.text(),
                    self.twitch_oauth_lineedit.text(),
                    self.channel_lineedit.text(),
                    self)
                self.chat_listener.start()

            self.chat_listener.add_callback(self.parse_message)

        else:
            if(self.chat_listener is not None):
                self.chat_listener.remove_callback(self.parse_message)

    code_re = re.compile("[0-9A-F]{4}[ \-_][0-9A-F]{4}[ \-_][0-9A-F]{4}[ \-_][0-9A-F]{4}")

    def parse_message(self, channel, name, tags, message):
        """Parse a message read from chat. This is the callback for the ChatListener.
        """
        s = self.code_re.search(message.upper())

        if(s is None):
            return
        else:
            self.level_list_model.add_level(message[s.start(): s.end()].upper(), name, tags)<commit_msg>Unified the code representation: upper case, separated by dashes<commit_after>﻿import re

from PySide import QtCore, QtGui
from ui.window import Ui_MainWindow

import ChatListener
import LevelListModel

class LevelsBotWindow(Ui_MainWindow, QtGui.QMainWindow):
    """The QMainWindow class for the Mario Maker Levels Bot, 
    containing all the UI logic."""

    
    def __init__(self):
        super().__init__(None)
        self.setupUi(self)

        self.level_list_model = LevelListModel.LevelListModel()
        self.levels_tableView.setModel(self.level_list_model)
        self.levels_tableView.horizontalHeader().setResizeMode(QtGui.QHeaderView.Stretch)

        self.chat_listener = None
        self.find_codes_checkbox.stateChanged.connect(self.toggle_check_codes)

    def toggle_check_codes(self, checked):
        """Slot receiving information about if chat should be parsed or not.
        """
        if(checked):
            
            if(self.chat_listener is None):
                self.chat_listener = ChatListener.ChatListener(
                    self.twitch_name_lineedit.text(),
                    self.twitch_oauth_lineedit.text(),
                    self.channel_lineedit.text(),
                    self)
                self.chat_listener.start()

            self.chat_listener.add_callback(self.parse_message)

        else:
            if(self.chat_listener is not None):
                self.chat_listener.remove_callback(self.parse_message)

    code_re = re.compile("[0-9A-F]{4}[ \-_][0-9A-F]{4}[ \-_][0-9A-F]{4}[ \-_][0-9A-F]{4}")

    def parse_message(self, channel, name, tags, message):
        """Parse a message read from chat. This is the callback for the ChatListener.
        """
        s = self.code_re.search(message.upper())

        if(s is None):
            return
        else:
            code = message[s.start(): s.end()].upper().replace(" ", "-").replace("_", "-")
            self.level_list_model.add_level(code, name, tags)
{'fraction_non_alphanumeric': 0.10950038829924928, 'fraction_numerical': 0.006212787988609888, 'mean_word_length': 2.410414827890556, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '134693', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1108, 'n_words': 230}