Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nk20
Manage
Activity
Members
Labels
Plan
Issues
31
Issue boards
Milestones
Wiki
Code
Merge requests
5
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BDE
nk20
Commits
9596aa7b
Verified
Commit
9596aa7b
authored
1 year ago
by
bleizi
Browse files
Options
Downloads
Patches
Plain Diff
base for questions instead of words
parent
ba0d64f0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!218
Wei with questions
Pipeline
#12966
failed with stages
in 12 minutes and 48 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/wei/forms/surveys/wei2023.py
+54
-49
54 additions, 49 deletions
apps/wei/forms/surveys/wei2023.py
with
54 additions
and
49 deletions
apps/wei/forms/surveys/wei2023.py
+
54
−
49
View file @
9596aa7b
...
...
@@ -13,31 +13,43 @@ from django.utils.translation import gettext_lazy as _
from
.base
import
WEISurvey
,
WEISurveyInformation
,
WEISurveyAlgorithm
,
WEIBusInformation
from
...models
import
WEIMembership
WORDS
=
[
'
ABBA
'
,
'
After
'
,
'
Alcoolique anonyme
'
,
'
Ambiance festive
'
,
'
Années 2000
'
,
'
Apéro
'
,
'
Art
'
,
'
Baby foot billard biere pong
'
,
'
BBQ
'
,
'
Before
'
,
'
Bière pong
'
,
'
Bon enfant
'
,
'
Calme
'
,
'
Canapé
'
,
'
Chanson paillarde
'
,
'
Chanson populaire
'
,
'
Chartreuse
'
,
'
Cheerleader
'
,
'
Chill
'
,
'
Choré
'
,
'
Cinéma
'
,
'
Cocktail
'
,
'
Comédie musicle
'
,
'
Commercial
'
,
'
Copaing
'
,
'
Danse
'
,
'
Dancefloor
'
,
'
Electro
'
,
'
Fanfare
'
,
'
Gin tonic
'
,
'
Inclusif
'
,
'
Jazz
'
,
"
Jeux d
'
alcool
"
,
'
Jeux de carte
'
,
'
Jeux de rôle
'
,
'
Jeux de société
'
,
'
JUL
'
,
'
Jus de fruit
'
,
'
Kfet
'
,
'
Kleptomanie assurée
'
,
'
LGBTQ+
'
,
'
Livre
'
,
'
Morning beer
'
,
'
Musique
'
,
'
NAPS
'
,
'
Paillettes
'
,
'
Pastis
'
,
'
Paté Hénaff
'
,
'
Peluche
'
,
'
Pena baiona
'
,
"
Peu d
'
alcool
"
,
'
Pilier de bar
'
,
'
PMU
'
,
'
Poulpe
'
,
'
Punch
'
,
'
Rap
'
,
'
Réveil
'
,
'
Rock
'
,
'
Rugby
'
,
'
Sandwich
'
,
'
Serge
'
,
'
Shot
'
,
'
Sociable
'
,
'
Spectacle
'
,
'
Techno
'
,
'
Techno house
'
,
'
Thérapie Taxi
'
,
'
Tradition kchanaises
'
,
'
Troisième mi-temps
'
,
'
Turn up
'
,
'
Vodka
'
,
'
Vodka pomme
'
,
'
Volley
'
,
'
Vomi stratégique
'
]
WORDS
=
{
"
ambiance
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
musique
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
boisson
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
beauferie
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
sommeil
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
vacances
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
activite
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
hygiene
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
animal
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
fensfoire
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
kokarde
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
copain
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
vie
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
jeux
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
calin
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
vommi
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
kfet
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
fatigue
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
duree trajet
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}],
"
scolarite
"
:[
"
Question
"
,
{
1
:
"
réponse 1
"
,
2
:
"
réponse 2
"
,
3
:
"
réponse 3
"
,
4
:
"
réponse 4
"
,
5
:
"
réponse 5
"
}]
}
class
WEISurveyForm2023
(
forms
.
Form
):
"""
Survey form for the year 2023.
Members
choose 20 words
, from which we calculate the best associated bus.
Members
answer 20 question
, from which we calculate the best associated bus.
"""
word
=
forms
.
ChoiceField
(
label
=
_
(
"
Choose a word:
"
),
widget
=
forms
.
RadioSelect
(),
)
def
__init__
(
self
,
**
kwargs
):
super
().
__init__
(
**
kwargs
)
for
question
in
WORDS
:
self
.
fields
[
question
]
=
forms
.
ChoiceField
(
label
=
WORDS
[
question
][
0
]
+
question
,
widget
=
forms
.
RadioSelect
(),
)
def
set_registration
(
self
,
registration
):
"""
...
...
@@ -50,41 +62,32 @@ class WEISurveyForm2023(forms.Form):
registration
.
_force_save
=
True
registration
.
save
()
if
self
.
data
:
self
.
fields
[
"
word
"
].
choices
=
[(
w
,
w
)
for
w
in
WORDS
]
if
self
.
is_valid
():
return
# if self.data:
# for question in WORDS:
# self.fields[question].choices = [answer for answer in WORDS[question][1]]
# if self.is_valid():
# return
rng
=
Random
((
information
.
step
+
1
)
*
information
.
seed
)
# rng = Random(information.seed) # add someting if it's alwais the same
# questions = list(WORDS.keys())
# rng.shuffle(questions)
words
=
None
buses
=
WEISurveyAlgorithm2023
.
get_buses
()
informations
=
{
bus
:
WEIBusInformation2023
(
bus
)
for
bus
in
buses
}
scores
=
sum
((
list
(
informations
[
bus
].
scores
.
values
())
for
bus
in
buses
),
[])
average_score
=
sum
(
scores
)
/
len
(
scores
)
preferred_words
=
{
bus
:
[
word
for
word
in
WORDS
if
informations
[
bus
].
scores
[
word
]
>=
average_score
]
for
bus
in
buses
}
while
words
is
None
or
len
(
set
(
words
))
!=
len
(
words
):
# Ensure that there is no the same word 2 times
words
=
[
rng
.
choice
(
words
)
for
_ignored2
,
words
in
preferred_words
.
items
()]
rng
.
shuffle
(
words
)
words
=
[(
w
,
w
)
for
w
in
words
]
self
.
fields
[
"
word
"
].
choices
=
words
# for question in questions:
for
question
in
WORDS
:
answers
=
[(
answer
,
WORDS
[
question
][
1
][
answer
])
for
answer
in
WORDS
[
question
][
1
]]
self
.
fields
[
question
].
choices
=
answers
class
WEIBusInformation2023
(
WEIBusInformation
):
"""
For each
word
, the bus has
a score
For each
question
, the bus has
ordered answers
"""
scores
:
dict
def
__init__
(
self
,
bus
):
self
.
scores
=
{}
for
word
in
WORDS
:
self
.
scores
[
word
]
=
0.0
for
question
in
WORDS
:
self
.
scores
[
question
]
=
[]
super
().
__init__
(
bus
)
...
...
@@ -95,11 +98,10 @@ class WEISurveyInformation2023(WEISurveyInformation):
"""
# Random seed that is stored at the first time to ensure that words are generated only once
seed
=
0
step
=
0
def
__init__
(
self
,
registration
):
for
i
in
range
(
1
,
21
)
:
setattr
(
self
,
"
word
"
+
str
(
i
),
None
)
for
question
in
WORDS
:
setattr
(
self
,
str
(
question
),
None
)
super
().
__init__
(
registration
)
...
...
@@ -127,9 +129,9 @@ class WEISurvey2023(WEISurvey):
@transaction.atomic
def
form_valid
(
self
,
form
):
w
or
d
=
form
.
cleaned_data
[
"
word
"
]
self
.
information
.
step
+=
1
setattr
(
self
.
information
,
"
word
"
+
str
(
self
.
information
.
step
),
word
)
f
or
question
in
WORDS
:
answer
=
form
.
cleaned_data
[
question
]
setattr
(
self
.
information
,
question
,
answer
)
self
.
save
()
@classmethod
...
...
@@ -140,7 +142,10 @@ class WEISurvey2023(WEISurvey):
"""
The survey is complete once the bus is chosen.
"""
return
self
.
information
.
step
==
20
for
question
in
WORDS
:
if
not
getattr
(
self
.
information
,
question
):
return
False
return
True
@classmethod
@lru_cache
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment