Add overlap check after schedule button is hit
When schedule button was hit, calculated observations were scheduled without any check if between calculation and scheduling has been any change on the already scheduled station observations. This resulted to scheduling of the same observation more than one time, if you opened and calculated the same observation in two different tabs and then hit schedule button. With this commit, this issue if fixed as a check is done when the schedule button is hit. If there is an overlap it returns an error message which inform the user that there are one or more overlaps.merge-requests/493/head
parent
6fef2c18cf
commit
6a61ccc1c6
|
@ -47,14 +47,14 @@ def resolve_overlaps(station, gs_data, start, end):
|
|||
return ()
|
||||
if start < datum.start and end > datum.end:
|
||||
start1 = start
|
||||
end1 = datum.start
|
||||
start2 = datum.end
|
||||
end1 = datum.start - timedelta(seconds=10)
|
||||
start2 = datum.end + timedelta(seconds=10)
|
||||
end2 = end
|
||||
return start1, end1, start2, end2
|
||||
if datum.start <= start:
|
||||
start = datum.end
|
||||
start = datum.end + timedelta(seconds=10)
|
||||
if datum.end >= end:
|
||||
end = datum.start
|
||||
end = datum.start - timedelta(seconds=10)
|
||||
if overlapped:
|
||||
return start, end, overlapped
|
||||
else:
|
||||
|
|
|
@ -235,6 +235,33 @@ def observation_new(request):
|
|||
messages.error(request, 'Please schedule an observation that begins in the future')
|
||||
return redirect(reverse('base:observation_new'))
|
||||
|
||||
total = int(request.POST.get('total'))
|
||||
changed = 0
|
||||
for item in range(total):
|
||||
start = make_aware(datetime.strptime(
|
||||
request.POST.get('{0}-starting_time'.format(item)), '%Y-%m-%d %H:%M:%S.%f'
|
||||
))
|
||||
end = make_aware(datetime.strptime(
|
||||
request.POST.get('{}-ending_time'.format(item)), '%Y-%m-%d %H:%M:%S.%f'
|
||||
))
|
||||
station_id = request.POST.get('{}-station'.format(item))
|
||||
station = Station.objects.get(id=station_id)
|
||||
gs_data = Observation.objects.filter(ground_station=station)
|
||||
window = resolve_overlaps(station, gs_data, start, end)
|
||||
if (len(window) > 2 or len(window) == 0):
|
||||
changed += 1
|
||||
|
||||
if changed > 0:
|
||||
error_message = (
|
||||
str(changed) + " observations are already scheduled or overlap with others."
|
||||
" Please recalculate and try schedule them again."
|
||||
)
|
||||
if(changed == 1):
|
||||
error_message = (
|
||||
"The observation is already scheduled or overlaps with others."
|
||||
" Please recalculate and try schedule it again.")
|
||||
messages.error(request, error_message)
|
||||
return redirect(reverse('base:observation_new'))
|
||||
start = make_aware(start_time, utc)
|
||||
end = make_aware(end_time, utc)
|
||||
sat = Satellite.objects.get(norad_cat_id=sat_id)
|
||||
|
@ -247,8 +274,6 @@ def observation_new(request):
|
|||
observer = ephem.Observer()
|
||||
observer.date = str(start)
|
||||
|
||||
total = int(request.POST.get('total'))
|
||||
|
||||
scheduled = []
|
||||
|
||||
for item in range(total):
|
||||
|
|
Loading…
Reference in New Issue