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

Web changes for NWB conversion #344

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions benchmarks/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ class Meta:
fields = ('zip_file', 'public', 'competition')


class UploadNWBMetadataForm(forms.Form):
json_file = forms.FileField(label="JSON", help_text='Required')
dandiset_file = forms.FileField(label="Optionally, you can also upload your DANDIset directly", required=False)

class Meta:
model = UploadPlaceHolder
fields = ('json_file', 'dandiset_file')


class ChangePasswordForm(PasswordChangeForm):
def __init__(self, *args, **kwargs):
super(ChangePasswordForm, self).__init__(*args, **kwargs)
Expand Down
5 changes: 5 additions & 0 deletions benchmarks/templates/benchmarks/central_profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ <h3 class="benefits_heading is-size-3-mobile">Welcome, {{ user.email }}</h3>
</p>
</div>
{% endfor %}
<div class="box">
<p class="benefits_info is-size-5-mobile">
Convert NWB data to a BrainScore data plugin <a href="https://{{ request.get_host }}/profile/nwb">here</a>.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a domain-specific button/address? For example, submission is at http://{{ request.get_host }}/profile/{{ domain }}/submit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave as is for now, look for a place to add a disclaimer that this is only for vision

</p>
</div>
<button onclick="location.href='logout/'" type="button" class="button button-primary tutorial_no_top">Logout</button>
</div>
{% else %}
Expand Down
56 changes: 56 additions & 0 deletions benchmarks/templates/benchmarks/convert_nwb.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{% extends "benchmarks/components/app-view.html" %}
{% load static %}

{% block banner %}
<h1> Convert NWB Data </h1>
<p>Here you can convert your NWB data to a BrainScore Benchmark!</p>
{% endblock %}

{% block info_section %}
{% include "benchmarks/tutorials/tutorial-info-section.html" %}
{% endblock %}


{% block content %}

{% if user %}
<div class="box leaderboard-table-component">
<h4 class="title is-4"> To convert, upload a JSON file containing the required NWB metadata.</h4>
<br>

<p>Feel free to download a reference template JSON file <a href="{% static "benchmarks/example_json.json" %}" download> here</a>,
and fill in the required values.</p>
<br>

<form action="" method="post" enctype="multipart/form-data">
{% csrf_token %}

{% for field in form %}
<p class="special">
<br>
{{ field.label_tag }}
<br>
{{ field }}
<br>
{% if field.help_text %}
<small style="display: none">{{ field.help_text }}</small>
{% endif %}
{% for error in field.errors %}
<p style="color: red">{{ error }}</p>
{% endfor %}
</p>
{% endfor %}
</p>
<br>
<button type="submit" class="button submission">Package Data</button>
<br>
</form>
<br>
<button onclick="location.href='logout/'" type="button" class="button button-primary tutorial_no_top">Logout</button>
</div>
{% else %}
{% endif %}

{% endblock %}


1 change: 1 addition & 0 deletions benchmarks/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
path('profile/submit/', user.Upload.as_view(domain="vision"), name=f'vision-submit'),
path('profile/resubmit/', partial(user.resubmit, domain="vision"), name='vision-resubmit'),
path('profile/logout/', user.Logout.as_view(domain="vision"), name='vision-logout'),
path('profile/nwb/', user.ConvertNWB.as_view(domain="vision"), name=f'convert-nwb'),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mike-ferguson to double check domain-specific url approach

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mike-ferguson just checking if the endpoint is good as is or if it should be profile/vision/nwb/?


# central tutorial page, constant across all Brain-Score domains
path('tutorials/', user.Tutorials.as_view(tutorial_type="tutorial"), name='tutorial'),
Expand Down
54 changes: 53 additions & 1 deletion benchmarks/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.utils.encoding import force_bytes, force_str
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
from django.views import View
from benchmarks.forms import SignupForm, LoginForm, UploadFileForm
from benchmarks.forms import SignupForm, LoginForm, UploadFileForm, UploadNWBMetadataForm
from benchmarks.models import Model, BenchmarkInstance, BenchmarkType
from benchmarks.tokens import account_activation_token
from benchmarks.views.index import get_context
Expand Down Expand Up @@ -234,6 +234,58 @@ def post(self, request):
_logger.debug("Job triggered successfully")
return render(request, 'benchmarks/success.html', {"domain": self.domain})

class ConvertNWB(View):
domain = None

def get(self, request):
assert self.domain is not None
if request.user.is_anonymous:
return HttpResponseRedirect(f'../profile/{self.domain}')
form = UploadNWBMetadataForm()
return render(request, 'benchmarks/convert_nwb.html',
{'form': form, 'domain': self.domain, 'formatted': self.domain.capitalize()})

def post(self, request):
assert self.domain is not None
form = UploadNWBMetadataForm(request.POST, request.FILES)

metadata_json = form.files.get('json_file')
json_data = json.load(metadata_json)
with open('submission.json', 'w') as fp:
json.dump(json_data, fp)

user_instance = User.objects.get_by_natural_key(request.user.email)
json_info = {
"model_type": request.POST['model_type'] if "model_type" in form.base_fields else "BrainModel",
"user_id": user_instance.id,
"public": str('public' in request.POST),
"domain": self.domain
}

with open('result.json', 'w') as fp:
json.dump(json_info, fp)

_logger.debug(request.user.get_full_name())
_logger.debug(f"request user: {request.user.get_full_name()}")

# submit to jenkins
jenkins_url = "http://www.brain-score-jenkins.com:8080"
auth = get_secret("brainscore-website_jenkins_access_aws")
auth = (auth['user'], auth['password'])
request_url = f"{jenkins_url}/job/brainscore_nwb_converter/buildWithParameters" \
f"?TOKEN=trigger2convertNWB" \
f"&email={request.user.email}"
_logger.debug(f"request_url: {request_url}")
params = {'metadata.json': open('submission.json', 'rb'), 'submission.config': open('result.json', 'rb')}
if 'dandiset_file' in request.FILES:
params['dandiset.zip'] = request.FILES['dandiset_file']
response = requests.post(request_url, files=params, auth=auth)
_logger.debug(f"response: {response}")

# update frontend
response.raise_for_status()
_logger.debug("Job triggered successfully")
return render(request, 'benchmarks/success.html', {"domain": self.domain})

def is_submission_original_and_under_plugin_limit(file, submitter: User) -> Tuple[bool, Union[None, List[str]]]:
"""
Expand Down
16 changes: 16 additions & 0 deletions static/benchmarks/example_json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"dandiset_id": "000788",
"nwb_file_path": "sub-pico/sub-pico_ecephys.nwb",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to change values to descriptors

"identifier": "DataGenerationTrial_emogan",
"assembly": {
"region": ["IT"],
"presentation": 8500,
"neuroid": 18,
"start_time_ms": 0,
"stop_time_ms": 300,
"tb_ms": 10
},
"stimulus_set": {
"length": 170
}
}