Пример #1
0
 public static function saveAnswer($base_url, $username, $answer_link_list)
 {
     foreach ($answer_link_list as $url) {
         if (preg_match('%^/question/(\\d+)/answer/(\\d+)%', $url, $matches)) {
             $qid = $matches[1];
             $aid = $matches[2];
         } else {
             echo "{$url} not good\n";
             exit(1);
         }
         $url = $base_url . $url;
         echo "\t{$url}";
         $t = microtime(true);
         list($code, $content) = odie_get($url);
         echo "\t[{$code}]";
         if ($code != 200) {
             // fail fast
             echo "\tfail\n";
             slog("{$url} [{$code}] error");
             $success_ratio = get_average(0, 'success_ratio');
             continue;
         } else {
             $success_ratio = get_average(1, 'success_ratio');
         }
         $t = intval((microtime(true) - $t) * 1000);
         $avg = intval(get_average($t));
         echo "\t{$t} ms\n";
         if (empty($content)) {
             echo "content is empty\n";
             slog("{$url} [{$code}] empty");
             return false;
         }
         list($question, $descript, $content, $vote) = parse_answer_pure($content);
         slog("{$url} [{$code}] ^{$vote}\t{$question}");
         Question::saveQuestion($qid, $question, $descript);
         Answer::_saveAnswer($aid, $qid, $username, $content, $vote);
     }
     if (isset($success_ratio) && isset($avg)) {
         $success_ratio = intval($success_ratio * 100) . '%';
         echo "\tAvg: {$avg} ms\tsuccess_ratio: {$success_ratio}\n";
     }
 }
Пример #2
0
echo "<tr><td>Subject Average</td>";
foreach ($subjects as $subj) {
    echo "<td>" . get_subject_avg($student_marks, $subj) . "</td>\n";
}
echo "<td>Class Average: <br />" . get_class_avg($student_marks) . "</td>\n</tr>\n";
echo "</table>";
echo "<p>Students achieveing <b>below</b> average: ";
foreach ($student_marks as $knum => $marks) {
    if (get_average($marks) < get_class_avg($student_marks)) {
        echo $knum . " ";
    }
}
echo "</p>\n";
echo "<p>Students achieveing <b>above</b> average: ";
foreach ($student_marks as $knum => $marks) {
    if (get_average($marks) > get_class_avg($student_marks)) {
        echo $knum . " ";
    }
}
echo "</p>\n";
function get_average($marks)
{
    $total = 0;
    foreach ($marks as $subject => $mark) {
        $total += $mark;
    }
    return $total / count($marks);
}
function get_subject_avg($data, $subj)
{
    $total = 0;
Пример #3
0
        case 'get_markers_by_category':
            get_markers_by_category($_REQUEST['id_categoria']);
            break;
        case 'add_post':
            add_post($_REQUEST['id_user'], $_REQUEST['post_title'], $_REQUEST['post_content']);
            break;
        case 'get_post':
            get_post($_REQUEST['id_post']);
            break;
        case 'get_comments':
            get_comments($_REQUEST['id_post']);
            break;
        case 'comment_post':
            comment_post($_REQUEST['id_post'], $_REQUEST['username'], $_REQUEST['id_user'], $_REQUEST['comment']);
            break;
        case 'qualify':
            qualify($_REQUEST['id_usuario'], $_REQUEST['qualification']);
            break;
        case 'get_average':
            get_average();
            break;
        case 'upload_image':
            upload_image($_FILES, $_REQUEST['id_user'], $_REQUEST['id_post']);
            break;
        case 'get_image':
            get_image($_REQUEST['filename']);
            break;
    }
} else {
    echo 'No se ha realizado solicitud http alguna.';
}
            if (($attr = $node->getAttribute('class')) == 'zm-profile-header-img zg-avatar-big zm-avatar-editor-preview') {
                $src = $node->getAttribute('src');
            }
        }
        User::updateByUserName($username, array('avatar' => $src));
        $link_list = get_answer_link_list($content);
        $rs = Answer::saveAnswer($base_url, $username, $link_list);
        $num = get_page_num($content);
        if ($num > 1) {
            foreach (range(2, $num) as $i) {
                echo "\nNo. {$n} fetch page {$i}\t";
                $url_page = "{$url}?page={$i}";
                timer();
                list($code, $content) = uget($url_page);
                $t = timer();
                $avg = intval(get_average($t, 'user page'));
                slog("{$url_page} [{$code}]");
                echo "[{$code}]\t{$t} ms\tAvg: {$avg} ms\n";
                if ($code != 200) {
                    echo "奇奇怪怪的返回码 {$code}\n";
                    continue;
                }
                $link_list = get_answer_link_list($content);
                Answer::saveAnswer($base_url, $username, $link_list);
            }
        }
        User::updateByUserName($username, array('has_fetch' => true));
    } catch (Exception $e) {
        slog('warning: resume with ' . $e->getCode() . ' ' . $e->getMessage());
    }
}
Пример #5
0
    echo $fillup['gallons'];
    ?>
</td>
    				<td><?php 
    echo number_format($fillup['miles'] / $fillup['gallons'], 2);
    ?>
</td>
  				</tr>
  				<?php 
}
?>
 
				<tr>
    				<th>Average</th>
    				<th><?php 
echo number_format(get_average('miles'), 2);
?>
</th>
    				<th><?php 
echo number_format(get_average('gallons'), 2);
?>
</th>
					<th><?php 
echo number_format(get_average('mpg'), 2);
?>
</th>
  				</tr>
			</table>
		</div>
	</body>
</html>