Skip to content

Commit

Permalink
Mostly skDB related changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tilusnet committed Oct 22, 2012
1 parent b1964f2 commit 0d2652c
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 26 deletions.
15 changes: 8 additions & 7 deletions Cities.pde
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@ class Cities {
}

Cities() {
int bs = 2;
int bs = 0;
cities = new ArrayList<CityData>();
cities.add(new CityData("Berlin", new LatLong(52, 13), #990000, bs, 400)); // Berlin
cities.add(new CityData("Sydney", new LatLong(-33.86, 151.21), #009900, bs, 200)); // Sydney
cities.add(new CityData("San Francisco", new LatLong(37.8, -122.4), #000099, bs, 300)); // San Francisco
cities.add(new CityData("London", new LatLong(51.5002, -0.1262), #FFFFFF, bs, 400));
//cities.add(new CityData("Berlin", new LatLong(52, 13), #990000, bs, 400));
//cities.add(new CityData("Sydney", new LatLong(-33.86, 151.21), #009900, bs, 200));
//cities.add(new CityData("San Francisco", new LatLong(37.8, -122.4), #000099, bs, 300));
dbgMyName = this.getClass().getName() + "::";
}

void display(MercatorMap mm) {
PVector cityXY;
noStroke();
fill(255, 0, 0, 200);
fill(255, 0, 0, 100);
translate(0, 0, 0.01);

for (CityData cdata: cities) {
Expand All @@ -58,12 +59,12 @@ class Cities {

pushMatrix();
translate(cityXY.x, cityXY.y, cdata.getBS()/2);
fill(cdata.getColour());
fill(cdata.getColour(), 100);
box(1,1,cdata.getBS());
cdata.incBS();
popMatrix();

dbgPrintCityLocation(cityLL, cityXY);
// dbgPrintCityLocation(cityLL, cityXY);
}

}
Expand Down
3 changes: 2 additions & 1 deletion LangDivercity.pde
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ int drawAreaSizeY = drawAreaSizeX;


void setup() {
size(screenSizeX, screenSizeY, P3D);
size(screenSizeX, screenSizeY, OPENGL);
smooth();

hint(ENABLE_STROKE_PERSPECTIVE);
Expand All @@ -24,6 +24,7 @@ void setup() {
myMap = new WorldMap3D(drawAreaSizeX, drawAreaSizeY, 4000);
myCities = new Cities();
// myUim.positionOnEurope(myMap.getMapSizeX());
myUim.positionOnLondon();
myMap.setTint(255, 150);

mercMap = myMap.getMercatorMap();
Expand Down
12 changes: 12 additions & 0 deletions UIManager.pde
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ class UIManager {
update();
}

void positionOnLondon() {

offsX = 79;
offsY = 346;
rotX = 0.265;
rotY = -0.194;
zoomScale = 1.41;

update();
}


void setInitialTranslate() {
// translate(initialTx, initialTy, 0);
translate(width/2.0, height/2.0, 0);
Expand Down
4 changes: 2 additions & 2 deletions WorldMap3D.pde
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class WorldMap3D {

textureMode(NORMAL);
wmap = create2DMap(mapSizeX, mapSizeY);
wmap2 = create2DMap(mapSizeX, mapSizeY, 200);
// wmap2 = create2DMap(mapSizeX, mapSizeY, 200);
// wmap = createCubeMap();

mercMap = new MercatorMap(-(mapSizeX/2.0), -(mapSizeY/2.0), mapSizeX, mapSizeY, 85.0511, -85.0511, -180, 180);
Expand Down Expand Up @@ -103,7 +103,7 @@ class WorldMap3D {

void update() {
shape(wmap);
shape(wmap2);
// shape(wmap2);
}

void setTint(int col, int al) {
Expand Down
82 changes: 66 additions & 16 deletions skDB.pde
Original file line number Diff line number Diff line change
@@ -1,32 +1,82 @@
import de.bezier.data.sql.*;
import java.sql.SQLException;


class skDB {

private SQLite db;

skDB(PApplet pa, String database) {

SQLite db = new SQLite( pa, database ); // open database file
db = new SQLite( pa, database ); // open database file

if ( db.connect() )
{
// list table names
db.query( "SELECT name as \"Name\" FROM SQLITE_MASTER where type=\"table\"" );

while (db.next())
{
println( db.getString("Name") );
}

// read all in table "table_one"
db.query( "SELECT * FROM table_one" );

while (db.next())
{
println( db.getString("field_one") );
println( db.getInt("field_two") );

try {

db.statement = db.connection.createStatement();
db.statement.setQueryTimeout(1);

//printListTables();
// printTimestamps();
//printTimestampsLondon();


} catch(SQLException e) {
println(e.getMessage());
}
}
}

void query(String q) {
db.query(q);
}

private void printListTables() {
// list table names
db.query( "SELECT name as \"Name\" FROM SQLITE_MASTER where type=\"table\"" );

while (db.next()) {
println( db.getString("Name") );
}
}

private void printTimestamps() {
long cnt = 0;

db.query( "SELECT ts FROM sk_data AS s LIMIT 10000" );

while (db.next())
{
println(getTimestamp("ts"));
cnt++;
}
println(cnt + " records.");
}

private void printTimestampsLondon() {
long cnt = 0, st, el;


st = System.currentTimeMillis();
db.query( "SELECT * from sk_data as s LEFT JOIN ip_group_city as i ON s.ip_start=i.ip_start WHERE i.city LIKE 'London'" );
el = System.currentTimeMillis() - st;
println(String.format("Query runtime = %d min %02d.%03d sec", el/1000/60, (el / 1000) % 60 , el % 1000));

st = System.currentTimeMillis();
while (db.next())
{
// println(getTimestamp("ts"));
cnt++;
//if (cnt % 1000 == 0) println(cnt + "...");
}
println(cnt + " records.");
el = System.currentTimeMillis() - st;
println(String.format("Loop through runtime = %d min %02d.%03d sec", el/1000/60, (el / 1000) % 60 , el % 1000));
}

Date getTimestamp(String field) {
return new Date(db.getLong("ts") * 1000);
}
}

0 comments on commit 0d2652c

Please sign in to comment.