<commit_before># Copyright 2016 <NAME> and <NAME>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


"""
Provides a class for representing a student and a function for building a
list of students from a CSV file.
"""

from gkeepcore.csv_files import CSVReader
from gkeepcore.gkeep_exception import GkeepException


class StudentError(GkeepException):
    pass


class Student:
    """
    Stores a student's attributes.

    Attributes stored:
        last_name
        first_name
        username
        email_address

    """
    def __init__(self, last_name: str, first_name: str, username: str,
                 email_address: str):
        """
        Constructor

        Simply set the attributes from the parameters.

        """
        self.last_name = last_name
        self.first_name = first_name
        self.username = username
        self.email_address = email_address

    @classmethod
    def from_csv_row(cls, csv_row: list):
        """
        Build a Student object form a CSV file row as a list.

        :param csv_row: the CSV file row as a list
        :return: a new Student object

        """

        if len(csv_row) != 3:
            raise StudentError('Not a valid student row: ' + str(csv_row))

        last_name, first_name, email_address = csv_row

        # FIXME - need to handle email address and username mapping
        split_email = email_address.split('@')

        try:
            username, domain = split_email
        except:
            error = ('{0} does not appear to be a valid email address'
                     .format(email_address))
            raise StudentError(error)

        return cls(last_name, first_name, username, email_address)

    def __repr__(self) -> str:
        """
        Build a string representation of a student.

        Format:

            Last, First (username) <<EMAIL>>

        :return: string representation of the object
        """

        return '{0}, {1} ({2}) <{3}>'.format(self.last_name, self.first_name,
                                             self.username, self.email_address)

    def get_last_first_username(self) -> str:
        """
        Build a string of the following form:

            last_first_username

        Spaces are stripped out of the names and all characters are converted
        to lowercase.

        This can be used to create directories or filenames to store student
        data.

        :return: a last_first_username string representation of a student
        """

        lower_first_name = self.first_name.lower().replace(' ', '')
        lower_last_name = self.last_name.lower().replace(' ', '')

        return '{0}_{1}_{2}'.format(lower_last_name, lower_first_name,<commit_msg>Remove punctuation when cleaning up names<commit_after># Copyright 2016 <NAME> and <NAME>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


"""
Provides a class for representing a student and a function for building a
list of students from a CSV file.
"""

import string

from gkeepcore.csv_files import CSVReader
from gkeepcore.gkeep_exception import GkeepException


class StudentError(GkeepException):
    pass


class Student:
    """
    Stores a student's attributes.

    Attributes stored:
        last_name
        first_name
        username
        email_address

    """
    def __init__(self, last_name: str, first_name: str, username: str,
                 email_address: str):
        """
        Constructor

        Simply set the attributes from the parameters.

        """
        self.last_name = last_name
        self.first_name = first_name
        self.username = username
        self.email_address = email_address

    @classmethod
    def from_csv_row(cls, csv_row: list):
        """
        Build a Student object form a CSV file row as a list.

        :param csv_row: the CSV file row as a list
        :return: a new Student object

        """

        if len(csv_row) != 3:
            raise StudentError('Not a valid student row: ' + str(csv_row))

        last_name, first_name, email_address = csv_row

        # FIXME - need to handle email address and username mapping
        split_email = email_address.split('@')

        try:
            username, domain = split_email
        except:
            error = ('{0} does not appear to be a valid email address'
                     .format(email_address))
            raise StudentError(error)

        return cls(last_name, first_name, username, email_address)

    def __repr__(self) -> str:
        """
        Build a string representation of a student.

        Format:

            Last, First (username) <<EMAIL>>

        :return: string representation of the object
        """

        return '{0}, {1} ({2}) <{3}>'.format(self.last_name, self.first_name,
                                             self.username, self.email_address)

    def get_last_first_username(self) -> str:
        """
        Build a string of the following form:

            last_first_username

        Spaces and punctuation are stripped out of the names and all characters
        are converted to lowercase.

        This can be used to create directories or filenames to store student
        data.

        :return: a last_first_username string representation of a student
        """

        def cleanup(s):
            # convert s to lowercase and strip out all spaces and punctuation
            s = s.lower().replace(' ', '')
            s = s.translate(str.maketrans('', '', string.punctuation))
            return s

        lower_first_name = cleanup(self.first_name)
        lower_last_name = cleanup(self.last_name)

        return '{0}_{1}_{2}'.format(lower_last_name, lower_first_name,
{'fraction_non_alphanumeric': 0.0762403608322421, 'fraction_numerical': 0.004073912410883166, 'mean_word_length': 2.354807223035627, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '653781', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1757, 'n_words': 700}