Browse files

Altered data structure to better match the way we work with paths in …

…the installation.
  • Loading branch information...
1 parent ec5604a commit 60a5c751b8326af3684244744a5c5fd1195456c7 @mrbichel mrbichel committed Sep 25, 2012
Showing with 91 additions and 112 deletions.
  1. +30 −30 src/data.cpp
  2. +26 −25 src/data.h
  3. +4 −0 src/defines.h
  4. +28 −54 src/visualizer.cpp
  5. +3 −3 src/visualizer.h
View
60 src/data.cpp
@@ -61,12 +61,13 @@ void Data::getLocations(){
lng = json_object_get(data, "lng");
Location loc;
+
loc.oid = ofxjan.getValueS(id, "$oid");
- loc.road = ofxjan.getValueS(data, "road");
- loc.dir_one_label = ofxjan.getValueS(data, "direction_one");
- loc.dir_two_label = ofxjan.getValueS(data, "direction_two");
+ loc.name = ofxjan.getValueS(data, "road");
loc.lat = json_real_value(lat);
loc.lng = json_real_value(lng);
+ loc.dir_one_name = ofxjan.getValueS(data, "direction_one");
+ loc.dir_two_name = ofxjan.getValueS(data, "direction_two");
locations.push_back(loc);
@@ -75,11 +76,11 @@ void Data::getLocations(){
json_decref(root);
}
-void Data::getStatEntries(Location* location){
+void Data::getStatEntries(Location* loc){
- ofLogNotice()<<"Importing stat entries for "<<location->road<<" ..."<<endl;
+ ofLogNotice()<<"Importing stat entries for "<<loc->name<<" ..."<<endl;
- ofHttpResponse response = ofLoadURL(endpoint + "locations/" + location->oid + "/entries" );
+ ofHttpResponse response = ofLoadURL(endpoint + "locations/" + loc->oid + "/entries" );
string responseStr = response.data;
@@ -88,7 +89,9 @@ void Data::getStatEntries(Location* location){
root = json_loads(responseStr.c_str(), &error);
- int i;
+ int i;
+ DataPoint newPoints [2];
+
for(i = 0; i < json_array_size(root); i++)
{
json_t *data, *id;
@@ -102,52 +105,49 @@ void Data::getStatEntries(Location* location){
maxStatEntry = amount;
}
- if (direction == 1) {
- location->dir_one.push_back(amount);
- } else if (direction == 2) {
- location->dir_two.push_back(amount);
- }
+
+ newPoints[direction-1].bikes.push_back(amount);
+
}
+ for(i = 0; i < 2; i++) {
+ newPoints[i].loc = loc;
+ dataPoints.push_back(newPoints[i]);
+ }
+
+
+
json_decref(root);
}
-void Path::addLocation(Location * loc) {
- locations.push_back(loc);
+void Path::addPoint(DataPoint * point) {
+ points.push_back(point);
update();
}
void Path::removeLocation(int index) {
- locations.erase(locations.begin()+index);
+ points.erase(points.begin()+index);
update();
}
void Path::update() {
- dir_one.clear();
- dir_two.clear();
+ sum.clear();
for(int h=0; h<DATA_HOURS; h++) {
- int dir_one_a = 0;
- int dir_two_a = 0;
+ int s = 0;
- for(int i=0; i<locations.size(); i++) {
- Location * loc = locations[i];
+ for(int i=0; i<points.size(); i++) {
+ DataPoint * point = points[i];
//cout<<ofToString(loc->dir_one.size())<<" long"<<endl;
- if(loc->dir_one.size()>0) {
- //cout<<"dir_one +"<<endl;
- dir_one_a += loc->dir_one.at(h);
- }
- if(loc->dir_two.size()>0) {
- //cout<<"dir_two +"<<endl;
- dir_two_a += loc->dir_two.at(h);
+ if(point->bikes.size()>0) {
+ s += point->bikes.at(h);
}
}
- dir_one.push_back(dir_one_a);
- dir_two.push_back(dir_two_a);
+ sum.push_back(s);
}
}
View
51 src/data.h
@@ -1,48 +1,47 @@
#pragma once
#include "ofMain.h"
-
#include "jansson.h"
#include "ofxJansson.h"
#include "MSAInterpolator.h"
-
#include "defines.h"
struct Location {
-
string oid;
+ string name;
- // global coordinates
- double lat;
- double lng;
+ string dir_one_name;
+ string dir_two_name;
- // local pixel coordinates in visualization
- ofPoint marker;
- float markerRadius;
+ double lat;
+ double lng;
+};
+
+struct DataPoint {
- // label
- string road;
+ string direction_name;
- string dir_one_label;
- string dir_two_label;
+ MSA::Interpolator1D bikes;
- MSA::Interpolator1D dir_one;
- MSA::Interpolator1D dir_two;
+ Location * loc;
+ // local pixel coordinates in visualization
+ ofPoint marker;
+ float markerRadius;
};
struct Path {
- vector<Location*> locations;
- MSA::Interpolator1D dir_one;
- MSA::Interpolator1D dir_two;
+ vector<DataPoint*> points;
+
+ MSA::Interpolator1D sum;
+ int sum_max;
- void addLocation(Location * loc);
+ void addPoint(DataPoint * point);
void removeLocation(int index);
void update();
-
- int size() { return locations.size(); };
+ int size() { return points.size(); };
};
class Data {
@@ -53,14 +52,16 @@ class Data {
void debugDraw();
void getData();
+ //void reloadData();
vector<Location> locations;
+ vector<DataPoint> dataPoints;
vector<Path> paths;
- //double maxLat;
- //double minLat;
- //double maxLng;
- //double minLng;
+ double maxLat;
+ double minLat;
+ double maxLng;
+ double minLng;
int maxStatEntry;
int maxCombinedStatEntry;
View
4 src/defines.h
@@ -7,3 +7,7 @@
#define NUM_CHANNELS 8
+#define MAXLAT 55.7368
+#define MINLAT 55.6108
+#define MAXLNG 12.6293
+#define MINLNG 12.4519
View
82 src/visualizer.cpp
@@ -23,11 +23,11 @@ void Visualizer::debugDraw(){
void Visualizer::mousePressed(int x, int y, int button){
- for (int i=0; i<data->locations.size(); i++) {
- Location * loc = &data->locations[i];
+ for (int i=0; i<data->dataPoints.size(); i++) {
+ DataPoint * point = &data->dataPoints[i];
- if (ofDist(x,y,loc->marker.x, loc->marker.y) < loc->markerRadius) {
- selectedLoc = loc;
+ if (ofDist(x,y,point->marker.x, point->marker.y) < point->markerRadius) {
+ selectedPoint = point;
}
}
@@ -41,31 +41,25 @@ void Visualizer::keyPressed(int key){
data->paths.push_back(p);
}
- if(selectedLoc) {
+ if(selectedPoint) {
if(key == '1') {
- data->paths[0].addLocation(selectedLoc);
+ data->paths[0].addPoint(selectedPoint);
}
}
}
-void Visualizer::drawMapPoint() {
-
-}
-void Visualizer::drawLocation(Location * loc) {
+void Visualizer::drawDataPoint(DataPoint * point) {
- if(loc->lat != 0 && loc->lng != 0) {
+ if(point->loc->lat != 0 && point->loc->lng != 0) {
- float aOne = loc->dir_one.sampleAt(sim->elapsedFloat);
- float aTwo = loc->dir_two.sampleAt(sim->elapsedFloat);
+ float a = point->bikes.sampleAt(sim->elapsedFloat);
- loc->marker = ofPoint(ofMap(loc->lng, minLng, maxLng, 200, 680), ofMap(loc->lat, minLat, maxLat, 680, 200));
+ point->marker = ofPoint(ofMap(point->loc->lng, minLng, maxLng, 200, 680), ofMap(point->loc->lat, minLat, maxLat, 680, 200));
+ point->markerRadius = ofMap(a, 0, data->maxStatEntry, 2, 36);
- loc->markerRadius = ofMap(aOne+aTwo, 0, data->maxCombinedStatEntry, 2, 36);
-
- ofSetColor(ofMap(aOne, 0, data->maxStatEntry, 80, 255), 100, ofMap(aTwo, 0, data->maxStatEntry, 0, 255));
- ofCircle(loc->marker, loc->markerRadius);
+ ofCircle(point->marker, point->markerRadius);
}
}
@@ -79,16 +73,16 @@ void Visualizer::draw() {
ofNoFill();
- for (int i=0; i<data->locations.size(); i++) {
- drawLocation(&data->locations[i]);
+ for (int i=0; i<data->dataPoints.size(); i++) {
+ drawDataPoint(&data->dataPoints[i]);
}
for (int i=0; i<data->paths.size(); i++) {
drawPath(&data->paths[i]);
}
- if (selectedLoc) {
- drawInterpolation(selectedLoc);
+ if (selectedPoint) {
+ drawInterpolation(selectedPoint);
}
}
@@ -97,24 +91,24 @@ void Visualizer::drawPath(Path * path) {
string s;
- for(int i=0; i<path->locations.size(); i++) {
- s += path->locations[i]->road + " < -- > ";
+ for(int i=0; i<path->points.size(); i++) {
+ s += path->points[i]->loc->name + " < -- > ";
}
ofDrawBitmapString(s, ofGetWidth()-800, 200);
- if(path->dir_one.size() > 0) {
+ if(path->points.size() > 0) {
- for(int i=0; i < path->dir_one.size(); i++) {
- ofDrawBitmapString(ofToString(path->dir_one.at(i)), (ofGetWidth()-300)+(i*(300/10)), ofGetHeight()-20);
+ for(int i=0; i < path->points.size(); i++) {
+ ofDrawBitmapString(ofToString(path->sum.at(i)), (ofGetWidth()-300)+(i*(300/10)), ofGetHeight()-20);
}
for(int p=0; p < 300; p++) {
float finto = p / float(300);
//cout<<ofToString(finto)<<endl;
- float val = path->dir_one.sampleAt(finto);
+ float val = path->sum.sampleAt(finto);
ofCircle(ofGetWidth()-300+p, ofMap(val, 0, data->maxStatEntry, ofGetHeight()-20, 20), 1);
}
@@ -126,30 +120,22 @@ void Visualizer::drawInterpolation(MSA::Interpolator1D * ipo, float width, float
}
-void Visualizer::drawInterpolation(Location * loc) {
+void Visualizer::drawInterpolation(DataPoint * point) {
int width = 700;
int i;
ofSetColor(100, 259, 60, 255);
- ofDrawBitmapString(loc->dir_one_label, 20, ofGetWindowHeight()-160);
-
- ofSetColor(250, 100, 60, 255);
- ofDrawBitmapString(loc->dir_two_label, 20, ofGetWindowHeight()-180);
+ ofDrawBitmapString(point->direction_name, 20, ofGetWindowHeight()-160);
ofSetColor(255, 255, 255, 255);
- for(i=0; i < loc->dir_one.size(); i++) {
- ofDrawBitmapString(ofToString(loc->dir_one.at(i)), 10+(i*(width/10)), ofGetHeight()-20);
+ for(i=0; i < DATA_HOURS; i++) {
+ ofDrawBitmapString(ofToString(point->bikes.at(i)), 10+(i*(width/10)), ofGetHeight()-20);
}
- for(i=0; i < loc->dir_two.size(); i++) {
-
- ofDrawBitmapString(ofToString(loc->dir_two.at(i)), 10+(i*(width/10)), ofGetHeight()-50);
- }
-
- ofDrawBitmapString(loc->road, 20, ofGetHeight()-200);
+ ofDrawBitmapString(point->loc->name, 20, ofGetHeight()-200);
ofSetColor(100, 250, 60, 200);
@@ -158,21 +144,9 @@ void Visualizer::drawInterpolation(Location * loc) {
float finto = i / float(width);
//cout<<ofToString(finto)<<endl;
- float val = loc->dir_one.sampleAt(finto);
+ float val = point->bikes.sampleAt(finto);
ofCircle(10+i, ofMap(val, 0, data->maxStatEntry, ofGetHeight()-20, 20), 1);
}
- ofSetColor(250, 100, 60, 200);
-
- for(i=0; i < width; i++) {
-
- float finto = i / float(width);
-
- //cout<<ofToString(finto)<<endl;
- float val = loc->dir_two.sampleAt(finto);
-
- ofCircle(10+i, ofMap(val, 0, data->maxStatEntry, ofGetWindowHeight()-20, 20), 1);
- }
-
}
View
6 src/visualizer.h
@@ -30,7 +30,7 @@ class Visualizer {
void draw();
- void drawLocation(Location * loc);
+ void drawDataPoint(DataPoint * point);
void drawPath(Path * path);
void drawMap();
@@ -41,13 +41,13 @@ class Visualizer {
void drawInterpolation(MSA::Interpolator1D * ipo, float width, float height, float max);
- void drawInterpolation(Location * loc);
+ void drawInterpolation(DataPoint * point);
void drawTimeline();
Path * selectedPath;
- Location * selectedLoc;
+ DataPoint * selectedPoint;
};

0 comments on commit 60a5c75

Please sign in to comment.