<commit_before>#  Copyright 2007-2014 University Of Southern California
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing,
#  software distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

__author__ = '<NAME>'

try:
    from collections import OrderedDict
except ImportError:
    from ordereddict import OrderedDict

from decimal import Decimal

from flask import url_for
from flask.json import JSONEncoder

from sqlalchemy.orm.attributes import instance_state

from Pegasus.db.schema import *

from Pegasus.service.base import PagedResponse, ErrorResponse
from Pegasus.service.monitoring.resources import RootWorkflowResource, RootWorkflowstateResource
from Pegasus.service.monitoring.resources import JobInstanceResource, JobstateResource, TaskResource, InvocationResource
from Pegasus.service.monitoring.resources import WorkflowResource, WorkflowstateResource, JobResource, HostResource

log = logging.getLogger(__name__)


class PegasusServiceJSONEncoder(JSONEncoder):
    """
    JSON Encoder for Pegasus Service API Resources
    """

    def default(self, obj):
        def obj_to_dict(resource, ignore_unloaded=False):
            obj_dict = OrderedDict()

            if ignore_unloaded:
                log.debug('ignore_unloaded is True')
                unloaded = instance_state(obj).unloaded

            for attribute in resource.fields:
                if not ignore_unloaded or (ignore_unloaded and attribute not in unloaded):
                    obj_dict[attribute] = getattr(obj, attribute)

            return obj_dict

        if isinstance(obj, PagedResponse):
            json_record = OrderedDict([
                ('records', obj.records)<commit_msg>Change logging message to show unloaded fields<commit_after>#  Copyright 2007-2014 University Of Southern California
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing,
#  software distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

__author__ = '<NAME>'

try:
    from collections import OrderedDict
except ImportError:
    from ordereddict import OrderedDict

from decimal import Decimal

from flask import url_for
from flask.json import JSONEncoder

from sqlalchemy.orm.attributes import instance_state

from Pegasus.db.schema import *

from Pegasus.service.base import PagedResponse, ErrorResponse
from Pegasus.service.monitoring.resources import RootWorkflowResource, RootWorkflowstateResource
from Pegasus.service.monitoring.resources import JobInstanceResource, JobstateResource, TaskResource, InvocationResource
from Pegasus.service.monitoring.resources import WorkflowResource, WorkflowstateResource, JobResource, HostResource

log = logging.getLogger(__name__)


class PegasusServiceJSONEncoder(JSONEncoder):
    """
    JSON Encoder for Pegasus Service API Resources
    """

    def default(self, obj):
        def obj_to_dict(resource, ignore_unloaded=False):
            obj_dict = OrderedDict()

            if ignore_unloaded:
                unloaded = instance_state(obj).unloaded
                log.debug('ignore_unloaded is True, ignoring %s' % unloaded)

            for attribute in resource.fields:
                if not ignore_unloaded or (ignore_unloaded and attribute not in unloaded):
                    obj_dict[attribute] = getattr(obj, attribute)

            return obj_dict

        if isinstance(obj, PagedResponse):
            json_record = OrderedDict([
                ('records', obj.records)
{'fraction_non_alphanumeric': 0.06236860546601261, 'fraction_numerical': 0.005606166783461808, 'mean_word_length': 3.639219934994583, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1085453', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1066, 'n_words': 394}