문제

I am running a server with custom python software that collects and stores data from linux-based devices. The data is stored on mysql and contains information such as serial numbers, access timestamps, average age of the users, etc.

What I'd like to do is to deploy a web application which can display statistics from the collected dataset in mysql.

Example

serial number

BBB45600
BBB56444
BBB23411
HHH00332
HHH45677

60% s/n is BBB class
40% s/n is HHH class

It would be nice to display these statistics via a web interface just like piwik does, but gathering the data from mysql db. I am looking for something like sofa which provides web access to the data analysis.

Is there anything like this that you are aware of? I am not a professional programmer so possibly I would go for something that does not require too much coding/interfacing to get it working. Something in-the-cloud could be just perfect, but server-based software would work just as well.

Willing to learn if a good solution comes up!

도움이 되었습니까?

해결책

I'm not familiar with piwik nor sofa, and after reviewing their websites cannot really determine how they would be immediately applicable to your desirable outcome as stated. For a quick and easy solution I would make a script in PHP that queries the existing database used by python, and writes the output to the display. PHP is relatively easy to set up, and if you are using Linux on your server you will find countless tutorials to do so.

As for the script itself; it looks like there are two parts to it - you want it to list all the serial numbers first and then output the percentage that the first 3 letter prefix group forms of the existing set. I am unsure how you intend for the other data in your set to be included, but you can adapt the following to suit.

<?php
$con=mysqli_connect("yourServerUrl","username","password","databaseName");

// Check connection
if (mysqli_connect_errno($con))
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else
{
    // Do Queries and output here

    /* Part 1, output Serial Numbers - note this will output all serial numbers, 
       which might not be desirable */

    // Get the serial numbers
    $result = mysqli_query($con,"SELECT serialNumberColumnName FROM SerialNumberTable");

    // count results, you need this later for the data/stat portion
    $totalResults = mysqli_num_rows($result);

    // Output Serial Numbers
    while($row = mysqli_fetch_array($result))
    {
        echo $row['serialNumberColumnName'];
        echo '<br />';
    }

    /* Part 2, output Serial Number prefix percentages - repeat this for each 'class' */

    // Do the Query
    $result = mysqli_query($con,"SELECT serialNumberColumnName FROM SerialNumberTable WHERE serialNumberColumnName like 'HHH%'");
    $resultQty = mysqli_num_rows($result);

    // Output Figure
    $percentage = ($resultQty / $totalResults) * 100;
    echo "$percentage s/n is HHH class. <br />";

}

// Close Connection to database
mysqli_close($con);
?>

There are more elegant and efficient ways to do this, but as you mentioned that you weren't a programmer, I pieced the entire thing together using only tutorials from w3Schools.

http://www.w3schools.com/php/default.asp

If you have trouble, check out the relevant tutorials on w3schools, understand how that portion works, and apply that knowledge to troubleshoot/expand your solution. PHP is a nice simple learning language, and fast to think in. Note that I have not tested the above code as I do not have a current PHP installation.

I hope that helps,

Gui

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top