<commit_before># -*- coding: utf-8 -*-
"""Playlist model."""

from balistos.models.user import User
from datetime import datetime
from datetime import timedelta
from pyramid_basemodel import Base
from pyramid_basemodel import BaseMixin
from sqlalchemy import Boolean
from sqlalchemy import Column
from sqlalchemy import DateTime
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import String
from sqlalchemy import Unicode
from sqlalchemy.orm import backref
from sqlalchemy.orm import relationship


class Playlist(Base, BaseMixin):
    """A class representing a Playlist."""

    __tablename__ = 'playlists'

    uri = Column(
        String,
        unique=True,
        nullable=False
    )

    title = Column(
        Unicode(200),
        nullable=False
    )

    description = Column(
        Unicode(200),
        nullable=True,
    )

    duration_limit = Column(
        Integer,
        nullable=False,
        default=600
    )

    locked = Column(
        Boolean,
        nullable=False,
        default=False
    )

    public = Column(
        Boolean,
        nullable=False,
        default=True
    )

    @classmethod
    def get(self, uri):
        """Get a Playlist by uri."""
        result = Playlist.query.filter_by(uri=uri)
        if result.count() < 1:
            return None

        return result.one()

    @classmethod
    def search_title(self, search_string):
        """Get Playlist by searching title."""
        search_string = '%' + search_string + '%'
        result = Playlist.query.filter(
            Playlist.title.ilike(search_string),
        )
        if result.count() < 1:
            return []

        return result.all()

    @classmethod
    def get_all(class_, order_by='title', filter_by=None):
        """Return all Playlists.

        filter_by: dict -> {'name': 'foo'}

        By default, order by Playlist.title.
        """
        Playlist = class_
        q = Playlist.query
        q = q.order_by(getattr(Playlist, order_by))
        if filter_by:
            q = q.filter_by(**filter_by)
        return q


class PlaylistUser(Base, BaseMixin):
<commit_msg>Add additional field and method to playlist model<commit_after># -*- coding: utf-8 -*-
"""Playlist model."""

from balistos.models.user import User
from datetime import datetime
from datetime import timedelta
from pyramid_basemodel import Base
from pyramid_basemodel import BaseMixin
from sqlalchemy import Boolean
from sqlalchemy import Column
from sqlalchemy import DateTime
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import String
from sqlalchemy import Unicode
from sqlalchemy.orm import backref
from sqlalchemy.orm import relationship


class Playlist(Base, BaseMixin):
    """A class representing a Playlist."""

    __tablename__ = 'playlists'

    uri = Column(
        String,
        unique=True,
        nullable=False
    )

    title = Column(
        Unicode(200),
        nullable=False
    )

    description = Column(
        Unicode(200),
        nullable=True,
    )

    duration_limit = Column(
        Integer,
        nullable=False,
        default=600
    )

    locked = Column(
        Boolean,
        nullable=False,
        default=False
    )

    public = Column(
        Boolean,
        nullable=False,
        default=True
    )

    last_active = Column(
        DateTime,
        nullable=False,
        default=datetime.now()
    )

    @classmethod
    def get(self, uri):
        """Get a Playlist by uri."""
        result = Playlist.query.filter_by(uri=uri)
        if result.count() < 1:
            return None

        return result.one()

    @classmethod
    def search_title(self, search_string):
        """Get Playlist by searching title."""
        search_string = '%' + search_string + '%'
        result = Playlist.query.filter(
            Playlist.title.ilike(search_string),
        )
        if result.count() < 1:
            return []

        return result.all()

    @classmethod
    def get_active_playlists(self):
        """Get active playlists"""
        result = Playlist.query.filter(
            Playlist.last_active > datetime.now() - timedelta(0, 10)
        )
        if result.count() < 1:
            return []

        return result.all()

    @classmethod
    def get_all(class_, order_by='title', filter_by=None):
        """Return all Playlists.

        filter_by: dict -> {'name': 'foo'}

        By default, order by Playlist.title.
        """
        Playlist = class_
        q = Playlist.query
        q = q.order_by(getattr(Playlist, order_by))
        if filter_by:
            q = q.filter_by(**filter_by)
        return q


class PlaylistUser(Base, BaseMixin):

{'fraction_non_alphanumeric': 0.09278785322648671, 'fraction_numerical': 0.005904681568958245, 'mean_word_length': 2.2221467391304346, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, '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': '5606306', 'n_tokens_mistral': 1423, 'n_tokens_neox': 1331, 'n_words': 370}