measures
This commit is contained in:
parent
3d5822901f
commit
e656ab4e64
|
@ -1,8 +1,9 @@
|
|||
from django.contrib import admin
|
||||
|
||||
from frog_api.models import Category, Entry, Project, Version
|
||||
from frog_api.models import Category, Entry, Measure, Project, Version
|
||||
|
||||
admin.site.register(Project)
|
||||
admin.site.register(Version)
|
||||
admin.site.register(Category)
|
||||
admin.site.register(Entry)
|
||||
admin.site.register(Measure)
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
# Generated by Django 4.1 on 2022-08-22 01:41
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
(
|
||||
"frog_api",
|
||||
"0003_rename_decompiled_functions_entry_decompiled_chunks_and_more",
|
||||
),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="category",
|
||||
options={"verbose_name_plural": "Categories"},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name="entry",
|
||||
options={"ordering": ["-timestamp"], "verbose_name_plural": "Entries"},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="version",
|
||||
name="project",
|
||||
field=models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="versions",
|
||||
to="frog_api.project",
|
||||
),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="Measure",
|
||||
fields=[
|
||||
("id", models.AutoField(primary_key=True, serialize=False)),
|
||||
("created_on", models.DateTimeField(auto_now_add=True)),
|
||||
("last_updated", models.DateTimeField(auto_now=True)),
|
||||
("type", models.CharField(max_length=255)),
|
||||
("value", models.IntegerField()),
|
||||
(
|
||||
"entry",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="measures",
|
||||
to="frog_api.entry",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -0,0 +1,37 @@
|
|||
# Generated by Django 4.1 on 2022-08-22 01:41
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("frog_api", "0004_alter_category_options_alter_entry_options_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name="entry",
|
||||
name="decompiled_bytes",
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="entry",
|
||||
name="decompiled_chunks",
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="entry",
|
||||
name="matching_bytes",
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="entry",
|
||||
name="matching_chunks",
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="entry",
|
||||
name="total_bytes",
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="entry",
|
||||
name="total_chunks",
|
||||
),
|
||||
]
|
|
@ -56,14 +56,6 @@ class Entry(models.Model):
|
|||
category = models.ForeignKey(Category, on_delete=models.CASCADE)
|
||||
timestamp = models.DateTimeField()
|
||||
git_hash = models.CharField(max_length=40)
|
||||
# Functions / files / whatever you want
|
||||
total_chunks = models.IntegerField()
|
||||
decompiled_chunks = models.IntegerField()
|
||||
matching_chunks = models.IntegerField()
|
||||
# Bytes
|
||||
total_bytes = models.IntegerField()
|
||||
decompiled_bytes = models.IntegerField()
|
||||
matching_bytes = models.IntegerField()
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Entries"
|
||||
|
@ -71,3 +63,17 @@ class Entry(models.Model):
|
|||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.category} {self.timestamp}"
|
||||
|
||||
|
||||
# A measure (total bytes, bytes matched, functions matched, bytes decompiled, etc) tied to an Entry
|
||||
class Measure(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
created_on = models.DateTimeField(auto_now_add=True)
|
||||
last_updated = models.DateTimeField(auto_now=True)
|
||||
|
||||
entry = models.ForeignKey(Entry, on_delete=models.CASCADE, related_name="measures")
|
||||
type = models.CharField(max_length=255)
|
||||
value = models.IntegerField()
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.entry} {self.type}: {self.value}"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from rest_framework import serializers
|
||||
|
||||
from frog_api.models import Entry, Project, Version
|
||||
from frog_api.models import Entry, Measure, Project, Version
|
||||
|
||||
|
||||
class VersionSerializer(serializers.HyperlinkedModelSerializer):
|
||||
|
@ -17,26 +17,30 @@ class ProjectSerializer(serializers.HyperlinkedModelSerializer):
|
|||
fields = ["slug", "name", "versions"]
|
||||
|
||||
|
||||
class MeasureSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Measure
|
||||
fields = ["type", "value"]
|
||||
|
||||
|
||||
class EntrySerializer(serializers.HyperlinkedModelSerializer):
|
||||
measures = MeasureSerializer(many=True)
|
||||
|
||||
class Meta:
|
||||
model = Entry
|
||||
fields = [
|
||||
"timestamp",
|
||||
"git_hash",
|
||||
"total_chunks",
|
||||
"decompiled_chunks",
|
||||
"matching_chunks",
|
||||
"total_bytes",
|
||||
"decompiled_bytes",
|
||||
"matching_bytes",
|
||||
"measures",
|
||||
]
|
||||
|
||||
|
||||
class TerseEntrySerializer(serializers.HyperlinkedModelSerializer):
|
||||
measures = MeasureSerializer(many=True)
|
||||
|
||||
class Meta:
|
||||
model = Entry
|
||||
fields = [
|
||||
"timestamp",
|
||||
"total_bytes",
|
||||
"matching_bytes",
|
||||
"measures",
|
||||
]
|
||||
|
|
|
@ -5,7 +5,6 @@ from rest_framework.views import APIView
|
|||
|
||||
from frog_api.models import Entry, Project, Version
|
||||
from frog_api.serializers import (
|
||||
EntrySerializer,
|
||||
ProjectSerializer,
|
||||
TerseEntrySerializer,
|
||||
)
|
||||
|
@ -38,7 +37,11 @@ def get_versions_digest_for_project(project) -> dict:
|
|||
for version in Version.objects.filter(project__slug=project):
|
||||
entry = get_latest_entry(project, version.slug, "total")
|
||||
if entry is not None:
|
||||
versions[version.slug] = TerseEntrySerializer(entry).data
|
||||
entry_data = TerseEntrySerializer(entry).data
|
||||
entry_data["measures"] = {
|
||||
m["type"]: m["value"] for m in entry_data["measures"]
|
||||
}
|
||||
versions[version.slug] = entry_data
|
||||
return versions
|
||||
|
||||
|
||||
|
@ -58,8 +61,6 @@ class RootDigestView(APIView):
|
|||
if len(versions) > 0:
|
||||
projects[project.slug] = versions
|
||||
|
||||
entry = get_latest_entry(project=None, version=None, category="total")
|
||||
|
||||
return Response({"progress": projects})
|
||||
|
||||
|
||||
|
@ -70,7 +71,7 @@ class ProjectDigestView(APIView):
|
|||
|
||||
def get(self, request, project):
|
||||
"""
|
||||
Return the most recent entry for ovreall progress for each version of a project.
|
||||
Return the most recent entry for overall progress for each version of a project.
|
||||
"""
|
||||
|
||||
if Project.objects.get(slug=project) is None:
|
||||
|
@ -82,6 +83,4 @@ class ProjectDigestView(APIView):
|
|||
if len(versions) > 0:
|
||||
projects[project] = versions
|
||||
|
||||
entry = get_latest_entry(project=None, version=None, category="total")
|
||||
|
||||
return Response({"progress": projects})
|
||||
|
|
Loading…
Reference in New Issue