Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bailey/experiment resource changes #89

Merged
merged 3 commits into from
Sep 25, 2024
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
42 changes: 7 additions & 35 deletions experiments/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from projects.models import Project
from reservations.models import Reservation
from resources.models import ResourceTypeChoice
from resources.models import Resource

from .models import Experiment, StageChoice, UserStageChoice

Expand Down Expand Up @@ -40,24 +41,7 @@ def __init__(self, *args, **kwargs):
)
"""

capabilities_list = [
("gimbal", "Gimbal and RGB/IR Camera"),
("lidar", "LIDAR"),
("jetson", "Jetson Nano"),
("sdr", "Software Defined Radio"),
("5g", "5G module(s)"),
("camera", "Camera"),
("gps", "GPS"),
("t12", "TEROS-12"),
("t21", "TEROS-21"),
("tts", "Thermistor Temperature Sensor"),
("tsl259", "TSL25911FN"),
("bme", "BME280"),
("icm", "ICM20948"),
("ltr", "LTR390-UV-1"),
("sgp", "SGP40"),
("cws", "Compact Weather Sensor"),
]
resource_choices = ((resource.uuid,resource.name + f" ({resource.resourceType})") for resource in Resource.objects.all())

dependencies = forms.CharField(
widget=forms.Textarea(
Expand All @@ -72,23 +56,11 @@ def __init__(self, *args, **kwargs):
label="Dependencies",
)

resourceType = forms.ChoiceField(
choices=ResourceTypeChoice.choices(),
widget=forms.Select(),
required=False,
label="Resource Type",
)

capability_filter = forms.MultipleChoiceField(
required=False,
widget=forms.CheckboxSelectMultiple(),
choices=capabilities_list,
)

resources = forms.CharField(
widget=forms.Textarea(),
required=False,
label="",
resources = forms.ChoiceField(
widget=forms.RadioSelect,
choices=resource_choices,
required=True,
label="Resource",
)

class Meta:
Expand Down
1 change: 0 additions & 1 deletion resources/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class ResourceLocationChoice(Enum): # A subclass of Enum
NAVAJO_TECH = "Navajo Tech"
CLEMSON = "Clemson"
# RENCIEMULAB = 'RENCIEmulab' # need correspondent entry in .env for the urn
OTHERS = "Others"

@classmethod
def choices(cls):
Expand Down
27 changes: 24 additions & 3 deletions schedule/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
from django import forms
from resources.models import ResourceLocationChoice

class DateTimeForm(forms.Form):
class ScheduleForm(forms.Form):
scheduled_time = forms.DateField(
widget=forms.DateInput(attrs={'type': 'date'})
)
widget=forms.DateInput(attrs={'type': 'date'}),
label="Schedule Time"
)

experiment_uuid = forms.UUIDField(
widget=forms.HiddenInput()
)

class LocationFilterForm(forms.Form):
location = forms.ChoiceField(
choices=ResourceLocationChoice.choices(),
widget=forms.Select(),
required=False,
label="Site",
)

class ExperimentSearchForm(forms.Form):
experiment_name = forms.CharField(
widget=forms.TextInput(attrs={"size": 60}),
required=False,
label="Search",
)
4 changes: 3 additions & 1 deletion schedule/urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from django.conf.urls import include
from django.urls import path
from .views import schedule, schedule_experiment, move_to_error, move_to_complete, move_to_not_scheduled
from .views import schedule, site_filter, search_experiments, schedule_experiment, move_to_error, move_to_complete, move_to_not_scheduled

#from experiments import views

#from .views import ()

urlpatterns = [
path("", schedule, name="schedule"),
path("siteFilter", site_filter, name="site_filter"),
path("searchExperiment", search_experiments, name="search_experiments"),
path("schedule", schedule_experiment, name="schedule_experiment"),
path("moveToError", move_to_error, name="move_to_error"),
path("moveToComplete", move_to_complete, name="move_to_complete"),
Expand Down
79 changes: 57 additions & 22 deletions schedule/views.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,69 @@
from django.shortcuts import render, redirect
from .forms import DateTimeForm
from .forms import ScheduleForm, LocationFilterForm, ExperimentSearchForm
from experiments.experiments import get_experiment_list
from django.shortcuts import get_object_or_404
from uuid import UUID
from experiments.models import Experiment
from .schedule import update_scheduled_time, change_experiment_state


def schedule(request):
experiments = get_experiment_list(request)
form = DateTimeForm() # Initialize form
return render(
request,
"schedule.html",
{"experiments": experiments, "form": form}) # Pass form to template
schedule_form = ScheduleForm()
location_form = LocationFilterForm()
search_form = ExperimentSearchForm()

return render(request, "schedule.html", {
"experiments": experiments,
"schedule_form": schedule_form,
"location_form": location_form,
"search_form": search_form
})

def schedule_experiment(request):
if request.method == "POST":
form = ScheduleForm(request.POST)
if form.is_valid():
scheduled_date = form.cleaned_data['scheduled_time']
experiment_uuid = form.cleaned_data['experiment_uuid']
experiment = get_object_or_404(Experiment, uuid=UUID(str(experiment_uuid)))
update_scheduled_time(experiment, scheduled_date)
change_experiment_state(experiment, 1)
return redirect('schedule')
return redirect('schedule')

def site_filter(request):
experiments = Experiment.objects.all()
location_form = LocationFilterForm(request.POST or None)
search_form = ExperimentSearchForm()

if location_form.is_valid():
location = location_form.cleaned_data['location']
experiments = experiments.filter(resources__location=location)

return render(request, "schedule.html", {
"experiments": experiments,
"schedule_form": ScheduleForm(),
"location_form": location_form,
"search_form": search_form
})

def search_experiments(request):
experiments = Experiment.objects.all()
location_form = LocationFilterForm()
search_form = ExperimentSearchForm(request.POST or None)

if search_form.is_valid():
name = search_form.cleaned_data['experiment_name']
experiments = experiments.filter(name__icontains=name)

return render(request, "schedule.html", {
"experiments": experiments,
"schedule_form": ScheduleForm(),
"location_form": location_form,
"search_form": search_form
})


def move_to_error(request):
if request.method == 'POST':
Expand All @@ -37,19 +88,3 @@ def move_to_not_scheduled(request):
change_experiment_state( experiment, 0 )

return redirect('schedule')

def schedule_experiment(request):
if request.method == "POST":
form = DateTimeForm(request.POST) # Bind form with POST data
if form.is_valid():
scheduled_date = form.data['scheduled_time']
experiment_uuid = form.data['experiment_uuid']
experiment = get_object_or_404(Experiment,
uuid=UUID(str(experiment_uuid)))
update_scheduled_time(experiment,scheduled_date)
# Redirect to prevent re-submission
return redirect('schedule')
else:
form = DateTimeForm() # If not POST, create a blank form

return render(request, "schedule.html", {"form": form}) # Pass form to template
22 changes: 6 additions & 16 deletions templates/experiments/experiment_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,16 @@ <h2>Create Experiment</h2>
Read about: <a href="https://sites.google.com/view/discover-user-manual/welcome/experiment-web-portal/creating-and-managing-experiments"
target="_blank">Creating and Managing Experiments</a>
</p>
<div id="resource_link_cont" style="display: none;">
{% for resource in resources.all %}
<a style="display: none;" id="resource_{{ forloop.counter }}" href="{% url 'resource_detail' resource_uuid=resource.uuid %}"></a>
{% endfor %}
</div>
<form id="create-experiment" method="POST" class="post-form">
{% csrf_token %}
{{ form.as_p }}
<p id="no_capabilities">No capabilities for secleted resource type.</p>
<h2>Available Resources</h2>
<div id="resources">
{% for resource in resources.all %}
<input id="resource_{{ forloop.counter }}"
value="{{ resource.uuid }}"
style="margin-left: 10px"
type="checkbox">
<a href="{% url 'resource_detail' resource_uuid=resource.uuid %}"
target="_blank">{{ resource.name }}({{ resource.resourceType }})</a>
<p style="display: none;">{{ resource.capabilities }}</p>
{% if forloop.counter|divisibleby:3 %}<br />{% endif %}
</input>
{% endfor %}
</div>
</form>
<script type="text/javascript" src="../../static/js/experiments.js"></script>
<script type="text/javascript" src="../../static/js/ResourceLinks.js"></script>
<button class="btn btn-success mr-2"
style="background-color:#076AE0!important"
type="submit"
Expand Down
2 changes: 1 addition & 1 deletion templates/experiments/experiment_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="container">
<h2>{{ experiment.name }} (in Project: <a href="{% url 'project_detail' project_uuid=experiment.project.uuid %}">{{ experiment.project }})</a></h2>
{% if experiment.state_temp == 0 %}
<p style="color: rgb(255, 255, 0); font-style: italic;">This may take 3-5 business days to complete!</p>
<p style="color: rgb(0, 183, 255); font-style: italic;">This may take 3-5 business days to complete!</p>
{% elif experiment.state_temp == 1 %}
<p style="color: rgb(255, 183, 15); font-style: italic;">Experiment is scheduled.</p>
{% elif experiment.state_temp == 2 %}
Expand Down
Loading
Loading