Private
Public Access
1
0

some connection with the lisp server, commit 2

This commit is contained in:
2025-05-07 20:50:59 +02:00
parent 237e52f9ab
commit e24b2f0d4a
6 changed files with 78 additions and 38 deletions

View File

@@ -317,7 +317,8 @@ class CNsummaryForm(forms.Form):
file = forms.FileField(required=True, validators=[must_be_csv]) file = forms.FileField(required=True, validators=[must_be_csv])
class NextWeekJsonForm(forms.Form): class NextWeekJsonForm(forms.Form):
file = forms.FileField(required=True) fitness = forms.IntegerField(required=False, label='Fitness', initial=0)
fatigue = forms.IntegerField(required=False, label='Fatigue', initial=0)
# The little window to type '4x2000m/500m' to update the workout summary # The little window to type '4x2000m/500m' to update the workout summary

View File

@@ -1089,11 +1089,11 @@ def correct_intensity(workout):
return workout return workout
def create_next_week_from_json(plansteps, rower, planbyrscore=False, plan=None,): def create_next_week_from_json(plansteps, rower, planbyrscore=False, plan=None,
startdate=timezone.now()-timezone.timedelta(days=timezone.now().weekday())+timezone.timedelta(days=7)):
trainingdays = plansteps['cycles'] trainingdays = plansteps['cycles']
# start date is the first day of the following week # start date is the first day of the following week
today = timezone.now()
startdate = today - timezone.timedelta(days=today.weekday())+timezone.timedelta(days=7)
ndays = 0 ndays = 0
for day in trainingdays: for day in trainingdays:
try: try:

View File

@@ -1111,5 +1111,7 @@ urlpatterns = [
name="braintree_webhook_view"), name="braintree_webhook_view"),
re_path(r'^nextweekplan/$', views.nextweekplan_view, re_path(r'^nextweekplan/$', views.nextweekplan_view,
name='nextweekplan_view'), name='nextweekplan_view'),
re_path(r'^currentweekplan/$', views.currentweekplan_view,
name='currentweekplan_view'),
] ]

View File

@@ -1381,26 +1381,25 @@ def step_to_string(step, short=False):
if isinstance(intensity, int): if isinstance(intensity, int):
intensity = intensitymap[intensity] intensity = intensitymap[intensity]
if stype != 'RepeatStep':
if short and intensity.lower() in ['warmup', 'cooldown', 'rest']: if short and intensity.lower() in ['warmup', 'cooldown', 'rest']:
s = '{intensity} {duration} {unit} {target} {repeat}'.format( s = '{intensity} {duration} {unit} {target} {repeat}'.format(
intensity=intensity, intensity=intensity,
duration=duration, duration=duration,
target=target, target=target,
repeat=repeat, repeat=repeat,
unit=unit unit=unit
) )
elif intensity.lower() in ['warmup', 'cooldown', 'rest']: elif intensity.lower() in ['warmup', 'cooldown', 'rest']:
s = '{intensity} {duration} {unit} {target} {repeat} {notes}'.format( s = '{intensity} {duration} {unit} {target} {repeat} {notes}'.format(
intensity=intensity, intensity=intensity,
duration=duration, duration=duration,
target=target, target=target,
repeat=repeat, repeat=repeat,
unit=unit, unit=unit,
notes=notes, notes=notes,
) )
else:
if stype == 'RepeatStep':
s = 'Repeat {duration}'.format(duration=duration) s = 'Repeat {duration}'.format(duration=duration)
return s, stype, nr, repeatID, repeatValue return s, stype, nr, repeatID, repeatValue

View File

@@ -4211,30 +4211,67 @@ def planmacrocyclebymonth(request, id=0, userid=0): # pragma: no cover
return HttpResponseRedirect(url) return HttpResponseRedirect(url)
@user_passes_test(can_plan, login_url="/rowers/paidplans",
message="This functionality requires a Pro plan",
redirect_field_name=None)
def currentweekplan_view(request):
r = getrower(request.user)
post_data = {
'secret': 'noot', # to be replaced
'plan': 'zwolsche', # to be replaced
}
url = "http://localhost:8898/current-week-plan/"
response = requests.post(url, data=post_data)
data = response.json()
create_next_week_from_json(data, r, startdate=timezone.now()-timezone.timedelta(days=timezone.now().weekday()))
messages.info(request,"Your planned sessions were created")
url = reverse("plannedsessions_view")
return HttpResponseRedirect(url)
@user_passes_test(can_plan, login_url="/rowers/paidplans", @user_passes_test(can_plan, login_url="/rowers/paidplans",
message="This functionality requires a Pro plan", message="This functionality requires a Pro plan",
redirect_field_name=None) redirect_field_name=None)
def nextweekplan_view(request): def nextweekplan_view(request):
r = getrower(request.user) r = getrower(request.user)
form = NextWeekJsonForm() fitness, fatigue = calculate_fitness(r)
form = NextWeekJsonForm(
initial={
'fitness': round(fitness),
'fatigue': round(fatigue),
}
)
if request.method == "POST": if request.method == "POST":
form = NextWeekJsonForm(request.POST, request.FILES) form = NextWeekJsonForm(request.POST)
if form.is_valid(): if form.is_valid():
f = form.cleaned_data['file'] fitness = form.cleaned_data['fitness']
if f is not None: fatigue = form.cleaned_data['fatigue']
filename, path_and_filename = handle_uploaded_file(f)
try: post_data = {
with open(path_and_filename,'r') as ff: 'fitness':fitness,
data = json.load(ff) 'fatigue':fatigue,
except: 'plan':'zwolsche', # to be replaced
messages.error(request,"Hmm, invalid file") 'secret':'noot', # to be replaced
}
# post form.cleaned_data to localhost:8898/next-week-plan
url = "http://localhost:8898/next-week-plan/"
response = requests.post(url, data=post_data)
data = response.json()
create_next_week_from_json(data, r)
messages.info(request,"Your planned sessions were created")
create_next_week_from_json(data, r)
messages.info(request,"Your planned sessions were created")
# remove path_and_filename
os.remove(path_and_filename)
active = 'nav-plan' active = 'nav-plan'

View File

@@ -13,6 +13,7 @@ from rowers.utils import (
my_dict_from_instance, wavg, NoTokenError, my_dict_from_instance, wavg, NoTokenError,
request_is_ajax, dologging request_is_ajax, dologging
) )
from rowers.fitness import calculate_fitness
from rowers.celery import result as celery_result from rowers.celery import result as celery_result
from rowers.interactiveplots import * from rowers.interactiveplots import *
from scipy.interpolate import griddata from scipy.interpolate import griddata