liquid_feedback_core
changeset 376:4a18576a359f
More verbose logging in lf_update_suggestion_order.c
author | jbe |
---|---|
date | Mon Mar 18 09:09:29 2013 +0100 (2013-03-18) |
parents | 3f7a89ad996d |
children | f65814f4d3fc |
files | lf_update_suggestion_order.c |
line diff
1.1 --- a/lf_update_suggestion_order.c Sun Mar 17 20:35:42 2013 +0100 1.2 +++ b/lf_update_suggestion_order.c Mon Mar 18 09:09:29 2013 +0100 1.3 @@ -65,6 +65,7 @@ 1.4 candidate = candidates + (candidate_count++); 1.5 candidate->key = *candidate_key; 1.6 candidate->seat = 0; 1.7 + if (logging) printf("Candidate #%i is suggestion #%s.\n", candidate_count, candidate->key); 1.8 } 1.9 } 1.10 1.11 @@ -105,6 +106,7 @@ 1.12 remaining = candidate_count - round_number; 1.13 // repeat following loop, as long as there is more than one remaining candidate: 1.14 while (remaining > 1) { 1.15 + if (logging) printf("There are %i remaining candidates.\n", remaining); 1.16 double scale; // factor to be later multiplied with score_per_step: 1.17 // reset score_per_step for all candidates: 1.18 for (i=0; i<candidate_count; i++) { 1.19 @@ -146,6 +148,9 @@ 1.20 } 1.21 // add scale*score_per_step to each candidates score: 1.22 for (i=0; i<candidate_count; i++) { 1.23 + int log_candidate = 0; 1.24 + if (logging && candidates[i].score < 1.0 && !candidates[i].seat) log_candidate = 1; 1.25 + if (log_candidate) printf("Score for suggestion #%s = %.4f+%.4f*%.4f=", candidates[i].key, candidates[i].score, scale, candidates[i].score_per_step); 1.26 if (candidates[i].score_per_step > 0.0) { 1.27 double max_scale; 1.28 max_scale = (1.0-candidates[i].score) / candidates[i].score_per_step; 1.29 @@ -157,8 +162,11 @@ 1.30 candidates[i].score += scale * candidates[i].score_per_step; 1.31 if (candidates[i].score >= 1.0) remaining--; 1.32 } 1.33 - // when there is only one candidate remaining, then break inner (and thus outer) loop: 1.34 - if (remaining <= 1) break; 1.35 + } 1.36 + if (log_candidate) printf("%.4f.\n", candidates[i].score); 1.37 + // when there is only one candidate remaining, then break inner (and thus outer) loop: 1.38 + if (remaining <= 1) { 1.39 + break; 1.40 } 1.41 } 1.42 } 1.43 @@ -293,8 +301,6 @@ 1.44 if (old_member_id && strcmp(old_member_id, member_id)) ballot_count++; 1.45 old_member_id = member_id; 1.46 } 1.47 - // print candidate count: 1.48 - if (logging) printf("Candidate count: %i\n", candidate_count); 1.49 // allocate memory for candidates[] array: 1.50 candidates = malloc(candidate_count * sizeof(struct candidate)); 1.51 if (!candidates) { 1.52 @@ -306,8 +312,6 @@ 1.53 twalk(candidate_tree, (void *)register_candidate); 1.54 // free memory of tree structure (tdestroy() is not available on all platforms): 1.55 while (candidate_tree) tdelete(*(void **)candidate_tree, &candidate_tree, (void *)compare_id); 1.56 - // print ballot count: 1.57 - if (logging) printf("Ballot count: %i\n", ballot_count); 1.58 // allocate memory for ballots[] array: 1.59 ballots = calloc(ballot_count, sizeof(struct ballot)); 1.60 if (!ballots) { 1.61 @@ -374,13 +378,31 @@ 1.62 ballot->sections[preference].candidates[candidates_in_sections[preference]++] = candidate_by_key(suggestion_id); 1.63 old_member_id = member_id; 1.64 } 1.65 + // print ballots, if logging is enabled: 1.66 + if (logging) { 1.67 + for (i=0; i<ballot_count; i++) { 1.68 + int j; 1.69 + printf("Ballot #%i: ", i+1); 1.70 + for (j=0; j<4; j++) { 1.71 + int k; 1.72 + if (j) printf(", "); 1.73 + printf("preference %i (", j+1); 1.74 + for (k=0; k<ballots[i].sections[j].count; k++) { 1.75 + if (k) printf(","); 1.76 + printf("s#%s", ballots[i].sections[j].candidates[k]->key); 1.77 + } 1.78 + printf(")"); 1.79 + } 1.80 + printf(".\n"); 1.81 + } 1.82 + } 1.83 } 1.84 1.85 // calculate ranks based on constructed data structures: 1.86 for (i=0; i<candidate_count; i++) { 1.87 struct candidate *candidate = loser(i, ballots, ballot_count); 1.88 candidate->seat = candidate_count - i; 1.89 - if (logging) printf("Assigning rank #%i to suggestion #%s.\n", candidate_count - i, candidate->key); 1.90 + if (logging) printf("Assigning rank #%i to suggestion #%s.\n", candidate_count-i, candidate->key); 1.91 } 1.92 1.93 // free ballots[] array: 1.94 @@ -491,7 +513,7 @@ 1.95 PGresult *res2; 1.96 initiative_id = PQgetvalue(res, i, 0); 1.97 final = (PQgetvalue(res, i, 1)[0] == 't') ? 1 : 0; 1.98 - if (logging) printf("Processing initiative_id: %s\n", initiative_id); 1.99 + if (logging) printf("Processing initiative #%s:\n", initiative_id); 1.100 escaped_initiative_id = escapeLiteral(db, initiative_id, strlen(initiative_id)); 1.101 if (!escaped_initiative_id) { 1.102 fprintf(stderr, "Could not escape literal in memory.\n");