<commit_before><?php

include_once "../../includes/easyparliament/init.php";
include_once INCLUDESPATH . 'easyparliament/video.php';

$from = get_http_var('from');
$gid = get_http_var('gid');
$start = intval(get_http_var('start'));
$gid_safe = $gid;

if (!$gid) {
	$this_page = 'video_front';
	$PAGE->page_start();
	$PAGE->stripe_start();
?>

<style type="text/css">
#attract {
	background-color: #ccccff;
	text-align: center;
	padding: 10px;
	margin-left: 2em;
	border: solid 2px #9999ff;
	font-size: 150%;
	line-height: 1.4;
}
</style>

<p style="margin-top:1em"><big>TheyWorkForYou has video of the House of Commons from the BBC, and
the text of Hansard from Parliament. Now we need <strong>your</strong>
help to match up the two.</big></p>

<p>We've written a little Flash app where you can (hopefully) match up the written speech being displayed to
what's playing on the video. We'll then store your results and use them to put the video,
timestamped to the right location, on the relevant page of TheyWorkForYou.</p>

<p>If you're a registered user and logged in,
your timestampings will appear in our chart below &ndash; there may be prizes for best timestampers&hellip; :)
Registration is not needed to timestamp videos, but you can <a href="/user/?pg=join&ret=/video/">register here</a> if you want.</p>

<p id="attract"><a href="next.php?action=random">Give me a random speech that needs timestamping</a></p>

<div id="top" style="float: left; width: 45%;">
<h3>Top timestampers</h3>
<ol>
<?

$db = new ParlDB;
$q = $db->query('select firstname,lastname,video_timestamps.user_id,count(*) as c from video_timestamps left join users on video_timestamps.user_id=users.user_id where video_timestamps.deleted=0 group by user_id order by c desc');
for ($i=0; $i<$q->rows(); $i++) {
	$name = $q->field($i, 'firstname') . ' ' . $q->field($i, 'lastname');
	$user_id = $q->field($i, 'user_id');
	if ($user_id == -1) $name = 'CaptionerBot';
	if ($user_id == 0) $name = 'Anonymous';
	$count = $q->field($i, 'c');
	echo "<li>$name : $count";
	if ($user_id == -1) {
		echo ' <small>(initial run program that tries to guess timestamp from captions, wildly variable)</small>';
	}
}
?>
</ol>
</div>

<div style="float: right; width: 50%">
<h3>Totaliser</h3>
<ul>
<?

$statuses = array(
	0 => 'Unchecked video',
	4 => 'Timestamped by users',
);
$q = $db->query('select video_status&4 as checked,count(*) as c from hansard
	where major=1 and video_status>0 and video_status!=2 and htype in (12,13) group by video_status&4');
for ($i=0; $i<$q->rows(); $i++) {
	$status = $q->field($i, 'checked');
	$count = $q->field($i, 'c');
	echo '<li>';
	echo $statuses[$status] . ' : ' . $count;
}

?>
</ul>

<h3 style="margin-top:1em">Latest stamped</h3>
<ul>
<?

$q = $db->query('select hansard.gid, body from video_timestamps, hansard, epobject
	where (user_id != -1 or user_id is null) and video_timestamps.deleted=0
		and video_timestamps.gid = hansard.gid and hansard.subsection_id = epobject.epobject_id
	order by whenstamped desc limit 10');
for ($i=0; $i<$q->rows(); $i++) {
	$gid = $q->field($i, 'gid');
	$body = $q->field($i, 'body');
	echo '<li><a href="/debate/?id=' . fix_gid_from_db($gid) . '">' . $body . '</a>';
}

?>
</ul>

</div>

<?
	$PAGE->stripe_end();
	$PAGE->page_end();
	exit;
}

$this_page = 'video_main';

$surrounding_speeches = 3;
if ($from == 'next') $surrounding_speeches = 2;

$gid = "uk.org.publicwhip/debate/$gid";

$q_gid = mysql_escape_string($gid);
$db = new ParlDB;
$q = $db->query("select hdate, htime, atime, hpos, (select h.gid from hansard as h where h.epobject_id=hansard.subsection_id) as parent_gid
    from hansard
    left join video_timestamps on hansard.gid = video_timestamps.gid and user_id = -1
    where hansard.gid='$q_gid'");
$hdate = $q->field(0, 'hdate');
$htime = $q->field(0, 'htime');
$atime = $q->field(0, 'atime');
if ($atime) $htime = $atime;
$hpos = $q->field(0, 'hpos');
$parent_gid = str_replace('uk.org.publicwhip/debate/', '/debates/?id=', $q->field(0, 'parent_gid'));

$q = $db->query("select hansard.gid, body, htype, htime, atime, hpos, first_name, last_name, video_status
	from hansard
		inner join epobject on hansard.epobject_id=epobject.epobject_id
		left join member on hansard.speaker_id=member.member_id
                left join video_timestamps on hansard.gid = video_timestamps.gid and user_id = -1
	where hpos>=$hpos-$surrounding_speeches and hpos<=$hpos+$surrounding_speeches and hdate='$hdate' and major=1
	ORDER BY hpos
");
$gids_previous = array();
$gids_following = array();
$gid_actual = array();
for ($i=0; $i<$q->rows(); $i++) {
	$row = $q->row($i);
	if ($row['atime']) $row['htime'] = $row['atime'];
	if ($row['hpos'] < $hpos) {
		$gids_previous[] = $row;
	} elseif ($row['hpos'] > $hpos) {
		$gids_following[] = $row;
		
	} else {
		$gid_actual = $row;
	}
}

#if (strlen(strip_tags($gid_actual['body'])) > 500) {
#	$gid_actual['body_first'] = '<p>' . substr(strip_tags($gid_actual['body']), 0, 500) . '...';
#} else {<commit_msg>Better error handling of bad GIDs.<commit_after><?php

include_once "../../includes/easyparliament/init.php";
include_once INCLUDESPATH . 'easyparliament/video.php';

$from = get_http_var('from');
$gid = get_http_var('gid');
$start = intval(get_http_var('start'));
$gid_safe = $gid;

if (!$gid) {
	$this_page = 'video_front';
	$PAGE->page_start();
	$PAGE->stripe_start();
?>

<style type="text/css">
#attract {
	background-color: #ccccff;
	text-align: center;
	padding: 10px;
	margin-left: 2em;
	border: solid 2px #9999ff;
	font-size: 150%;
	line-height: 1.4;
}
</style>

<p style="margin-top:1em"><big>TheyWorkForYou has video of the House of Commons from the BBC, and
the text of Hansard from Parliament. Now we need <strong>your</strong>
help to match up the two.</big></p>

<p>We've written a little Flash app where you can (hopefully) match up the written speech being displayed to
what's playing on the video. We'll then store your results and use them to put the video,
timestamped to the right location, on the relevant page of TheyWorkForYou.</p>

<p>If you're a registered user and logged in,
your timestampings will appear in our chart below &ndash; there may be prizes for best timestampers&hellip; :)
Registration is not needed to timestamp videos, but you can <a href="/user/?pg=join&ret=/video/">register here</a> if you want.</p>

<p id="attract"><a href="next.php?action=random">Give me a random speech that needs timestamping</a></p>

<div id="top" style="float: left; width: 45%;">
<h3>Top timestampers</h3>
<ol>
<?

$db = new ParlDB;
$q = $db->query('select firstname,lastname,video_timestamps.user_id,count(*) as c from video_timestamps left join users on video_timestamps.user_id=users.user_id where video_timestamps.deleted=0 group by user_id order by c desc');
for ($i=0; $i<$q->rows(); $i++) {
	$name = $q->field($i, 'firstname') . ' ' . $q->field($i, 'lastname');
	$user_id = $q->field($i, 'user_id');
	if ($user_id == -1) $name = 'CaptionerBot';
	if ($user_id == 0) $name = 'Anonymous';
	$count = $q->field($i, 'c');
	echo "<li>$name : $count";
	if ($user_id == -1) {
		echo ' <small>(initial run program that tries to guess timestamp from captions, wildly variable)</small>';
	}
}
?>
</ol>
</div>

<div style="float: right; width: 50%">
<h3>Totaliser</h3>
<ul>
<?

$statuses = array(
	0 => 'Unchecked video',
	4 => 'Timestamped by users',
);
$q = $db->query('select video_status&4 as checked,count(*) as c from hansard
	where major=1 and video_status>0 and video_status!=2 and htype in (12,13) group by video_status&4');
for ($i=0; $i<$q->rows(); $i++) {
	$status = $q->field($i, 'checked');
	$count = $q->field($i, 'c');
	echo '<li>';
	echo $statuses[$status] . ' : ' . $count;
}

?>
</ul>

<h3 style="margin-top:1em">Latest stamped</h3>
<ul>
<?

$q = $db->query('select hansard.gid, body from video_timestamps, hansard, epobject
	where (user_id != -1 or user_id is null) and video_timestamps.deleted=0
		and video_timestamps.gid = hansard.gid and hansard.subsection_id = epobject.epobject_id
	order by whenstamped desc limit 10');
for ($i=0; $i<$q->rows(); $i++) {
	$gid = $q->field($i, 'gid');
	$body = $q->field($i, 'body');
	echo '<li><a href="/debate/?id=' . fix_gid_from_db($gid) . '">' . $body . '</a>';
}

?>
</ul>

</div>

<?
	$PAGE->stripe_end();
	$PAGE->page_end();
	exit;
}

$this_page = 'video_main';

$surrounding_speeches = 3;
if ($from == 'next') $surrounding_speeches = 2;

$gid = "uk.org.publicwhip/debate/$gid";

$q_gid = mysql_escape_string($gid);
$db = new ParlDB;
$q = $db->query("select hdate, htime, atime, hpos, (select h.gid from hansard as h where h.epobject_id=hansard.subsection_id) as parent_gid, video_status
    from hansard
    left join video_timestamps on hansard.gid = video_timestamps.gid and user_id = -1
    where hansard.gid='$q_gid'");
if (!$q->rows()) {
	$PAGE->error_message('That GID does not appear to exist.', true);
	exit;
}
$video_status = $q->field('video_status');
$hpos = $q->field(0, 'hpos');
$hdate = $q->field(0, 'hdate');
$htime = $q->field(0, 'htime');
$atime = $q->field(0, 'atime');
if ($atime) $htime = $atime;
$parent_gid = str_replace('uk.org.publicwhip/debate/', '/debates/?id=', $q->field(0, 'parent_gid'));

if (!$video_source&1) {
	$PAGE->error_message('That GID does not appear to have any video. Please visit the <a href="/video/">video front page</a>.', true);
	exit;
}

$q = $db->query("select hansard.gid, body, htype, htime, atime, hpos, first_name, last_name, video_status
	from hansard
		inner join epobject on hansard.epobject_id=epobject.epobject_id
		left join member on hansard.speaker_id=member.member_id
                left join video_timestamps on hansard.gid = video_timestamps.gid and user_id = -1
	where hpos>=$hpos-$surrounding_speeches and hpos<=$hpos+$surrounding_speeches and hdate='$hdate' and major=1
	ORDER BY hpos
");
$gids_previous = array();
$gids_following = array();
$gid_actual = array();
for ($i=0; $i<$q->rows(); $i++) {
	$row = $q->row($i);
	if ($row['atime']) $row['htime'] = $row['atime'];
	if ($row['hpos'] < $hpos) {
		$gids_previous[] = $row;
	} elseif ($row['hpos'] > $hpos) {
		$gids_following[] = $row;
		
	} else {
		$gid_actual = $row;
	}
}

#if (strlen(strip_tags($gid_actual['body'])) > 500) {
#	$gid_actual['body_first'] = '<p>' . substr(strip_tags($gid_actual['body']), 0, 500) . '...';
#} else {
{'fraction_non_alphanumeric': 0.1915264074289031, 'fraction_numerical': 0.012671696653124396, 'mean_word_length': 4.851160158460668, 'pattern_counts': {'":': 0, '<': 111, '<?xml version=': 0, '>': 167, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1172944', 'n_tokens_mistral': 4131, 'n_tokens_neox': 3974, 'n_words': 1037}