source: trunk/scripts/round-statistics @ 1184

Revision 1110, 3.3 KB checked in by savin.tiberiu@…, 2 years ago (diff)

The long awaited moment. *drumroll*

Split ia score.

Scores are now separated from the ratings. Also the rankings macro can take detail_round and detail_task parameters to add more columns.

REVIEW URL: http://reviewboard.infoarena.ro/r/64/

  • Property svn:executable set to *
Line 
1#! /usr/bin/env php
2<?php
3/*
4 * Script for calculating statistics for contest rounds
5 * Supports rounds with multiple age groups
6 */
7require_once(dirname($argv[0]) . "/utilities.php");
8
9db_connect();
10
11log_assert(2 == $argc, "Expecting a single argument: round_id_like (example: 'algoritmiada2009-runda1-%' will match all age groups for 'algoritmiada2009-runda1')!");
12$round_like = $argv[1];
13
14// Get number of contestants who submitted at least one solution
15$query = sprintf("
16SELECT COUNT(DISTINCT(`user_id`))
17    FROM ia_job
18    WHERE round_id LIKE %s", db_quote($round_like));
19
20$result = db_fetch($query);
21$result = array_pop($result);
22
23print "Number of contestants who submitted at least one solution: " . $result . "\n";
24
25// Get number of registered users
26$query = sprintf("
27SELECT COUNT(DISTINCT(`user_id`))
28    FROM `ia_user_round`
29    WHERE `round_id` LIKE %s", db_quote($round_like));
30
31$result = db_fetch($query);
32$result = array_pop($result);
33
34print "Number of registered users: " . $result . "\n";
35
36// Get number of submitted jobs
37$query = sprintf("
38SELECT COUNT(*)
39    FROM `ia_job`
40    WHERE `round_id` LIKE %s", db_quote($round_like));
41
42$result = db_fetch($query);
43$result = array_pop($result);
44
45print "Number of submitted jobs: " . $result . "\n";
46
47// Get number of submitted jobs with positive score
48$query = sprintf("
49SELECT COUNT(*)
50    FROM `ia_job`
51    WHERE `score` > 0 AND `round_id` LIKE %s", db_quote($round_like));
52
53$result = db_fetch($query);
54$result = array_pop($result);
55
56print "Number of submitted jobs with positive score: " . $result . "\n";
57
58// Get number of contestants with positive scores
59// Counts number of distinct users that received a
60// score greater than 0 on at least one task
61$query = sprintf('
62SELECT COUNT(DISTINCT(`user_id`))
63    FROM `ia_score_user_round`
64    WHERE `score` > 0 AND
65          `round_id` LIKE %s', db_quote($round_like));
66
67$result = db_fetch($query);
68$result = array_pop($result);
69
70print "Number of users with positive scores: " . $result . "\n";
71
72// Get average score of contestants
73// Big query, first groups scores by user and task,
74// then groups by users and calculates total score for each,
75// then calculates average score for all
76$query = sprintf('
77SELECT AVG(`grouped_by_users`.`score`)
78FROM (
79    SELECT `user_id`, SUM(`grouped_by_tasks`.`score`) AS `score`
80    FROM (
81        SELECT `user_id`, `task_id`, `score`
82        FROM `ia_score_user_round_task`
83        WHERE `round_id` LIKE %s
84        GROUP BY `user_id`, `task_id`
85        ) AS `grouped_by_tasks`
86    GROUP BY `user_id`
87    ) AS `grouped_by_users`', db_quote($round_like));
88
89$result = db_fetch($query);
90$result = array_pop($result);
91
92print "Average score of contestants: " . $result . "\n";
93
94// Get average score of contestants with positive scores
95$query = sprintf('
96SELECT AVG(`grouped_by_users`.`score`)
97FROM (
98    SELECT `user_id`, SUM(`grouped_by_tasks`.`score`) AS `score`
99    FROM (
100        SELECT `user_id`, `task_id`, `score`
101        FROM `ia_score_user_round_task`
102        WHERE `round_id` LIKE %s AND
103              `score` > 0
104        GROUP BY `user_id`, `task_id`
105        ) AS `grouped_by_tasks`
106    GROUP BY `user_id`
107    ) AS `grouped_by_users`', db_quote($round_like));
108
109$result = db_fetch($query);
110$result = array_pop($result);
111
112print "Average score of contestants with strictly positive scores: " . $result . "\n";
113
114?>
Note: See TracBrowser for help on using the repository browser.