Skip to content

Commit

Permalink
updated filterdict key based on the dynamic filter changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aykutaaykut committed Oct 15, 2023
1 parent a0cda89 commit 08a1133
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 25 deletions.
8 changes: 4 additions & 4 deletions backend/experiment/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ async def set_video_group_filter_aggregators(
# Reuse existing filter for matching id and type.
if (
filter_id in old_group_filter_aggregators
and old_group_filter_aggregators[filter_id]._group_filter.config["type"]
== config["type"]
and old_group_filter_aggregators[filter_id]._group_filter.config["name"]
== config["name"]
):
self._video_group_filter_aggregators[
filter_id
Expand Down Expand Up @@ -492,8 +492,8 @@ async def set_audio_group_filter_aggregators(
# Reuse existing filter for matching id and type.
if (
filter_id in old_group_filter_aggregators
and old_group_filter_aggregators[filter_id]._group_filter.config["type"]
== config["type"]
and old_group_filter_aggregators[filter_id]._group_filter.config["name"]
== config["name"]
):
self._audio_group_filter_aggregators[
filter_id
Expand Down
2 changes: 1 addition & 1 deletion backend/filters/filter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def is_valid_filter_dict(data) -> TypeGuard[FilterDict]:
True if `data` is a valid FilterDict.
"""
if "name" not in data:
logger.debug("Missing key: type")
logger.debug("Missing key: name")
return False

filter_name = data["name"]
Expand Down
4 changes: 2 additions & 2 deletions backend/group_filters/group_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(self, config: FilterDict, participant_id: str) -> None:
Parameters
----------
config : custom_types.filter.FilterDict
Configuration for filter. `config["type"]` must match the filter
Configuration for filter. `config["name"]` must match the filter
implementation.
Notes
Expand All @@ -49,7 +49,7 @@ def __init__(self, config: FilterDict, participant_id: str) -> None:
filters after __init__ (if they are designed to be).
"""
self._logger = logging.getLogger(
f"{config['type']}-GroupFilter-P-{participant_id}"
f"{config['name']}-GroupFilter-P-{participant_id}"
)
self._config = config
self.participant_id = participant_id
Expand Down
8 changes: 4 additions & 4 deletions backend/group_filters/group_filter_aggregator_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
def create_group_filter_aggregator(
channel: str, group_filter_config: FilterDict, port: int
) -> GroupFilterAggregator:
group_filter_type = group_filter_config["type"]
group_filter_name = group_filter_config["name"]

group_filters = group_filter_utils.get_group_filter_dict()

if group_filter_type not in group_filters:
if group_filter_name not in group_filters:
raise ErrorDictException(
code=404,
type="UNKNOWN_FILTER_TYPE",
description=f"Unknown group filter type {group_filter_type}.",
description=f"Unknown group filter type {group_filter_name}.",
)

return GroupFilterAggregator(channel, group_filters[group_filter_type], port)
return GroupFilterAggregator(channel, group_filters[group_filter_name], port)
8 changes: 4 additions & 4 deletions backend/group_filters/group_filter_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
def create_group_filter(
group_filter_config: FilterDict, participant_id: str
) -> GroupFilter:
group_filter_type = group_filter_config["type"]
group_filter_name = group_filter_config["name"]

group_filters = group_filter_utils.get_group_filter_dict()

if group_filter_type not in group_filters:
if group_filter_name not in group_filters:
raise ErrorDictException(
code=404,
type="UNKNOWN_FILTER_TYPE",
description=f"Unknown group filter type {group_filter_type}.",
description=f"Unknown group filter type {group_filter_name}.",
)

return group_filters[group_filter_type](group_filter_config, participant_id)
return group_filters[group_filter_name](group_filter_config, participant_id)
16 changes: 8 additions & 8 deletions backend/group_filters/group_filter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@


def is_valid_filter_dict(data) -> TypeGuard[FilterDict]:
if "type" not in data:
logger.debug("Missing key: type")
if "name" not in data:
logger.debug("Missing key: name")
return False

group_filter_type = data["type"]
group_filter_name = data["name"]

if not isinstance(group_filter_type, str):
logger.debug('GroupFilter "type" must be of type str.')
if not isinstance(group_filter_name, str):
logger.debug('GroupFilter "name" must be of type str.')
return False

group_filters = get_group_filter_dict()

if group_filter_type not in group_filters:
logging.debug(f"Invalid filter type: {group_filter_type}.")
if group_filter_name not in group_filters:
logging.debug(f"Invalid filter type: {group_filter_name}.")
return False

return isinstance(data["id"], str) and group_filters[
group_filter_type
group_filter_name
].validate_dict(data)


Expand Down
2 changes: 1 addition & 1 deletion backend/hub/track_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ async def _set_group_filters(
# Reuse existing filter for matching id and type.
if (
filter_id in old_group_filters
and old_group_filters[filter_id].config["type"] == config["type"]
and old_group_filters[filter_id].config["name"] == config["name"]
):
self._group_filters[filter_id] = old_group_filters[filter_id]
self._group_filters[filter_id].set_config(config)
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/pages/ConnectionTest/ConnectionTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,15 @@ function SetFilterPresets(props: { connection: Connection }): JSX.Element {
onClick={() =>
props.connection.sendMessage("SET_GROUP_FILTERS", {
audio_group_filters: [],
video_group_filters: [{ type: "TEMPLATE_GF", id: "template_gf" }]
video_group_filters: [
{
name: "TEMPLATE_GF",
id: "template_gf",
channel: "video",
groupFilter: true,
config: {}
}
]
})
}
disabled={props.connection.state !== ConnectionState.CONNECTED}
Expand Down

0 comments on commit 08a1133

Please sign in to comment.