jazzido/crowdata — pull request #3 by gusajz (2013-07-29 18:02:18+00:00)
Title: Add validity logic

It adds logic to manage validity per field.

Important methods:

Document.validated(): returns True if the document has at least the document set's threshold coincidental entries for each DocumentSetFormField. That way, if, for example, if threshold=3, and a field receives three different answers for the same field, it won't be considered validated, until it has three matching answers.

Document.validity_rate(): a 0 to 1 rate which shows how much controversial (or difficult to read maybe) was the document, even if it is already considered validated. It is implemented as the avarage of the ratio of each field (defined as the number of matching responses / total responses).

Document.get_answer(): takes and entry key (its slug) and return a tuple with: the most coincidental value, how many matching answers it has and its validity rate (defined as the number of matching responses / total responses).

DocumentSet.get_pending_documents(): returns a django.db.models.query.QuerySet, giving the document set's documents that were no already validated. Note that since it is a QuerySet it is possible to filter them later without an extra query.

Some methods should be optimized in the future.