6 #include <unordered_map> 28 #include "rapidjson/document.h" 30 #include "rapidjson/error/en.h" 32 #include <sys/types.h> 69 string getOSMBaseURL()
const {
71 return "http://cci-bridges-osm.uncc.edu/";
76 : bridges_inst(br), my_cache(120) {}
95 using namespace rapidjson;
100 ServerComm::makeRequest(
"http://bridgesdata.herokuapp.com/api/games",
101 {
"Accept: application/json"}).c_str());
103 const Value& D = d[
"data"];
104 vector<Game> wrapper;
105 for (SizeType i = 0; i < D.Size(); i++) {
106 const Value& V = D[i];
107 const Value& G = V[
"genre"];
109 vector<string> genre;
110 for (SizeType j = 0; j < G.Size(); j++) {
111 genre.push_back(G[j].GetString());
114 Game( V[
"game"].GetString(),
115 V[
"platform"].GetString(),
116 V[
"rating"].GetDouble(),
133 using namespace rapidjson;
135 vector<ActorMovieIMDB> wrapper;
136 string url =
"http://bridgesdata.herokuapp.com/api/imdb?limit=" +
140 d.Parse(ServerComm::makeRequest( url, {
"Accept: application/json"}).c_str());
142 const Value& D = d[
"data"];
143 for (SizeType i = 0; i < D.Size(); i++) {
144 const Value& V = D[i];
147 V[
"actor"].GetString(),
148 V[
"movie"].GetString()
167 using namespace rapidjson;
169 vector<ActorMovieIMDB> wrapper;
170 string url =
"http://bridgesdata.herokuapp.com/api/imdb2";
173 d.Parse(ServerComm::makeRequest( url, {
"Accept: application/json"}).c_str());
175 const Value& D = d[
"data"];
176 for (SizeType i = 0; i < D.Size(); i++) {
177 const Value& V = D[i];
178 string actor = V[
"actor"].GetString();
179 string movie = V[
"movie"].GetString();
180 double rating = V[
"rating"].GetDouble();
181 const Value& G = V[
"genres"];
182 vector<string> genres;
183 for (SizeType j = 0; j < G.Size(); j++) {
184 genres.push_back(G[j].GetString());
186 wrapper.push_back(
ActorMovieIMDB( actor, movie, (
float)rating, genres));
203 using namespace rapidjson;
205 vector<EarthquakeUSGS> wrapper;
207 d.Parse(ServerComm::makeRequest(
"http://earthquakes-uncc.herokuapp.com/eq",
208 {
"Accept: application/json"}).c_str());
209 for (SizeType i = 0; i < d.Size(); i++) {
210 const Value& V = d[i][
"properties"];
211 const Value& G = d[i][
"geometry"][
"coordinates"];
214 V[
"mag"].GetDouble(),
217 V[
"place"].GetString(),
218 V[
"title"].GetString(),
219 V[
"url"].GetString(),
220 V[
"time"].GetString() )
225 d.Parse(ServerComm::makeRequest(
"http://earthquakes-uncc.herokuapp.com/eq/latest/" +
226 to_string(number), {
"Accept: application/json"}).c_str());
228 const Value& D = d[
"Earthquakes"];
229 for (SizeType i = 0; i < D.Size(); i++) {
230 const Value& V = D[i][
"properties"];
231 const Value& G = D[i][
"geometry"][
"coordinates"];
235 V[
"mag"].GetDouble(),
238 V[
"place"].GetString(),
239 V[
"title"].GetString(),
240 V[
"url"].GetString(),
241 V[
"time"].GetString() )
263 bool textonly =
false) {
264 using namespace rapidjson;
266 vector<Shakespeare> wrapper;
268 string url =
"http://bridgesdata.herokuapp.com/api/shakespeare/";
270 if (type ==
"plays" || type ==
"poems")
273 url +=
"?format=simple";
276 d.Parse(ServerComm::makeRequest( url, {
"Accept: application/json"}).c_str());
278 const Value& D = d[
"data"];
279 for (SizeType i = 0; i < D.Size(); i++) {
280 const Value& V = D[i];
283 V[
"title"].GetString(),
284 V[
"type"].GetString(),
285 V[
"text"].GetString()
309 using namespace rapidjson;
312 vector<Song> wrapper;
313 string url =
"http://bridgesdata.herokuapp.com/api/songs/find/";
315 if (songTitle.size() > 0)
318 throw "Incorrect use of getSong. songTitle should be given.";
321 if (artistName.size())
322 url +=
"?artistName=" + artistName;
324 throw "Incorrect use of getSong. artistName should be given.";
327 string::size_type n = 0;
328 while ( (n = url.find(
" ", n)) != string::npos) {
329 url.replace(n, 1,
"%20");
333 d.Parse(ServerComm::makeRequest( url, {
"Accept: application/json"}).c_str());
335 string artist = (d.HasMember(
"artist")) ?
336 d[
"artist"].GetString() : string();
337 string song = (d.HasMember(
"song")) ?
338 d[
"song"].GetString() : string();
339 string album = (d.HasMember(
"album")) ?
340 d[
"album"].GetString() : string();
341 string lyrics = (d.HasMember(
"lyrics")) ?
342 d[
"lyrics"].GetString() : string();
343 string release_date = (d.HasMember(
"release_date")) ?
344 d[
"release_date"].GetString() : string();
346 return Song (artist, song, album, lyrics, release_date);
364 using namespace rapidjson;
367 vector<Song> all_songs;
369 string url =
"http://bridgesdata.herokuapp.com/api/songs/";
372 d.Parse(ServerComm::makeRequest( url, {
"Accept: application/json"}).c_str());
374 const Value& D = d[
"data"];
377 for (SizeType i = 0; i < D.Size(); i++) {
378 const Value& v = D[i];
381 string artist = (v.HasMember(
"artist")) ? v[
"artist"].GetString() : string();
382 string song = (v.HasMember(
"song")) ? v[
"song"].GetString() : string();
383 string album = (v.HasMember(
"album")) ? v[
"album"].GetString() : string();
384 string lyrics = (v.HasMember(
"lyrics")) ? v[
"lyrics"].GetString() : string();
385 string release_date = (v.HasMember(
"release_date")) ?
386 v[
"release_date"].GetString() : string();
387 all_songs.push_back(
Song ( artist, song, album, lyrics, release_date) );
404 using namespace rapidjson;
407 vector<GutenbergBook> wrapper;
408 string url =
"http://bridgesdata.herokuapp.com/api/books";
410 url +=
"?limit=" + to_string(num);
413 d.Parse(ServerComm::makeRequest( url, {
"Accept: application/json"}).c_str());
414 const Value& D = d[
"data"];
415 for (SizeType i = 0; i < D.Size(); i++) {
416 const Value& V = D[i];
418 const Value& A = V[
"author"];
419 const Value& L = V[
"languages"];
422 for (SizeType j = 0; j < L.Size(); j++) {
423 lang.push_back(L[j].GetString());
426 const Value& G = V[
"genres"];
427 vector<string> genre;
428 for (SizeType j = 0; j < G.Size(); j++) {
429 genre.push_back(G[j].GetString());
432 const Value& S = V[
"subjects"];
433 vector<string> subject;
434 for (SizeType j = 0; j < S.Size(); j++) {
435 subject.push_back(S[j].GetString());
438 const Value& M = V[
"metrics"];
441 A[
"name"].GetString(),
444 V[
"title"].GetString(),
448 M[
"characters"].GetInt(),
450 M[
"sentences"].GetInt(),
451 M[
"difficultWords"].GetInt(),
452 V[
"url"].GetString(),
453 V[
"downloads"].GetInt()
465 using namespace rapidjson;
468 vector<CancerIncidence> wrapper;
469 string url =
"http://bridgesdata.herokuapp.com/api/cancer/withlocations";
471 url +=
"?limit=" + to_string(num);
474 d.Parse(ServerComm::makeRequest( url, {
"Accept: application/json"}).c_str());
477 const Value& D = d[
"data"];
480 for (SizeType i = 0; i < D.Size(); i++) {
481 const Value& v = D[i];
482 const Value& age = v[
"Age"];
490 const Value& data = v[
"Data"];
494 c.
setRace(data[
"Race"].GetString());
500 const Value& loc = v[
"loc"];
504 wrapper.push_back(c);
516 using namespace rapidjson;
520 osm_data.Parse(osm_json.c_str());
525 if (osm_data.HasMember(
"nodes")) {
526 vector<OSMVertex> vertices;
527 Value& nodes = osm_data[
"nodes"];
529 vector<long> vertex_ids;
531 for (SizeType i = 0; i < nodes.Size(); i++) {
532 const Value& node = nodes[i];
535 vertex_ids.push_back(
id);
536 double lat = node[1].GetDouble(), longit = node[2].GetDouble();
537 vertices.push_back(
OSMVertex(
id, lat, longit));
544 if (osm_data.HasMember(
"edges")) {
545 vector<OSMEdge> edges;
546 Value& links = osm_data[
"edges"];
548 for (SizeType i = 0; i < links.Size(); i++) {
549 const Value& link = links[i];
552 double dist = link[2].GetDouble();
554 edges.push_back(
OSMEdge(id1, id2, dist));
560 if (osm_data.HasMember(
"meta")) {
562 Value& meta = osm_data[
"meta"];
563 double lat_min = meta[
"lat_min"].GetDouble();
564 double lat_max = meta[
"lat_max"].GetDouble();
565 double longit_min = meta[
"lon_min"].GetDouble();
566 double longit_max = meta[
"lon_max"].GetDouble();
569 osm.
setName(meta[
"name"].GetString());
586 double lat_max,
double long_max,
string level =
"default") {
589 string hash_url = getOSMBaseURL() +
"hash?minLon=" + std::to_string(long_min) +
590 "&minLat=" + std::to_string(lat_min) +
591 "&maxLon=" + std::to_string(long_max) +
592 "&maxLat=" + std::to_string(lat_max) +
593 "&level=" + ServerComm::encodeURLPart(level);
597 getOSMBaseURL() +
"coords?minLon=" + std::to_string(long_min) +
598 "&minLat=" + std::to_string(lat_min) +
599 "&maxLon=" + std::to_string(long_max) +
600 "&maxLat=" + std::to_string(lat_max) +
601 "&level=" + ServerComm::encodeURLPart(level);
605 std::cerr <<
"Hitting hash URL: " << hash_url <<
"\n";
606 string hash_value = ServerComm::makeRequest(hash_url, {
"Accept: application/json"});
609 std::string osm_json;
613 if (my_cache.
inCache(hash_value) ==
true) {
615 if (my_cache.
inCache(hash_value)) {
616 osm_json = my_cache.
getDoc(hash_value);
621 std::cout <<
"Exception while reading from cache. Ignoring cache and continue." << std::endl;
625 else if (hash_value.compare(
"false") == 0 || my_cache.
inCache(hash_value) ==
false) {
629 std::cerr <<
"Hitting json URL: " << url <<
"\n";
631 osm_json = ServerComm::makeRequest(url, {
"Accept: application/json"});
633 std::cerr <<
"Hitting hash URL: " << hash_url <<
"\n";
635 hash_value = ServerComm::makeRequest(hash_url, {
"Accept: application/json"});
637 if (hash_value.compare(
"false") == 0) {
638 std::cerr <<
"Error while gathering hash data for generated map..." << std::endl;
639 std::cerr << osm_json << std::endl;
645 my_cache.
putDoc(hash_value, osm_json);
651 std::cerr <<
"Exception while storing in cache. Weird but not critical." << std::endl;
653 std::cerr <<
"Tried to store hash=" << hash_value <<
" key=" << osm_json << std::endl;
657 return getOSMDataFromJSON(osm_json);
671 string hash_url = getOSMBaseURL() +
"hash?location=" + ServerComm::encodeURLPart(location) +
672 "&level=" + ServerComm::encodeURLPart(level);
676 getOSMBaseURL() +
"loc?location=" + ServerComm::encodeURLPart(location) +
677 "&level=" + ServerComm::encodeURLPart(level);
681 std::cerr <<
"Hitting hash URL: " << hash_url <<
"\n";
682 string hash_value = ServerComm::makeRequest(hash_url, {
"Accept: application/json"});
685 std::string osm_json;
687 std::cerr <<
"url: " << url <<
"\n";
689 if (my_cache.
inCache(hash_value) ==
true) {
691 if (my_cache.
inCache(hash_value)) {
692 osm_json = my_cache.
getDoc(hash_value);
696 std::cout <<
"Exception while reading from cache. Ignoring cache and continue." << std::endl;
700 else if (hash_value.compare(
"false") == 0 || my_cache.
inCache(hash_value) ==
false) {
702 std::cerr <<
"Hitting json URL: " << url <<
"\n";
703 osm_json = ServerComm::makeRequest(url, {
"Accept: application/json"});
705 std::cerr <<
"Hitting hash URL: " << hash_url <<
"\n";
706 hash_value = ServerComm::makeRequest(hash_url, {
"Accept: application/json"});
707 if (hash_value.compare(
"false") == 0) {
708 std::cerr <<
"Error while gathering hash data for generated map..." << std::endl;
709 std::cerr << osm_json << std::endl;
715 my_cache.
putDoc(hash_value, osm_json);
719 std::cerr <<
"Exception while storing in cache. Weird but not critical." << std::endl;
721 std::cerr <<
"Tried to store hash=" << hash_value <<
" key=" << osm_json << std::endl;
725 return getOSMDataFromJSON(osm_json);
740 std::transform(location.begin(), location.end(), location.begin(),
742 std::string osm_json;
743 bool from_cache =
false;
745 if (my_cache.
inCache(location)) {
746 osm_json = my_cache.
getDoc(location);
752 std::cout <<
"Exception while reading from cache. Ignoring cache and continue." << std::endl;
755 string url = string(
"http://osm-api.herokuapp.com/name/") + location;
759 osm_json = ServerComm::makeRequest(url, {
"Accept: application/json"});
762 my_cache.
putDoc(location, osm_json);
766 std::cerr <<
"Exception while storing in cache. Weird but not critical." << std::endl;
770 return getOSMDataFromJSON(osm_json);
789 int subassignment = 0) {
792 std::string s = this->getAssignment(user, assignment, subassignment);
794 rapidjson::Document doc;
795 doc.Parse(s.c_str());
796 if (doc.HasParseError())
797 throw "Malformed JSON";
800 const auto& assjson = doc.FindMember(
"assignmentJSON");
802 if (assjson == doc.MemberEnd())
803 throw "Malformed GraphAdjacencyList JSON: no assignmentJSON";
806 const auto& dataArray = assjson->value.FindMember(
"data");
808 if (dataArray == assjson->value.MemberEnd()
809 || dataArray->value.IsArray() ==
false)
810 throw "Malformed GraphAdjacencyList JSON: No data";
812 const auto& data = dataArray->value.GetArray()[0];
815 const auto& dataVisual = data.FindMember(
"visual");
817 if (dataVisual == data.MemberEnd() ||
818 dataVisual->value.IsString() ==
false)
819 throw "Malformed GraphAdjacencyList JSON";
821 std::string assignment_type = dataVisual->value.GetString();
823 if (assignment_type !=
"GraphAdjacencyList")
824 throw "Malformed GraphAdjacencyList JSON: Not a GraphAdjacencyList";
828 const auto& nodes = data.FindMember(
"nodes");
829 if (nodes == data.MemberEnd() ||
830 nodes->value.IsArray() ==
false)
831 throw "Malformed GraphAdjacencyList JSON: malformed nodes";
834 const auto& nodeArray = nodes->value.GetArray();
835 int nbVertex = nodeArray.Size();
836 for (
int i = 0; i < nbVertex; ++i) {
839 const auto& vertexJSONstr = nodeArray[i];
841 const auto& nameJSON = vertexJSONstr.FindMember(
"name");
842 if (nameJSON != vertexJSONstr.MemberEnd()
843 && nameJSON->value.IsString()) {
844 name = nameJSON->value.GetString();
852 const auto& links = data.FindMember(
"links");
853 if (links == data.MemberEnd() ||
854 links->value.IsArray() ==
false)
855 throw "Malformed GraphAdjacencyList JSON: malformed links";
857 const auto& linkArray = links->value.GetArray();
858 int nbLink = linkArray.Size();
859 for (
int i = 0; i < nbLink; ++i) {
865 const auto& linkJSONstr = linkArray[i];
868 const auto& nameJSON = linkJSONstr.FindMember(
"label");
869 if (nameJSON != linkJSONstr.MemberEnd()
870 && nameJSON->value.IsString()) {
871 name = nameJSON->value.GetString();
875 const auto& srcJSON = linkJSONstr.FindMember(
"source");
876 if (srcJSON == linkJSONstr.MemberEnd()
877 || srcJSON->value.IsInt() ==
false) {
878 throw "Malformed GraphAdjacencyList JSON: malformed link";
880 src = srcJSON->value.GetInt();
884 const auto& dstJSON = linkJSONstr.FindMember(
"target");
885 if (dstJSON == linkJSONstr.MemberEnd()
886 || dstJSON->value.IsInt() ==
false) {
887 throw "Malformed GraphAdjacencyList JSON: malformed link";
889 dest = dstJSON->value.GetInt();
892 const auto& wgtJSON = linkJSONstr.FindMember(
"weight");
893 if (wgtJSON == linkJSONstr.MemberEnd()
894 || wgtJSON->value.IsInt() ==
false) {
895 throw "Malformed GraphAdjacencyList JSON: malformed link";
897 wgt = wgtJSON->value.GetInt();
917 int subassignment = 0) {
919 std::string s = this->getAssignment(user, assignment, subassignment);
921 rapidjson::Document doc;
922 doc.Parse(s.c_str());
923 if (doc.HasParseError())
924 throw "Malformed JSON";
927 std::string assignment_type = doc[
"assignment_type"].GetString();
929 if (assignment_type !=
"ColorGrid")
930 throw "Malformed ColorGrid JSON: Not a ColorGrid";
933 throw "Malformed JSON: Not a Bridges assignment?";
938 auto& data = doc[
"data"][0];
940 std::string encoding = data[
"encoding"].GetString();
941 if (encoding !=
"RAW" && encoding !=
"RLE")
942 throw "Malformed ColorGrid JSON: encoding not supported";
946 const auto& dimensions = data[
"dimensions"];
947 int dimx = dimensions[0].GetInt();
948 int dimy = dimensions[1].GetInt();
951 std::cerr <<
"Dimensions: " << dimx <<
"x" << dimy << std::endl;
954 std::string base64_encoded_assignment = data[
"nodes"][0].GetString();
962 if (encoding ==
"RAW") {
964 std::cerr <<
"decoding RAW" << std::endl;
966 std::cerr <<
"length: " << decoded.size() << std::endl;
967 if (decoded.size() < dimx * dimy * 4)
968 throw "Malformed ColorGrid JSON: nodes is smaller than expected";
977 for (
int x = 0; x < dimx; ++x) {
978 for (
int y = 0; y < dimy; ++y) {
980 (
int)decoded[base + 1],
981 (
int)decoded[base + 2],
982 (
int)decoded[base + 3]
990 else if (encoding ==
"RLE") {
992 std::cerr <<
"Decoding RLE" << std::endl;
994 int currentInDecoded = 0;
996 while (currentInDecoded != decoded.size()) {
997 if (currentInDecoded + 5 > decoded.size())
998 throw "Malformed ColorGrid JSON: nodes is not a multiple of 5";
1002 int repeat = (
BYTE) decoded[currentInDecoded++];
1003 int r = (
BYTE) decoded[currentInDecoded++];
1004 int g = (
BYTE) decoded[currentInDecoded++];
1005 int b = (
BYTE) decoded[currentInDecoded++];
1006 int a = (
BYTE) decoded[currentInDecoded++];
1009 std::cerr <<
"indecoded: " << currentInDecoded
1010 <<
" repeat: " << (
int)repeat
1011 <<
" color(" << (int)r <<
"," << (
int)g <<
"," << (int)b <<
"," << (
int)a <<
")" 1016 while (repeat >= 0) {
1017 int posX = currentInCG / dimy;
1018 int posY = currentInCG % dimy;
1019 if (posX >= dimx || posY >= dimy) {
1021 std::cerr << posX <<
" " << dimx <<
" " << posY <<
" " << dimy << std::endl;
1022 throw "Malformed ColorGrid JSON: Too much data in nodes";
1024 cg.
set(posX, posY, c);
1031 std::cerr <<
"written " << currentInCG <<
" pixels" << std::endl;
1032 if (currentInCG != dimx * dimy)
1033 throw "Malformed ColorGrid JSON: Not enough data in nodes";
1039 throw "Malformed ColorGrid JSON";
1052 std::string getAssignment(std::string user,
1054 int subassignment = 0) {
1055 std::vector<std::string> headers;
1057 std::stringstream ss;
1061 ss << bridges_inst->getServerURL();
1063 ss << bridges::Bridges::getDefaultServerURL();
1064 ss <<
"/assignmentJSON/" 1065 << assignment <<
".";
1066 ss << std::setfill(
'0') << std::setw(2) << subassignment;
1069 std::string url = ss.str();
1073 std::string s = bridges::ServerComm::makeRequest(url, headers);
1079 void removeFirstOccurence (std::string & str,
const std::string & toRemove) {
1080 size_t pos = str.find(toRemove);
1081 if (pos != std::string::npos) {
1082 str.erase(pos, toRemove.length());
1095 void getWikidataActorMovieDirect (
int yearbegin,
int yearend, std::vector<MovieActorWikidata>& vout) {
1096 std::string codename =
"wikidata-actormovie-" + std::to_string(yearbegin) +
"-" + std::to_string(yearend);
1098 bool from_cache =
false;
1100 if (my_cache.
inCache(codename)) {
1101 json = my_cache.
getDoc(codename);
1107 std::cout <<
"Exception while reading from cache. Ignoring cache and continue." << std::endl;
1112 std::vector<std::string> http_headers;
1113 http_headers.push_back(
"User-Agent: bridges-cxx");
1114 http_headers.push_back(
"Accept: application/json");
1116 string url =
"https://query.wikidata.org/sparql?";
1125 std::string sparqlquery =
"SELECT ?movie ?movieLabel ?actor ?actorLabel WHERE \ 1127 ?movie wdt:P31 wd:Q11424.\ 1128 ?movie wdt:P161 ?actor.\ 1129 ?movie wdt:P364 wd:Q1860.\ 1130 ?movie wdt:P577 ?date.\ 1131 FILTER(YEAR(?date) >= " + std::to_string(yearbegin) +
" && YEAR(?date) <= " + std::to_string(yearend) +
").\ 1132 SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\". } \ 1134 url +=
"query=" + ServerComm::encodeURLPart(sparqlquery);
1136 url +=
"format=json";
1139 json = ServerComm::makeRequest(url, http_headers);
1142 my_cache.
putDoc(codename, json);
1146 std::cerr <<
"Exception while storing in cache. Weird but not critical." << std::endl;
1151 using namespace rapidjson;
1152 rapidjson::Document doc;
1153 doc.Parse(json.c_str());
1154 if (doc.HasParseError())
1155 throw "Malformed JSON";
1158 const auto& resultsArray = doc[
"results"][
"bindings"].GetArray();
1160 for (
auto& mak_json : resultsArray) {
1166 std::string actoruri = mak_json[
"actor"][
"value"].GetString();
1167 std::string movieuri = mak_json[
"movie"][
"value"].GetString();
1168 removeFirstOccurence (actoruri,
"http://www.wikidata.org/entity/");
1170 removeFirstOccurence (movieuri,
"http://www.wikidata.org/entity/");
1175 mak.
setActorName(mak_json[
"actorLabel"][
"value"].GetString());
1176 mak.
setMovieName(mak_json[
"movieLabel"][
"value"].GetString());
1177 vout.push_back(mak);
1182 throw "Malformed JSON: Not from wikidata?";
1206 std::vector<MovieActorWikidata> ret;
1207 for (
int y = yearbegin; y <= yearend; ++y) {
1208 cout <<
"getting year " << y << endl;
1209 getWikidataActorMovieDirect (y, y, ret);
1227 double latitMin,
double longitMin,
1228 double latitMax,
double longitMax,
double res = 0.0166) {
1233 "http://cci-bridges-elevation-t.dyn.uncc.edu/";
1235 string elev_str =
"elevation?";
1238 "&minLon=" + std::to_string(longitMin) +
1239 "&minLat=" + std::to_string(latitMin) +
1240 "&maxLon=" + std::to_string(longitMax) +
1241 "&maxLat=" + std::to_string(latitMax);
1243 string resn_str =
"&resX=" + std::to_string(res)
1244 +
"&resY=" + std::to_string(res);
1246 string elev_data_url =
1247 server_str + elev_str + bbox_str + resn_str;
1250 cerr <<
"Hitting data URL: " << elev_data_url <<
"\n";
1251 string hash_str =
"hash?";
1252 string hash_url = server_str + hash_str + bbox_str;
1257 cerr <<
"Hitting hash URL: " << hash_url <<
"\n";
1260 string hash_value = ServerComm::makeRequest(hash_url,
1261 {
"Accept: application/json"});
1266 if (my_cache.
inCache(hash_value)) {
1268 elev_json = my_cache.
getDoc(hash_value);
1272 cout <<
"Exception while reading from cache. Ignoring cache." << std::endl;
1278 cerr <<
"Hitting json URL: " << elev_data_url <<
"\n";
1281 elev_json = ServerComm::makeRequest(elev_data_url,
1282 {
"Accept: application/json"});
1285 cerr <<
"Hitting elev data URL: " << elev_data_url <<
"\n";
1287 string hash_value = ServerComm::makeRequest(hash_url,
1288 {
"Accept: application/json"});
1290 if (hash_value ==
"false") {
1291 cerr <<
"Error in getting hash value for generated map..." << endl;
1292 cerr << elev_json << endl;
1298 my_cache.
putDoc(hash_value, elev_json);
1302 cerr <<
"Exception while storing in cache. Weird but not critical." 1306 return getElevationDataFromJSON(elev_json);
1314 stringstream ss(elev_json);
1316 int rows, cols, elev_val;
1317 double ll_x, ll_y, cell_size;
1321 ss >> tmp >> cols >> tmp >> rows >>
1322 tmp >> ll_x >> tmp >> ll_y >>
1336 for (
int i = 0; i < rows; i++) {
1337 for (
int j = 0; j < cols; j++) {
1339 elev_data->
setVal(i, j, elev_val);
void setEventType(const string &et)
Set event type.
Definition: CancerIncidence.h:233
void setYear(int y)
Definition: CancerIncidence.h:183
void setMovieURI(std::string mu)
Definition: MovieActorWikidata.h:18
void setAffectedArea(const string &area)
Set cancer incidenc area.
Definition: CancerIncidence.h:269
A Gutenberg Book object metadata only, used along with the books data source.
Definition: GutenbergBook.h:25
void setCrudeRate(double cr)
Definition: CancerIncidence.h:126
vector< Shakespeare > getShakespeareData(string type="", bool textonly=false)
Get data of Shakespeare works (plays, poems)
Definition: DataSource.h:262
Definition: ActorMovieIMDB.h:10
A Shakespeare book object, used along with the Shakespeare books data source.
Definition: Shakespeare.h:28
virtual void putDoc(const std::string &hash_value, const std::string &content) override
Definition: Cache.h:168
std::vector< MovieActorWikidata > getWikidataActorMovie(int yearbegin, int yearend)
This function returns the Movie and Actors playing in them between two years.
Definition: DataSource.h:1195
Definition: MovieActorWikidata.h:8
void setCrudeRate_CI_Lower(double cr_l)
Definition: CancerIncidence.h:145
void setCrudeRate_CI_Upper(double cr_u)
Set crude rate CI (upper)
Definition: CancerIncidence.h:165
vector< Game > getGameData()
Definition: DataSource.h:94
This class provides methods to represent adjacency list based graphs.
Definition: Element.h:19
void setActorName(std::string an)
Definition: MovieActorWikidata.h:30
A Song object, used along with the Songs data source.
Definition: Song.h:24
long OSMVertexID
Definition: OSMVertex.h:30
vector< Song > getSongData()
Definition: DataSource.h:363
Class that hold Open Street Map edges.
Definition: OSMEdge.h:21
void setLocationX(double locX)
Set location (X coord)
Definition: CancerIncidence.h:303
This is a class in BRIDGES for representing an image.
Definition: ColorGrid.h:22
bridges::ColorGrid getColorGridFromAssignment(const std::string &user, int assignment, int subassignment=0)
Definition: DataSource.h:915
void setName(const string &n)
change the name of the dataset
Definition: OSMData.h:222
void setAgeAdjustedCI_Lower(double ci_l)
Definition: CancerIncidence.h:90
virtual std::string getDoc(const std::string &hash_value) override
Definition: Cache.h:152
OSMData getOSMDataOld(string location)
old interface for the OSM data set.
Definition: DataSource.h:739
vector< ActorMovieIMDB > getActorMovieIMDBData(int number=0)
Definition: DataSource.h:132
This class represents Color, and supports rgba, hexadecimal and named color values.
Definition: Color.h:51
This class contains methods to connect and transmit a user's data structure representation to the Bri...
Definition: Bridges.h:39
void addVertex(const K &k, const E1 &e=E1())
Definition: GraphAdjList.h:96
void setActorURI(std::string au)
Definition: MovieActorWikidata.h:22
void setLocationY(double locY)
Set location (Y coord)
Definition: CancerIncidence.h:321
vector< EarthquakeUSGS > getEarthquakeUSGSData(int number=0)
Definition: DataSource.h:202
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
This class provides an API to various data sources used in BRIDGES.
Definition: DataSource.h:59
void setPopulation(int pop)
Set population size.
Definition: CancerIncidence.h:251
void setyll(int y_ll)
Definition: ElevationData.h:163
void setMovieName(std::string mn)
Definition: MovieActorWikidata.h:26
void setVertices(const vector< OSMVertex > &verts)
replace the vertices stored by this new set.
Definition: OSMData.h:267
vector< GutenbergBook > getGutenbergBookData(int num=0)
Definition: DataSource.h:403
A class to hold actor movie data – using IMDB dataset.
Definition: ActorMovieIMDB.h:19
void setLatLongRange(double *lat_range, double *longit_range)
set the latitude and longitude range of the dataset
Definition: OSMData.h:108
void setAgeAdjustedCI_Upper(double ci_u)
Definition: CancerIncidence.h:109
vector< CancerIncidence > getCancerIncidenceData(int num=0)
Definition: DataSource.h:464
unsigned char BYTE
Definition: base64.h:44
Class that hold elevation data.
Definition: ElevationData.h:21
bridges::GraphAdjList< int, std::string > getGraphFromAssignment(const std::string &user, int assignment, int subassignment=0)
Definition: DataSource.h:787
Song getSong(string songTitle, string artistName)
Definition: DataSource.h:308
ElevationData * getElevationData(double latitMin, double longitMin, double latitMax, double longitMax, double res=0.0166)
Definition: DataSource.h:1226
Class that hold Open Street Map vertices.
Definition: OSMData.h:34
void setRace(const string &r)
Set race.
Definition: CancerIncidence.h:216
DataSource(bridges::Bridges *br=nullptr)
Definition: DataSource.h:75
void set(int row, int col, E val)
Definition: Grid.h:144
OSMData getOSMData(double lat_min, double long_min, double lat_max, double long_max, string level="default")
Definition: DataSource.h:585
ElevationData * getElevationDataFromJSON(string elev_json)
Definition: DataSource.h:1310
void setxll(int x_ll)
Definition: ElevationData.h:145
OSMData getOSMData(string location, string level="default")
Definition: DataSource.h:669
DataSource(bridges::Bridges &br)
Definition: DataSource.h:78
void setCellSize(int cell_size)
Definition: ElevationData.h:181
void setAgeAdjustedRate(double aar)
Definition: CancerIncidence.h:69
virtual bool inCache(const std::string &hash_value) override
Definition: Cache.h:161
void setEdges(const vector< OSMEdge > &e)
set edges
Definition: OSMData.h:305
A Game object, used along with the Games data source.
Definition: Game.h:24
A class representing the attributes for cancer incidence.
Definition: CancerIncidence.h:26
OSMData getOSMDataFromJSON(const string &osm_json)
Definition: DataSource.h:515
Class that hold earthquake data, for use with USGIS retrieved quake data.
Definition: EarthquakeUSGS.h:21
void setVal(int r, int c, int val)
Definition: ElevationData.h:108
vector< ActorMovieIMDB > getActorMovieIMDBData2()
Definition: DataSource.h:166
void addEdge(const K &src, const K &dest, const E2 &data=E2())
add an edge with data.
Definition: GraphAdjList.h:119
Class that hold Open Street Map vertices.
Definition: OSMVertex.h:28
vector< BYTE > decode(string const &encoded_string)
Definition: base64.h:103