<commit_before>"use strict"

define ['underscore', 'backbone', 'app/models'], (_, Backbone, models) ->
    class Accessibility
        constructor: ->
            _.extend @, Backbone.Events
            #setTimeout @_request_data, 3000
            @_request_data()

        _request_data: =>
            settings =
                url: "#{app_settings.service_map_backend}/accessibility_rule/"
                success: (data) =>
                    @rules = data.rules
                    @messages = data.messages
                    @trigger 'change'
                error: (data) =>
                    throw new Error "Unable to retrieve accessibility data"
            Backbone.ajax settings
        _emit_shortcoming: (rule, messages) ->
            if rule.id not of @messages
                return
            msg = @messages[rule.id]
            if 'shortcoming' of msg
                requirement_id = rule.requirement_id
                unless requirement_id of messages
                    messages[requirement_id] = []
                current_messages = messages[requirement_id]
                if rule.id == requirement_id
                    # This is a top level requirement -
                    # only add top level message
                    # if there are no specific messages.
                    unless current_messages.length
                        current_messages.push msg.shortcoming
                else
                    current_messages.push msg.shortcoming
            return

        _calculate_shortcomings: (rule, properties, messages, level=None) ->
            if rule.operands[0] not instanceof Object
                op = rule.operands
                prop = properties[op[0]]
                # If the information is not supplied, pretend that everything
                # is fine.
                if not prop
                    return true
                val = op[1]
                if rule.operator == 'NEQ'
                    is_okay = prop != val
                else if rule.operator == 'EQ'
                    is_okay = prop == val
                else
                    throw new Error "invalid operator #{rule.operator}"
                if not is_okay
                    @_emit_shortcoming rule, messages
                return is_okay

            ret_values = []
            for op in rule.operands
                is_okay = @_calculate_shortcomings op, properties, messages, level=level+1
                ret_values.push is_okay

            if rule.operator not in ['AND', 'OR']
                throw new Error "invalid operator #{rule.operator}"<commit_msg>Adapt to deduplicated messages api.<commit_after>"use strict"

define ['underscore', 'backbone', 'app/models'], (_, Backbone, models) ->
    class Accessibility
        constructor: ->
            _.extend @, Backbone.Events
            #setTimeout @_request_data, 3000
            @_request_data()

        _request_data: =>
            settings =
                url: "#{app_settings.service_map_backend}/accessibility_rule/"
                success: (data) =>
                    @rules = data.rules
                    @messages = data.messages
                    @trigger 'change'
                error: (data) =>
                    throw new Error "Unable to retrieve accessibility data"
            Backbone.ajax settings
        _emit_shortcoming: (rule, messages) ->
            if rule.msg == null or rule.msg not of @messages
                return
            msg = @messages[rule.msg]
            if msg?
                requirement_id = rule.requirement_id
                unless requirement_id of messages
                    messages[requirement_id] = []
                current_messages = messages[requirement_id]
                if rule.id == requirement_id
                    # This is a top level requirement -
                    # only add top level message
                    # if there are no specific messages.
                    unless current_messages.length
                        current_messages.push msg
                else
                    current_messages.push msg
            return

        _calculate_shortcomings: (rule, properties, messages, level=None) ->
            if rule.operands[0] not instanceof Object
                op = rule.operands
                prop = properties[op[0]]
                # If the information is not supplied, pretend that everything
                # is fine.
                if not prop
                    return true
                val = op[1]
                if rule.operator == 'NEQ'
                    is_okay = prop != val
                else if rule.operator == 'EQ'
                    is_okay = prop == val
                else
                    throw new Error "invalid operator #{rule.operator}"
                if not is_okay
                    @_emit_shortcoming rule, messages
                return is_okay

            ret_values = []
            for op in rule.operands
                is_okay = @_calculate_shortcomings op, properties, messages, level=level+1
                ret_values.push is_okay

            if rule.operator not in ['AND', 'OR']
                throw new Error "invalid operator #{rule.operator}"
{'fraction_non_alphanumeric': 0.07077451354444868, 'fraction_numerical': 0.003052270125906143, 'mean_word_length': 1.3005704256252741, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '4790044', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1168, 'n_words': 360}