Exemple #1
0
 def _buffer_context(self, event):
     """Show a context menu when the menu is right clicked."""
     item = self.currentItem()
     if not item:
         return
     menu = QtGui.QMenu()
     label_action = QtGui.QAction(self)
     if item.buf:
         label_action.setText(item.buf.data["full_name"])
     else:
         label_action.setText(str(item.childCount()) + " buffers")
     actions = utils.build_actions(self.actions_def, self)
     for action_name, action_def in self.actions_def.items():
         if len(action_def) > 4 and item.buf:
             checked = item.buf.flag(action_def[4])
             actions[action_name].setChecked(checked)
     menu.addAction(label_action)
     if item.buf:
         menu.addAction(utils.separator(self))
         menu.addActions([actions['beep on message'],
                          actions['blink tray icon'],
                          actions['blink task bar']])
     menu.addActions([utils.separator(self), actions['close']])
     if item.buf and len(self.by_number[item.buf.data["number"]]) > 1:
         menu.addActions([utils.separator(self), actions['unmerge']])
     menu.exec_(self.mapToGlobal(event))
Exemple #2
0
def make_vecs():
    utils.set_logger('log')
    log(utils.separator())

    data_loader.convert_data_to_vectors(root_path_str='./training_data/expressive_all_tr', text_file_str='tr_data.txt')
    data_loader.convert_data_to_vectors(root_path_str='./training_data/normal_all_tr', text_file_str='tr_data.txt')
    data_loader.convert_data_to_vectors(root_path_str='./faceScrub_big_train', text_file_str='tr_data.txt')
    data_loader.convert_data_to_vectors(root_path_str='./validation_data/expressive_all_val', text_file_str='val_data.txt')
    data_loader.convert_data_to_vectors(root_path_str='./validation_data/normal_all_val', text_file_str='val_data.txt')
    data_loader.convert_data_to_vectors(root_path_str='./test_data/expressive_all_test', text_file_str='test_data.txt')
    data_loader.convert_data_to_vectors(root_path_str='./test_data/normal_all_test', text_file_str='test_data.txt')
    log(utils.separator())
Exemple #3
0
 def _context(self, event):
     """Show a context menu when the chat is right clicked."""
     menu = QtGui.QMenu()
     self.actions_def = {
         'copy':       ['edit-copy', False, False,
                        lambda: self.copy()],
         'select all': ['edit-select-all', False, False,
                        lambda: self.selectAll()],
         'clear':      ['edit-clear', False, False,
                        lambda: self.clear()],
     }
     actions = utils.build_actions(self.actions_def, self)
     menu.addActions([
         actions['copy'], actions['select all'], utils.separator(self),
         actions['clear'], utils.separator(self)])
     menu.exec_(self.mapToGlobal(event))
Exemple #4
0
 def all_stats(self, conversations: List[NamedConversation]):
     """
     Runs all statistics for specified list of conversations.
     :param conversations: list of conversation to run statistics generators on
     :return:
     """
     for func in [
             self.global_stats, self.top_conversations_by_chars,
             self.top_conversations_by_messages,
             self.conversation_people_variability, self.hourly_histogram,
             self.years_histogram, self.day_in_week_histogram,
             self.msg_lenghts, self.msgs_before_reply,
             self.time_before_reply, self.who_started_conv,
             self.most_used_words
     ]:
         separator()
         func(conversations)
Exemple #5
0
 def _update_context_menu(self):
     """Create a menu object for the context menu."""
     self.menu.clear()
     if self.parent.isHidden():
         self.menu.addAction("Restore Window", self._toggle_parent_window)
     else:
         self.menu.addAction("Hide Window", self._toggle_parent_window)
     self.menu.addAction(utils.separator(self.parent))
     if len(self.records):
         for full_name, records in self.records.items():
             for rec in records:
                 text = " ".join(rec[0:4])
                 action = self.menu.addAction(text[0:50])
                 action.triggered.connect(
                     lambda name=full_name: self._set_current_buffer(name))
         self.menu.addAction(utils.separator(self.parent))
     self.menu.addAction("Quit", QtGui.QApplication.instance().quit)
Exemple #6
0
    def parse_my_name(self) -> None:
        """
        Parses name of person whose archive is being processed.
        
        Name is than stored as field `my_name`.
        """
        if path.isdir(path.join(self.root_path, 'profile_information')):
            print('Parsing profile...')
            with open(path.join(self.root_path, 'profile_information',
                                'profile_information.json'),
                      encoding='raw_unicode_escape') as f:

                # Facebook export tool produces invalid JSONs. Here we try to fix
                # wrongly encoded characters.
                encoded = f.read().encode('raw_unicode_escape')
                decoded = encoded.decode()

                # Also some of the control characters are not encoded correctly, so
                # we remove all of them - we are safe to remove line break as JSON is
                # valid without any whitespace.
                for i in range(32):
                    decoded = decoded.replace(chr(i), '')

                try:
                    doc = json.loads(decoded)
                except JSONDecodeError as e:
                    print(">>>>> JSON DECODE ERROR in profile_information")
                    print(e)
                    exit(1)
                    return

            self.my_name = doc['profile']['name']
        else:
            separator()
            print(
                'Profile Information section is not included in this export!')
            print(
                'Please provide your name (exactly as on Facebook) so we can '
                + 'differentiate your messages from messages of your friends.')
            self.my_name = input(
                'Your name (exactly as on Facebook): ').strip()
            separator()
        print(f'Person name: {self.my_name}')
Exemple #7
0
 def _nicklist_context(self, event):
     """Show a context menu when the nicklist is right clicked."""
     item = self.nicklist.currentItem()
     if not item:
         return
     nick = item.text()
     menu = QtGui.QMenu()
     label_action = QtGui.QAction(nick, self.nicklist)
     actions = utils.build_actions(self.nicklist_actions_def, self.nicklist)
     menu.addActions([label_action, utils.separator(self.nicklist),
                      actions['query'],
                      actions['whois'],
                      actions['ignore']])
     menu.exec_(self.nicklist.mapToGlobal(event))
Exemple #8
0
    def __init__(self, *args):
        QtGui.QMainWindow.__init__(*(self,) + args)
        app = QtGui.QApplication.instance()
        self.config = config.read()
        app.config = self.config

        self.resize(1000, 600)
        self.setWindowTitle(NAME)

        self.debug_dialog = None
        self.debug_lines = []

        self.about_dialog = None
        self.connection_dialog = None
        self.preferences_dialog = None

        # network
        self.network = Network()
        self.network.statusChanged.connect(self._network_status_changed)
        self.network.messageFromWeechat.connect(self._network_weechat_msg)
        self._last_msgid = None

        # list of buffers
        self.switch_buffers = BufferSwitchWidget()
        self.switch_buffers.currentItemChanged.connect(self._buffer_switch)
        self._hotlist = []

        # default buffer
        self.buffers = [Buffer()]
        self.stacked_buffers = QtGui.QStackedWidget()
        self.stacked_buffers.addWidget(self.buffers[0].widget)

        # splitter with buffers + chat/input
        self.splitter = QtGui.QSplitter()
        self.splitter.addWidget(self.switch_buffers)
        self.splitter.addWidget(self.stacked_buffers)

        self.setCentralWidget(self.splitter)

        # notification manager:
        self.notifier = NotificationManager(self)

        # actions for menu and toolbar
        actions_def = {
            'connect': [
                'network-connect', 'Connect to WeeChat',
                'Ctrl+O', self.open_connection_dialog],
            'disconnect': [
                'network-disconnect', 'Disconnect from WeeChat',
                'Ctrl+D', self.network.disconnect_weechat],
            'debug': [
                'edit-find', 'Debug console window',
                'Ctrl+Shift+B', self.open_debug_dialog],
            'view source': [
                None, 'View buffer chat source',
                'Ctrl+Shift+U', self.open_chat_source],
            '_reconnect': [
                None, 'Test Reconnect',
                None, self.network._reconnect_weechat],
            'preferences': [
                'preferences-other', 'Preferences',
                'Ctrl+P', self.open_preferences_dialog],
            'about': [
                'help-about', 'About',
                'Ctrl+H', self.open_about_dialog],
            'save connection': [
                'document-save', 'Save connection configuration',
                'Ctrl+S', self.save_connection],
            'quit': [
                'application-exit', 'Quit application',
                'Ctrl+Q', self.close],
        }
        # toggleable actions
        self.toggles_def = {
            'show menubar': [
                False, 'Show Menubar', 'Ctrl+M',
                lambda: self.config_toggle('look', 'menubar'),
                'look.menubar'],
            'show toolbar': [
                False, 'Show Toolbar',
                False, lambda: self.config_toggle('look', 'toolbar'),
                'look.toolbar'],
            'show status bar': [
                False, 'Show Status Bar',
                False, lambda: self.config_toggle('look', 'statusbar'),
                'look.statusbar'],
            'show title': [
                False, 'Show Topic',
                False, lambda: self.config_toggle('look', 'title'),
                'look.title'],
            'show nick list': [
                False, 'Show Nick List',
                'Ctrl+F7', lambda: self.config_toggle('look', 'nicklist'),
                'look.nicklist'],
            'fullscreen': [
                False, 'Fullscreen',
                'F11', self.toggle_fullscreen],
        }
        self.actions = utils.build_actions(actions_def, self)
        self.actions.update(utils.build_actions(self.toggles_def, self))

        # menu
        self.menu = self.menuBar()
        menu_file = self.menu.addMenu('&File')
        menu_file.addActions([self.actions['connect'],
                              self.actions['disconnect'],
                              self.actions['preferences'],
                              self.actions['save connection'],
                              self.actions['quit']])
        menu_view = self.menu.addMenu('&View')
        menu_view.addActions([self.actions['show menubar'],
                              self.actions['show toolbar'],
                              self.actions['show status bar'],
                              utils.separator(self),
                              self.actions['show title'],
                              self.actions['show nick list'],
                              utils.separator(self),
                              self.actions['fullscreen']])
        menu_window = self.menu.addMenu('&Window')
        menu_window.addAction(self.actions['debug'])
        menu_window.addAction(self.actions['view source'])
        menu_window.addAction(self.actions['_reconnect'])
        menu_help = self.menu.addMenu('&Help')
        menu_help.addAction(self.actions['about'])

        # network status indicator
        self.network_status = QtGui.QPushButton()
        self.network_status.setContentsMargins(0, 0, 10, 0)
        self.network_status.setFlat(True)
        self.network_status.setFocusPolicy(QtCore.Qt.NoFocus)
        self.network_status.setStyleSheet("""text-align:right;padding:0;
            background-color: transparent;min-width:216px;min-height:20px""")
        if hasattr(self.menu, 'setCornerWidget'):
            self.menu.setCornerWidget(self.network_status,
                                      QtCore.Qt.TopRightCorner)

        # toolbar
        toolbar = self.addToolBar('toolBar')
        toolbar.setMovable(False)
        toolbar.addActions([self.actions['connect'],
                            self.actions['disconnect'],
                            self.actions['debug'],
                            self.actions['preferences'],
                            self.actions['about'],
                            self.actions['quit']])
        self.toolbar = toolbar

        # Override context menu for both -- default is a simple menubar toggle.
        self.menu.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.toolbar.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.menu.customContextMenuRequested.connect(self._menu_context)
        self.toolbar.customContextMenuRequested.connect(self._toolbar_context)

        self.buffers[0].widget.input.setFocus()

        # requested buffers for focus:
        self.requested_buffer_names = set()

        # open debug dialog
        if self.config.getboolean('look', 'debug'):
            self.open_debug_dialog()

        self.apply_preferences()
        self.network_status_set(self.network.status_disconnected)

        # auto-connect to relay
        if self.config.getboolean('relay', 'autoconnect'):
            self.network.connect_weechat(self.config.get('relay', 'server'),
                                         self.config.get('relay', 'port'),
                                         self.config.getboolean('relay',
                                                                'ssl'),
                                         self.config.get('relay', 'password'),
                                         self.config.get('relay', 'lines'),
                                         self.config.get('relay', 'ping'))

        self.show()
Exemple #9
0
        statistics.msgs_before_reply(self.my_name, conversations)

    def time_before_reply(self, conversations: List[NamedConversation]):
        statistics.time_before_reply(self.my_name, conversations)

    def most_used_words(self, conversations: List[NamedConversation]):
        statistics.most_used_words(self.my_name, conversations,
                                   self.exhaustive_lists)

    def who_started_conv(self, conversations: List[NamedConversation]):
        statistics.who_started_conv(self.my_name, conversations)


if __name__ == '__main__':
    print('You invoked script as interactive shell.')
    separator()
    print(
        'Please enter path to unzipped Facebook export ' +
        'directory (the one which contains subfolder messages and JSON files).'
    )

    # Check if user provided argument and wants to use it as root folder for
    # generating statistics from.
    if len(argv) > 1 and len(argv[1]) > 0:
        p = argv[1]
        print('Using provided argument as path: ', argv[1])
    else:
        p = input('Export root: ')

    # Verify that provided path is valid Facebook export archive by checking
    # the presence of most important folders and files.
import data_loader
import train_identifier
from utils import log
import utils
from pathlib import Path

root = Path('.')
training_dir = root / 'training_data'
val_dir = root / 'validation_data'
test_dir = root / 'test_data'
fs_tr_dir = training_dir / 'expressive_all_tr' / 'faceScrub_train'
fs_val_dir = val_dir / 'expressive_all_val' / 'faceScrub_val'

utils.set_logger('log')

log(utils.separator())

# # data_loader.convert_data_to_vectors(root_path_str='./Data7', text_file_str='tr_data.txt')
# # data_loader.convert_data_to_vectors(root_path_str='./Validation', text_file_str='val_data.txt')
# # data_loader.convert_data_to_vectors(root_path_str='./Test', text_file_str='test_data.txt')

# m = train_identifier.train_model(training_dir / 'expressive_all_tr' / 'Brynn_Szczesniak', fs_tr_dir, .1, 'linear')
# model_dict = {'Brynn_Szczesniak': m}

# # c = .01
# # for i in range (1, 8):
# #     c *= 10
# #     m = train_identifier.train_model('./Data6', c, 'linear')
# #     train_identifier.test_model(m, "./Validation", "val_data.txt", 'Validation')

# # m = train_identifier.train_model('./Data7', 1000000, 'linear')