Skip to content

Instantly share code, notes, and snippets.

@nelsondspy
Created November 20, 2017 18:55
Show Gist options
  • Save nelsondspy/91f0ee89217ddfb1bb1c3a5f188334e5 to your computer and use it in GitHub Desktop.
Save nelsondspy/91f0ee89217ddfb1bb1c3a5f188334e5 to your computer and use it in GitHub Desktop.
guardado de resultado de tiro dentro del manejador de rutinas
xy = json.loads(recv_data)
print("desempaquetado", xy)
print finishTime
print datetime.now().strftime("%H:%M:%S:%f")
startTime = datetime.now().replace(hour=startTime.hour, minute=startTime.minute,
second=startTime.second,
microsecond=startTime.microsecond)
finishTime = datetime.now().replace(hour=finishTime.hour, minute=finishTime.minute,
second=finishTime.second,
microsecond=finishTime.microsecond)
delta = (finishTime - startTime).total_seconds()
target_x = tiro.x_initial + (tiro.x_final - tiro.x_initial) * (delta / tiro.time)
target_y = tiro.y_initial + (tiro.y_final - tiro.y_initial) * (delta / tiro.time)
distance = math.sqrt(math.pow(xy['x'] - target_x, 2) + math.pow(xy['y'] - target_y, 2))
r = Resultado(startTime=startTime,
finishTime=finishTime,
x=xy['x'],
y=xy['y'],
distance=distance,
sesion=sesion,
tiro=tiro)
r.save()
# crear o actualizar estadisticas
statistics = Estadisticas.objects.filter(deportista=deportista_pk)
acierto = 0
if distance < 2 * tiro.radius: # TODO: the minimun distance should be calculated more accurately!
acierto = 1
if len(statistics) == 0:
estadistica = Estadisticas()
estadistica.tiros = 1
estadistica.aciertos = acierto
estadistica.tiempo_total = tiro.time
estadistica.tiempo_utilizado = delta
estadistica.deportista = Deportista.objects.get(pk=deportista_pk)
estadistica.save()
elif len(statistics) == 1:
estadistica = statistics[0]
estadistica.actualizar(1, acierto, tiro.time, delta)
estadistica.save()
sock.close()
url = reverse_lazy("controller:resultado_show",
args=[entrenador_pk, deportista_pk, rutina_pk,
unicode(tiro.id), unicode(r.id)])
return redirect(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment