<commit_before># (c) <NAME>.  MIT licensed, see LICENSE.rst.
from __future__ import unicode_literals

from ddsc_core.models import Location, Timeseries, Parameter, LogicalGroup
from django.contrib.auth.models import User, Group as Role
from rest_framework import serializers
from lizard_security.models import DataOwner, DataSet, UserGroup


class UserListSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('url', 'username', )


class UserDetailSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        exclude = ('password', 'groups', 'user_permissions', )


class GroupListSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = UserGroup
        fields = ('url', 'name', )


class GroupDetailSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = UserGroup


class RoleListSerializer(serializers.HyperlinkedModelSerializer):
    url = serializers.HyperlinkedIdentityField(view_name='role-detail')

    class Meta:
        model = Role
        exclude = ('permissions', 'permission_mappers', )


class RoleDetailSerializer(serializers.HyperlinkedModelSerializer):
    url = serializers.HyperlinkedIdentityField(view_name='role-detail')

    class Meta:
        model = Role
        exclude = ('permissions', 'permission_mappers', )


class DataSetListSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = DataSet


class DataSetDetailSerializer(serializers.HyperlinkedModelSerializer):
    timeseries = serializers.ManyHyperlinkedRelatedField(
        view_name='timeseries-detail', slug_field='uuid')

    class Meta:
        model = DataSet


class DataOwnerListSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = DataOwner


class DataOwnerDetailSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = DataOwner


class ParameterListSerializer(serializers.HyperlinkedModelSerializer):

    class Meta:
        model = Parameter
        fields = ('url', 'code', 'description')


class ParameterDetailSerializer(serializers.HyperlinkedModelSerializer):

    class Meta:
        model = Parameter
        fields = ('url', 'code', 'description', 'cas_number', 'group', 'sikb_id',)


class LocationListSerializer(serializers.HyperlinkedModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name='location-detail', slug_field='uuid')
    point_geometry = serializers.Field()

    class Meta:
        model = Location
        fields = (
            'url',
            'point_geometry',
            'uuid',
            'name',
        )


class LocationLinkSerializer(serializers.HyperlinkedModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name='location-detail', slug_field='uuid')

    class Meta:
        model = Location
        fields = (
            'url',
            'name',
            'description',
        )


class LocationDetailSerializer(serializers.HyperlinkedModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name='location-detail', slug_field='uuid')
    timeseries = serializers.ManyHyperlinkedRelatedField(
        view_name='timeseries-detail', slug_field='uuid')
    superlocation = LocationLinkSerializer(source='superlocation')
    sublocations = LocationLinkSerializer(source='sublocations')
    point_geometry = serializers.Field()

    class Meta:
        model = Location
        fields = (
            'url',
            'timeseries',
            'superlocation',
            'sublocations',
            'point_geometry',
            'uuid',
            'name',
            'description',
        )


class TimeseriesListSerializer(serializers.HyperlinkedModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name='timeseries-detail', slug_field='uuid')
    value_type = serializers.Field('get_value_type')
    latest_value = serializers.Field()

    class Meta:
        model = Timeseries
        fields = ('url', 'name', 'value_type', 'latest_value', )


class TimeseriesDetailSerializer(serializers.HyperlinkedModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name='timeseries-detail', slug_field='uuid')
    location = serializers.HyperlinkedRelatedField(
        view_name='location-detail', slug_field='uuid')
    events = serializers.HyperlinkedIdentityField(
        view_name='event-list', slug_field='uuid')
    value_type = serializers.Field('get_value_type')
    latest_value = serializers.Field()

    class Meta:
        model = Timeseries
        fields = (
            'url',
            'location',
            'events',
            'latest_value',
            'uuid',
            'name',
            'description',
            'value_type',
            'source',
            'owner',
            'first_value_timestamp',
            'latest_value_timestamp',
            'supplying_systems',
            'parameter',
        )
        depth = 1


class LogicalGroupListSerializer(serializers.HyperlinkedModelSerializer):
    timeseries = serializers.ManyHyperlinkedRelatedField(
        view_name='timeseries-detail', slug_field='uuid')

    class Meta:
        model = LogicalGroup
        fields = (
            'url',
            'name',
            'timeseries',
        )


class LogicalGroupLinkSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = LogicalGroup
        fields = (
            'url',
            'name',
        )


class LogicalGroupDetailSerializer(serializers.HyperlinkedModelSerializer):
    timeseries = serializers.ManyHyperlinkedRelatedField(
        view_name='timeseries-detail', slug_field='uuid')
    parents = LogicalGroupLinkSerializer(source='parents')
    children = LogicalGroupLinkSerializer(source='children')

    class Meta:
        model = LogicalGroup
<commit_msg>Added 'events' property to timeserieslist serializer.<commit_after># (c) <NAME>.  MIT licensed, see LICENSE.rst.
from __future__ import unicode_literals

from ddsc_core.models import Location, Timeseries, Parameter, LogicalGroup
from django.contrib.auth.models import User, Group as Role
from rest_framework import serializers
from lizard_security.models import DataOwner, DataSet, UserGroup


class UserListSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('url', 'username', )


class UserDetailSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        exclude = ('password', 'groups', 'user_permissions', )


class GroupListSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = UserGroup
        fields = ('url', 'name', )


class GroupDetailSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = UserGroup


class RoleListSerializer(serializers.HyperlinkedModelSerializer):
    url = serializers.HyperlinkedIdentityField(view_name='role-detail')

    class Meta:
        model = Role
        exclude = ('permissions', 'permission_mappers', )


class RoleDetailSerializer(serializers.HyperlinkedModelSerializer):
    url = serializers.HyperlinkedIdentityField(view_name='role-detail')

    class Meta:
        model = Role
        exclude = ('permissions', 'permission_mappers', )


class DataSetListSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = DataSet


class DataSetDetailSerializer(serializers.HyperlinkedModelSerializer):
    timeseries = serializers.ManyHyperlinkedRelatedField(
        view_name='timeseries-detail', slug_field='uuid')

    class Meta:
        model = DataSet


class DataOwnerListSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = DataOwner


class DataOwnerDetailSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = DataOwner


class ParameterListSerializer(serializers.HyperlinkedModelSerializer):

    class Meta:
        model = Parameter
        fields = ('url', 'code', 'description')


class ParameterDetailSerializer(serializers.HyperlinkedModelSerializer):

    class Meta:
        model = Parameter
        fields = ('url', 'code', 'description', 'cas_number', 'group', 'sikb_id',)


class LocationListSerializer(serializers.HyperlinkedModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name='location-detail', slug_field='uuid')
    point_geometry = serializers.Field()

    class Meta:
        model = Location
        fields = (
            'url',
            'point_geometry',
            'uuid',
            'name',
        )


class LocationLinkSerializer(serializers.HyperlinkedModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name='location-detail', slug_field='uuid')

    class Meta:
        model = Location
        fields = (
            'url',
            'name',
            'description',
        )


class LocationDetailSerializer(serializers.HyperlinkedModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name='location-detail', slug_field='uuid')
    timeseries = serializers.ManyHyperlinkedRelatedField(
        view_name='timeseries-detail', slug_field='uuid')
    superlocation = LocationLinkSerializer(source='superlocation')
    sublocations = LocationLinkSerializer(source='sublocations')
    point_geometry = serializers.Field()

    class Meta:
        model = Location
        fields = (
            'url',
            'timeseries',
            'superlocation',
            'sublocations',
            'point_geometry',
            'uuid',
            'name',
            'description',
        )


class TimeseriesListSerializer(serializers.HyperlinkedModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name='timeseries-detail', slug_field='uuid')
    events = serializers.HyperlinkedIdentityField(
        view_name='event-list', slug_field='uuid')
    value_type = serializers.Field('get_value_type')
    latest_value = serializers.Field()

    class Meta:
        model = Timeseries
        fields = ('url', 'name', 'value_type', 'latest_value', 'events', )


class TimeseriesDetailSerializer(serializers.HyperlinkedModelSerializer):
    url = serializers.HyperlinkedIdentityField(
        view_name='timeseries-detail', slug_field='uuid')
    location = serializers.HyperlinkedRelatedField(
        view_name='location-detail', slug_field='uuid')
    events = serializers.HyperlinkedIdentityField(
        view_name='event-list', slug_field='uuid')
    value_type = serializers.Field('get_value_type')
    latest_value = serializers.Field()

    class Meta:
        model = Timeseries
        fields = (
            'url',
            'location',
            'events',
            'latest_value',
            'uuid',
            'name',
            'description',
            'value_type',
            'source',
            'owner',
            'first_value_timestamp',
            'latest_value_timestamp',
            'supplying_systems',
            'parameter',
        )
        depth = 1


class LogicalGroupListSerializer(serializers.HyperlinkedModelSerializer):
    timeseries = serializers.ManyHyperlinkedRelatedField(
        view_name='timeseries-detail', slug_field='uuid')

    class Meta:
        model = LogicalGroup
        fields = (
            'url',
            'name',
            'timeseries',
        )


class LogicalGroupLinkSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = LogicalGroup
        fields = (
            'url',
            'name',
        )


class LogicalGroupDetailSerializer(serializers.HyperlinkedModelSerializer):
    timeseries = serializers.ManyHyperlinkedRelatedField(
        view_name='timeseries-detail', slug_field='uuid')
    parents = LogicalGroupLinkSerializer(source='parents')
    children = LogicalGroupLinkSerializer(source='children')

    class Meta:
        model = LogicalGroup

{'fraction_non_alphanumeric': 0.09405530717006128, 'fraction_numerical': 0.00016559032952475575, 'mean_word_length': 3.0357500835282325, 'pattern_counts': {'":': 0, '<': 5, '<?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': '212459', 'n_tokens_mistral': 3212, 'n_tokens_neox': 3041, 'n_words': 604}