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

Bump faker from 8.1.2 to 8.10.3 #394

Open
wants to merge 3 commits into
base: main
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
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 flare-kcl

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
88 changes: 85 additions & 3 deletions flare_portal/experiments/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@
from django.core.validators import FileExtensionValidator
from django.db.models import QuerySet
from django.forms import inlineformset_factory
from django.utils.datastructures import MultiValueDict

from flare_portal.experiments.models.modules import get_volume_increments
from flare_portal.users.models import User

from .models import BreakEndModule, BreakStartModule, Experiment, Participant, Project
from .models import (
BreakEndModule,
BreakStartModule,
Experiment,
InstructionsModule,
Participant,
Project,
)


class ExperimentForm(forms.ModelForm):
Expand All @@ -20,8 +29,24 @@ class ExperimentForm(forms.ModelForm):
max_value=1,
min_value=0,
widget=forms.NumberInput(attrs={"step": "0.01"}),
help_text="The minimum volume that you would like the participant to "
"abide by. Must be a value between 0 - 1, e.g. 0.5 equates to 50% volume.",
label="Minimum Device Volume",
help_text="Must be a value between 0 - 1, e.g. 0.5 equates to 50% volume. "
"The minimum volume that your participants must set their phones to during "
"the experiment. Setting this value lower than 1 gives participants the "
"option to reduce their device’s volume without interrupting the experiment.",
)
us_file_volume = forms.FloatField(
required=True,
max_value=1,
min_value=0,
widget=forms.NumberInput(attrs={"step": "0.01"}),
label="US File Volume",
help_text="Must be a value between 0 - 1, e.g. 0.5 equates to 50% volume. Each "
".wav file has a built-in volume setting, this is what will limit the true "
"volume a participant will hear. True volume equals file volume multiplied "
"by device volume. For example, if you set the file volume to .5 and the "
"participant’s device volume is set to 1, the true volume the participant "
"will hear is .5.",
)

class Meta:
Expand All @@ -36,6 +61,7 @@ class Meta:
"rating_delay",
"iti_min_delay",
"iti_max_delay",
"us_file_volume",
"minimum_volume",
"rating_scale_anchor_label_left",
"rating_scale_anchor_label_center",
Expand Down Expand Up @@ -246,6 +272,62 @@ def save(self) -> None:
self.participants.delete()


class VolumeIncrementsWidget(forms.MultiWidget):
"""
This is a Form Widget for use with a Postgres ArrayField. It implements
a multi-field interface to allow multiple float values to be submitted.
"""

template_name = "widgets/volume_increments.html"

def __init__(self, *args: Any, **kwargs: Any) -> None:
self.default_values = kwargs.pop(
"default_values", [0.1, 0.2, 0.3, 0.9, 0.95, 1]
)
widgets = []
for _ in range(0, len(self.default_values)):
widgets.append(forms.NumberInput(attrs={"step": "0.01"}))
super().__init__(widgets, *args, **kwargs)

def decompress(self, value: str) -> List[str]:
# Split combined value of the arrayfield into the values for each widget
if isinstance(value, str):
return list(value.split(","))
return [
None for _ in range(0, len(self.default_values))
] # return None for each widget

def value_from_datadict(self, data: Any, files: Any, name: str) -> List[str]:
# Parse inputs by name and output array of values
if isinstance(data, MultiValueDict):
values = []
for i in range(0, len(self.default_values)):
value = data.get(name + "_" + str(i), None)
if value:
values.append(value)
return values
return []


class InstructionsModuleForm(forms.ModelForm):
class Meta:
model = InstructionsModule
fields = [
"experiment",
"label",
"include_volume_calibration",
"volume_increments",
"end_screen_title",
"end_screen_body",
]
widgets = {
"experiment": forms.HiddenInput(),
"volume_increments": VolumeIncrementsWidget(
default_values=get_volume_increments(),
),
}


class BreakStartModuleForm(forms.ModelForm):
class Meta:
model = BreakStartModule
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.1.6 on 2021-04-15 15:20

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('experiments', '0059_rename_task_to_trial'),
]

operations = [
migrations.AddField(
model_name='experiment',
name='us_file_volume',
field=models.FloatField(default=1, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(1)]),
),
migrations.AlterField(
model_name='instructionsmodule',
name='include_volume_calibration',
field=models.BooleanField(default=False, help_text='Enabling volume calibration will override the US file volume set in the experiment settings.'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.1.6 on 2021-04-16 12:04

import django.contrib.postgres.fields
import django.core.validators
from django.db import migrations, models
import flare_portal.experiments.models.modules
import flare_portal.utils.validators


class Migration(migrations.Migration):

dependencies = [
('experiments', '0060_add_us_file_volume_fields'),
]

operations = [
migrations.AddField(
model_name='instructionsmodule',
name='volume_increments',
field=django.contrib.postgres.fields.ArrayField(base_field=models.FloatField(validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(1)]), default=flare_portal.experiments.models.modules.get_volume_increments, size=6, validators=[flare_portal.utils.validators.validate_ascending_order]),
),
]
4 changes: 4 additions & 0 deletions flare_portal/experiments/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class Experiment(models.Model):
project = models.ForeignKey("experiments.Project", on_delete=models.CASCADE)
trial_length = models.FloatField()
rating_delay = models.FloatField(default=1)
us_file_volume = models.FloatField(
default=1,
validators=[MinValueValidator(0), MaxValueValidator(1)],
)
minimum_volume = models.FloatField(
default=1,
validators=[MinValueValidator(0), MaxValueValidator(1)],
Expand Down
26 changes: 25 additions & 1 deletion flare_portal/experiments/models/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from typing import Any, List

from django import forms
from django.contrib.postgres.fields import ArrayField
from django.core.exceptions import ValidationError
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.template.defaultfilters import pluralize
from django.utils.text import get_text_list
Expand All @@ -11,6 +13,8 @@
from model_utils import Choices
from model_utils.managers import InheritanceManager

from flare_portal.utils.validators import validate_ascending_order

from .. import constants
from .core import Nameable

Expand Down Expand Up @@ -365,8 +369,27 @@ class InstructionsScreenInline(InlineFormSetFactory):
factory_kwargs = {"extra": 0}


def get_volume_increments() -> List[float]:
return [0.5, 0.65, 0.8, 0.9, 0.95, 1]


class InstructionsModule(Module):
include_volume_calibration = models.BooleanField(default=False)
include_volume_calibration = models.BooleanField(
default=False,
help_text=(
"Enabling volume calibration will override the US file "
"volume set in the experiment settings."
),
)
volume_increments = ArrayField(
models.FloatField(
blank=False,
validators=[MinValueValidator(0), MaxValueValidator(1)],
),
size=6,
default=get_volume_increments,
validators=[validate_ascending_order],
)
end_screen_title = models.CharField(max_length=255, blank=True)
end_screen_body = models.TextField(
blank=True,
Expand All @@ -384,6 +407,7 @@ def get_module_config(self) -> constants.ModuleConfigType:
type=self.get_module_tag(),
config={
"include_volume_calibration": self.include_volume_calibration,
"volume_increments": self.volume_increments,
"end_screen_title": self.end_screen_title,
"end_screen_body": self.end_screen_body,
"screens": [
Expand Down
18 changes: 16 additions & 2 deletions flare_portal/experiments/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
UpdateWithInlinesView,
)

from .forms import BreakStartModuleForm
from .forms import BreakStartModuleForm, InstructionsModuleForm
from .models import (
AffectiveRatingData,
AffectiveRatingModule,
Expand Down Expand Up @@ -251,6 +251,16 @@ class BreakModuleCreateView(ModuleCreateView):
form_class = BreakStartModuleForm


class InstructionsModuleUpdateView(ModuleUpdateView):
model = InstructionsModule
form_class = InstructionsModuleForm


class InstructionsModuleCreateView(ModuleCreateView):
model = InstructionsModule
form_class = InstructionsModuleForm


module_registry = ModuleRegistry()

module_registry.register(AffectiveRatingModule)
Expand All @@ -261,7 +271,11 @@ class BreakModuleCreateView(ModuleCreateView):
module_registry.register(CriterionModule)
module_registry.register(ContingencyAwarenessModule)
module_registry.register(FearConditioningModule)
module_registry.register(InstructionsModule)
module_registry.register(
InstructionsModule,
update_view_class=InstructionsModuleUpdateView,
create_view_class=InstructionsModuleCreateView,
)
module_registry.register(TaskInstructionsModule)
module_registry.register(TextModule)
module_registry.register(WebModule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ <h3 class="card-title">Assets</h3>
<div class="card-body">
{% include "includes/form-group.html" with field=form.us accept="audio/wav,audio/mp3" %}
<div class="row gutter-xs mt-6">
<div class="col-8">
{% include "includes/form-group.html" with field=form.us_file_volume %}
</div>
<div class="col-8">
{% include "includes/form-group.html" with field=form.minimum_volume %}
</div>
Expand Down
2 changes: 2 additions & 0 deletions flare_portal/experiments/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ def test_create_experiment(self) -> None:
"iti_min_delay": "1",
"iti_max_delay": "3",
"minimum_volume": "1",
"us_file_volume": "0.5",
"rating_scale_anchor_label_left": "Certain no beep",
"rating_scale_anchor_label_center": "Uncertain",
"rating_scale_anchor_label_right": "Certain beep",
Expand Down Expand Up @@ -541,6 +542,7 @@ def test_update_experiment(self) -> None:
"iti_min_delay": "1",
"iti_max_delay": "3",
"minimum_volume": "1",
"us_file_volume": "0.5",
"rating_scale_anchor_label_left": "Certain no beep",
"rating_scale_anchor_label_center": "Uncertain",
"rating_scale_anchor_label_right": "Certain beep",
Expand Down
11 changes: 11 additions & 0 deletions flare_portal/static_src/sass/components/_custom-array-widget.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.custom-array-widget {
display: flex;

&__input-wrapper {
margin-right: 6px;

&:last-child {
margin-right: 0;
}
}
}
1 change: 1 addition & 0 deletions flare_portal/static_src/sass/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
@import 'vendor/tabler';

@import 'components/custom-checkbox-group';
@import 'components/custom-array-widget';
@import 'components/custom-file';
4 changes: 4 additions & 0 deletions flare_portal/templates/includes/form-group.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
{% endif %}
</div>
</div>
{% elif field|widget_type == 'volumeincrementswidget' %}
<div class="form-group{% if field.errors %} has-errors{% endif %}">
{{ field|add_class:"form-control"|add_error_class:"is-invalid" }}
</div>
{% else %}
{{ field|add_class:"form-control"|add_error_class:"is-invalid" }}
{% endif %}
Expand Down
12 changes: 12 additions & 0 deletions flare_portal/templates/widgets/volume_increments.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% spaceless %}
<div class="custom-array-widget">
{% for widget in widget.subwidgets %}
<div class="custom-array-widget__input-wrapper">
<label class="sr-only" for="{{ widget.attrs.id }}">
Step {{ forloop.counter }}
</label>
{% include widget.template_name %}
</div>
{% endfor %}
</div>
{% endspaceless %}
9 changes: 9 additions & 0 deletions flare_portal/utils/validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import List

from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _


def validate_ascending_order(values: List[float]) -> None:
if not all(values[i] <= values[i + 1] for i in range(len(values) - 1)):
raise ValidationError(_("Values must be in ascending order"))
Loading