Skip to content

Commit ac02b55

Browse files
committed
add new endpoints for data pipeline
1 parent fc8263b commit ac02b55

File tree

6 files changed

+393
-9
lines changed

6 files changed

+393
-9
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Generated by Django 5.1.4 on 2025-01-26 08:41
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [
8+
("api", "0023_alter_speech_speaker"),
9+
]
10+
11+
operations = [
12+
migrations.RenameIndex(
13+
model_name="speech",
14+
new_name="api_speech_speech__c0087e_gin",
15+
old_name="speech_speech__adebe1_gin",
16+
),
17+
migrations.AlterModelTable(
18+
name="area",
19+
table="api_area",
20+
),
21+
migrations.AlterModelTable(
22+
name="attendance",
23+
table="api_attendance",
24+
),
25+
migrations.AlterModelTable(
26+
name="author",
27+
table="api_author",
28+
),
29+
migrations.AlterModelTable(
30+
name="authorhistory",
31+
table="api_author_history",
32+
),
33+
migrations.AlterModelTable(
34+
name="parliamentarycycle",
35+
table="api_parliamentary_cycle",
36+
),
37+
migrations.AlterModelTable(
38+
name="sitting",
39+
table="api_sitting",
40+
),
41+
migrations.AlterModelTable(
42+
name="speech",
43+
table="api_speech",
44+
),
45+
]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Generated by Django 5.1.4 on 2025-02-25 16:18
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
(
10+
"api",
11+
"0024_rename_speech_speech__adebe1_gin_api_speech_speech__c0087e_gin_and_more",
12+
),
13+
]
14+
15+
operations = [
16+
migrations.AlterField(
17+
model_name="author",
18+
name="birth_year",
19+
field=models.IntegerField(null=True),
20+
),
21+
migrations.AlterField(
22+
model_name="authorhistory",
23+
name="area",
24+
field=models.ForeignKey(
25+
null=True, on_delete=django.db.models.deletion.CASCADE, to="api.area"
26+
),
27+
),
28+
migrations.AlterField(
29+
model_name="authorhistory",
30+
name="party",
31+
field=models.CharField(max_length=32, null=True),
32+
),
33+
]

src/api/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Author(models.Model):
6565

6666
new_author_id = models.AutoField(primary_key=True)
6767
name = models.TextField()
68-
birth_year = models.IntegerField()
68+
birth_year = models.IntegerField(null=True)
6969
ethnicity = models.TextField() # possible choices?
7070
sex = models.CharField(max_length=1, choices=(("m", "male"), ("f", "female")))
7171

@@ -89,8 +89,8 @@ class AuthorHistory(models.Model):
8989

9090
record_id = models.AutoField(primary_key=True)
9191
author = models.ForeignKey(Author, on_delete=models.CASCADE)
92-
party = models.CharField(max_length=32) # map to party table?
93-
area = models.ForeignKey(Area, on_delete=models.CASCADE)
92+
party = models.CharField(max_length=32, null=True) # map to party table?
93+
area = models.ForeignKey(Area, on_delete=models.CASCADE, null=True)
9494
# seat = models.ForeignKey(Seat, on_delete=models.CASCADE)
9595
exec_posts = models.TextField(null=True)
9696
service_posts = models.TextField(null=True)

src/api/serializers.py

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,94 @@
11
from rest_framework import serializers
2-
from .models import Sitting, ParliamentaryCycle
2+
from .models import ParliamentaryCycle, Sitting, Speech, AuthorHistory, Author
33

44

55
class ParliamentaryCycleSerializer(serializers.ModelSerializer):
66
class Meta:
77
model = ParliamentaryCycle
8-
fields = ["house", "term", "session", "meeting"]
8+
fields = [
9+
"cycle_id",
10+
"start_date",
11+
"end_date",
12+
"house",
13+
"term",
14+
"session",
15+
"meeting",
16+
]
17+
read_only_fields = ["cycle_id"]
918

1019

1120
class SittingSerializer(serializers.ModelSerializer):
12-
cycle = ParliamentaryCycleSerializer()
21+
cycle_id = serializers.PrimaryKeyRelatedField(
22+
source="cycle", queryset=ParliamentaryCycle.objects.all(), write_only=True
23+
)
24+
cycle = ParliamentaryCycleSerializer(read_only=True)
1325

1426
class Meta:
1527
model = Sitting
16-
fields = ["cycle", "date", "filename"]
28+
fields = [
29+
"sitting_id",
30+
"cycle",
31+
"cycle_id",
32+
"date",
33+
"filename",
34+
"has_dataset",
35+
"is_final",
36+
"speech_data",
37+
]
38+
read_only_fields = ["sitting_id"]
39+
40+
41+
class SpeechSerializer(serializers.ModelSerializer):
42+
sitting_id = serializers.PrimaryKeyRelatedField(
43+
source="sitting", queryset=Sitting.objects.all(), write_only=True
44+
)
45+
speaker_id = serializers.PrimaryKeyRelatedField(
46+
source="speaker",
47+
queryset=AuthorHistory.objects.all(),
48+
write_only=True,
49+
required=False,
50+
allow_null=True,
51+
)
52+
53+
class Meta:
54+
model = Speech
55+
fields = [
56+
"speech_id",
57+
"sitting_id",
58+
"index",
59+
"speaker_id",
60+
"timestamp",
61+
"speech",
62+
"speech_tokens",
63+
"length",
64+
"level_1",
65+
"level_2",
66+
"level_3",
67+
"is_annotation",
68+
]
69+
read_only_fields = ["speech_id", "speech_vector"]
70+
71+
72+
class AuthorSerializer(serializers.ModelSerializer):
73+
class Meta:
74+
model = Author
75+
fields = ["new_author_id", "name", "birth_year", "ethnicity", "sex"]
76+
77+
78+
class AuthorHistorySerializer(serializers.ModelSerializer):
79+
author = serializers.PrimaryKeyRelatedField(
80+
queryset=Author.objects.all(), write_only=True
81+
)
82+
83+
class Meta:
84+
model = AuthorHistory
85+
fields = [
86+
"record_id",
87+
"author",
88+
"party",
89+
"area",
90+
"exec_posts",
91+
"service_posts",
92+
"start_date",
93+
"end_date",
94+
]

src/api/urls.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
HansardView,
66
SearchPlotView,
77
AttendanceView,
8+
ParliamentaryCycleCreateView,
9+
SpeechView,
10+
AuthorHistoryView,
811
health_check,
912
)
1013

@@ -13,6 +16,13 @@
1316
path("search/", SearchResultsList.as_view(), name="search"),
1417
path("search-plot/", SearchPlotView.as_view(), name="search-plot"),
1518
path("sitting/", HansardView.as_view(), name="sitting"),
19+
path("speech/", SpeechView.as_view(), name="speech"),
1620
path("attendance/", AttendanceView.as_view(), name="attendance"),
21+
path(
22+
"parliamentary-cycle/",
23+
ParliamentaryCycleCreateView.as_view(),
24+
name="parliamentary-cycle-create",
25+
),
26+
path("author-history/", AuthorHistoryView.as_view(), name="author-history"),
1727
path("health/", health_check, name="health"),
1828
]

0 commit comments

Comments
 (0)