Skip to content

API reference

Core

best_strategy(num_banners: int, num_polygons: int = 10 ** 2, target_audience: dict[str, ...] = {'gender': 'all', 'ageFrom': 18, 'ageTo': 100, 'income': 'abc'}, iterations: int = 10) -> list[Polygon]

Synchronously predict best strategy

Parameters:

  • num_banners (int) –

    number of banners the company can afford

  • num_polygons (int, default: 10 ** 2 ) –

    number of polygons the city would be divided in (should be a full square)

  • target_audience (dict[str, ...], default: {'gender': 'all', 'ageFrom': 18, 'ageTo': 100, 'income': 'abc'} ) –

    target audience as a dict ("name" field doesn't matter)

  • iterations (int, default: 10 ) –

    number of iterations

Returns:

  • list[Polygon]

    Predicted strategy

Source code in src/advertising_locations/main.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def best_strategy(
        num_banners: int,
        num_polygons: int = 10 ** 2,
        target_audience: dict[str, ...] = {"gender": "all", "ageFrom": 18, "ageTo": 100, "income": "abc"},
        iterations: int = 10,
) -> list[Polygon]:
    """
        Synchronously predict best strategy

        Args:
            num_banners: number of banners the company can afford
            num_polygons: number of polygons the city would be divided in (should be a full square)
            target_audience: target audience as a dict ("name" field doesn't matter)
            iterations: number of iterations

        Returns:
            Predicted strategy
    """
    value, genome = genetic_optimizer.find_optimum(
        num_banners=num_banners,
        num_polygons=num_polygons,
        TA=target_audience,
        iters=iterations
    )[-1]

    return genetic_optimizer.get_polygons(genome)

best_strategy_async(num_banners: int, num_polygons: int = 10 ** 2, target_audience: dict[str, ...] = {'gender': 'all', 'ageFrom': 18, 'ageTo': 100, 'income': 'abc'}, iterations: int = 10) -> list[Polygon] async

Asynchronous wrapper around the best_strategy function

Parameters:

  • num_banners (int) –

    number of banners the company can afford

  • num_polygons (int, default: 10 ** 2 ) –

    number of polygons the city would be divided in (should be a full square)

  • target_audience (dict[str, ...], default: {'gender': 'all', 'ageFrom': 18, 'ageTo': 100, 'income': 'abc'} ) –

    target audience as a dict ("name" field doesn't matter)

  • iterations (int, default: 10 ) –

    number of iterations

Returns:

  • list[Polygon]

    Predicted strategy

Source code in src/advertising_locations/main.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
async def best_strategy_async(
        num_banners: int,
        num_polygons: int = 10 ** 2,
        target_audience: dict[str, ...] = {"gender": "all", "ageFrom": 18, "ageTo": 100, "income": "abc"},
        iterations: int = 10,
) -> list[Polygon]:
    """
        Asynchronous wrapper around the ``best_strategy`` function

        Args:
            num_banners: number of banners the company can afford
            num_polygons: number of polygons the city would be divided in (should be a full square)
            target_audience: target audience as a dict ("name" field doesn't matter)
            iterations: number of iterations

        Returns:
            Predicted strategy
    """
    return await asyncio.to_thread(best_strategy, num_banners, num_polygons, target_audience, iterations)

Polygon(lon_left: float, lon_right: float, lat_top: float, lat_bottom: float, count: int) dataclass

lon_left: float instance-attribute

lon_right: float instance-attribute

lat_top: float instance-attribute

lat_bottom: float instance-attribute

count: int instance-attribute