Ejemplo n.º 1
0
         $paragraph['done_by_me'] = true;
     }
     // если текущий пользователь - модератор, забираем разметку других пользователей
     if (!$is_book_moderator) {
         continue;
     }
     $annotators = get_paragraph_annotators($paragraph['id'], $tagset_id);
     $paragraph['all_annotations'] = array();
     foreach ($annotators as $user_id) {
         $paragraph['all_annotations'][$user_id] = array();
         $PAR =& $paragraph['all_annotations'][$user_id];
         $ne = get_ne_by_paragraph($paragraph['id'], $user_id, $tagset_id);
         $mentions = get_ne_by_paragraph($paragraph['id'], $user_id, $tagset_id, TRUE);
         $PAR['named_entities'] = isset($ne['entities']) ? $ne['entities'] : array();
         $PAR['mentions'] = isset($mentions['entities']) ? $mentions['entities'] : array();
         $PAR['user_shown_name'] = get_user_shown_name($user_id);
         $PAR['annotation_id'] = isset($ne['annot_id']) ? $ne['annot_id'] : 0;
         $PAR['ne_by_token'] = get_ne_tokens_by_paragraph($paragraph['id'], $_SESSION['user_id'], $tagset_id);
         $PAR['comments'] = get_comments_by_paragraph($paragraph['id'], $_SESSION['user_id'], $tagset_id);
     }
 }
 if ($is_book_moderator) {
     $spans = get_ne_entities_by_book($book_id, $_SESSION['user_id'], $tagset_id);
     $spans = array_unique(array_map(function ($span) {
         $tokens = '';
         foreach ($span['tokens'] as $t) {
             $tokens .= $t[1] . ' ';
         }
         return trim($tokens);
     }, $spans));
     $book['all_spans'] = $spans;
Ejemplo n.º 2
0
        alert_set('success', 'Настройки сохранены');
        header('Location:options.php');
        break;
    case 'save_team':
        save_user_team($_POST['team_id'], $_POST['new_team_name']);
        if ($_POST['team_id'] || $_POST['new_team_name']) {
            $am = new AchievementsManager((int) $_SESSION['user_id']);
            $am->emit(EventTypes::JOINED_TEAM);
        }
        alert_set('success', 'Настройки сохранены');
        header('Location:options.php');
        break;
    case 'readonly_on':
        set_readonly_on();
        header('Location:options.php');
        break;
    case 'readonly_off':
        set_readonly_off();
        header('Location:options.php');
        break;
    default:
        check_logged();
        $mgr = new UserOptionsManager();
        $smarty->assign('meta', $mgr->get_all_options(true));
        $smarty->assign('current_email', get_user_email($_SESSION['user_id']));
        $smarty->assign('current_name', get_user_shown_name($_SESSION['user_id']));
        $smarty->assign('teams', get_team_list());
        $smarty->assign('user_team', get_user_team($_SESSION['user_id']));
        $smarty->display('options.tpl');
}
log_timing();
Ejemplo n.º 3
0
    $user1 = get_user_shown_name($user1);
    print "{$user1} with mod <br />";
    $stats = kappa_stats_with_filter($kappas, function ($e) use($user1) {
        return $e['user1'] == $user1 && $e['with_m'] or $e['user2'] == $user1 && $e['with_m'];
    });
    if ($stats) {
        list($min, $max, $avg) = $stats;
        print sprintf("%.4f (%s, %s) [%.4f] %.4f (%s, %s)<br />", $min['kappa'], $min['user1'], $min['user2'], $avg, $max['kappa'], $max['user1'], $max['user2']);
        print '<br />';
    }
}
print "<h2>All pairs of annotators, without moderator</h2>";
foreach ($USERS as $user1) {
    $user1 = get_user_shown_name($user1);
    foreach ($USERS as $user2) {
        $user2 = get_user_shown_name($user2);
        if ($user1 === $user2) {
            continue;
        }
        $stats = kappa_stats_with_filter($kappas, function ($e) use($user1, $user2) {
            return $e['user1'] === $user1 && $e['user2'] === $user2 && !$e['with_m'] or $e['user2'] === $user1 && $e['user1'] === $user2 && !$e['with_m'];
        });
        if ($stats) {
            print "{$user1} vs {$user2}</br>";
            list($min, $max, $avg) = $stats;
            print sprintf("%.4f (%s, %s) [%.4f] %.4f (%s, %s)<br />", $min['kappa'], $min['user1'], $min['user2'], $avg, $max['kappa'], $max['user1'], $max['user2']);
            print '<br />';
        }
    }
}
print '<h2>All books (without moderator, >=2 annotators)</h2>';
Ejemplo n.º 4
0
function get_user_stats($weekly = false, $team = 0)
{
    if ($weekly) {
        $start_time = time() - 7 * SEC_PER_DAY;
        $counter_param = 58;
        $params = array(59, 60, 61);
    } else {
        $start_time = 0;
        $counter_param = 33;
        $params = array(STATS_ANNOTATOR_DIVERGENCE_TOTAL, 38, 39);
    }
    $annotators = array();
    // team info
    $uid2team = array();
    $res = sql_query("SELECT user_id, user_team FROM users WHERE user_team > 0");
    while ($r = sql_fetch_array($res)) {
        $uid2team[$r['user_id']] = $r['user_team'];
    }
    $teams = get_team_list();
    foreach ($teams as $i => $v) {
        if ($v['num_users'] == 0) {
            unset($teams[$i]);
            continue;
        }
        $teams[$i]['total'] = $teams[$i]['moderated'] = $teams[$i]['correct'] = $teams[$i]['active_users'] = 0;
    }
    $uid2sid = array();
    $res = sql_pe("\n        SELECT user_id, COUNT(*) AS cnt, user_rating10 AS rating\n        FROM morph_annot_instances\n        LEFT JOIN users USING(user_id)\n        WHERE answer > 0\n            AND ts_finish > ?\n            " . ($team ? "AND user_team = ?" : "") . "\n        GROUP BY user_id\n        ORDER BY " . ($weekly ? 'cnt' : 'rating') . " DESC\n    ", $team ? array($start_time, $team) : array($start_time));
    foreach ($res as $r) {
        $annotators[] = array('total' => number_format($r['cnt'], 0, '', ' '), 'user_id' => $r['user_id'], 'rating' => number_format($r['rating'], 0, '', ' '));
        $uid2sid[$r['user_id']] = sizeof($annotators) - 1;
        if (isset($uid2team[$r['user_id']])) {
            $teams[$uid2team[$r['user_id']]]['total'] += $r['cnt'];
            $teams[$uid2team[$r['user_id']]]['active_users'] += 1;
        }
    }
    uasort($teams, function ($a, $b) {
        if ($a['total'] > $b['total']) {
            return -1;
        }
        if ($a['total'] < $b['total']) {
            return 1;
        }
        return 0;
    });
    // last activity info
    $last_click = array();
    $res = sql_query("\n        SELECT user_id, MAX(timestamp) AS last_time\n        FROM morph_annot_click_log\n        WHERE timestamp > UNIX_TIMESTAMP(NOW()) - " . SEC_PER_DAY . " * " . ($weekly ? "7" : "60") . "\n        GROUP BY user_id\n    ");
    while ($r = sql_fetch_array($res)) {
        $last_click[$r['user_id']] = $r['last_time'];
    }
    // divergence and moderation info
    $divergence = array();
    $moderated = array();
    $correct = array();
    $res = sql_query("SELECT user_id, param_id, param_value FROM user_stats WHERE param_id IN (" . join(', ', $params) . ")");
    while ($r = sql_fetch_array($res)) {
        switch ($r['param_id']) {
            case STATS_ANNOTATOR_DIVERGENCE_TOTAL:
            case 59:
                $divergence[$r['user_id']] = $r['param_value'];
                break;
            case 38:
            case 60:
                $moderated[$r['user_id']] = $r['param_value'];
                if (isset($uid2team[$r['user_id']])) {
                    $teams[$uid2team[$r['user_id']]]['moderated'] += $r['param_value'];
                }
                break;
            case 39:
            case 61:
                $correct[$r['user_id']] = $r['param_value'];
                if (isset($uid2team[$r['user_id']])) {
                    $teams[$uid2team[$r['user_id']]]['correct'] += $r['param_value'];
                }
        }
    }
    foreach ($teams as $i => $v) {
        if ($v['total'] == 0) {
            unset($teams[$i]);
            continue;
        }
        if ($v['moderated']) {
            $teams[$i]['error_rate'] = get_error_rate($v['moderated'], $v['correct']);
        } else {
            $teams[$i]['error_rate'] = 0;
        }
    }
    $res = sql_query("SELECT u.user_id, u.user_shown_name AS user_name, param_value FROM user_stats s LEFT JOIN users u ON (s.user_id=u.user_id) WHERE param_id={$counter_param} ORDER BY param_value DESC");
    while ($r = sql_fetch_array($res)) {
        $t = array('user_id' => $r['user_id'], 'user_name' => $r['user_name'], 'value' => number_format($r['param_value'], 0, '', ' '), 'divergence' => $divergence[$r['user_id']] / $r['param_value'] * 100, 'last_active' => isset($last_click[$r['user_id']]) ? $last_click[$r['user_id']] : 0, 'moderated' => isset($moderated[$r['user_id']]) ? $moderated[$r['user_id']] : 0, 'error_rate' => isset($correct[$r['user_id']]) ? get_error_rate($moderated[$r['user_id']], $correct[$r['user_id']]) : 0);
        if (isset($uid2team[$r['user_id']])) {
            $t['team_id'] = $uid2team[$r['user_id']];
            $t['team_name'] = $teams[$t['team_id']]['name'];
        }
        if (isset($uid2sid[$r['user_id']])) {
            $annotators[$uid2sid[$r['user_id']]]['fin'] = $t;
        }
    }
    foreach ($annotators as $k => $v) {
        if (!isset($v['fin']['user_name'])) {
            $annotators[$k]['fin']['user_id'] = $v['user_id'];
            $annotators[$k]['fin']['user_name'] = get_user_shown_name($v['user_id']);
            $annotators[$k]['fin']['last_active'] = isset($last_click[$v['user_id']]) ? $last_click[$v['user_id']] : 0;
            $annotators[$k]['fin']['moderated'] = isset($moderated[$v['user_id']]) ? $moderated[$v['user_id']] : 0;
            $annotators[$k]['fin']['error_rate'] = isset($moderated[$v['user_id']]) ? get_error_rate($moderated[$v['user_id']], $correct[$v['user_id']]) : 0;
        }
    }
    $timestamp_yesterday = ($timestamp_today = mktime(0, 0, 0)) - SEC_PER_DAY;
    return array('annotators' => $annotators, 'teams' => $teams, 'timestamp_today' => $timestamp_today, 'timestamp_yesterday' => $timestamp_yesterday, 'added_sentences' => get_sentence_adders_stats($weekly, $team));
}