Skip to content

Commit

Permalink
rename study counts
Browse files Browse the repository at this point in the history
  • Loading branch information
atarkowska committed Dec 12, 2017
1 parent cf1bf68 commit 868cb26
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion emgapi/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class Meta:

class Top10BiomeSerializer(BiomeSerializer):

study_count = serializers.IntegerField()
studies_count = serializers.IntegerField()

class Meta:
model = emg_models.Biome
Expand Down
6 changes: 3 additions & 3 deletions emgapi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def top10(self, request):
"""

sql = """
SELECT parent.BIOME_ID, COUNT(distinct ss.STUDY_ID) as study_count
SELECT parent.BIOME_ID, COUNT(distinct ss.STUDY_ID) as studies_count
FROM BIOME_HIERARCHY_TREE AS node,
BIOME_HIERARCHY_TREE AS parent,
SAMPLE as sample,
Expand All @@ -152,13 +152,13 @@ def top10(self, request):
LIMIT 10;"""

res = emg_models.Biome.objects.raw(sql)
biomes = {b.biome_id: b.study_count for b in res}
biomes = {b.biome_id: b.studies_count for b in res}
biomes = OrderedDict(
sorted(biomes.items(), key=operator.itemgetter(1), reverse=True))
queryset = emg_models.Biome.objects.filter(
biome_id__in=list(biomes))
for q in queryset:
q.study_count = biomes[q.biome_id]
q.studies_count = biomes[q.biome_id]

serializer = self.get_serializer(queryset, many=True)
return Response(serializer.data)
Expand Down

0 comments on commit 868cb26

Please sign in to comment.