Skip to content

Commit

Permalink
Merge pull request #75 from ctreffe/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jobrachem authored Oct 28, 2021
2 parents 017b792 + 96ba06b commit 19a6156
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 24 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Mortimer v0.8.12 (Released 2021-10-28)

### Added

- Added support for alfred3's new test mode
- Added "sid" prefix for session ids
- Added quickstart options for alfred3's test mode and debug mode
- Added a warning that will appear upon codebook download if element
labels in *the two newest* datasets are unequal.

## Mortimer v0.8.11 (Released 2021-10-14)

### Changed
Expand Down
3 changes: 2 additions & 1 deletion src/mortimer/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
# 3) we can import it into your module module


__version__ = "0.8.11"

__version__ = "0.8.12"
88 changes: 68 additions & 20 deletions src/mortimer/templates/experiment.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,34 @@ <h1>{{ experiment.title }}</h1>
</div>
</div>

<div class="form-row mb-3 justify-content-end">
<div class="col col-sm-8">
<small class="text-muted pl-2">You can use the field and button below to start your experiment with url parameters, for example: <code>param1=value1&amp;param2=value2</code></small>
<div class="input-group pl-2">
<input type="text" class="form-control" placeholder="param=value" value="{{ experiment.urlparam }}" id="start_param">
<div class="input-group-append">
<button class="btn btn-primary" type="button" id="start_with_param">
<i class="fas fa-play mr-2"></i>Start with parameters
</button>
</div>
</div>
<div class="input-group mb-3">
<input type="text" class="form-control" aria-describedby="basic-addon2" id="link-to-exp-test"
value="{{ url_for('alfredo.start', expid=expid, _external=True) }}?test=true">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" data-clipboard-target="#link-to-exp-test">
<img src="{{ url_for('static', filename='clippy.svg')}}" alt="Copy to clipboard" width="20"> Copy Link
</button>
<a class="btn btn-dark" target="_blank" rel="noopener noreferrer"
href="{{ url_for('alfredo.start', expid=expid) }}?test=true"><i class="fas fa-play mr-2"></i>Test</a>
<a class="btn btn-info" target="_blank" rel="noopener noreferrer"
href="{{ url_for('alfredo.start', expid=expid) }}?debug=true"><i class="fas fa-play mr-2"></i>Debug</a>
</div>
</div>

<div class="form-row mb-3 justify-content-end">
<div class="col col-sm-8">
<small class="text-muted pl-2">You can use the field and button below to start your experiment with url
parameters, for example: <code>param1=value1&amp;param2=value2</code></small>
<div class="input-group pl-2">
<input type="text" class="form-control" placeholder="param=value" value="{{ experiment.urlparam }}"
id="start_param">
<div class="input-group-append">
<button class="btn btn-primary" type="button" id="start_with_param">
<i class="fas fa-play mr-2"></i>Start with parameters
</button>
</div>
</div>
</div>
</div>


Expand All @@ -67,6 +83,36 @@ <h1>{{ experiment.title }}</h1>
</div>
</div>

<div class="input-group mb-3">
<input type="text" class="form-control" aria-describedby="basic-addon2" id="link-to-exp-test"
value="{{ url_for('alfredo.start', expid=expid, _external=True) }}?test=true">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" data-clipboard-target="#link-to-exp-test">
<img src="{{ url_for('static', filename='clippy.svg')}}" alt="Copy to clipboard" width="20"> Copy Link
</button>
<a class="btn btn-dark" target="_blank" rel="noopener noreferrer"
href="{{ url_for('alfredo.start', expid=expid) }}?test=true"><i class="fas fa-play mr-2"></i>Test</a>
<a class="btn btn-info" target="_blank" rel="noopener noreferrer"
href="{{ url_for('alfredo.start', expid=expid) }}?debug=true"><i class="fas fa-play mr-2"></i>Debug</a>
</div>
</div>

<div class="form-row mb-3 justify-content-end">
<div class="col col-sm-8">
<small class="text-muted pl-2">You can use the field and button below to start your experiment with url
parameters, for example: <code>param1=value1&amp;param2=value2</code></small>
<div class="input-group pl-2">
<input type="text" class="form-control" placeholder="param=value" value="{{ experiment.urlparam }}"
id="start_param">
<div class="input-group-append">
<button class="btn btn-primary" type="button" id="start_with_param">
<i class="fas fa-play mr-2"></i>Start with parameters
</button>
</div>
</div>
</div>
</div>

{% endif %}
</div>
</div>
Expand Down Expand Up @@ -341,14 +387,16 @@ <h5 class="modal-title" id="uploadModalLabel">Upload script.py</h5>

<script>
var starturl = "{{ url_for('alfredo.start', expid=expid, _external=True) }}"
var updateurl = "{{ url_for('web_experiments.update_urlparam', experiment_title=experiment.title, username=experiment.author, _external=True) }}"

$( "#start_with_param" ).click(function() {
var startparam = $( "#start_param" ).val();
var targeturl = starturl + "?" + startparam;
$.post( updateurl, {urlparam: startparam} );
window.open(targeturl).focus();
});

var updateurl =
"{{ url_for('web_experiments.update_urlparam', experiment_title=experiment.title, username=experiment.author, _external=True) }}"

$("#start_with_param").click(function () {
var startparam = $("#start_param").val();
var targeturl = starturl + "?" + startparam;
$.post(updateurl, {
urlparam: startparam
});
window.open(targeturl).focus();
});
</script>
{% endblock %}
7 changes: 5 additions & 2 deletions src/mortimer/web_experiments/alfredo.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def start(expid):
experiment = WebExperiment.objects.get_or_404(id=ObjectId(expid))

# create session id
sid = str(uuid4())
sid = "sid-" + str(uuid4())

config = experiment.parse_exp_config(sid)
secrets = experiment.parse_exp_secrets()
Expand All @@ -178,7 +178,10 @@ def start(expid):
% exp_url
)

if not experiment.active:
args = request.args.to_dict()
test_mode = args.get("test") in ["true", "True", "TRUE"]
debug_mode = args.get("debug") in ["true", "True", "TRUE"] or config.getboolean("general", "debug")
if not experiment.active and not test_mode and not debug_mode:
return render_template("exp_inactive.html")

session["sid"] = sid
Expand Down
21 changes: 20 additions & 1 deletion src/mortimer/web_experiments/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,26 @@ def export_codebook_data(username, experiment_title, delim: str, version: str):
# combine them to a single dictionary, overwriting old values
# with newer ones
data = {}
for entry in cbdata_collection:
n = len(cbdata_collection)
for i, entry in enumerate(cbdata_collection):

# check if all labels in the last two data sets match
if i == n-1 and data:
for name, cb in entry.items():
for lab in ["label_top", "label_left", "label_right", "label_bottom", "placeholder"]:
old = data.get(name, "")
oldlab = old.get(lab, "") if old else ""
newlab = cb.get(lab, "")
if not oldlab == newlab:
flash(
(
f"Codebook: {lab} of '{name}' has changed from '{oldlab}' to '{newlab}'. "
"This introduces inconsistencies into the codebook. "
"Do you have dynamic labels that do not match their elements' names? "
"To change a label, increase the experiment version."
),
"warning"
)
data.update(entry)

fieldnames = data_manager.DataManager.extract_fieldnames(data.values())
Expand Down

0 comments on commit 19a6156

Please sign in to comment.