Commit a37b5522 authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

Start having static stats table

parent 366e21e1
Pipeline #20116 passed with stages
in 2 minutes and 31 seconds
......@@ -57,6 +57,7 @@ api_router.register(r'kegg-orthologies', views.KeggOrthologyViewSet, basename='k
api_router.register(r'eggnogs', views.EggNOGViewSet, basename='eggnogs')
api_router.register(r'genes', views.GeneViewSet, basename='genes')
api_router.register(r'taxonomy', views.TaxonomyViewSet, basename='taxonomy')
api_router.register(r'statistics', views.StatisticsViewSet, basename='statistics')
urlpatterns = [
......
from .function import EggNOGViewSet, KeggOrthologyViewSet, FunctionViewSet # noqa
from .gene import GeneViewSet # noqa
from .statistics import StatisticsViewSet # noqa
from .taxonomy import TaxonomyViewSet # noqa
from django.shortcuts import get_object_or_404
from rest_framework import viewsets
from rest_framework.response import Response
from metagenedb.apps.catalog.models import Statistics
from metagenedb.apps.catalog.serializers import StatisticsSerializer
class StatisticsViewSet(viewsets.ViewSet):
"""
A simple ViewSet for listing or retrieving statistics.
"""
lookup_field = 'stats_id'
def list(self, request):
queryset = Statistics.objects.all()
serializer = StatisticsSerializer(queryset, many=True)
return Response(serializer.data)
def retrieve(self, request, stats_id=None):
queryset = Statistics.objects.all()
stats = get_object_or_404(queryset, stats_id=stats_id)
serializer = StatisticsSerializer(stats)
return Response(serializer.data)
# Generated by Django 3.0 on 2019-12-16 10:59
import django.contrib.postgres.fields.jsonb
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('catalog', '0019_get_back_original_name'),
]
operations = [
migrations.CreateModel(
name='Statistics',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('stats_id', models.SlugField(max_length=400, unique=True)),
('body', django.contrib.postgres.fields.jsonb.JSONField()),
],
),
]
from .function import EggNOG, EggNogFunctionalCategory, Function, KeggOrthology # noqa
from .gene import Gene, GeneFunction # noqa
from .statistics import Statistics # noqa
from .taxonomy import Taxonomy # noqa
from django.db import models
from django.contrib.postgres.fields import JSONField
class Statistics(models.Model):
"""
Model for the different static statistics that can be computed in a daily manner about the catalog
"""
stats_id = models.SlugField(max_length=400, db_index=True, unique=True)
body = JSONField()
from metagenedb.apps.catalog.models import Gene
class GeneStatistics:
model = Gene
@staticmethod
def count_has_function():
return GeneStatistics.model.objects.filter(functions__isnull=False).distinct().count()
@staticmethod
def count_has_taxonomy():
return GeneStatistics.model.objects.filter(taxonomy__isnull=False).count()
from .function import EggNOGSerializer, FunctionSerializer, KeggOrthologySerializer # noqa
from .gene import GeneSerializer # noqa
from .statistics import StatisticsSerializer # noqa
from .taxonomy import TaxonomySerializer # noqa
from rest_framework import serializers
from metagenedb.apps.catalog.models import Statistics
class StatisticsSerializer(serializers.ModelSerializer):
class Meta:
model = Statistics
fields = ('stats_id', 'body')
......@@ -169,10 +169,7 @@ export default {
});
},
getGeneCountsFunctions() {
axios.get('/api/catalog/v1/genes', {
params: {
no_functions: false,
},
axios.get('/api/catalog/v1/statistics/genestatistics-count-has-function', {
headers: {
Accept: 'application/json',
},
......@@ -181,7 +178,7 @@ export default {
this.geneCountFunctions = {
class: "secondary",
icon: "bar_chart",
text: response.data.count,
text: response.data.body.count,
title: "Functions annotation",
};
})
......@@ -260,9 +257,6 @@ export default {
doughnut: Doughnut,
},
watch: {
// taxLevel(val) {
// this.getTaxoCounts();
// },
stopAt(val) {
this.getGeneLength();
},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment