Hi there. I believe I'm having a simple variable issue when using processing. Can anyone take a look and see why my node availability is printing as 0.0% ? There's 100 rows in the database with a status of 'UP' for the date specified. I think its something very simple, but i'm having difficulty spotting it!! Thanks for the help!
I believe the problem lies somewhere with
rowDayPercentageEach DB row represents a minute in my project hence the 1440 minutes in a day
Code:import de.bezier.data.sql.*;
MySQL msql;
int nodeAvail;
int barMaxHeight = 470;
int barWidth = 80;
int hBarStart = 95;
float rowDayPercentage;
// Display percentage on graph. 470 = 100%. 4.7 = 1%
float UpTimeDisplay = rowDayPercentage * 4.7;
void setup()
{
int hSize = 700;
int vSize = 500;
size(hSize, vSize);
background(206,225,176);
calcGraphAxisH();
// MySQL specifics
String user = "root";
String pass = "9631";
String date="2009-03-23";
String database = "suasdb";
msql = new MySQL(this, "localhost", database, user, pass);
if ( msql.connect() )
{
msql.query( "SELECT COUNT(*) FROM alertlist WHERE status='UP' AND datetime LIKE '" + date + "%'");
msql.next();
println( "Number of rows: " + msql.getInt(1) );
nodeAvail = msql.getInt(1);
rowDayPercentage = (nodeAvail / 1440) * 100;
println( "Node Availability for day: " + rowDayPercentage + "%");
}
else
{
println("Unable to connect to Suas database!");
}
}
void draw()
{
// draw bars
fill(126,191,11,150);
noStroke();
for(int j = 0; j < 560; j = j + (barWidth+5)){
rect(hBarStart+j,barMaxHeight,barWidth,-UpTimeDisplay);
}
}
void calcGraphAxisH(){
for(int i = 0; i <= barMaxHeight; i = i + 47){
line(700, i, 0, i);
}
}