<commit_before>#! /usr/bin/python2
# -*- coding: utf-8 -*-

import numpy as np

from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import QVariant, QModelIndex, Qt

from data_tree_node import DataTreeNode


# Refer to http://pyqt.sourceforge.net/Docs/PyQt4/qabstractitemmodel.html
# for subclassing QAbstractItemModel


class DataTreeModel(QtCore.QAbstractItemModel):
    """The tree model of data (DataTreeModel)

    The DataTreeModel class is the model of tree view widget in data viewer.
    """

    def __init__(self, data_manager, parent=None):
        super(DataTreeModel, self).__init__(parent)

        # Setup model data
        self._root = DataTreeNode([QVariant("Name"), QVariant("Size")])

        for gid in xrange(data_manager.n_groups()):
            # Get the pedestrian Matrix
            P = data_manager.get_pedes(gid)

            # Group node
            gdata = [QVariant("Group {0}".format(gid)), 
                     QVariant("{0}×{1}".format(P.shape[0], P.shape[1]))]
            gnode = DataTreeNode(gdata, self._root)

            self._root.add_child(gnode)

            # Pedestrian nodes
            for pid in xrange(P.shape[0]):
                pdata = [QVariant("Pedestrian {0}".format(pid)), 
                         QVariant("")]
                pnode = DataTreeNode(pdata, gnode)

                gnode.add_child(pnode)


    def parent(self, index):
        """Get the parent index of a tree node

        Args:
            index: A QModelIndex of the queried tree node

        Returns:
            A QModelIndex of the corresponding parent node
        """

        if not index.isValid(): return QModelIndex()

        p = index.internalPointer().get_parent()

        if p == self._root: return QModelIndex()

        return self.createIndex(p.get_parent().get_child_index(p), 0, p)


    def data(self, index, role):
        if not index.isValid() or role != Qt.DisplayRole: return QVariant()

        return index.internalPointer().get_data(index.column())

    def index(self, row, column, parent=QModelIndex()):
        if not self.hasIndex(row, column, parent): return QModelIndex()

        p = parent.internalPointer() if parent.isValid() else self._root

        c = p.get_child(row)

        return self.createIndex(row, column, c)

    def rowCount(self, parent=QModelIndex()):
        if parent.column() > 0: return 0<commit_msg>Add header information for data tree model<commit_after>#! /usr/bin/python2
# -*- coding: utf-8 -*-

import numpy as np

from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import QVariant, QModelIndex, Qt

from data_tree_node import DataTreeNode


# Refer to http://pyqt.sourceforge.net/Docs/PyQt4/qabstractitemmodel.html
# for subclassing QAbstractItemModel


class DataTreeModel(QtCore.QAbstractItemModel):
    """The tree model of data (DataTreeModel)

    The DataTreeModel class is the model of tree view widget in data viewer.
    """

    def __init__(self, data_manager, parent=None):
        super(DataTreeModel, self).__init__(parent)

        # Setup model data
        self._root = DataTreeNode([QVariant("Name"), QVariant("Size")])

        for gid in xrange(data_manager.n_groups()):
            # Get the pedestrian Matrix
            P = data_manager.get_pedes(gid)

            # Group node
            gdata = [QVariant("Group {0}".format(gid)), 
                     QVariant("{0}×{1}".format(P.shape[0], P.shape[1]))]
            gnode = DataTreeNode(gdata, self._root)

            self._root.add_child(gnode)

            # Pedestrian nodes
            for pid in xrange(P.shape[0]):
                pdata = [QVariant("Pedestrian {0}".format(pid)), 
                         QVariant("")]
                pnode = DataTreeNode(pdata, gnode)

                gnode.add_child(pnode)


    def parent(self, index):
        """Get the parent index of a tree node

        Args:
            index: A QModelIndex of the queried tree node

        Returns:
            A QModelIndex of the corresponding parent node
        """

        if not index.isValid(): return QModelIndex()

        p = index.internalPointer().get_parent()

        if p == self._root: return QModelIndex()

        return self.createIndex(p.get_parent().get_child_index(p), 0, p)

    def headerData(self, section, orientation, role):
        if orientation != Qt.Horizontal or role != Qt.DisplayRole: 
            return QVariant()

        return self._root.get_data(section)

    def data(self, index, role):
        if not index.isValid() or role != Qt.DisplayRole: return QVariant()

        return index.internalPointer().get_data(index.column())

    def index(self, row, column, parent=QModelIndex()):
        if not self.hasIndex(row, column, parent): return QModelIndex()

        p = parent.internalPointer() if parent.isValid() else self._root

        c = p.get_child(row)

        return self.createIndex(row, column, c)

    def rowCount(self, parent=QModelIndex()):
        if parent.column() > 0: return 0
{'fraction_non_alphanumeric': 0.11148919135308247, 'fraction_numerical': 0.00600480384307446, 'mean_word_length': 2.455739972337483, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7632372', 'n_tokens_mistral': 1522, 'n_tokens_neox': 1441, 'n_words': 394}