def get_multiple_event_list_for_feature(
    environment_id: int,
    feature_name: str,
    date_start: datetime | None = None,
    aggregate_every: str = "24h",
) -> list[dict]:  # type: ignore[type-arg]
    """
    Get aggregated request data for the given feature in a given environment across
    all time, aggregated into time windows of length defined by the period argument.

    Example data structure
    [
        {
            "first_feature_name": 13,  // feature name and number of requests
            "datetime": '2020-12-18'
        },
        {
            "first_feature_name": 15,
            "datetime": '2020-11-18'  // 30 days prior
        }
    ]

    :param environment_id: an id of the environment to get usage for
    :param feature_name: the name of the feature to get usage for
    :param date_start: the influx datetime period to filter on
    :param aggregate_every: the influx time period to aggregate the data by, e.g. 24h

    :return: a list of dicts with feature and request count in a specific environment
    """
    now = timezone.now()
    if date_start is None:
        date_start = now - timedelta(days=30)

    results = InfluxDBWrapper.influx_query_manager(
        date_start=date_start,
        filters=f'|> filter(fn:(r) => r._measurement == "feature_evaluation") \
                  |> filter(fn: (r) => r["_field"] == "request_count") \
                  |> filter(fn: (r) => r["environment_id"] == "{environment_id}") \
                  |> filter(fn: (r) => r["feature_id"] == "{feature_name}")',
        extra=f'|> aggregateWindow(every: {aggregate_every}, fn: sum, createEmpty: false, timeSrc: "_start") \
                   |> yield(name: "sum")',
    )
    if not results:
        return []

    dataset = [{} for _ in range(len(results[0].records))]  # type: ignore[var-annotated]

    # Iterating over Influx data looking for feature_id, and adding proper requests value and datetime to it
    # todo move it to marshmallow schema
    for result in results:
        for i, record in enumerate(result.records):
            dataset[i][record.values["feature_id"]] = record.values["_value"]
            dataset[i]["datetime"] = record.values["_time"].strftime("%Y-%m-%d")

    return dataset

    Get aggregated request data for the given feature in a given environment across
    all time, aggregated into time windows of length defined by the period argument.

    Example data structure
    [
        {
            "first_feature_name": 13,  // feature name and number of requests
            "datetime": '2020-12-18'
        },
        {
            "first_feature_name": 15,
            "datetime": '2020-11-18'  // 30 days prior
        }
    ]

    :param environment_id: an id of the environment to get usage for
    :param feature_name: the name of the feature to get usage for
    :param date_start: the influx datetime period to filter on
    :param aggregate_every: the influx time period to aggregate the data by, e.g. 24h

    :return: a list of dicts with feature and request count in a specific environment
    
api/app_analytics/influxdb_wrapper.py