I'm trying to do the following:
Find and print 5 closest objects (represented as 3 numbers) to the given object
database = dbnumbers
table = numbers
One object is represented as:
4 fields (id, C1, C2, C3)
id = INT
C1 = FLOAT
C2 = FLOAT
C3 = FLOAT
C1, C2, C3 are random numbers 0-100
Required object is represented as 3 float values:
certain_number1
certain_number2
certain_number3
1. step
Find the closest numbers to the certain_number1 from a numbers table (field C1)
condition: ABS( C1 - certain_number1 ) <= threshold_value
2. step
Between a list of numbers that are seperated by step 1,
pull of the closest numbers to the certain_number2 from a numbers table (field C2)
condition: ABS( C2 - certain_number2 ) <= threshold_value
3. step
Between a list of numbers that are seperated by step 2,
pull of the closest numbers to the certain_number3 from a numbers table (field C3)
condition: ABS( C3 - certain_number3 ) <= threshold_value
Print object whit appropriate values (id, C1, C2, C3)..
Selecting closest values in MySQL:
http://www.techfounder.net/2009/02/02/selecting-closest-values-in-mysql/
Here is code for creating dbnumbers database:
Find and print 5 closest objects (represented as 3 numbers) to the given object
database = dbnumbers
table = numbers
One object is represented as:
4 fields (id, C1, C2, C3)
id = INT
C1 = FLOAT
C2 = FLOAT
C3 = FLOAT
C1, C2, C3 are random numbers 0-100
Required object is represented as 3 float values:
certain_number1
certain_number2
certain_number3
1. step
Find the closest numbers to the certain_number1 from a numbers table (field C1)
condition: ABS( C1 - certain_number1 ) <= threshold_value
2. step
Between a list of numbers that are seperated by step 1,
pull of the closest numbers to the certain_number2 from a numbers table (field C2)
condition: ABS( C2 - certain_number2 ) <= threshold_value
3. step
Between a list of numbers that are seperated by step 2,
pull of the closest numbers to the certain_number3 from a numbers table (field C3)
condition: ABS( C3 - certain_number3 ) <= threshold_value
Print object whit appropriate values (id, C1, C2, C3)..
Selecting closest values in MySQL:
http://www.techfounder.net/2009/02/02/selecting-closest-values-in-mysql/
Here is code for creating dbnumbers database:
- import de.bezier.data.sql.*;
MySQL msql;
float c_1, c_2, c_3;
void setup()
{
size( 100, 100 );
String user = "root";
String pass = "admin";
String database = "dbnumbers";
String table = "numbers";
msql = new MySQL( this, "localhost:3306", database, user, pass );
if ( msql.connect() )
{
// create a table with an id, C1, C2, C3
msql.execute( "CREATE TABLE IF NOT EXISTS " + table + " ("+"id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, C1 DECIMAL (5,2), C2 DECIMAL (5,2), C3 DECIMAL (5,2))");
// fill the table with some data
for(int i=0; i<100; i++){
c_1 = random(100);
c_2 = random(100);
c_3 = random(100);
msql.execute( "INSERT INTO " + table + " (C1, C2 , C3) VALUES (\"" + c_1 + "\", \"" + c_2 + "\", \"" + c_3 + "\")" );
}
// need to find out how many rows there are in table?
msql.query( "SELECT COUNT(*) FROM " + table );
msql.next();
println( "number of rows: " + msql.getInt(1) );
}
else
{
// connection failed !
println("connection failed!");
}
}
void draw()
{
// ...
}
1