Skip to content

Commit

Permalink
Resolves #26
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxwellDPS committed Feb 10, 2024
1 parent bfdbd81 commit 864e881
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/radio/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ class TransmissionFilter(filters.FilterSet):
start_time = IsoDateTimeFromToRangeFilter()
end_time = IsoDateTimeFromToRangeFilter()

tones_detected = django_filters.CharFilter(lookup_expr='icontains')

system__name = django_filters.CharFilter(lookup_expr='icontains')
recorder__name = django_filters.CharFilter(lookup_expr='icontains')

Expand Down Expand Up @@ -434,6 +436,9 @@ class Meta:
"length",
"locked",
"transcript",
"has_tones",
"is_dispatch",
"tones_detected",
]

class GlobalAnnouncementFilter(filters.FilterSet):
Expand Down
16 changes: 11 additions & 5 deletions src/radio/helpers/transmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ def _new_transmission_handler(data: dict) -> dict:
from radio.tasks import forward_transmission, send_transmission_to_web, send_transmission_notifications

logger.info(f"Got new transmission - {data['name'].split('.')[0]}", extra=data["json"])
recorder_uuid = data["recorder"]
jsonx = data["json"]
audio = data["audio_file"]
tx_uuid = data["UUID"]
recorder_uuid: str = data["recorder"]
jsonx: dict = data["json"]
audio: str = data["audio_file"]
tx_uuid: str = data["UUID"]
tones: dict = data.get("tones", None)



recorder: SystemRecorder = SystemRecorder.objects.get(
api_key=recorder_uuid
Expand All @@ -66,11 +69,14 @@ def _new_transmission_handler(data: dict) -> dict:
payload["recorder"] = str(recorder_uuid)
payload["system"] = str(system.UUID)

if tones and isinstance(tones, dict):
payload["tones"] = tones

name = data["name"].split(".")
payload["audio_file"] = ContentFile(
audio_bytes, name=f'{name[0]}_{str(uuid.uuid4()).rsplit("-", maxsplit=1)[-1]}.{name}.m4a'
)

transmission = TransmissionUploadSerializer(data=payload, partial=True)

if transmission.is_valid(raise_exception=True):
Expand Down
7 changes: 7 additions & 0 deletions src/radio/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ class Transmission(models.Model):
frequency = models.FloatField(default=0.0)
length = models.FloatField(default=0.0, null=True)

# @kcwebby <3
# https://github.com/Trunk-Player/Trunk-PlayerNG-Backend/issues/26
has_tones = models.BooleanField(default=False, db_index=True)
is_dispatch = models.BooleanField(default=False, db_index=True)
tones_detected = models.CharField(max_length=255, blank=True, null=True)
tones_meta = models.JSONField(default=dict, blank=True)

locked = models.BooleanField(default=False, db_index=True)
transcript = models.TextField(null=True, blank=True)

Expand Down
19 changes: 16 additions & 3 deletions src/radio/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,12 @@ class Meta:
"frequencys",
"length",
"locked",
"transcript"
"transcript",
"has_tones",
"is_dispatch",
"tones_detected",
"tones_meta",

]

class TransmissionListSerializer(serializers.ModelSerializer):
Expand All @@ -234,7 +239,11 @@ class Meta:
"frequencys",
"length",
"locked",
"transcript"
"transcript",
"has_tones",
"is_dispatch",
"tones_detected",
"tones_meta"
]

def get_system_name(self, obj):
Expand Down Expand Up @@ -268,7 +277,11 @@ class Meta:
"frequencys",
"length",
"locked",
"transcript"
"transcript",
"has_tones",
"is_dispatch",
"tones_detected",
"tones_meta",
]


Expand Down
18 changes: 18 additions & 0 deletions src/radio/views/api/transmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@ class Create(APIView):
"audio_file": openapi.Schema(
type=openapi.TYPE_STRING, description="M4A Base64"
),
"tones": openapi.Schema(
type=openapi.TYPE_OBJECT, description="Tones Info",
required=[],
properties={
"has_tones": openapi.Schema(
type=openapi.TYPE_BOOLEAN, description="Has Tones"
),
"is_dispatch": openapi.Schema(
type=openapi.TYPE_BOOLEAN, description="Is a Dispatch"
),
"tones_detected": openapi.Schema(
type=openapi.TYPE_STRING, description="Tones Detected"
),
"tones_meta": openapi.Schema(
type=openapi.TYPE_OBJECT, description="Any Arbatray extra data",
)
}
),
"name": openapi.Schema(
type=openapi.TYPE_STRING, description="Audio File Name"
),
Expand Down

0 comments on commit 864e881

Please sign in to comment.