float ofApp::getAverage(ofxJSONElement vals) { float sum = 0; for (int i = 0; i < vals.size(); i++) { sum += vals[i][1].asFloat(); } return sum / vals.size(); }
void ofApp::newDocument( int session_id, ofxJSONElement& json ) { if ( json.isMember("type") ) { string type = json[ "type" ].asString(); //openTableDocument* document = m_current_session->getCurrentDocument(); if ( type == "image" ) { openTableImageCollection* collection = ( openTableImageCollection* ) m_current_session->getDocument( 0 ); openTableImageGroup* group = new openTableImageGroup; group->setup(json); if ( group->nImages() > 0 ) { ofVec2f p = m_server.getSessionPosition(session_id); if (p.y < ofGetHeight() / 2) { p.y += 120.f; } else { p.y -= 120.f; } group->setPosition(p); collection->addGroup(group); } else { delete group; } m_db.save(); } else if ( type == "text" ) { openTableBusinessModelCanvas* bmc = ( openTableBusinessModelCanvas* ) m_current_session->getDocument( 1 ); bmc->updateElement(json); m_db.save(); } else if( type == "session" ) { m_current_session->unlock(); if ( json.isMember("sessions") ) { m_db.markAllDocumentsOfTypeForDelete( "session" ); for ( int i = 0; i < json[ "sessions"].size(); i++ ) { string id = json[ "sessions"][ i ].isMember( "id" ) ? json[ "sessions"][ i ][ "id" ].asString() : ""; string title = json[ "sessions"][ i ][ "session_title" ].asString(); bool active = json[ "sessions"][ i ][ "session_active" ].asBool(); openTableSession* session; if ( id.length() > 0 ) { session = ( openTableSession* )m_db.get(id); // // update existing // session->setSessionTitle( title ); m_db.clearPendingDelete(id); } else { // // create new // session = ( openTableSession* )m_db.add( "session" ); session->setSessionTitle(title); } if ( active ) m_current_session = session; } m_db.commitPendingDeletes(); m_db.save(); } } } }
void ofxLayout::loadData(ofxJSONElement jsonData){ vector<string> keys = jsonData.getMemberNames(); for(int i = 0; i < keys.size(); i++){ string key = keys[i]; ofxJSONElement value = jsonData[key]; setData(key, value.asString()); } }
ofVec2f ofApp::getMinMax(ofxJSONElement vals) { ofVec2f minMax; float min; float max; for (int i = 0; i < vals.size(); i++) { if (i == 0) { min = vals[i][1].asFloat(); max = vals[i][1].asFloat(); } if (min > vals[i][1].asFloat()) { min = vals[i][1].asFloat(); } if (max < vals[i][1].asFloat()) { max = vals[i][1].asFloat(); } } minMax.set(min,max); return minMax; }
//-------------------------------------------------------------- void ofxTwitter::parseResponse(ofxJSONElement result) { if(result.isMember("statuses")) { data.clear(); ofxJSONElement trends = result["statuses"]; for(int i = 0; i < trends.size(); i++) { ofxTwitterTweet tweet; tweet.id_str = trends[i]["id_str"].asString(); tweet.created_at = trends[i]["created_at"].asString(); tweet.language = trends[i]["language"].asString(); tweet.text = trends[i]["text"].asString(); if(trends[i]["geo"] != Json::Value::null) { tweet.geo = trends[i]["geo"]["type"].asString(); tweet.coordinates.x = trends[i]["geo"]["coordinates"][0].asFloat(); tweet.coordinates.y = trends[i]["geo"]["coordinates"][1].asFloat(); } tweet.source = trends[i]["source"].asString(); tweet.retweet_count = trends[i]["retweet_count"].asInt(); tweet.truncated = trends[i]["truncated"].asBool(); ofxJSONElement author = trends[i]["user"]; tweet.user.id_str = author["id_str"].asString(); tweet.user.uri = "https://twitter.com/"+author["screen_name"].asString(); tweet.user.name = author["name"].asString(); tweet.user.screen_name = author["screen_name"].asString(); tweet.user.description = author["description"].asString(); if(author["location"].asString() != " ") { tweet.user.location = author["location"].asString(); } tweet.user.lang = author["lang"].asString(); tweet.user.url = author["url"].asString(); tweet.user.default_profile = author["default_profile"].asBool(); tweet.user.default_profile_image = author["default_profile_image"].asBool(); tweet.user.geo_enabled = author["geo_enabled"].asBool(); tweet.user.profile_image_url = author["profile_image_url"].asString(); if(author["profile_image_url"] != Json::Value::null && bLoadUserProfileImageOnMemory) { ofLoadURLAsync(tweet.user.profile_image_url, "profile_"+tweet.user.id_str); } tweet.user.profile_banner_url = author["profile_banner_url"].asString(); if(author["profile_banner_url"] != Json::Value::null && bLoadUserBannerImageOnMemory) { ofLoadURLAsync(tweet.user.profile_banner_url, "banner_"+tweet.user.id_str); } tweet.user.profile_background_image_url = author["profile_background_image_url"].asString(); tweet.user.profile_background_color = author["profile_background_color"].asString(); tweet.user.profile_background_tile = author["profile_background_tile"].asBool(); tweet.user.profile_use_background_image = author["profile_use_background_image"].asBool(); data.push_back( tweet ); //tweet.print(); } ofLogNotice("ofxTwitter::parseResponse") << "(" << data.size() << ") Tweets ready"; } }
void Spot:: loadBackPoints( ofxJSONElement json,int _number){ // cleanPoints(); number = _number; frameCurrent=0; frameFirstBack=0; frameLastBack=0; int points = json.size(); if(points>= 2) { int pointBottomIndex=0; frameFirstBack= json[pointBottomIndex]["frame"].asInt(); frameCurrent=frameFirstBack; SpotPoint * pointBottom = new SpotPoint( json[pointBottomIndex]["x"].asInt(), json[pointBottomIndex]["y"].asInt(), json[pointBottomIndex]["scale"].asDouble()*SCALE_FACTOR, json[pointBottomIndex]["alpha"].asInt() ); backFollower = new SpotPoint( json[pointBottomIndex]["x"].asInt(), json[pointBottomIndex]["y"].asInt(), json[pointBottomIndex]["scale"].asDouble()*SCALE_FACTOR, json[pointBottomIndex]["alpha"].asInt() ); SpotPoint * pointTop; addBackPoint(frameCurrent,pointBottom); //pointsMap[frameCurrent]=pointBottom; frameCurrent++; for(int pointTopIndex=pointBottomIndex+1; pointTopIndex<points; pointTopIndex++) { pointTop = new SpotPoint( json[pointTopIndex]["x"].asInt(), json[pointTopIndex]["y"].asInt(), json[pointTopIndex]["scale"].asDouble()*SCALE_FACTOR, json[pointTopIndex]["alpha"].asInt() ); while(frameCurrent<=json[pointTopIndex]["frame"].asInt()) { addBackPoint(frameCurrent,pointInterPolateFrom( pointBottom, pointTop, json[pointBottomIndex]["frame"].asInt(), frameCurrent, json[pointTopIndex]["frame"].asInt() )); //cout << "added frame: "+ofToString(frameCurrent)+" points: "+ofToString(pointsMap.size())<< endl; frameCurrent++; } addBackPoint(frameCurrent,pointTop); pointBottom = pointTop; pointBottomIndex = pointTopIndex; } frameLastBack=frameCurrent; smoothOutBacks(frameFirstBack,frameLastBack); cout <<" " << ofToString(frameCurrent)<< " frames "<< endl; } else { cout << "Spot: any point"<< endl; } cout << "[MAP SIZE ONCE LOADED ]: "+ofToString(backPointsMap.size())<< endl; cout << "[FRAMES]: "+ofToString(frameLastBack - frameFirstBack )<< endl; }
void Spot:: loadFrontPoints( ofxJSONElement json,int _number){ // cleanPoints(); number = _number; frameCurrent=0; frameFirstFront=0; frameLastFront=0; int points = json.size(); if(points>= 2) { int pointBottomIndex=0; frameFirstFront= json[pointBottomIndex]["frame"].asInt(); frameCurrent=frameFirstFront; SpotPoint * pointBottom = new SpotPoint( json[pointBottomIndex]["x"].asInt(), json[pointBottomIndex]["y"].asInt(), json[pointBottomIndex]["scale"].asDouble()*SCALE_FACTOR, json[pointBottomIndex]["alpha"].asInt() ); // frontFollower = new SpotPoint( json[pointBottomIndex]["x"].asInt(), json[pointBottomIndex]["y"].asInt(), json[pointBottomIndex]["scale"].asDouble()*SCALE_FACTOR, json[pointBottomIndex]["alpha"].asInt() ); SpotPoint * pointTop; addFrontPoint(frameCurrent,pointBottom); frameCurrent++; for(int pointTopIndex=pointBottomIndex+1; pointTopIndex<points; pointTopIndex++) { pointTop = new SpotPoint( json[pointTopIndex]["x"].asInt(), json[pointTopIndex]["y"].asInt(), json[pointTopIndex]["scale"].asDouble()*SCALE_FACTOR, json[pointTopIndex]["alpha"].asInt() ); while(frameCurrent<=json[pointTopIndex]["frame"].asInt()) { addFrontPoint(frameCurrent,pointInterPolateFrom( pointBottom, pointTop, json[pointBottomIndex]["frame"].asInt(), frameCurrent, json[pointTopIndex]["frame"].asInt() )); //cout << "added frame: "+ofToString(frameCurrent)+" points: "+ofToString(pointsMap.size())<< endl; frameCurrent++; } addFrontPoint(frameCurrent,pointTop); pointBottom = pointTop; pointBottomIndex = pointTopIndex; } frameLastFront=frameCurrent; smoothOutFronts(frameFirstFront,frameLastFront); cout <<" " << ofToString(frameCurrent)<< " frames "<< endl; } else { cout << "Spot: dont have any point"<< endl; } cout << "[frontPointsMap ONCE LOADED ]: "+ofToString(frontPointsMap.size())<< endl; cout << "[FRAMES]: "+ofToString(frameLastFront - frameFirstFront )<< endl; verdana.loadFont("verdana.ttf", 40, true, true); verdana.setLineHeight(34.0f); verdana.setLetterSpacing(1.035); }