Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Tomas Lang  >  Stable  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example of using
Class: Stable
Compute statistics on a set of integer values
Author: By
Last change:
Date: 6 years ago
Size: 3,224 bytes
 

Contents

Class file image Download
<?php

    
require_once 'stable.php';

    
session_start();
    
    if ( !isset( 
$_SESSION'table' ] ) ) {
        
$_SESSION'table' ] = new StatisticTable();
    }
    
    if ( isset( 
$_POST'compute' ] ) ) {
        
$data explode','$_POST'values' ] );
        
$_SESSION'table' ]->clear();
        foreach ( 
$data as $item ) {
            
$_SESSION'table' ]->add$item);
        }
    }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
        <title>Statistic table - test</title>
        <style type="text/css">
            table {
                border-left: 1px solid orange;
                border-top: 1px solid orange;
                border-collapse: collapse;
            }
            table th, table td {
                border-right: 1px solid orange;
                border-bottom: 1px solid orange;
            }

            th {
                background: orange;
            }

            td.center {
                text-align: center;
            }
            
            th.left {
                text-align: left;
            }

            table {
                background: yellow;
                margin: 1em 1em 0 0;
            }

            textarea {
                border: 1px solid orange;
                background: yellow;
            }

            input {
                background: orange;
                border: 3px solid red;
                font-size: 100%;
                font-weight: bold;
                margin-top: 0.5em;
            }
        </style>
    </head>
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
        <form method="post">
            <textarea name="values" rows="10" cols="10" style="width: 100%"><?= $_POST'values' ?></textarea>
            <input type="submit" name="compute" value="Compute"  style="width: 100%" />
        </form>
        <table style="float: left;">
            <tbody>
                <?php $i 0$all count$_SESSION'table' ]->getData() ); foreach ( $_SESSION'table' ]->getSortedData() as $value => $count ): ?>
                <tr>
                    <td class="center"><?= ++$i ?></td>
                    <td class="center"><?= $value ?></td>
                    <td class="center"><?= $count ?></td>
                    <td class="center"><?= round( ( $count $all ) * 100?></td>
                </tr>
                <?php endforeach; ?>
            </tbody>
            <thead>
                <tr>
                    <th>i</th>
                    <th>x<sub>i</sub></th>
                    <th>n<sub>i</sub></th>
                    <th>%</th>
                </tr>
            </thead>
        </table>
        <table style="float: left;">
            <?php $info $_SESSION'table' ]->getTableInfo() ?>
            <tr>
                <th class="left">Min</th>
                <td><?= round$info'min' ], ?></td>
            </tr>
            <tr>
                <th class="left">Max</th>
                <td><?= round$info'max' ], ?></td>
            </tr>
            <tr>
                <th class="left">Arithmetic mean</th>
                <td><?= round$info'arithmeticMean' ], ?></td>
            </tr>
            <tr>
                <th class="left">Quadratic mean</th>
                <td><?= round$info'quadraticMean' ], ?></td>
            </tr>
            <tr>
                <th class="left">Harmonic mean</th>
                <td><?= round$info'harmonicMean' ], ?></td>
            </tr>
            <tr>
                <th class="left">Median</th>
                <td><?= round$info'median' ], ?></td>
            </tr>
            <tr>
                <th class="left">Modus</th>
                <td><?= round$info'modus' ], ?></td>
            </tr>
            <tr>
                <th class="left">Expansion</th>
                <td><?= round$info'expansion' ], ?></td>
            </tr>
        </table>
    </html>
</html>