Exemplo n.º 1
0
def ctr(clicks: int, impressions: int) -> float:
    """Calculate CTR(Click Through Rate)

    Args:
        clicks (integer): count of times users have clicked on ads
        impressions (integer): count of times ads display to users
    Returns:
        float: Return value
    Usage:
      >>> from py_admetric import py_admetric
      >>> val = py_admetric.ctr(1,1)
    """
    validate_integer(clicks, impressions)
    validate_negative(clicks, impressions)
    return safe_div(clicks, impressions)
Exemplo n.º 2
0
def cpa(cost: int, conversions: int) -> float:
    """Calculate CPA(Cost Per Action (Cost Per Acquisition))

    Args:
        cost (integer): expense to earn impressions
        conversions (integer): count of times users have acted on ads
    Returns:
        float: Return value
    Usage:
      >>> from py_admetric import py_admetric
      >>> val = py_admetric.cpa(1,1)
    """
    validate_integer(cost, conversions)
    validate_negative(cost, conversions)
    return safe_div(cost, conversions)
Exemplo n.º 3
0
def cpv(cost: int, video_views: int) -> float:
    """Calculate CPV(Cost Per View)

    Args:
        cost (integer): expense to earn impressions
        video_views (integer): count of times ads viewed
    Returns:
        float: Return value
    Usage:
      >>> from py_admetric import py_admetric
      >>> val = py_admetric.cpv(1,1)
    """
    validate_integer(cost, video_views)
    validate_negative(cost, video_views)
    return safe_div(cost, video_views)
Exemplo n.º 4
0
def cpc(cost: int, clicks: int) -> float:
    """Calculate CPC(Cost Per Click)

    Args:
        cost (integer): expense to earn impressions
        clicks (integer): count of times users have clicked on ads
    Returns:
        float: Return value
    Usage:
      >>> from py_admetric import py_admetric
      >>> val = py_admetric.cpc(1,1)
    """
    validate_integer(cost, clicks)
    validate_negative(cost, clicks)
    return safe_div(cost, clicks)
Exemplo n.º 5
0
def cpi(cost: int, impressions: int) -> float:
    """Calculate CPI(Cost Per Impression)

    Args:
        cost (integer): expense to earn impressions
        impressions (integer): count of times ads display to users
    Returns:
        float: Return value
    Usage:
      >>> from py_admetric import py_admetric
      >>> val = py_admetric.cpi(1,1)
    """
    validate_integer(cost, impressions)
    validate_negative(cost, impressions)
    return safe_div(cost, impressions)
Exemplo n.º 6
0
def cvr(conversions: int, clicks: int) -> float:
    """Calculate CVR(Conversion Rate)

    Args:
        conversions (integer): count of times users have acted on ads
        clicks (integer): count of times users have clicked on ads
    Returns:
        float: Return value
    Usage:
      >>> from py_admetric import py_admetric
      >>> val = py_admetric.cvr(1,1)
    """
    validate_integer(conversions, clicks)
    validate_negative(conversions, clicks)
    return safe_div(conversions, clicks)
Exemplo n.º 7
0
def vtr(video_views: int, impressions: int) -> float:
    """Calculate VTR(View Through Rate)

    Args:
        video_views (integer): count of times ads viewed
        impressions (integer): count of times ads display to users
    Returns:
        float: Return value
    Usage:
      >>> from py_admetric import py_admetric
      >>> val = py_admetric.vtr(1,1)
    """
    validate_integer(video_views, impressions)
    validate_negative(video_views, impressions)
    return safe_div(video_views, impressions)
Exemplo n.º 8
0
    def test_validate_integer(self):
        test_cases = [
            {
                "name": "standard_case: both of a and b are integer value",
                "args": {
                    "a": 200,
                    "b": 100,
                },
                "want_error": False,
            },
            {
                "name": "standard_case: a is string value",
                "args": {
                    "a": "aa",
                    "b": 0,
                },
                "want_error": True,
                "error_type": ValueError
            },
            {
                "name": "standard_case: both of a and b are string value",
                "args": {
                    "a": "aa",
                    "b": "aw",
                },
                "want_error": True,
                "error_type": ValueError
            },
            {
                "name": "standard_case: both of a and b are float value",
                "args": {
                    "a": 1.11,
                    "b": 1.12,
                },
                "want_error": True,
                "error_type": ValueError
            },
            {
                "name": "standard_case: a is a list of integer",
                "args": {
                    "a": [1],
                    "b": 1,
                },
                "want_error": True,
                "error_type": ValueError
            },
            {
                "name": "standard_case: b is a dict",
                "args": {
                    "a": {
                        "a": 1,
                        "b": 2
                    },
                    "b": 1,
                },
                "want_error": True,
                "error_type": ValueError
            },
        ]

        test_length = len(test_cases)
        for i in range(test_length):
            target_test = test_cases[i]

            with self.subTest(target_test["name"]):
                # cases which raises error
                if target_test.get("want_error", False):
                    with self.assertRaises(target_test["error_type"]):
                        utils.validate_integer(target_test["args"]["a"],
                                               target_test["args"]["b"])
                    continue

                # cases which returns None
                actual = utils.validate_integer(target_test["args"]["a"],
                                                target_test["args"]["b"])
                self.assertIsNone(actual)