Huge Update, everything works fine now

This commit is contained in:
Sven Zemanek
2013-08-04 00:37:56 +02:00
parent 72a0c182fc
commit dca939fee4
10 changed files with 718 additions and 78 deletions

View File

@@ -1,71 +1,158 @@
<?php
function int_to_answer($int){
if($int == 0){
function count_equal_answers($hsg, $votes){
$len = max(sizeof($hsg), sizeof($votes));
$count = 0;
for($i = 0; $i < $len; $i++){
if($hsg[$i] == $votes[$i] and !('skip' === $my[$i])){
$count++;
}
}
return $count;
}
function count_contrary_answers($hsg, $votes){
$len = max(sizeof($hsg), sizeof($votes));
$count = 0;
for($i = 0; $i < $len; $i++){
if(($hsg[$i] == 1 and $votes[$i] == -1) or ($hsg[$i] == -1 and $votes[$i] == 1)){
$count++;
}
}
return $count;
}
function count_relevant_answers($votes){
$count = 0;
for($i = 0; $i < sizeof($votes); $i++){
if(!('skip' === $my[$i])){
$count++;
}
}
return $count;
}
function count_achievable_points($my, $emph){
$count = 0;
for($i = 0; $i < sizeof($my); $i++){
if(!($my[$i] === 'skip')){
$count += 2 * $emph[$i];
}
}
return $count;
}
function count_party_points($hsg, $votes, $emph){
return similarity_index($votes, $hsg, $emph);
}
function html_hsg_bar($hsg, $votes, $emph, $class){
$hsg_name = $hsg['name'];
$party_points = count_party_points($hsg['answers'], $votes, $emph);
$ach_points = count_achievable_points($votes, $emph);
if($ach_points != 0){
$hsg_percentage = intval( 100 * $party_points / $ach_points);
} else {
$hsg_percentage = 0;
}
echo "<tr class='$class'>
<td><b>$hsg_name</b></td><td>$party_points von $ach_points</td>
<td><div class='progress'><div class='bar' title='$hsg_percentage %' style='width: $hsg_percentage%;'></div></div>
</td>
</tr>";
}
/* unused
function html_hsg_bar_tricolore($hsg, $votes, $emph, $class){
$hsg_name = $hsg['name'];
$hsg_percentage_equal = intval( 100 * count_equal_answers($hsg['answers'], $votes) / count_relevant_answers($votes));
$hsg_percentage_contrary = intval( 100 * count_contrary_answers($hsg['answers'], $votes) / count_relevant_answers($votes));
$hsg_percentage_medium = 100 - $hsg_percentage_equal - $hsg_percentage_contrary;
echo "<tr class='$class'>
<td><b>$hsg_name</b></td><td>$hsg_percentage_equal %</td>
<td><div class='progress'>
<div class='bar bar-success' style='width: $hsg_percentage_equal%;'></div>
<div class='bar bar-warning' style='width: $hsg_percentage_medium%;'></div>
<div class='bar bar-danger' style='width: $hsg_percentage_contrary%;'></div>
</div>
</td>
</tr>";
}*/
function code_to_answer($code){
if($code === 'skip'){
return '-';
}
if($int == 1){
if($code == 1){
return 'Zustimmung';
}
if($int == 2){
if($code == 0){
return 'Neutral';
}
if($int == 3){
if($code == -1){
return 'Ablehnung';
}
}
function int_to_td($int){
if($int == 0){
return '<td><button class="btn btn-block disabled">-</button></td>';
function hsg_get_td($hsg, $i){
$vote = $hsg['answers'][$i];
$popover = 'data-toggle="tooltip" data-placement="top" data-original-title="'.$hsg['comments'][$i].'"';
if($vote === 'skip'){
return "<td><a class='btn btn-block disabled hsganswer' $popover>-</a></td>";
}
if($int == 1){
return '<td><button class="btn btn-success btn-block disabled"><i class="icon-thumbs-up"></i></button></td>';
if($vote == 1){
return "<td><button class='btn btn-success btn-block disabled hsganswer' $popover><i class='icon-thumbs-up'></i></button></td>";
}
if($int == 2){
return '<td><button class="btn btn-warning btn-block disabled"><i class="bg-icon-circle"></i></button></td>';
if($vote == 0){
return "<td><button class='btn btn-warning btn-block disabled hsganswer' $popover><i class='bg-icon-circle'></i></button></td>";
}
if($int == 3){
return '<td><button class="btn btn-danger btn-block disabled"><i class="icon-thumbs-down"></i></button></td>';
if($vote == -1){
return "<td><button class='btn btn-danger btn-block disabled hsganswer' $popover><i class='icon-thumbs-down'></i></button></td>";
}
}
function int_to_btnclass($int){
if($int == 0){
function code_to_btnclass($int){
if($int === 'skip'){
return '';
}
if($int == 1){
return 'btn-success';
}
if($int == 2){
if($int == 0){
return 'btn-warning';
}
if($int == 3){
if($int == -1){
return 'btn-danger';
}
}
function similarity_index($my, $hsg, $mul){
function similarity_index($my, $hsg, $emph){
$max = max(sizeof($my), sizeof($hsg));
$pointvector = Array();
/* my = skip: +0
* my != skip && hsg = skip: -1
* my = hsg: +2
* |my - hsg| = 1: -1
* |my - hsg| = 2: -2
/* my = skip: skip / skip
* my != skip && hsg = skip: +0 / +0
* |my - hsg| = 0: +2 / +4
* |my - hsg| = 1: +1 / +2
* |my - hsg| = 2: +0 / +0
*/
for($i = 0; $i < $max; $i = $i + 1){
$pointvector[$i] = 0;
if($my[$i] == 0){continue;}
elseif($my[$i] != 0 and $hsg[$i] == 0){$pointvector[$i] = -1;}
elseif($my[$i] == $hsg[$i]){$pointvector[$i] = 2;}
elseif(abs($my[$i] - $hsg[$i]) == 1){$pointvector[$i] = -1;}
elseif(abs($my[$i] - $hsg[$i]) == 2){$pointvector[$i] = -2;}
else {print 'my:'.$my[$i].', hsg:'.$hsg[$i].'<br />';}
if($my[$i] === 'skip'){continue;}
elseif(!('skip' === $my[$i]) and $hsg[$i] === 'skip'){$pointvector[$i] = 0;}
else{ $pointvector[$i] = 2-abs($my[$i]-$hsg[$i]);}
}
$pointvector = vec_mul($pointvector, $mul);
$pointvector = vec_mul($pointvector, $emph);
return vectorsum($pointvector);
@@ -90,20 +177,49 @@ function int_to_answer($int){
}
}
function vec_mul2($a, $b){
if(sizeof($a) != sizeof($b)){
echo 'vector2 dimensions do not match|'.sizeof($a).'|'.sizeof($b).'<br />';
} else {
$sum = 0;
for($i = 0; $i < sizeof($a); $i = $i + 1){
$sum += $a[$i] * $b[$i];
}
return $sum;
}
}
function vec_abs($a){
$sum = 0;
for($i = 0; $i < sizeof($a); $i++){
$sum += ($a[$i] * $a[$i]);
}
return sqrt($sum);
}
function cosalpha($a, $b){
if(vec_abs($a) * vec_abs($b) == 0){
return 0;
} else {
return vec_mul2($a, $b) / (vec_abs($a) * vec_abs($b));
}
}
function pagitem($i, $curr){
if($i == $curr){
return '<li class="active"><a href="#">'.$i."</a></li>\n";
} else {
return '<li class="disabled"><a href="#">'.$i."</a></li>\n";
return '<li class=""><a href="index.php?id='.$i.'">'.$i."</a></li>\n";
}
}
function sort_hsgs($my, $hsg_array, $mul){
function sort_hsgs($my, $hsg_array, $emph){
$offset = 1/floatval(sizeof($hsg_array));
for($i = 0; $i < sizeof($hsg_array); $i = $i + 1){
$sorted[$i] = (similarity_index($my, $hsg_array[$i]['answers'], $mul)-($i*$offset));
$temp[(string)(similarity_index($my, $hsg_array[$i]['answers'], $mul)-($i*$offset))] = $hsg_array[$i];
$sorted[$i] = (similarity_index($my, $hsg_array[$i]['answers'], $emph)-($i*$offset));
$temp[(string)(similarity_index($my, $hsg_array[$i]['answers'], $emph)-($i*$offset))] = $hsg_array[$i];
}
sort($sorted);

78
includes/hsg.php Normal file
View File

@@ -0,0 +1,78 @@
<?php
function get_hsg_array(){
$hsg_array[0]['name'] = 'GHG';
$hsg_array[0]['answers'] = Array(0,0,0,0,0,0);
$hsg_array[0]['comments'] = Array(
"Das ist doof",
"Das nehmen wir sehr ernst",
"Das interessiert uns nicht",
"Im übrigen bin ich der Meinung, dass Karthago zerstört werden muss",
"-",
"Moppelkotze!"
);
$hsg_array[1]['name'] = 'RCDS';
$hsg_array[1]['answers'] = Array(-1,-1,-1,-1,0,1);
$hsg_array[1]['comments'] = Array(
"Das ist doof",
"Das nehmen wir sehr ernst",
"Das interessiert uns nicht",
"Im übrigen bin ich der Meinung, dass Karthago zerstört werden muss",
"-",
"Moppelkotze!"
);
$hsg_array[2]['name'] = 'Jusos';
$hsg_array[2]['answers'] = Array(1,0,1,1,-1,0);
$hsg_array[2]['comments'] = Array(
"Das ist doof",
"Das nehmen wir sehr ernst",
"Das interessiert uns nicht",
"Im übrigen bin ich der Meinung, dass Karthago zerstört werden muss",
"-",
"Moppelkotze!"
);
$hsg_array[3]['name'] = 'LUST';
$hsg_array[3]['answers'] = Array('skip',1,0,-1,'skip',1);
$hsg_array[3]['comments'] = Array(
"Das ist doof",
"Das nehmen wir sehr ernst",
"Das interessiert uns nicht",
"Im übrigen bin ich der Meinung, dass Karthago zerstört werden muss",
"-",
"Moppelkotze!"
);
$hsg_array[4]['name'] = 'Piraten';
$hsg_array[4]['answers'] = Array(-1,-1,0,1,0,1);
$hsg_array[4]['comments'] = Array(
"Das ist doof",
"Das nehmen wir sehr ernst",
"Das interessiert uns nicht",
"Im übrigen bin ich der Meinung, dass Karthago zerstört werden muss",
"-",
"Moppelkotze!"
);
$hsg_array[5]['name'] = 'LHG';
$hsg_array[5]['answers'] = Array(1,1,1,-1,1,-1);
$hsg_array[5]['comments'] = Array(
"Das ist doof",
"Das nehmen wir sehr ernst",
"Das interessiert uns nicht",
"Im übrigen bin ich der Meinung, dass Karthago zerstört werden muss",
"-",
"Moppelkotze!"
);
return $hsg_array;
}
?>

25
includes/theses.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
function get_theses_array(){
$theses_array['l'] = Array(
'Die UniCard muss so schnell wie möglich eingeführt werden!',
'Der VeggieDay gehört abgeschafft.',
'Grün ist das neue Blau.',
'Mehr Geld für die Universitäten!',
'Das NRW-Ticket ist eine tolle Einrichtung.',
'Heute ist ein schöner Tag.'
);
$theses_array['s'] = Array(
'UniCard',
'VeggieDay',
'Grün',
'Geld für Unis',
'NRW-Ticket',
'schöner Tag'
);
return $theses_array;
}
?>