-
Notifications
You must be signed in to change notification settings - Fork 5
CDD-3295: Dual Category Chart Interface #3222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c8300ed
CDD-3295: Add dual category chart.
tushortz 3dca217
Add dual category support to tables
aidan b1025d4
Merge branch 'main' into feature/CDD-3295-dual-category-chart-interface
sahmed06 8fe78dc
pip: (deps): bump virtualenv from 21.4.2 to 21.5.0
dependabot[bot] c4aebe3
Merge branch 'main' into feature/CDD-3295-dual-category-chart-interface
tushortz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| import contextlib | ||
|
|
||
| from django.db.utils import OperationalError | ||
| from rest_framework import serializers | ||
| from rest_framework.request import Request | ||
|
|
||
| from metrics.api.serializers import help_texts | ||
| from metrics.api.serializers.plots import PlotSerializer | ||
| from metrics.domain.common.utils import ( | ||
| DEFAULT_CHART_HEIGHT, | ||
| DEFAULT_CHART_WIDTH, | ||
| DEFAULT_X_AXIS, | ||
| DEFAULT_Y_AXIS, | ||
| ChartAxisFields, | ||
| ) | ||
| from metrics.domain.models import ChartRequestParams | ||
|
|
||
|
|
||
| class DualCategoryTableSegmentSerializer(serializers.Serializer): | ||
| colour = serializers.CharField( | ||
| required=False, | ||
| allow_blank=True, | ||
| allow_null=True, | ||
| default="", | ||
| help_text=help_texts.LABEL_FIELD, | ||
| ) | ||
|
|
||
| secondary_field_value = serializers.CharField( | ||
| required=False, | ||
| allow_blank=True, | ||
| allow_null=True, | ||
| default="", | ||
| help_text=help_texts.LABEL_FIELD, | ||
| ) | ||
|
|
||
| label = serializers.CharField( | ||
| required=False, | ||
| allow_blank=True, | ||
| allow_null=True, | ||
| default="", | ||
| help_text=help_texts.LABEL_FIELD, | ||
| ) | ||
|
|
||
|
|
||
| class DualCategoryTableSegmentListSerializer(serializers.ListSerializer): | ||
| child = DualCategoryTableSegmentSerializer() | ||
|
|
||
|
|
||
| class DualCategoryTablesSerializer(serializers.Serializer): | ||
|
|
||
| segments = DualCategoryTableSegmentListSerializer() | ||
|
|
||
| static_fields = PlotSerializer() | ||
|
|
||
| x_axis = serializers.ChoiceField( | ||
| choices=ChartAxisFields.choices(), | ||
| required=False, | ||
| allow_blank=True, | ||
| allow_null=True, | ||
| help_text=help_texts.CHART_X_AXIS, | ||
| default=DEFAULT_X_AXIS, | ||
| ) | ||
|
|
||
| y_axis = serializers.ChoiceField( | ||
| choices=ChartAxisFields.choices(), | ||
| required=False, | ||
| allow_blank=True, | ||
| allow_null=True, | ||
| help_text=help_texts.CHART_Y_AXIS, | ||
| default=DEFAULT_Y_AXIS, | ||
| ) | ||
|
|
||
| primary_field_values = serializers.ListField( | ||
| child=serializers.CharField(), | ||
| help_text="List of primary field values for this segment", | ||
| required=True, | ||
| allow_empty=False, | ||
| ) | ||
|
|
||
| secondary_category = serializers.CharField( | ||
| help_text="Secondary category field for the chart", | ||
| required=True, | ||
| ) | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| with contextlib.suppress(OperationalError): | ||
| super().__init__(*args, **kwargs) | ||
|
|
||
| def to_models(self, request: Request) -> ChartRequestParams: | ||
|
|
||
| groups_plots = [] | ||
| primary_field_values = self.data.get("primary_field_values") | ||
| x_axis = self.data.get("x_axis") or DEFAULT_X_AXIS | ||
| y_axis = self.data.get("y_axis") or DEFAULT_Y_AXIS | ||
| static_fields = self.data.get("static_fields") | ||
| print(f"AIDAN static_fields {static_fields}") | ||
| topic = static_fields.get("topic") | ||
|
Check warning on line 97 in metrics/api/serializers/dual_category_tables.py
|
||
|
|
||
| for primary_field_value in primary_field_values: | ||
| for segment in self.data["segments"]: | ||
| plot = { | ||
| "y_axis": y_axis, | ||
| "x_axis": primary_field_value, | ||
| self.data.get("secondary_category"): segment[ | ||
| "secondary_field_value" | ||
| ], | ||
| **static_fields, | ||
| } | ||
| groups_plots.append(plot) | ||
| print(f"AIDAN: plots {groups_plots}") | ||
| return ChartRequestParams( | ||
| chart_height=DEFAULT_CHART_HEIGHT, | ||
| chart_width=DEFAULT_CHART_WIDTH, | ||
| file_format="svg", | ||
| plots=groups_plots, | ||
| request=request, | ||
| x_axis=x_axis, | ||
| y_axis=y_axis, | ||
| ) | ||
|
|
||
|
|
||
| class DualCategoryTablesResponseValueSerializer(serializers.Serializer): | ||
| label = serializers.CharField() | ||
| value = serializers.CharField() | ||
| in_reporting_delay_period = serializers.BooleanField() | ||
| # Confidence intervals aren't implemented for dual category charts | ||
|
|
||
|
|
||
| class DualCategoryTablesResponseValuesListSerializer(serializers.ListSerializer): | ||
| child = DualCategoryTablesResponseValueSerializer() | ||
|
|
||
|
|
||
| class DualCategoryTablesResponsePlotsListSerializer(serializers.Serializer): | ||
| reference = serializers.CharField() | ||
| values = DualCategoryTablesResponseValuesListSerializer() | ||
|
|
||
|
|
||
| class DualCategoryTablesResponseSerializer(serializers.ListSerializer): | ||
| child = DualCategoryTablesResponsePlotsListSerializer() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.