Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions mcserver/migrations/0049_session_uselidar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.14 on 2026-06-30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mcserver', '0048_video_saved_local_index'),
]

operations = [
migrations.AddField(
model_name='session',
name='useLidar',
field=models.BooleanField(default=False),
),
]
1 change: 1 addition & 0 deletions mcserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Session(models.Model):

isMono = models.BooleanField(default=False, db_index=True)
save_local = models.BooleanField(default=False)
useLidar = models.BooleanField(default=False)

class Meta:
ordering = ['-created_at']
Expand Down
4 changes: 2 additions & 2 deletions mcserver/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class Meta:
fields = [
'id', 'user', 'public', 'name', 'sessionName',
'qrcode', 'meta', 'trials', 'server',
'subject', 'isMono', 'save_local',
'subject', 'isMono', 'save_local', 'useLidar',
'created_at', 'updated_at',
'trashed', 'trashed_at', 'trials_count', 'trashed_trials_count',
]
Expand All @@ -255,7 +255,7 @@ class Meta:
fields = [
'id', 'user', 'public', 'name', 'sessionName',
'qrcode', 'meta', 'trials', 'server',
'subject', 'isMono', 'save_local',
'subject', 'isMono', 'save_local', 'useLidar',
'created_at', 'updated_at',
'trashed', 'trashed_at', 'trials_count', 'trashed_trials_count',
]
Expand Down
4 changes: 3 additions & 1 deletion mcserver/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
AnalysisDashboardViewSet,
GetUserInfo,
UserUpdate,
UpdateProfilePicture
UpdateProfilePicture,
UserGroupsView
)
from rest_framework import routers, serializers, viewsets
from rest_framework.authtoken.views import obtain_auth_token
Expand Down Expand Up @@ -98,6 +99,7 @@
path('reset-password/', ResetPasswordView.as_view()),
path('new-password/', NewPasswordView.as_view()),
path('user-institutional-use/', UserInstitutionalUseView.as_view()),
path('user-groups/', UserGroupsView.as_view(), name='user-groups'),
path('swagger<format>/', schema_view.without_ui(cache_timeout=0), name='schema-json'),
path('docs/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
path('redocs/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
Expand Down
74 changes: 72 additions & 2 deletions mcserver/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,52 @@ def save_local(self, request, pk):
raise APIException(_("error") % {"error_message": str(traceback.format_exc())})
raise NotFound(_("session_uuid_not_valid") % {"uuid": str(pk)})

@action(detail=True, methods=['get', 'patch'], permission_classes=[AllowAny])
def useLidar(self, request, pk):
try:
if pk == 'undefined':
raise ValueError(_("undefined_uuid"))

session = get_object_or_404(Session, pk=pk)

if request.method == 'GET':
return Response({"useLidar": session.useLidar})

if not request.user.is_authenticated:
raise NotAuthenticated(_('login_needed'))

has_permission = (
IsOwner().has_permission(request, self) and
IsOwner().has_object_permission(request, self, session)
) or IsAdmin().has_object_permission(request, self, session) or \
IsBackend().has_object_permission(request, self, session)

if not has_permission:
raise PermissionDenied(_('permission_denied'))

useLidar = request.data.get('useLidar', request.query_params.get('useLidar'))
if isinstance(useLidar, bool):
session.useLidar = useLidar
elif isinstance(useLidar, str) and useLidar.lower() in ['true', 'false']:
session.useLidar = useLidar.lower() == 'true'
else:
return Response(
{'useLidar': ['Expected true or false.']},
status=status.HTTP_400_BAD_REQUEST
)

session.save(update_fields=['useLidar', 'updated_at'])
return Response({"useLidar": session.useLidar})

except Http404:
if settings.DEBUG:
raise APIException(_("error") % {"error_message": str(traceback.format_exc())})
raise NotFound(_("session_uuid_not_found") % {"uuid": str(pk)})
except ValueError:
if settings.DEBUG:
raise APIException(_("error") % {"error_message": str(traceback.format_exc())})
raise NotFound(_("session_uuid_not_valid") % {"uuid": str(pk)})

@action(
detail=True,
methods=["get", "post"],
Expand Down Expand Up @@ -758,6 +804,7 @@ def new_subject(self, request, pk):
user = User.objects.get(id=1)
sessionNew.user = user
sessionNew.save_local = sessionOld.save_local
sessionNew.useLidar = sessionOld.useLidar

except Http404:
if settings.DEBUG:
Expand Down Expand Up @@ -856,6 +903,7 @@ def get_status(self, request, pk):
if trial.video_set.filter(device_id=request.GET["device_id"]).count() == 0:
video = Video()
video.device_id = request.GET["device_id"]
video.isLidar = str(request.GET.get("usingLidar", "")).lower() == "true"
video.trial = trial
video.save()
status = "recording"
Expand All @@ -870,6 +918,8 @@ def get_status(self, request, pk):
video_uploaded = video.video and video.video.url
if video_uploaded:
n_videos_uploaded = n_videos_uploaded + 1
if "device_id" not in request.GET:
n_cameras_using_lidar = trial.video_set.filter(isLidar=True).count() if trial else 0

video_url = None
if trial and trial.status == "recording" and "device_id" in request.GET:
Expand All @@ -884,11 +934,13 @@ def get_status(self, request, pk):
else:
newSessionURL = None

if session.meta and "settings" in session.meta and "framerate" in session.meta['settings']:
if session.useLidar:
frameRate = 60
elif session.meta and "settings" in session.meta and "framerate" in session.meta['settings']:
frameRate = int(session.meta['settings']['framerate'])
else:
frameRate = 60
if trial and (trial.name in {'calibration','neutral'}):
if not session.useLidar and trial and (trial.name in {'calibration','neutral'}):
frameRate = 30


Expand All @@ -898,11 +950,15 @@ def get_status(self, request, pk):
"trialname": trial.name if trial else None,
"video": video_url,
"framerate": frameRate,
"useLidar": session.useLidar,
"newSessionURL": newSessionURL,
"n_cameras_connected": n_cameras_connected,
"n_videos_uploaded": n_videos_uploaded
}

if "device_id" not in request.GET:
res["n_cameras_using_lidar"] = n_cameras_using_lidar

if "ret_session" in request.GET:
res["session"] = SessionSerializer(session, many=False).data

Expand Down Expand Up @@ -983,6 +1039,10 @@ def get_count_from_name(name, base_name):
name = "{}_{}".format(name, highest_count + 1)

trial.name = name
session.trial_set.filter(status="recording").update(
status="error",
updated_at=timezone.now()
)
trial.save()

if name == "calibration" or name == "neutral":
Expand Down Expand Up @@ -2656,6 +2716,16 @@ def post(self, request, format='json'):
return Response(serializer.data)


class UserGroupsView(APIView):
permission_classes = [IsAuthenticated]

def get(self, request, format='json'):
group_names = list(request.user.groups.values_list('name', flat=True))
return Response({
'groups': group_names,
})


class AnalysisFunctionsListAPIView(ListAPIView):
""" Returns active AnalysisFunction's.
"""
Expand Down
Loading