-
Notifications
You must be signed in to change notification settings - Fork 5
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
Operational learning stats API #2335
Operational learning stats API #2335
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor Changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's Check the queries and remove duplicated queries.
mostly for country and region.
3e73ced
to
4d61d3d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add some filter on it
ad5e19a
to
c1245a6
Compare
Add validated filter
c1245a6
to
2a6d79f
Compare
3c9dda6
to
ca1c3d3
Compare
per/serializers.py
Outdated
|
||
|
||
class LearningSourcesOvertimeSerializer(serializers.Serializer): | ||
type = serializers.IntegerField() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@susilnem Do we return type as integer or get display name for type? If no may be we need to do type = serializers.CharField(source='get_type_display', read_only=True)
to get the type name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, for now it's not required as it should be managed by the client side
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure about this? It will be complicated for the client side to do this mapping.
source='get_type_display'
can't be used here, as the object will be a dict instead of a proper object. We could use serializer_method or do the enum->label in the views.
32c4d62
to
afff697
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Few integration required
per/drf_views.py
Outdated
learning_by_sector = ( | ||
SectorTag.objects.filter(validated_sectors__in=queryset, title__isnull=False) | ||
.annotate(count=Count("validated_sectors", distinct=True)) | ||
.values("title", "count") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to add 'id', this will be used by client as unique key
date=F("start_date"), | ||
count=Count("appealdocument", distinct=True), | ||
) | ||
.values("type", "date", "count") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to add 'id', this will be used by client as unique key
per/drf_views.py
Outdated
source_used=Count("appeal_code__appealdocument", distinct=True), | ||
) | ||
|
||
learning_by_sector = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add _qs
as postfix (learning_by_sector_qs
) for all querysets variables
per/drf_views.py
Outdated
region_name=F("label"), | ||
count=Count("appeal__opslearning", distinct=True), | ||
) | ||
.values("region_name", "count") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to add 'id', this will be used by client as unique key
country_name=F("name"), | ||
count=Count("appeal__opslearning", distinct=True), | ||
) | ||
.values("country_id", "country_name", "count") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to add 'id', this will be used by client as unique key
per/serializers.py
Outdated
|
||
|
||
class LearningSourcesOvertimeSerializer(serializers.Serializer): | ||
type = serializers.IntegerField() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure about this? It will be complicated for the client side to do this mapping.
source='get_type_display'
can't be used here, as the object will be a dict instead of a proper object. We could use serializer_method or do the enum->label in the views.
per/factories.py
Outdated
class Meta: | ||
model = Appeal | ||
|
||
country = factory.SubFactory(CountryFactory) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not use factory.SubFactory
, this will create objects without developer knowledge which can have weird confusing related to data generation, and it's effect.
per/factories.py
Outdated
class OpsLearningFactory(factory.django.DjangoModelFactory): | ||
learning = fuzzy.FuzzyText(length=50) | ||
|
||
class Meta: | ||
model = OpsLearning | ||
|
||
appeal_code = factory.SubFactory(AppealFactory) | ||
is_validated = fuzzy.FuzzyChoice([True, False]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not use fuzzy choice for is_validated, we should manually define in the test cases as lots of endpoints depends on this
learning_by_region = LearningByRegionSerializer(many=True) | ||
learning_by_country = LearningByCountrySerializer(many=True) | ||
learning_by_sector = LearningBySectorSerializer(many=True) | ||
sources_overtime = LearningSourcesOvertimeSerializer(many=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's explicitly define required=True for all fields
url = "/api/v2/ops-learning/stats/" | ||
response = self.client.get(url) | ||
|
||
self.assert_200(response) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are comparing all fields data, it will be better to just use basic dict assert instead.
assert response.data == expected_data
* Add Opslearning stats Add validated filter * Refactor ops learning stat api * Change in source over time * Add filter check for validated opslearning * fix test cases and refactor queryset * Add start date field in appeal serailizer * Change filter queryset and add label for appealtype * Define required field in serializers * Remove subfactories and id in appeal queryset --------- Co-authored-by: Sushil Tiwari <[email protected]>
Addresses
Changes
Checklist
Things that should succeed before merging.
Release
If there is a version update, make sure to tag the repository with the latest version.