Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nk20
Manage
Activity
Members
Labels
Plan
Issues
32
Issue boards
Milestones
Wiki
Code
Merge requests
6
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
dbc7b344
Verified
Commit
dbc7b344
authored
3 years ago
by
ynerant
Browse files
Options
Downloads
Patches
Plain Diff
[WEI] Add script to import bus scores
Signed-off-by:
Yohann D'ANELLO
<
ynerant@crans.org
>
parent
f25eb1d2
No related branches found
No related tags found
Loading
Pipeline
#9039
failed with stages
in 14 minutes and 22 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/wei/management/commands/import_scores.py
+50
-0
50 additions, 0 deletions
apps/wei/management/commands/import_scores.py
with
50 additions
and
0 deletions
apps/wei/management/commands/import_scores.py
0 → 100644
+
50
−
0
View file @
dbc7b344
# Copyright (C) 2018-2021 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
import
argparse
import
sys
from
django.core.management
import
BaseCommand
from
django.db
import
transaction
from
...forms
import
CurrentSurvey
from
...forms.surveys.wei2021
import
WORDS
# WARNING: this is specific to 2021
from
...models
import
Bus
class
Command
(
BaseCommand
):
"""
This script is used to load scores for buses from a CSV file.
"""
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'
file
'
,
nargs
=
'
?
'
,
type
=
argparse
.
FileType
(
'
r
'
),
default
=
sys
.
stdin
,
help
=
'
Input CSV file
'
)
@transaction.atomic
def
handle
(
self
,
*
args
,
**
options
):
file
=
options
[
'
file
'
]
head
=
file
.
readline
().
replace
(
'
\n
'
,
''
)
bus_names
=
head
.
split
(
'
;
'
)
bus_names
=
[
name
for
name
in
bus_names
if
name
]
buses
=
[]
for
name
in
bus_names
:
qs
=
Bus
.
objects
.
filter
(
name__iexact
=
name
)
if
not
qs
.
exists
():
raise
ValueError
(
f
"
Bus
'
{
name
}
'
does not exist
"
)
buses
.
append
(
qs
.
get
())
informations
=
{
bus
:
CurrentSurvey
.
get_algorithm_class
().
get_bus_information
(
bus
)
for
bus
in
buses
}
for
line
in
file
:
elem
=
line
.
split
(
'
;
'
)
word
=
elem
[
0
]
if
word
not
in
WORDS
:
raise
ValueError
(
f
"
Word
{
word
}
is not used
"
)
for
i
,
bus
in
enumerate
(
buses
):
info
=
informations
[
bus
]
info
.
scores
[
word
]
=
float
(
elem
[
i
+
1
].
replace
(
'
,
'
,
'
.
'
))
for
bus
,
info
in
informations
.
items
():
info
.
save
()
bus
.
save
()
if
options
[
'
verbosity
'
]
>
0
:
self
.
stdout
.
write
(
f
"
Bus
{
bus
.
name
}
saved!
"
)
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