WeBWorK Main Forum

Assign users (logins in csv) to a set

Assign users (logins in csv) to a set

by Robert Mařík -
Number of replies: 4

Hello.

I have a subset of users in a csv file. The task is to assign one HW to these students. Is there any other way than select the users manually?

I have access to the database via phpmyadmin, if neessary.

Thank you for suggestions.

In reply to Robert Mařík

Re: Assign users (logins in csv) to a set

by Danny Glin -
The first thing that came to mind was to use either the section or recitation field to do this. I haven't tested this, but I believe that you can add either a section or recitation number to the students in your csv file, and then import again and have it update the records. Then you can use the Instructor Tools page to filter by that section, and assign just to those users.

I recommend testing this on non-student data first, as it's possible that importing existing users and replacing them may delete existing student progress.
In reply to Danny Glin

Re: Assign users (logins in csv) to a set

by Robert Mařík -
Thank you so much. I was also thinking about this problem and I think that another method could be to enter the page where I can assign HW by selecting students and check the checkboxes by a javascript in Firefox console and using a list of users which should be checked. Will investigate and will post the final solution in the case of success.
In reply to Robert Mařík

Re: Assign users (logins in csv) to a set

by Danny Glin -
The attached script may be of use. I used this to update the section and recitation numbers for a whole class from a csv file. It expects a csv where the first column is the user_id, the second column is the desired section number and the third column is the desired recitation.

It also depends on putting the DB username and password into .my.cnf so that you don't have to authenticate for each DB action.

This is very cobbled together, so use at your own risk.
In reply to Danny Glin

Re: Assign users (logins in csv) to a set

by Robert Mařík -
Thank you. I finally use the following:

1. From csv extract comma separated logins using something like

for i in `cat ~/Downloads/export.csv | cut -f6 -d,`; do echo $i; done | sort | paste -sd "," | sed 's/"//g'
2. On the webpage where I can add the users by checking checkboxes ( http://SERVER/webwork2/COURSE/instructor/sets2/SET_NAME/users/ ) I run the following code and enter the comma separated logins from the previous step.

str=prompt("Enter logins, comma separated"); 
logins=str.split(",");
$.each(logins,function(index,login){$('input[value='+login+']').each(function() { $(this).prop( "checked", true ); }) })

3. Save the changes


Hope this helps to someone else in future.