Skip to content

Commit

Permalink
Add control for cheating
Browse files Browse the repository at this point in the history
  • Loading branch information
frasanz committed Oct 16, 2024
1 parent 437c299 commit 0768116
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
14 changes: 13 additions & 1 deletion georeferencing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,22 @@ def patch(self, request, pk=None):
elif request.data['status'] == 'DONE':
# let's start the georeferencing process
# for the moment, launch a batch script
print('doing georeferencing')
print('Submitting the final result')
print(request.data['controlPoints'])
geoattemp.finishedDateTime = timezone.now()
geoattemp.save()
spend_time = (geoattemp.finishedDateTime - geoattemp.assignedDateTime).total_seconds()
if spend_time < 60:
print('User is cheating')
geoattemp.finishedDateTime = None
geoattemp.save()
user_profile, created = UserProfile.objects.get_or_create(user=geoattemp.assignedUser)
if created:
print('User profile created')
user_profile.cheating += 1
user_profile.save()
return Response({"error": f"Are you cheating?. {spend_time}"}, status=status.HTTP_400_BAD_REQUEST)

serializer.save()
if geoattemp.assignedUser:
print('User is authenticated')
Expand Down
18 changes: 18 additions & 0 deletions user_profile/migrations/0004_userprofile_cheating.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.16 on 2024-10-16 19:02

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('user_profile', '0003_userprofile_controlpointsdone'),
]

operations = [
migrations.AddField(
model_name='userprofile',
name='cheating',
field=models.IntegerField(default=0),
),
]
1 change: 1 addition & 0 deletions user_profile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class UserProfile(models.Model):
profile_pic = models.ImageField(upload_to='profile_pics', blank=True)
geoattempts_done = models.IntegerField(default=0)
time_spent = models.PositiveBigIntegerField(default=0)
cheating = models.IntegerField(default=0)
controlPointsDone = models.PositiveBigIntegerField(default=0)

def __str__(self):
Expand Down

0 comments on commit 0768116

Please sign in to comment.