Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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, 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>.
</p>
</div>
<button onclick="location.href='logout/'" type="button" class="button button-primary tutorial_no_top">Logout</button>
</div>
{% else %}
Expand Down
57 changes: 57 additions & 0 deletions benchmarks/templates/benchmarks/convert_nwb.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{% extends "benchmarks/components/app-view.html" %}
{% load static %}

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

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


{% block content %}

{% if user %}
<div class="box leaderboard-table-component">
<h1 style="font-size: 1.25em;">Upload a JSON file containing the required NWB metadata</h1>
<br>

<p>Download a template JSON file below and fill in the required values.</p>
<a href="{% static "benchmarks/example_json.json" %}" class="button button-primary" download>
Download JSON template
</a>

<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'),

# central tutorial page, constant across all Brain-Score domains
path('tutorials/', user.Tutorials.as_view(tutorial_type="tutorial"), name='tutorial'),
Expand Down
53 changes: 52 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,57 @@ 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),
"competition": 'cosyne2022' if 'competition' in request.POST and request.POST['competition'] else None,
"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'), '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
17 changes: 17 additions & 0 deletions static/benchmarks/example_json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"dandiset_id": "000788",
"nwb_file_path": "sub-pico/sub-pico_ecephys.nwb",
"exp_path": "/home/ubuntu/vision/brainscore_vision/nwb_integration/",
"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
}
}