<commit_before>#
# CDR-Stats License
# http://www.cdr-stats.org
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2012 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# <NAME> <<EMAIL>>
#

from voip_billing.models import VoIPRetailPlan
from voip_billing.function_def import prefix_list_string


def rate_engine(voipplan_id=None, destination_no=None):
    """
    To determine the cost of the voip call and get provider/gateway
    to use to deliver the call.
    """

    if destination_no is not None:
        destination_prefix_list = prefix_list_string(str(destination_no))
    else:
        destination_prefix_list = prefix_list_string(str(voipcall.recipient_number))

    #destination_prefix_list = '34, 346, 3465, 34650'
    #voipplan_id = 1

    # updated query For postgresql
    query = VoIPRetailPlan.objects.raw(
        'SELECT rpid as id, cpid, cr_prefix, prefix as rt_prefix, rrid, \
        carrier_rate, retail_rate, crid, provider_id, gateway_id, sum_metric \
        FROM ( \
            SELECT DISTINCT allsellrates.*, \
                    voipbilling_voip_carrier_rate.id AS crid, \
                    voipbilling_voip_carrier_rate.prefix AS cr_prefix, \
                    voip_provider.id AS provider_id, \
                    voip_provider.gateway_id AS gateway_id, \
                    voipbilling_voip_carrier_rate.carrier_rate,\
                    (voipbilling_voip_carrier_plan.metric + \
                     allsellrates.metric + voip_provider.metric)\
                     AS sum_metric, \
                     voipbilling_voip_carrier_plan.id AS cpid \
            FROM ( \
            SELECT DISTINCT voipbilling_voip_retail_plan.id AS rpid, \
                    voipbilling_voip_retail_rate.prefix, \
                    voipbilling_voip_retail_rate.id AS rrid, \<commit_msg>update rate_engine<commit_after>#
# CDR-Stats License
# http://www.cdr-stats.org
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2012 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# <NAME> <<EMAIL>>
#

from voip_billing.models import VoIPRetailPlan
from voip_billing.function_def import prefix_list_string


def rate_engine(voipplan_id=None, destination_no=None):
    """
    To determine the cost of the voip call and get provider/gateway
    to use to deliver the call.
    """
    destination_prefix_list = prefix_list_string(str(destination_no))

    #destination_prefix_list = '34, 346, 3465, 34650'
    #voipplan_id = 1

    # updated query For postgresql
    query = VoIPRetailPlan.objects.raw(
        'SELECT rpid as id, cpid, cr_prefix, prefix as rt_prefix, rrid, \
        carrier_rate, retail_rate, crid, provider_id, gateway_id, sum_metric \
        FROM ( \
            SELECT DISTINCT allsellrates.*, \
                    voipbilling_voip_carrier_rate.id AS crid, \
                    voipbilling_voip_carrier_rate.prefix AS cr_prefix, \
                    voip_provider.id AS provider_id, \
                    voip_provider.gateway_id AS gateway_id, \
                    voipbilling_voip_carrier_rate.carrier_rate,\
                    (voipbilling_voip_carrier_plan.metric + \
                     allsellrates.metric + voip_provider.metric)\
                     AS sum_metric, \
                     voipbilling_voip_carrier_plan.id AS cpid \
            FROM ( \
            SELECT DISTINCT voipbilling_voip_retail_plan.id AS rpid, \
                    voipbilling_voip_retail_rate.prefix, \
                    voipbilling_voip_retail_rate.id AS rrid, \
{'fraction_non_alphanumeric': 0.07462686567164178, 'fraction_numerical': 0.014410705095213588, 'mean_word_length': 2.3479758828596036, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4136072', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1191, 'n_words': 303}