Category Weighting when weights don't add up to 100
---------------------------------------------------

We'll test that the Category Weights view doesn't need the weights to
add up to 100 anymore.

Log in as manager:

    >>> manager = browsers.manager
    >>> manager.ui.login('manager', 'schooltool')

Now, set up a school year (2005-2006) with a single term (Year):

    >>> manager.ui.schoolyear.add('2005-2006', '2005-09-01', '2006-07-15')
    >>> manager.ui.term.add('2005-2006', 'Year', '2005-09-01', '2006-07-15')

Set up a course:

    >>> manager.ui.course.add('2005-2006', 'Physics I')

Set up persons:

    >>> manager.ui.person.add('Paul', 'Carduner', 'paul', 'pwd')
    >>> manager.ui.person.add('Tom', 'Hoffman', 'tom', 'pwd')
    >>> manager.ui.person.add('Claudia', 'Richter', 'claudia', 'pwd')
    >>> manager.ui.person.add('Stephan', 'Richter', 'stephan', 'pwd')

Set up a section with instructor and students:

    >>> manager.ui.section.add('2005-2006', 'Year', 'Physics I')
    >>> manager.ui.section.instructors.add('2005-2006', 'Year', 'Physics I (1)',
    ...                                    ['stephan'])
    >>> manager.ui.section.students.add('2005-2006', 'Year', 'Physics I (1)',
    ...                                 ['tom', 'claudia', 'paul'])

Log in as teacher and go to his gradebook:

    >>> stephan = browsers.stephan
    >>> stephan.ui.login('stephan', 'pwd')
    >>> stephan.query.link('Gradebook').click()

Add some activities to the default worksheet:

    >>> stephan.query.link('Activity').click()
    >>> stephan.query.id('form-widgets-title').ui.set_value('HW 1')
    >>> stephan.query.id('form-widgets-category').ui.set_value('Homework')
    >>> stephan.query.id('form-widgets-max').clear()
    >>> stephan.query.id('form-widgets-max').ui.set_value('50')
    >>> stephan.query.id('form-buttons-add').click()

    >>> stephan.query.link('Activity').click()
    >>> stephan.query.id('form-widgets-title').ui.set_value('Quiz 1')
    >>> stephan.query.id('form-widgets-category').ui.set_value('Exam')
    >>> stephan.query.id('form-buttons-add').click()

    >>> stephan.query.link('Activity').click()
    >>> stephan.query.id('form-widgets-title').ui.set_value('HW 2')
    >>> stephan.query.id('form-widgets-category').ui.set_value('Homework')
    >>> stephan.query.id('form-widgets-max').clear()
    >>> stephan.query.id('form-widgets-max').ui.set_value('50')
    >>> stephan.query.id('form-buttons-add').click()

    >>> stephan.query.link('Activity').click()
    >>> stephan.query.id('form-widgets-title').ui.set_value('Quiz 2')
    >>> stephan.query.id('form-widgets-category').ui.set_value('Exam')
    >>> stephan.query.id('form-buttons-add').click()

Add grades for the first three activities for Paul:

    >>> stephan.ui.gradebook.worksheet.score('Carduner, Paul', 'HW1', '40')
    >>> stephan.ui.gradebook.worksheet.score('Carduner, Paul', 'Quiz1', '90')
    >>> stephan.ui.gradebook.worksheet.score('Carduner, Paul', 'HW2', '45')

Add grades for the first three activities for Tom:

    >>> stephan.ui.gradebook.worksheet.score('Hoffman, Tom', 'HW1', '45')
    >>> stephan.ui.gradebook.worksheet.score('Hoffman, Tom', 'Quiz1', '80')
    >>> stephan.ui.gradebook.worksheet.score('Hoffman, Tom', 'HW2', '50')

Add grades for the first three activities for Claudia:

    >>> stephan.ui.gradebook.worksheet.score('Richter, Claudia', 'HW1', '50')
    >>> stephan.ui.gradebook.worksheet.score('Richter, Claudia', 'Quiz1', '95')
    >>> stephan.ui.gradebook.worksheet.score('Richter, Claudia', 'HW2', '50')

    >>> stephan.query.name('UPDATE_SUBMIT').click()

By default the Average column is calculated normally:

    >>> stephan.ui.gradebook.worksheet.pprint()
    +----------+
    | *Sheet1* |
    +----------+
    +------------------+-----+-------+-----+-------+-------+-------+
    | Name             | HW1 | Quiz1 | HW2 | Quiz2 | Total | Ave.  |
    |                  | 50  | 100   | 50  | 100   |       |       |
    +------------------+-----+-------+-----+-------+-------+-------+
    | Carduner, Paul   | 40  | 90    | 45  |       | 175.0 | 87.5% |
    | Hoffman, Tom     | 45  | 80    | 50  |       | 175.0 | 87.5% |
    | Richter, Claudia | 50  | 95    | 50  |       | 195.0 | 97.5% |
    +------------------+-----+-------+-----+-------+-------+-------+

Let's create some category weights for the current worksheet. We'll
fill in valid values for Assignment, Homework and Exam, even though
they don't add up to 100, hitting 'Submit' will succeed and return us
to the gradebook.  There we will note the effect of the weighting in
the Average column.

    >>> stephan.query.link('Category Weights').click()
    >>> stephan.query.id('assignment').clear()
    >>> stephan.query.id('assignment').ui.set_value('10')
    >>> stephan.query.id('exam').clear()
    >>> stephan.query.id('exam').ui.set_value('25')
    >>> stephan.query.id('homework').clear()
    >>> stephan.query.id('homework').ui.set_value('15')
    >>> stephan.query.name('UPDATE_SUBMIT').click()
    >>> stephan.ui.gradebook.worksheet.pprint()
    +----------+
    | *Sheet1* |
    +----------+
    +------------------+-----+-------+-----+-------+-------+-------+
    | Name             | HW1 | Quiz1 | HW2 | Quiz2 | Total | Ave.  |
    |                  | 50  | 100   | 50  | 100   |       |       |
    +------------------+-----+-------+-----+-------+-------+-------+
    | Carduner, Paul   | 40  | 90    | 45  |       | 175.0 | 88.1% |
    | Hoffman, Tom     | 45  | 80    | 50  |       | 175.0 | 85.6% |
    | Richter, Claudia | 50  | 95    | 50  |       | 195.0 | 96.9% |
    +------------------+-----+-------+-----+-------+-------+-------+

Let's add a new Assignment activity:

    >>> stephan.query.link('Activity').click()
    >>> stephan.query.id('form-widgets-title').ui.set_value('Experiment')
    >>> stephan.query.id('form-widgets-category').ui.set_value('Assignment')
    >>> stephan.query.id('form-widgets-max').clear()
    >>> stephan.query.id('form-widgets-max').ui.set_value('10')
    >>> stephan.query.id('form-buttons-add').click()

Let's grade the new assignment for Paul and Tom:

    >>> stephan.ui.gradebook.worksheet.score('Carduner, Paul', 'Exper', '9')
    >>> stephan.ui.gradebook.worksheet.score('Hoffman, Tom', 'Exper', '7')
    >>> stephan.query.name('UPDATE_SUBMIT').click()

Note how the Average changed for Paul and Tom, but not for Claudia:

    >>> stephan.ui.gradebook.worksheet.pprint()
    +----------+
    | *Sheet1* |
    +----------+
    +------------------+-----+-------+-----+-------+-------+-------+-------+
    | Name             | HW1 | Quiz1 | HW2 | Quiz2 | Exper | Total | Ave.  |
    |                  | 50  | 100   | 50  | 100   | 10    |       |       |
    +------------------+-----+-------+-----+-------+-------+-------+-------+
    | Carduner, Paul   | 40  | 90    | 45  |       | 9     | 184.0 | 88.5% |
    | Hoffman, Tom     | 45  | 80    | 50  |       | 7     | 182.0 | 82.5% |
    | Richter, Claudia | 50  | 95    | 50  |       |       | 195.0 | 96.9% |
    +------------------+-----+-------+-----+-------+-------+-------+-------+

Now, let's only give Homeworks some weight:

    >>> stephan.query.link('Category Weights').click()
    >>> stephan.query.id('assignment').clear()
    >>> stephan.query.id('exam').clear()
    >>> stephan.query.id('homework').clear()
    >>> stephan.query.id('homework').ui.set_value('1')
    >>> stephan.query.name('UPDATE_SUBMIT').click()

The Averages have changed:

    >>> stephan.ui.gradebook.worksheet.pprint()
    +----------+
    | *Sheet1* |
    +----------+
    +------------------+-----+-------+-----+-------+-------+-------+--------+
    | Name             | HW1 | Quiz1 | HW2 | Quiz2 | Exper | Total | Ave.   |
    |                  | 50  | 100   | 50  | 100   | 10    |       |        |
    +------------------+-----+-------+-----+-------+-------+-------+--------+
    | Carduner, Paul   | 40  | 90    | 45  |       | 9     | 184.0 | 85.0%  |
    | Hoffman, Tom     | 45  | 80    | 50  |       | 7     | 182.0 | 95.0%  |
    | Richter, Claudia | 50  | 95    | 50  |       |       | 195.0 | 100.0% |
    +------------------+-----+-------+-----+-------+-------+-------+--------+

Let's test that explicit zeros are saved:

    >>> stephan.query.link('Category Weights').click()
    >>> stephan.query.id('assignment').clear()
    >>> stephan.query.id('assignment').ui.set_value('0.0')
    >>> stephan.query.id('essay').clear()
    >>> stephan.query.id('essay').ui.set_value('0.0')
    >>> stephan.query.id('exam').clear()
    >>> stephan.query.id('lab').clear()
    >>> stephan.query.id('lab').ui.set_value('0.0')
    >>> stephan.query.id('project').clear()
    >>> stephan.query.id('project').ui.set_value('0.0')
    >>> stephan.query.name('UPDATE_SUBMIT').click()

Since all these weights are zero, they shouldn't affect the averages:

    >>> stephan.ui.gradebook.worksheet.pprint()
    +----------+
    | *Sheet1* |
    +----------+
    +------------------+-----+-------+-----+-------+-------+-------+--------+
    | Name             | HW1 | Quiz1 | HW2 | Quiz2 | Exper | Total | Ave.   |
    |                  | 50  | 100   | 50  | 100   | 10    |       |        |
    +------------------+-----+-------+-----+-------+-------+-------+--------+
    | Carduner, Paul   | 40  | 90    | 45  |       | 9     | 184.0 | 85.0%  |
    | Hoffman, Tom     | 45  | 80    | 50  |       | 7     | 182.0 | 95.0%  |
    | Richter, Claudia | 50  | 95    | 50  |       |       | 195.0 | 100.0% |
    +------------------+-----+-------+-----+-------+-------+-------+--------+
