Skip to content

Commit

Permalink
bug fixes and readability improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dxenes1 committed Oct 23, 2024
1 parent bdeb22e commit c6d258e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 22 deletions.
Binary file modified neuvue_project/neuvueDB.sqlite3
Binary file not shown.
43 changes: 35 additions & 8 deletions neuvue_project/templates/inspect.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ <h3 class="text-white mb-3"> Inspect Task </h3>
</div>
</div>
</div>
<script type="text/javascript" src="{% static "workspace/main.bundle.js" %}"></script>
{% if ng_host == "spelunker" %}
<script type="module" src="562.1d0cecad9cc0725955f0.js"></script><script type="module" src="993.ca23372ceee17151541a.js"></script><script type="module" src="367.ad6071abcab399305157.js"></script><script type="module" src="main.cb26101b553ed6b82856.js"></script><link href="main.cb26101b553ed6b82856.css" rel="stylesheet">
{% else %}
<script type="text/javascript" src="{% static 'workspace/main.bundle.js' %}"></script>
{% endif %}
<script type="text/javascript" src="{% static "js/utils.js" %}"></script>
{% endif%}
<style> .overlay-hidden { display:none; } </style>
Expand All @@ -111,18 +115,41 @@ <h3 class="text-white mb-3"> Inspect Task </h3>
<script type="text/javascript">

function getLink() {
viewer.postJsonState(true, undefined, true, function() {
let url_prefix = "https://neuroglancer.neuvue.io/?json_url="
copyToClipboard(url_prefix.concat(viewer.saver.savedUrl));
});
{% if ng_host == "neuvue" %}
viewer.postJsonState(true, undefined, true, function() {
let url_prefix = "https://neuroglancer.neuvue.io/?json_url="
copyToClipboard(url_prefix.concat(viewer.saver.savedUrl));
});
{% elif ng_host == "spelunker" %}
let url_prefix = "https://spelunker.cave-explorer.org/#!";
copyToClipboard(url_prefix.concat(JSON.stringify(viewer.state.toJSON())));
{% else %}
//pass
{% endif %}
}

// Function to attempt restoring the viewer state
function tryRestoreState() {
if (typeof viewer !== 'undefined') {
// Viewer is defined, attempt to restore the state
try {
var received_data = {{ ng_state|safe }};
viewer.state.restoreState(received_data);
console.log('Viewer state restored successfully.');
} catch (error) {
console.error('Error restoring viewer state:', error);
}
} else {
// Viewer is not yet defined, retry after a short delay
setTimeout(tryRestoreState, 100); // Retry every 100 milliseconds
}
}

// Neuroglancer State Load
$(document).ready(function() {
{% if ng_state %}
const state = {{ ng_state|safe }};
openSideMenu();
viewer.state.restoreState(state);
openSideMenu();
tryRestoreState();
{% endif %}
})

Expand Down
20 changes: 15 additions & 5 deletions neuvue_project/templates/workspace.html
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,19 @@
})

function getLink() {
viewer.postJsonState(true, undefined, true, function() {
let url_prefix = "https://neuroglancer.neuvue.io/?json_url="
copyToClipboard(url_prefix.concat(viewer.saver.savedUrl));
});
{% if ng_host == "neuvue" %}
viewer.postJsonState(true, undefined, true, function() {
let url_prefix = "https://neuroglancer.neuvue.io/?json_url="
copyToClipboard(url_prefix.concat(viewer.saver.savedUrl));
triggerToast("Copied link to clipboard");
});
{% elif ng_host == "spelunker" %}
let url_prefix = "https://spelunker.cave-explorer.org/#!";
copyToClipboard(url_prefix.concat(JSON.stringify(viewer.state.toJSON())));
triggerToast("Copied link to clipboard");
{% else %}
triggerToast("Copy Link unavailable on embedded Neuroglancer task type");
{% endif %}
}

function saveState() {
Expand All @@ -326,7 +335,8 @@
});
});
{% else %}
triggerToast("Autosave disabled for embedded neuroglancer");
triggerToast("State saving disabled for non-native Neuroglancer");
removeLoadingSpinner("save_state", "Save State");
{% endif %}
}

Expand Down
8 changes: 5 additions & 3 deletions neuvue_project/workspace/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# import the logging library
import logging

import warnings
logging.basicConfig(level=logging.DEBUG)
# Get an instance of a logger
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -111,8 +111,10 @@ def create_stats_table(pending_tasks, closed_tasks):
for namespace, namespace_df in df.groupby("namespace"):
n_tasks = len(namespace_df)
m = namespace_df[status].min()
average_event_time = (m + (namespace_df[status] - m)).mean().to_pydatetime()
changelog.append((average_event_time, n_tasks, status, namespace))
with warnings.catch_warnings():
warnings.simplefilter("ignore")
average_event_time = (m + (namespace_df[status] - m)).mean().to_pydatetime()
changelog.append((average_event_time, n_tasks, status, namespace))

# Sort changelogs by datetime
daily_changelog_items = sorted(
Expand Down
8 changes: 4 additions & 4 deletions neuvue_project/workspace/views/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def get(self, request, task_id=None, *args, **kwargs):
"task_id": task_id,
"ng_state": None,
"ng_url": None,
"ng_host": None,
"error": None,
"num_edits": 0,
}
Expand Down Expand Up @@ -79,14 +80,13 @@ def get(self, request, task_id=None, *args, **kwargs):
task_df, points, return_as="json"
)

context["ng_host"] = namespace_obj.ng_host
context["task_id"] = task_df["_id"]
context["seg_id"] = task_df["seg_id"]
context["instructions"] = task_df["instructions"]
context["assignee"] = task_df["assignee"]
context["display_name"] = Namespace.objects.get(
namespace=namespace
).display_name
context["pcg_url"] = Namespace.objects.get(namespace=namespace).pcg_source
context["display_name"] = namespace_obj.display_name
context["pcg_url"] = namespace_obj.pcg_source
context["status"] = task_df["status"]
if "flag_reason" in task_df["metadata"].keys():
context["flag_reason"] = task_df["metadata"]["flag_reason"]
Expand Down
7 changes: 5 additions & 2 deletions neuvue_project/workspace/views/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def get(self, request, namespace=None, **kwargs):

if ng_state:
if is_url(ng_state.replace("middleauth+", "")):
if namespace_obj.ng_host not in [NeuroglancerHost.NEUVUE]:
if namespace_obj.ng_host not in [NeuroglancerHost.NEUVUE, NeuroglancerHost.SPELUNKER]:
# Assume its a url to json state
context["ng_state"] = ng_state
else:
Expand Down Expand Up @@ -428,4 +428,7 @@ def post(self, request, *args, **kwargs):
client.post_differ_stack(task_df["_id"], ng_differ_stack)
return redirect(reverse("tasks"))

return redirect(reverse("workspace", args=[namespace]))
if namespace_obj.ng_host == NeuroglancerHost.SPELUNKER:
return redirect(reverse("spelunker-workspace", args=[namespace]))
else:
return redirect(reverse("workspace", args=[namespace]))

0 comments on commit c6d258e

Please sign in to comment.