This file is indexed.

/usr/share/pyshared/schooltool/gradebook/README.txt is in python-schooltool.gradebook 2.1.0-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
=============
The Gradebook
=============

Traditionally, the gradebook is a simple spreadsheet where the columns are the
activities to be graded and each row is a student. Since SchoolTool is an
object-oriented application, we have the unique oppurtunity to implement it a
little bit different and to provide some unique features.

First we'll set up the site and initialize the gradebook related data.

    >>> from schooltool.testing import setup
    >>> school = setup.setUpSchoolToolSite()
    >>> from schooltool.gradebook.gradebook_init import GradebookInit
    >>> plugin = GradebookInit(school)
    >>> plugin()

We note that there is a special gradebook root object attached to the
application root.  We find it using the supplied adapter.

    >>> from zope.component import provideAdapter
    >>> from schooltool.app.interfaces import ISchoolToolApplication
    >>> from schooltool.gradebook.interfaces import IGradebookRoot
    >>> from schooltool.gradebook.interfaces import IGradebookTemplates
    >>> from schooltool.gradebook.interfaces import IGradebookDeployed
    >>> from schooltool.gradebook.interfaces import IGradebookLayouts
    >>> from schooltool.gradebook.gradebook_init import getGradebookRoot
    >>> provideAdapter(getGradebookRoot,
    ...                adapts=[ISchoolToolApplication],
    ...                provides=IGradebookRoot)
    >>> gradebook_root = IGradebookRoot(ISchoolToolApplication(None))
    >>> from zope.interface.verify import verifyObject
    >>> verifyObject(IGradebookRoot, gradebook_root)
    True
    >>> verifyObject(IGradebookTemplates, gradebook_root.templates)
    True
    >>> verifyObject(IGradebookDeployed, gradebook_root.deployed)
    True
    >>> verifyObject(IGradebookLayouts, gradebook_root.layouts)
    True

We also need adapters to get from the gradebook root to its attributes for
use during travesal adaptation.  These adapters must locate themselves in the
gradebook root object so that traversal works.

    >>> from schooltool.gradebook.gradebook_init import getGradebookTemplates
    >>> provideAdapter(getGradebookTemplates,
    ...                adapts=[IGradebookRoot],
    ...                provides=IGradebookTemplates)
    >>> templates = IGradebookTemplates(gradebook_root)
    >>> verifyObject(IGradebookTemplates, templates)
    True
    >>> templates is gradebook_root.templates
    True


Categories
----------

When the SchoolTool instance is initially setup, it is part of the
administations job to setup activity categories. Activity categories can be
"homework", "paper", "test", "final exam", etc.  By default, some categories
are already available in the vocabulary.

The categories are stored in a container in school tool application.
As soon as the SchoolTool application is registered as a site, the
vocabulary can be easily initiated.

    >>> from schooltool.gradebook import category
    >>> from schooltool.gradebook.interfaces import ICategoryContainer

    >>> categories = ICategoryContainer(ISchoolToolApplication(None))

There is also a vocabulary for the brower views:

    >>> vocabulary = category.CategoriesVocabulary(categories)

    >>> sorted([term.title for term in vocabulary])
    [u'Assignment', u'Essay', u'Exam', u'Homework', u'Journal', u'Lab',
     u'Presentation', u'Project']

We can add,

    >>> categories['quiz'] = u'Quiz'
    >>> sorted([term.title for term in vocabulary])
    [u'Assignment', u'Essay', u'Exam', u'Homework', u'Journal', u'Lab',
     u'Presentation', u'Project', u'Quiz']

delete,

    >>> del categories['quiz']
    >>> sorted([term.title for term in vocabulary])
    [u'Assignment', u'Essay', u'Exam', u'Homework', u'Journal', u'Lab',
     u'Presentation', u'Project']

and query values:

    >>> categories.get('assignment')
    u'Assignment'

    >>> print categories['faux']
    Traceback (most recent call last):
    ...
    KeyError: 'faux'

    >>> categories.get('faux', default=u'default')
    u'default'

    >>> sorted(categories.keys())
    [u'assignment', u'essay', u'exam', u'homework', u'journal', u'lab',
     u'presentation', u'project']


Activities
----------

Activities are items that can be graded.  In other software they are also
referred to as assignments or grading items.  Activities can be defined for
courses and sections.  They are organized into worksheets to allow teachers
to keep activities separate from quarter to quarter.  Worksheets could be used
to keep assignments organized by type.  It's up to the teacher.

Let's create some people, a course and a section:

    >>> from schooltool.person import person
    >>> from schooltool.course import course, section
    >>> tom = person.Person('tom', 'Tom Hoffman')
    >>> paul = person.Person('paul', 'Paul Cardune')
    >>> claudia = person.Person('claudia', 'Claudia Richter')
    >>> stephan = person.Person('stephan', 'Stephan Richter')
    >>> alg1 = course.Course('Alg1', 'Algebra 1')
    >>> sectionA = section.Section('Alg1-A')
    >>> alg1.sections.add(sectionA)

We add some students and a teacher to the class,

    >>> sectionA.members.add(tom)
    >>> sectionA.members.add(paul)
    >>> sectionA.members.add(claudia)
    >>> sectionA.instructors.add(stephan)

We will deal with the most common case first.  Here, Stephan teaches a
two week course in algebra, and he would like to have two worksheets,
one for each week.  At first there will be no worksheets in the section.

    >>> from schooltool.gradebook import interfaces
    >>> sectionA_act = interfaces.IActivities(sectionA)
    >>> sectionA_act
    Activities(u'Activities')
    >>> list(sectionA_act.items())
    []

We'll create two worksheets, while adding them to the section activities.

    >>> from schooltool.gradebook import activity
    >>> sectionA_act['week1'] = activity.Worksheet(u'Week 1')
    >>> week1 = sectionA_act['week1']
    >>> sectionA_act['week2'] = activity.Worksheet(u'Week 2')
    >>> week2 = sectionA_act['week2']
    >>> list(sectionA_act.items())
    [('week1', Worksheet(u'Week 1')), ('week2', Worksheet(u'Week 2'))]

Both worksheets start out empty.

    >>> list(week1.items())
    []
    >>> list(week2.items())
    []

We will add three activities to each worksheet, a homework assignment, a project
with a letter-grade score system, and a test.

    >>> from schooltool.requirement import scoresystem
    >>> week1['homework'] = activity.Activity(
    ...     title=u'HW 1',
    ...     description=u'Week 1 Homework',
    ...     category=u'assignment',
    ...     scoresystem=scoresystem.RangedValuesScoreSystem(max=10))
    >>> hw1 = week1['homework']
    >>> week1['project'] = activity.Activity(
    ...     title=u'Project 1',
    ...     description=u'Week 1 Project',
    ...     category=u'project',
    ...     scoresystem=scoresystem.AmericanLetterScoreSystem)
    >>> project1 = week1['project']
    >>> week1['quiz'] = activity.Activity(
    ...     title=u'Quiz',
    ...     description=u'End of Week Quiz',
    ...     category=u'exam',
    ...     scoresystem=scoresystem.PercentScoreSystem)
    >>> quiz = week1['quiz']
    >>> week2['homework'] = activity.Activity(
    ...     title=u'HW 2',
    ...     description=u'Week 2 Homework',
    ...     category=u'assignment',
    ...     scoresystem=scoresystem.RangedValuesScoreSystem(max=15))
    >>> hw2 = week2['homework']
    >>> week2['project'] = activity.Activity(
    ...     title=u'Project 2',
    ...     description=u'Week 2 Project',
    ...     category=u'project',
    ...     scoresystem=scoresystem.AmericanLetterScoreSystem)
    >>> project2 = week2['project']
    >>> week2['final'] = activity.Activity(
    ...     title=u'Final',
    ...     description=u'Final Exam',
    ...     category=u'exam',
    ...     scoresystem=scoresystem.PercentScoreSystem)
    >>> final = week2['final']

Besides the title and description, one must also specify the category and the
score system. The category is used to group similar activities together and
later facilitate in computing the final grade. The score system is an object
describing the type of score that can be associated with the activity.

Now we note that both worksheets have the activities in them.

    >>> list(week1.items())
    [('homework', <Activity u'HW 1'>), ('project', <Activity u'Project 1'>),
     ('quiz', <Activity u'Quiz'>)]
    >>> list(week2.items())
    [('homework', <Activity u'HW 2'>), ('project', <Activity u'Project 2'>),
     ('final', <Activity u'Final'>)]


Evaluations
-----------

Now that all of our activities have been defined, we can finally enter some
grades using the gradebook.

    >>> from schooltool.gradebook import interfaces
    >>> gradebook = interfaces.IGradebook(week1)

Already the gradebook has worksheets which it got from the section.

    >>> gradebook.worksheets
    [Worksheet(u'Week 1'), Worksheet(u'Week 2')]

Those worksheets have, int turn, the activities we added to them.

    >>> gradebook.getWorksheetActivities(week1)
    [<Activity u'HW 1'>, <Activity u'Project 1'>, <Activity u'Quiz'>]
    >>> gradebook.getWorksheetActivities(week2)
    [<Activity u'HW 2'>, <Activity u'Project 2'>, <Activity u'Final'>]

The current worksheet for the teacher will automatically be set to the first
one.

    >>> gradebook.getCurrentWorksheet(stephan)
    Worksheet(u'Week 1')
    >>> gradebook.getCurrentActivities(stephan)
    [<Activity u'HW 1'>, <Activity u'Project 1'>, <Activity u'Quiz'>]

We can change it to be the second worksheet.

    >>> gradebook.setCurrentWorksheet(stephan, week2)
    >>> gradebook.getCurrentWorksheet(stephan)
    Worksheet(u'Week 2')
    >>> gradebook.getCurrentActivities(stephan)
    [<Activity u'HW 2'>, <Activity u'Project 2'>, <Activity u'Final'>]

Let's enter some grades:

    >>> gradebook.evaluate(student=tom, activity=hw1, score=8)
    >>> gradebook.evaluate(student=paul, activity=hw1, score=10)
    >>> gradebook.evaluate(student=claudia, activity=hw1, score=7)

    >>> gradebook.evaluate(student=tom, activity=quiz, score=90)
    >>> gradebook.evaluate(student=paul, activity=quiz, score=80)
    >>> gradebook.evaluate(student=claudia, activity=quiz, score=99)

    >>> gradebook.evaluate(student=tom, activity=project1, score='B')
    >>> gradebook.evaluate(student=paul, activity=project1, score='C')
    >>> gradebook.evaluate(student=claudia, activity=project1, score='C')

    >>> gradebook = interfaces.IGradebook(week2)
    >>> gradebook.evaluate(student=tom, activity=hw2, score=10)
    >>> gradebook.evaluate(student=paul, activity=hw2, score=12)
    >>> gradebook.evaluate(student=claudia, activity=hw2, score=14)

    >>> gradebook.evaluate(student=tom, activity=final, score=85)
    >>> gradebook.evaluate(student=paul, activity=final, score=99)
    >>> gradebook.evaluate(student=claudia, activity=final, score=90)

    >>> gradebook.evaluate(student=tom, activity=project2, score='D')
    >>> gradebook.evaluate(student=paul, activity=project2, score='A')
    >>> gradebook.evaluate(student=claudia, activity=project2, score='B')

Of course there are some safety precautions:

1. You cannot add a grade for someone who is not in the section:

    >>> marius = person.Person('marius', 'Marius Gedminas')
    >>> gradebook.evaluate(student=marius, activity=final, score=99)
    Traceback (most recent call last):
    ...
    ValueError: Student 'marius' is not in this section.

2. You cannot add a grade for an activity that does not belong to the section:

    >>> hw3 = activity.Activity(
    ...     title=u'HW 3',
    ...     category=u'assignment',
    ...     scoresystem=scoresystem.RangedValuesScoreSystem(max=10))

    >>> gradebook.evaluate(student=claudia, activity=hw3, score=8)
    Traceback (most recent call last):
    ...
    ValueError: u'HW 3' is not part of this section.

3. You cannot add a grade that is not a valid value of the score system:

    >>> gradebook.evaluate(student=claudia, activity=hw2, score=-8)
    Traceback (most recent call last):
    ...
    ValueError: -8 is not a valid score.

4. In the case of score systems providing IRangedValuesScoreSystem, a score
   greater than the max is allowed in order to give the teacher the chance
   to award extra credit.

    >>> gradebook.evaluate(student=claudia, activity=hw2, score=16)
    >>> gradebook.evaluate(student=claudia, activity=hw2, score=14)

There are a couple more management functions that can be used to maintain the
evaluations. For example, you can ask whether an evaluation for a particular
student and activity has been made:

    >>> gradebook = interfaces.IGradebook(week1)
    >>> gradebook.hasEvaluation(student=tom, activity=hw1)
    True

You can then also delete evaluations:

    >>> gradebook.removeEvaluation(student=tom, activity=hw1)
    >>> gradebook.hasEvaluation(student=tom, activity=hw1)
    False


Working with Worksheets
-----------------------

Now that we have created worksheets for our gradebook, added activities to
them, and evaulated the activities, it's time to look at the methods that
will facilitate the gradebook view in getting the info it needs.  We will
assume the currently viewed worksheet is the one for week 1 and get the
activities and evaluations for it.

    >>> gradebook.setCurrentWorksheet(stephan, week1)
    >>> sorted(gradebook.getCurrentActivities(stephan),
    ...        key=lambda x: x.title)
    [<Activity u'HW 1'>, <Activity u'Project 1'>, <Activity u'Quiz'>]

    >>> sorted(gradebook.getCurrentEvaluationsForStudent(stephan, paul),
    ...        key=lambda x: x[0].title)
    [(<Activity u'HW 1'>, <Evaluation for <Activity u'HW 1'>, value=10>),
     (<Activity u'Project 1'>, <Evaluation for <Activity u'Project 1'>,
      value='C'>),
     (<Activity u'Quiz'>, <Evaluation for <Activity u'Quiz'>, value=80>)]

For a given activity, we can query the grades for all students for that
activity.  This represents a column of the worksheet

    >>> sorted(gradebook.getEvaluationsForActivity(hw1),
    ...        key=lambda x: x[0].username)
    [(<...Person ...>, <Evaluation for <Activity u'HW 1'>, value=7>),
     (<...Person ...>, <Evaluation for <Activity u'HW 1'>, value=10>)]

We can get an evaluation for a student, activity pair, which represents
a cell in the worksheet.

    >>> score = gradebook.getScore(paul, hw1)
    >>> (score.value, score.scoreSystem)
    (10, <RangedValuesScoreSystem None>)

We can get the total of points and the average in a worksheet for a
student. If both values can be determined, they are returned as
Decimal numbers. It's responsability of the caller code to format them
as needed.

    >>> '%.1f, %.3f' % gradebook.getWorksheetTotalAverage(week1, paul)
    '92.0, 80.702'


Sorting by Column
~~~~~~~~~~~~~~~~~

Another important feature of the gradebook is to be able to tell the sorting
rules for the grades table for a particular person. The method to get the
sorting key is ``getSortKey(person)``. By default the gradebook is sorted by
the student's title in A-Z:

    >>> gradebook.getSortKey(stephan)
    ('student', False)

The first element of the returned tuple is the field to sort by. "student" is
a special field. All other fields are the hash of the activity to be sorted
by. The second element specifies whether the sorting should be reversed. You
can set the key using the ``setSortKey(person, (key, reverse))`` method:

    >>> gradebook.setSortKey(stephan, ('student', True))
    >>> gradebook.getSortKey(stephan)
    ('student', True)

    >>> gradebook.setSortKey(stephan, ('-234', False))
    >>> gradebook.getSortKey(stephan)
    ('-234', False)

And that's it. The gradebook itself will not interpret the sorting key any
further. It is up to the view code to implement the rest of the sorting
feature. This is because the view code can often be much more efficient in
implement ordering.


Weighting Categories
--------------------

By default, the gradebook calculates worksheet averages by weighting each
activitiy by its possible number of points.  For example, a quiz that is
graded on a ten point scale will have on tenth the weight of an exam graded
on a hundred point scale.  However, there are cases where a teacher may want
to assign an arbitrary weight to a whole category of activities.  In other
words, all quizes averaged together could have a 40% weight, and the exams
have a 60% weight.  Therefore, we need to allow the teacher to override the
default behaviour for a given worksheet with a cotegory weighting or their
choosing.

Let's look again at our current worksheet for our gradebook.  We see that
there's a homework assignment with 10 possible points, a project with 4 possible
points, and an exam with 100.  Paul got a 10 out of 10 on the homework, a 2 out
of 4 for the project, and an 80 out of 100 on the quiz.  The default calculation
of the average would be (10 + 2 + 80) / (10 + 4 + 100) = 80.7%.

    >>> sorted(gradebook.getCurrentEvaluationsForStudent(stephan, paul),
    ...        key=lambda x: x[0].title)
    [(<Activity u'HW 1'>, <Evaluation for <Activity u'HW 1'>, value=10>),
     (<Activity u'Project 1'>, <Evaluation for <Activity u'Project 1'>,
      value='C'>),
     (<Activity u'Quiz'>, <Evaluation for <Activity u'Quiz'>, value=80>)]
    >>> '%.1f, %.3f' % gradebook.getWorksheetTotalAverage(week1, paul)
    '92.0, 80.702'

Let's create some category weights for the current worksheet.

    >>> from decimal import Decimal
    >>> sorted(week1.getCategoryWeights().items())
    []
    >>> week1.setCategoryWeight('assignment', Decimal("0.38"))
    >>> week1.setCategoryWeight('exam', Decimal("0.62"))
    >>> sorted(week1.getCategoryWeights().items())
    [('assignment', Decimal("0.38")), ('exam', Decimal("0.62"))]

We left out the project category intentionally to test handling the case
where the user creates an activity with a category that is not weighted.
We will deal with this case by ignoring the activity while calulating
the average.

Now we will see that the average for paul will change to reflect the new
calculation of ((10/10) * 0.38) + ((80/100) * 0.62) = 87.6% which rounds up
to 88%.  Once again, the total is 92 even though only 90 points will factor
into the average.

    >>> '%.1f, %.1f' % gradebook.getWorksheetTotalAverage(week1, paul)
    '92.0, 87.6'

We need to be able to ignore activities that are not scored when making our
calculation because it is not fair to punish a student for an activity that
the teacher has not yet graded.  We will test this by removing one of the
evaluations for Paul, say, the grade for HW 1.

    >>> gradebook.removeEvaluation(student=paul, activity=hw1)

Now, the calculation will be (80/100) * 100% = 80% because the other
category, assignment, is no longer represented with a score.  As above, the
project score of 2 is included in the total, but not the average.

    >>> '%.1f, %.1f' % gradebook.getWorksheetTotalAverage(week1, paul)
    '82.0, 80.0'

Let's add that evaluation back to test another edge case.

    >>> gradebook.evaluate(student=paul, activity=hw1, score=10)

We need to test handling having more than one activity of the same category,
so let's add another homework assignment and an evaluation for it.

    >>> week1['homework3'] = activity.Activity(
    ...     title=u'HW 3',
    ...     description=u'Week 1 Homework 3',
    ...     category=u'assignment',
    ...     scoresystem=scoresystem.RangedValuesScoreSystem(max=10))
    >>> hw3 = week1['homework3']
    >>> gradebook = interfaces.IGradebook(week1)
    >>> gradebook.evaluate(student=paul, activity=hw3, score=9)

Now we will see that the average for paul will change to reflect the new
calculation of (((10 + 9)/(10 + 10)) * 0.38) + ((80/100) * 0.62) = 85.7%.
Once again, the total is 101 even though only 99 points will factor
into the average.

    >>> '%.1f, %.1f' % gradebook.getWorksheetTotalAverage(week1, paul)
    '101.0, 85.7'


External Activities
-------------------

External Activities allow other schooltool modules to provide grades
that can be used in worksheets.

This will make possible, for example, to integrate CanDo skilldrivers
(or assignments) grades into the schooltool gradebook.

In order to integrate with the schooltool gradebook, the external
module must register a named adapter that adapts a section and
provides the IExternalActivities interface:

    >>> from zope.component import getAdapters, getAdapter
    >>> sorted(list(getAdapters((sectionA,),
    ...                         interfaces.IExternalActivities)))
    [(u'someproduct', <ExternalActivities...>),
     (u'thirdparty', <ExternalActivities...>)]

These named adapters must have a ``source`` attribute that should
match under wich the adapter was registered in Zope::

    >>> someproduct = getAdapter(sectionA,
    ...                          interfaces.IExternalActivities,
    ...                          name=u"someproduct")
    >>> someproduct.source
    'someproduct'

They also have a ``title`` attribute used for presentation::

    >>> someproduct.title
    u'Some Product'

They also have a ``getExternalActivities()`` method that returns a
list of IExternalActivity objects that the adapter provides:

    >>> someproduct.getExternalActivities()
    [<ExternalActivity u'Some1'>]
    >>> thirdparty = getAdapter(sectionA,
    ...                         interfaces.IExternalActivities,
    ...                         name=u"thirdparty")
    >>> thirdparty.getExternalActivities()
    [<ExternalActivity u'Third1'>, <ExternalActivity u'Third2'>,
     <ExternalActivity u'Third3'>]

ExternalActivity objects have an external_activity_id attribute:

    >>> someproduct.getExternalActivities()[0].external_activity_id
    u'some1'

This allow the adapters to look up and return an external activity,
using its ``getExternalActivity(activity_id)`` method:

    >>> someproduct.getExternalActivity("some1")
    <ExternalActivity u'Some1'>

If the adapter cannot find an external activity for an id, None should
be returned:

    >>> someproduct.getExternalActivity("non_existent") is None
    True

An ExternalActivity object also has a ``title`` and a ``description``
attribute that are used for presentation:

    >>> someproduct.getExternalActivity("some1").title
    u'Some1'
    >>> someproduct.getExternalActivity("some1").description
    u'Some1 description'

It provides a ``getGrade(student)`` method that returns a percentage
for the given student:

    >>> external_activity = someproduct.getExternalActivities()[0]
    >>> external_activity.getGrade(paul)
    Decimal("0.5")

If the student doesn't have a grade for that external activity, None
should be returned:

    >>> other_external_activity = thirdparty.getExternalActivities()[1]
    >>> other_external_activity.getGrade(paul) is None
    True


Linked Activities
-----------------

External activities are not persitent objects, but rather proxies for a source
of grades within a schooltool plugin like cando.  In order to present the
values of an external activity in the gradebook, we need to create a special
kind of activity called LinkedActivity that has the attributes necessary for
linking up with the external activity.  The LinkedActivity object subtypes
Activity:

    >>> some1 = someproduct.getExternalActivity("some1")
    >>> week1["external1"] = activity.LinkedActivity(
    ...     external_activity=some1,
    ...     category=u"assignment",
    ...     points=15,
    ...     label=u"Some1")
    >>> linked_activity = week1["external1"]
    >>> linked_activity
    <LinkedActivity u'Some1'>
    >>> interfaces.IActivity.providedBy(linked_activity)
    True

To be able to extract information from an external activity, a linked
activity stores the name of the source (since it can be many) and the
id of the external activity in that source. It also provides a
``getExternalActivity()`` method that returns the external activity to
which it is linked:

    >>> linked_activity.getExternalActivity()
    <ExternalActivity u'Some1'>

If the method cannot find a match, it returns None:

    >>> week1["non_existent"] = activity.LinkedActivity(
    ...     external_activity=some1,
    ...     category=u"assignment",
    ...     points=25,
    ...     label=u"Some1")
    >>> non_existent = week1["non_existent"]
    >>> non_existent.external_activity_id = "non_existent"
    >>> non_existent.getExternalActivity() is None
    True

Since LinkedActivity is an Activity, it provides a ``title`` and a
``description`` attribute. Both of these are set at the beginning with
the attributes from the external activity:

    >>> linked_activity.getExternalActivity().title
    u'Some1'
    >>> linked_activity.getExternalActivity().description
    u'Some1 description'
    >>> linked_activity.title
    u'Some1'
    >>> linked_activity.description
    u'Some1 description'

An integer attribute called ``points`` is used to set a custom score
system for the linked activity and it's also used to calculate the
actual worksheet grade for the linked activity:

    >>> linked_activity.points
    15
    >>> linked_activity.scoresystem
    <RangedValuesScoreSystem u'generated'>
    >>> linked_activity.scoresystem.max
    Decimal("15")

If the points attribute changes, the score system also changes:

    >>> linked_activity.points = 20
    >>> linked_activity.scoresystem.max
    Decimal("20")

Course Activities
-----------------

Course leaders can create a set of worksheets that they can later choose to
deploy to all the sections of that course for specific terms or the whole
school year.  There is an adapter that returns this set, which it locates
in the course's annotations.

    >>> alg1_act = interfaces.ICourseActivities(alg1)
    >>> alg1_act
    CourseActivities(u'Course Activities')

There is also an adapter that returns the deployed worksheets for the course,
also stored as annotations.

    >>> alg1_deployed = interfaces.ICourseDeployedWorksheets(alg1)
    >>> alg1_deployed
    CourseDeployedWorksheets(u'Deployed Worksheets')