Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions benchmarks/templates/benchmarks/benchmark.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{% extends "benchmarks/components/app-view.html" %}
{% load static %}

{% block body_class %}app-shell-page app-shell-page--brain{% endblock %}

{% block page_title %}Brain-Score - {{ benchmark.benchmark_type.identifier }}{% endblock %}

{% block og_title %}{{ benchmark.benchmark_type.identifier }} - Benchmark{% endblock %}
Expand Down
2 changes: 2 additions & 0 deletions benchmarks/templates/benchmarks/components/app-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

{% load static %}

{% block body_class %}app-shell-page{% endblock %}

{% block main %}
<div class="left-sidebar">
{% include "benchmarks/components/left-sidebar.html" %}
Expand Down
383 changes: 260 additions & 123 deletions benchmarks/templates/benchmarks/landing_page.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{% extends 'benchmarks/components/app-view.html' %}
{% load static compress %}

{% block body_class %}app-shell-page app-shell-page--model{% endblock %}

{% block page_title %}Brain-Score - Leaderboard{% endblock %}

{# The leaderboard uses none of the viz libs (Plotly/d3/Chart/select2/jstat/countdown). #}
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/templates/benchmarks/metadata_preview.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends "benchmarks/components/app-view.html" %}
{% load static %}
{% block third_party_viz_libs %}{% endblock %}
{% block body_class %}model-page{% endblock %}
{% block body_class %}model-page app-shell-page app-shell-page--model{% endblock %}
{% block viewport %}<meta name="viewport" content="width=device-width, initial-scale=1">{% endblock %}
{% block page_title %}Metadata PR preview{% endblock %}
{% block banner %}<h1 class="title">Metadata proposal preview</h1><p>{{ model.name }}</p>{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/templates/benchmarks/model.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<script defer src="https://cdn.plot.ly/plotly-3.3.0.min.js" integrity="sha256-bO3dS6yCpk9aK4gUpNELtCiDeSYvGYnK7jFI58NQnHI=" crossorigin="anonymous"></script>
{% endblock %}

{% block body_class %}model-page{% endblock %}
{% block body_class %}model-page app-shell-page app-shell-page--model{% endblock %}
{% block viewport %}<meta name="viewport" content="width=device-width, initial-scale=1">{% endblock %}

{% block page_title %}Brain-Score - {% if model.public %}{{ model.name }}{% else %}Anonymous Model #{{ model.id }}{% endif %}{% endblock %}
Expand Down
102 changes: 102 additions & 0 deletions benchmarks/tests/test_landing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import math
from types import SimpleNamespace
from unittest.mock import patch

from django.test import SimpleTestCase

from benchmarks.views.landing import PCA_BENCHMARKS, build_benchmark_space


def _model(model_id, values, rank=None):
scores = [
{"benchmark_type_id": identifier, "score_ceiled": value}
for (identifier, _), value in zip(PCA_BENCHMARKS, values)
]
scores.append({"benchmark_type_id": "average_vision", "score_ceiled": sum(values) / len(values)})
return SimpleNamespace(
model_id=model_id,
name=f"model-{model_id}",
rank=rank or model_id,
scores=scores,
submitter={"display_name": "Test Researcher"},
timestamp=None,
)


class BenchmarkSpaceTests(SimpleTestCase):
def test_projects_complete_models_onto_three_components(self):
models = [
_model(1, [0.20, 0.24, 0.30, 0.35, 0.40]),
_model(2, [0.23, 0.28, 0.31, 0.39, 0.42]),
_model(3, [0.31, 0.25, 0.38, 0.44, 0.36]),
_model(4, [0.37, 0.34, 0.45, 0.48, 0.50]),
_model(5, [0.42, 0.39, 0.40, 0.52, 0.47]),
_model(6, [0.48, 0.45, 0.54, 0.58, 0.56]),
]

projection = build_benchmark_space(models)

self.assertEqual(len(projection["points"]), len(models))
self.assertEqual(projection["benchmarks"], ["V1", "V2", "V4", "IT", "Behavior"])
self.assertTrue(all(math.isfinite(point["x"]) for point in projection["points"]))
self.assertTrue(all(math.isfinite(point["y"]) for point in projection["points"]))
self.assertTrue(all(math.isfinite(point["z"]) for point in projection["points"]))
self.assertEqual(len(projection["variance"]), 3)
self.assertGreater(projection["variance"][0], 0)
self.assertGreaterEqual(projection["variance"][0], projection["variance"][1])
self.assertGreaterEqual(projection["variance"][1], projection["variance"][2])

def test_excludes_models_without_complete_nonzero_branch_scores(self):
complete = _model(1, [0.20, 0.24, 0.30, 0.35, 0.40])
second = _model(2, [0.25, 0.29, 0.36, 0.41, 0.46])
third = _model(3, [0.32, 0.37, 0.42, 0.48, 0.52])
incomplete = _model(4, [0.35, 0.39, 0, 0.50, 0.55])

projection = build_benchmark_space([complete, second, third, incomplete])

self.assertEqual([point["id"] for point in projection["points"]], [1, 2, 3])

def test_reports_leaf_benchmark_completion_counts(self):
models = [
_model(1, [0.20, 0.24, 0.30, 0.35, 0.40]),
_model(2, [0.25, 0.29, 0.36, 0.41, 0.46]),
_model(3, [0.32, 0.37, 0.42, 0.48, 0.52]),
]
models[0].scores += [
{"benchmark_type_id": "leaf-a", "score_ceiled": "0"},
{"benchmark_type_id": "leaf-b", "score_ceiled": "X"},
]
models[1].scores += [
{"benchmark_type_id": "leaf-a", "score_ceiled": ".3"},
{"benchmark_type_id": "leaf-b", "score_ceiled": ".4"},
]

projection = build_benchmark_space(models, {"leaf-a", "leaf-b"})

self.assertEqual([point["completed"] for point in projection["points"]], [1, 2, 0])
self.assertEqual(projection["benchmark_total"], 2)
self.assertEqual(projection["points"][0]["behavior"], 0.40)


class LandingPageTests(SimpleTestCase):
@patch("benchmarks.views.landing.landing_context")
def test_homepage_exposes_dashboard_entry_points(self, context):
context.return_value = {
"comparison_data": "[]",
"news_items": [],
"recent_models": [],
"leaderboard_models": [],
"benchmark_space": {"points": [], "variance": [0, 0, 0], "benchmarks": []},
"public_model_count": None,
"benchmark_count": None,
}

response = self.client.get("/")

self.assertEqual(response.status_code, 200)
self.assertContains(response, "Latest updates")
self.assertContains(response, "The 2D benchmark space")
self.assertContains(response, 'data-space-mode="2d"')
self.assertContains(response, "Compare benchmarks")
self.assertContains(response, "Compare models")
self.assertContains(response, "Run locally")
15 changes: 15 additions & 0 deletions benchmarks/tests/test_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pathlib import Path

from django.template.loader import get_template
from django.test import SimpleTestCase

TEMPLATE_ROOT = Path(__file__).resolve().parent.parent / "templates"


class TemplateCompileTests(SimpleTestCase):
def test_every_template_compiles(self):
# Catches merge damage such as a block defined twice, without a database.
for path in sorted(TEMPLATE_ROOT.rglob("*.html")):
name = path.relative_to(TEMPLATE_ROOT).as_posix()
with self.subTest(template=name):
get_template(name)
2 changes: 2 additions & 0 deletions benchmarks/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def test_vision_leaderboard(self):
response = self.client.get('/vision/', follow=True)
self.assertEqual(response.status_code, 200)
self.assertIn(b'Leaderboard', response.content)
self.assertIn(b'<body class="app-shell-page app-shell-page--model">', response.content)

def test_language_leaderboard(self):
"""Test the language leaderboard page"""
Expand All @@ -81,6 +82,7 @@ def test_compare_page(self):
"""Test the compare page loads"""
response = self.client.get('/vision/compare/')
self.assertEqual(response.status_code, 200)
self.assertIn(b'<body class="app-shell-page">', response.content)

def test_tutorials_home(self):
"""Test the tutorials home page loads"""
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.conf import settings
from django.urls import path
from django.views.generic import RedirectView
from .views import user, model, competition2022, competition2024, compare, community, \
from .views import user, model, competition2022, competition2024, compare, community, landing, \
release2_0, brain_model, content_utils, benchmark, explore, leaderboard, report_issue, blog, tutorials
from .views import metadata_edit
from .utils import show_token, refresh_cache, refresh_score_trends
Expand All @@ -17,8 +17,8 @@
path('metadata/proposals/<str:key>/', metadata_edit.review, name='metadata-review'),
path('metadata/github/callback/', metadata_edit.callback, name='metadata-github-callback'),
# landing
path('', user.LandingPage.as_view(), name='landing_page'),
path('/', user.LandingPage.as_view(), name='landing_page'),
path('', landing.LandingPage.as_view(), name='landing_page'),
path('/', landing.LandingPage.as_view(), name='landing_page'),

# global pages - default to vision domain
path('explore/', RedirectView.as_view(url='/vision/explore/', permanent=False), name='default-explore'),
Expand Down
Loading
Loading