<commit_before>"""
GraphQL definitions for the Stocks App
"""
from datetime import datetime
from django.db.models import Q
from django.db import transaction
from graphene_django import DjangoObjectType
from graphene import AbstractType, Argument, Boolean, Field, Float, ID, \
    InputObjectType, List, Mutation, NonNull, String, relay
from graphql_relay.node.node import from_global_id
from trading.models import Trade
from .models import DailyStockQuote, InvestmentBucket, \
    InvestmentBucketDescription, InvestmentStockConfiguration, Stock
from .historical import create_new_stock


# pylint: disable=too-few-public-methods
class GInvestmentBucketConfigurationUpdate(InputObjectType):
    """
    Represents one choice of stock for a bucket
    """
    id_value = ID()
    quantity = Float()


class GDailyStockQuote(DjangoObjectType):
    """
    GraphQL representation of a DailyStockQuote
    """
    class Meta:
        """
        Meta Model for DailyStockQuote
        """
        model = DailyStockQuote
        interfaces = (relay.Node, )


class GInvestmentBucketAttribute(DjangoObjectType):
    """
    GraphQL representation of a InvestmentBucketDescription
    """
    class Meta:
        """
        Meta Model for InvestmentBucketDescription
        """
        model = InvestmentBucketDescription
        interfaces = (relay.Node, )


class GInvestmentBucket(DjangoObjectType):
    """
    GraphQL representation of a InvestmentBucket
    """
    is_owner = Boolean()

    class Meta:
        """
        Meta Model for InvestmentBucket
        """
        model = InvestmentBucket
        interfaces = (relay.Node, )
        only_fields = ('id', 'name', 'public', 'description', 'stocks', 'available')

    @staticmethod
    def resolve_is_owner(data, _args, context, _info):
        """
        Returns whether the user ownes the investment bucket
        """
        return data.owner.id == context.user.profile.id

    @staticmethod
    def resolve_stocks(data, _args, _context, _info):
        """
        Returns the *current* stocks in the bucket
        """
        return data.stocks.filter(end=None)


class GInvestmentStockConfiguration(DjangoObjectType):
    """
    GraphQL representation of a InvestmentStockConfiguration
    """
    class Meta:
        """
        Meta Model for InvestmentStockConfiguration
        """
        model = InvestmentStockConfiguration
        interfaces = (relay.Node, )


class GStock(DjangoObjectType):
    """
    GraphQL representation of a Stock
    """
    quote_in_range = NonNull(List(GDailyStockQuote), args={'start': Argument(
        NonNull(String)), 'end': Argument(NonNull(String))})
    latest_quote = Field(GDailyStockQuote)

    class Meta(object):
        """
        Meta Model for Stock
        """
        model = Stock
        interfaces = (relay.Node, )

    @staticmethod
    def resolve_latest_quote(data, _args, _context, _info):
        """
        Returns the most recent stock quote
        """
        return data.latest_quote()

    @staticmethod<commit_msg>Reduced permissions on stock (#79)<commit_after>"""
GraphQL definitions for the Stocks App
"""
from datetime import datetime
from django.db.models import Q
from django.db import transaction
from graphene_django import DjangoObjectType
from graphene import AbstractType, Argument, Boolean, Field, Float, ID, \
    InputObjectType, List, Mutation, NonNull, String, relay
from graphql_relay.node.node import from_global_id
from trading.models import Trade
from .models import DailyStockQuote, InvestmentBucket, \
    InvestmentBucketDescription, InvestmentStockConfiguration, Stock
from .historical import create_new_stock


# pylint: disable=too-few-public-methods
class GInvestmentBucketConfigurationUpdate(InputObjectType):
    """
    Represents one choice of stock for a bucket
    """
    id_value = ID()
    quantity = Float()


class GDailyStockQuote(DjangoObjectType):
    """
    GraphQL representation of a DailyStockQuote
    """
    class Meta:
        """
        Meta Model for DailyStockQuote
        """
        model = DailyStockQuote
        interfaces = (relay.Node, )


class GInvestmentBucketAttribute(DjangoObjectType):
    """
    GraphQL representation of a InvestmentBucketDescription
    """
    class Meta:
        """
        Meta Model for InvestmentBucketDescription
        """
        model = InvestmentBucketDescription
        interfaces = (relay.Node, )


class GInvestmentBucket(DjangoObjectType):
    """
    GraphQL representation of a InvestmentBucket
    """
    is_owner = Boolean()

    class Meta:
        """
        Meta Model for InvestmentBucket
        """
        model = InvestmentBucket
        interfaces = (relay.Node, )
        only_fields = ('id', 'name', 'public', 'description', 'stocks', 'available')

    @staticmethod
    def resolve_is_owner(data, _args, context, _info):
        """
        Returns whether the user ownes the investment bucket
        """
        return data.owner.id == context.user.profile.id

    @staticmethod
    def resolve_stocks(data, _args, _context, _info):
        """
        Returns the *current* stocks in the bucket
        """
        return data.stocks.filter(end=None)


class GInvestmentStockConfiguration(DjangoObjectType):
    """
    GraphQL representation of a InvestmentStockConfiguration
    """
    class Meta:
        """
        Meta Model for InvestmentStockConfiguration
        """
        model = InvestmentStockConfiguration
        interfaces = (relay.Node, )


class GStock(DjangoObjectType):
    """
    GraphQL representation of a Stock
    """
    quote_in_range = NonNull(List(GDailyStockQuote), args={'start': Argument(
        NonNull(String)), 'end': Argument(NonNull(String))})
    latest_quote = Field(GDailyStockQuote)

    class Meta(object):
        """
        Meta Model for Stock
        """
        model = Stock
        interfaces = (relay.Node, )
        only_fields = ('quote_in_range', 'latest_quote', 'name', 'ticker', 'trades')

    @staticmethod
    def resolve_latest_quote(data, _args, _context, _info):
        """
        Returns the most recent stock quote
        """
        return data.latest_quote()

    @staticmethod
{'fraction_non_alphanumeric': 0.09134770022515278, 'fraction_numerical': 0.000321646831778707, 'mean_word_length': 2.93109987357775, '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': '6673022', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1607, 'n_words': 457}