Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
2415680e
Commit
2415680e
authored
Mar 20, 2013
by
Diana Huang
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1677 from MITx/victor/fix-auto-cohorting
Fix randomness bug in cohort placement
parents
e0184453
d91008b7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
7 deletions
+19
-7
common/djangoapps/course_groups/cohorts.py
+19
-7
No files found.
common/djangoapps/course_groups/cohorts.py
View file @
2415680e
...
...
@@ -15,6 +15,24 @@ from .models import CourseUserGroup
log
=
logging
.
getLogger
(
__name__
)
# tl;dr: global state is bad. capa reseeds random every time a problem is loaded. Even
# if and when that's fixed, it's a good idea to have a local generator to avoid any other
# code that messes with the global random module.
_local_random
=
None
def
local_random
():
"""
Get the local random number generator. In a function so that we don't run
random.Random() at import time.
"""
# ironic, isn't it?
global
_local_random
if
_local_random
is
None
:
_local_random
=
random
.
Random
()
return
_local_random
def
is_course_cohorted
(
course_id
):
"""
Given a course id, return a boolean for whether or not the course is
...
...
@@ -129,13 +147,7 @@ def get_cohort(user, course_id):
return
None
# Put user in a random group, creating it if needed
choice
=
random
.
randrange
(
0
,
n
)
group_name
=
choices
[
choice
]
# Victor: we are seeing very strange behavior on prod, where almost all users
# end up in the same group. Log at INFO to try to figure out what's going on.
log
.
info
(
"DEBUG: adding user {0} to cohort {1}. choice={2}"
.
format
(
user
,
group_name
,
choice
))
group_name
=
local_random
()
.
choice
(
choices
)
group
,
created
=
CourseUserGroup
.
objects
.
get_or_create
(
course_id
=
course_id
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment