<commit_before>import json
from django.http import HttpResponse, Http404
from mpr import models

def as_currency(x):
    try:
        x = float(x)
        return "R %.2f" % x
    except (ValueError, TypeError):
        return "-"

dosage_form = {
    "Liq" : "liquid",
    "Tab" : "tablet",
    "Cap" : "capsule",
    "Oin" : "ointment",
    "Lit" : "lotion",
    "Inj" : "injection",
    "Syr" : "syrup",
    "Eft" : "Effervescent",
    "Drp" : "Drops",
    "Sus" : "Suspension",
    "Cal" : "Calasthetic",
    "Sol" : "Solution",
    "Neb" : "Nebuliser",
    "Inh" : "Inhaler",
    "Inf" : "Infusion",
}

def int_or_float(x):
    try:
        x = float(x)
        if int(x) == float(x):
            return int(x)
        return x
    except (ValueError, TypeError):
        return "-"

def serialize_ingredient(ingredient, strength):
    return {
        "name" : ingredient.name,
        "unit" : ingredient.unit,
        "strength" : int_or_float(strength),
    }

def serialize_product(product):
    return {
        "regno" : product.regno,
        "schedule" : product.schedule,
        "name" : product.name,
        "dosage_form" : dosage_form.get(product.dosage_form, product.dosage_form),
        "pack_size" : product.pack_size,
        "num_packs" : product.num_packs,
        "sep" : as_currency(product.sep),
        "is_generic" : "Generic" if product.is_generic else "Innovator",
        "ingredients" : [
            serialize_ingredient(pi.ingredient, pi.strength)<commit_msg>Added calculation for maximum dispensing fee<commit_after>import json
from django.http import HttpResponse, Http404
from mpr import models

dosage_form = {
    "Liq" : "liquid",
    "Tab" : "tablet",
    "Cap" : "capsule",
    "Oin" : "ointment",
    "Lit" : "lotion",
    "Inj" : "injection",
    "Syr" : "syrup",
    "Eft" : "Effervescent",
    "Drp" : "Drops",
    "Sus" : "Suspension",
    "Cal" : "Calasthetic",
    "Sol" : "Solution",
    "Neb" : "Nebuliser",
    "Inh" : "Inhaler",
    "Inf" : "Infusion",
}

def calc_max_fee(x):
    try:
        if x < 81:
            return x * 1.46 + 6.3
        elif x < 216:
            return x * 1.33 + 16
        elif x < 756:
            return x * 1.15 + 52
        else:
            return x * 1.05 + 123
    except (ValueError, TypeError):
        return "-"

def as_currency(x):
    try:
        x = float(x)
        return "R %.2f" % x
    except (ValueError, TypeError):
        return "-"

def int_or_float(x):
    try:
        x = float(x)
        if int(x) == float(x):
            return int(x)
        return x
    except (ValueError, TypeError):
        return "-"

def serialize_ingredient(ingredient, strength):
    return {
        "name" : ingredient.name,
        "unit" : ingredient.unit,
        "strength" : int_or_float(strength),
    }

def serialize_product(product):
    return {
        "regno" : product.regno,
        "schedule" : product.schedule,
        "name" : product.name,
        "dosage_form" : dosage_form.get(product.dosage_form, product.dosage_form),
        "pack_size" : product.pack_size,
        "num_packs" : product.num_packs,
        "sep" : as_currency(calc_max_fee(product.sep)),
        "is_generic" : "Generic" if product.is_generic else "Innovator",
        "ingredients" : [
            serialize_ingredient(pi.ingredient, pi.strength)
{'fraction_non_alphanumeric': 0.14555822328931572, 'fraction_numerical': 0.011104441776710685, 'mean_word_length': 2.261252446183953, 'pattern_counts': {'":': 0, '<': 6, '<?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': '191302', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1174, 'n_words': 253}