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()
310 using namespace rapidjson;
313 vector<Song> wrapper;
314 string url =
"http://bridgesdata.herokuapp.com/api/songs/find/";
316 if (songTitle.size() > 0)
319 throw "Incorrect use of getSong. songTitle should be given.";
322 if (artistName.size())
323 url +=
"?artistName=" + artistName;
325 throw "Incorrect use of getSong. artistName should be given.";
328 string::size_type n = 0;
329 while ( (n = url.find(
" ", n)) != string::npos) {
330 url.replace(n, 1,
"%20");
334 d.Parse(ServerComm::makeRequest( url, {
"Accept: application/json"}).c_str());
336 string artist = (d.HasMember(
"artist")) ?
337 d[
"artist"].GetString() : string();
338 string song = (d.HasMember(
"song")) ?
339 d[
"song"].GetString() : string();
340 string album = (d.HasMember(
"album")) ?
341 d[
"album"].GetString() : string();
342 string lyrics = (d.HasMember(
"lyrics")) ?
343 d[
"lyrics"].GetString() : string();
344 string release_date = (d.HasMember(
"release_date")) ?
345 d[
"release_date"].GetString() : string();
347 return Song (artist, song, album, lyrics, release_date);
365 using namespace rapidjson;
368 vector<Song> all_songs;
370 string url =
"http://bridgesdata.herokuapp.com/api/songs/";
373 d.Parse(ServerComm::makeRequest( url, {
"Accept: application/json"}).c_str());
375 const Value& D = d[
"data"];
378 for (SizeType i = 0; i < D.Size(); i++) {
379 const Value& v = D[i];
382 string artist = (v.HasMember(
"artist")) ? v[
"artist"].GetString() : string();
383 string song = (v.HasMember(
"song")) ? v[
"song"].GetString() : string();
384 string album = (v.HasMember(
"album")) ? v[
"album"].GetString() : string();
385 string lyrics = (v.HasMember(
"lyrics")) ? v[
"lyrics"].GetString() : string();
386 string release_date = (v.HasMember(
"release_date")) ?
387 v[
"release_date"].GetString() : string();
388 all_songs.push_back(
Song ( artist, song, album, lyrics, release_date) );
405 using namespace rapidjson;
408 vector<GutenbergBook> wrapper;
409 string url =
"http://bridgesdata.herokuapp.com/api/books";
411 url +=
"?limit=" + to_string(num);
414 d.Parse(ServerComm::makeRequest( url, {
"Accept: application/json"}).c_str());
415 const Value& D = d[
"data"];
416 for (SizeType i = 0; i < D.Size(); i++) {
417 const Value& V = D[i];
419 const Value& A = V[
"author"];
420 const Value& L = V[
"languages"];
423 for (SizeType j = 0; j < L.Size(); j++) {
424 lang.push_back(L[j].GetString());
427 const Value& G = V[
"genres"];
428 vector<string> genre;
429 for (SizeType j = 0; j < G.Size(); j++) {
430 genre.push_back(G[j].GetString());
433 const Value& S = V[
"subjects"];
434 vector<string> subject;
435 for (SizeType j = 0; j < S.Size(); j++) {
436 subject.push_back(S[j].GetString());
439 const Value& M = V[
"metrics"];
442 A[
"name"].GetString(),
445 V[
"title"].GetString(),
449 M[
"characters"].GetInt(),
451 M[
"sentences"].GetInt(),
452 M[
"difficultWords"].GetInt(),
453 V[
"url"].GetString(),
454 V[
"downloads"].GetInt()
467 using namespace rapidjson;
470 vector<CancerIncidence> wrapper;
471 string url =
"http://bridgesdata.herokuapp.com/api/cancer/withlocations";
473 url +=
"?limit=" + to_string(num);
476 d.Parse(ServerComm::makeRequest( url, {
"Accept: application/json"}).c_str());
479 const Value& D = d[
"data"];
482 for (SizeType i = 0; i < D.Size(); i++) {
483 const Value& v = D[i];
484 const Value& age = v[
"Age"];
492 const Value& data = v[
"Data"];
496 c.
setRace(data[
"Race"].GetString());
503 const Value& loc = v[
"loc"];
507 wrapper.push_back(c);
519 using namespace rapidjson;
523 osm_data.Parse(osm_json.c_str());
528 if (osm_data.HasMember(
"nodes")) {
529 vector<OSMVertex> vertices;
530 Value& nodes = osm_data[
"nodes"];
532 vector<long> vertex_ids;
534 for (SizeType i = 0; i < nodes.Size(); i++) {
535 const Value& node = nodes[i];
538 vertex_ids.push_back(
id);
539 double lat = node[1].GetDouble(), longit = node[2].GetDouble();
540 vertices.push_back(
OSMVertex(
id, lat, longit));
547 if (osm_data.HasMember(
"edges")) {
548 vector<OSMEdge> edges;
549 Value& links = osm_data[
"edges"];
551 for (SizeType i = 0; i < links.Size(); i++) {
552 const Value& link = links[i];
555 double dist = link[2].GetDouble();
557 edges.push_back(
OSMEdge(id1, id2, dist));
563 if (osm_data.HasMember(
"meta")) {
565 Value& meta = osm_data[
"meta"];
566 double lat_min = meta[
"lat_min"].GetDouble();
567 double lat_max = meta[
"lat_max"].GetDouble();
568 double longit_min = meta[
"lon_min"].GetDouble();
569 double longit_max = meta[
"lon_max"].GetDouble();
572 osm.
setName(meta[
"name"].GetString());
594 double lat_max,
double long_max,
string level =
"default") {
597 string hash_url = getOSMBaseURL() +
"hash?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 getOSMBaseURL() +
"coords?minLon=" + std::to_string(long_min) +
606 "&minLat=" + std::to_string(lat_min) +
607 "&maxLon=" + std::to_string(long_max) +
608 "&maxLat=" + std::to_string(lat_max) +
609 "&level=" + ServerComm::encodeURLPart(level);
613 std::cerr <<
"Hitting hash URL: " << hash_url <<
"\n";
614 string hash_value = ServerComm::makeRequest(hash_url, {
"Accept: application/json"});
617 std::string osm_json;
621 if (my_cache.
inCache(hash_value) ==
true) {
623 if (my_cache.
inCache(hash_value)) {
624 osm_json = my_cache.
getDoc(hash_value);
629 std::cout <<
"Exception while reading from cache. Ignoring cache and continue." << std::endl;
633 else if (hash_value.compare(
"false") == 0 || my_cache.
inCache(hash_value) ==
false) {
637 std::cerr <<
"Hitting json URL: " << url <<
"\n";
639 osm_json = ServerComm::makeRequest(url, {
"Accept: application/json"});
641 std::cerr <<
"Hitting hash URL: " << hash_url <<
"\n";
643 hash_value = ServerComm::makeRequest(hash_url, {
"Accept: application/json"});
645 if (hash_value.compare(
"false") == 0) {
646 std::cerr <<
"Error while gathering hash data for generated map..." << std::endl;
647 std::cerr << osm_json << std::endl;
653 my_cache.
putDoc(hash_value, osm_json);
659 std::cerr <<
"Exception while storing in cache. Weird but not critical." << std::endl;
661 std::cerr <<
"Tried to store hash=" << hash_value <<
" key=" << osm_json << std::endl;
665 return getOSMDataFromJSON(osm_json);
669 maxLat,
double maxLon, std::string amenity) {
673 std::string url = getOSMBaseURL() +
"amenity?location=" + location
674 +
"&amenity=" + amenity;
676 std::string hash_url = getOSMBaseURL() +
"hash?location=" + location
677 +
"&amenity=" + amenity;
697 string hash_url = getOSMBaseURL() +
"hash?location=" + ServerComm::encodeURLPart(location) +
698 "&level=" + ServerComm::encodeURLPart(level);
702 getOSMBaseURL() +
"loc?location=" + ServerComm::encodeURLPart(location) +
703 "&level=" + ServerComm::encodeURLPart(level);
707 std::cerr <<
"Hitting hash URL: " << hash_url <<
"\n";
708 string hash_value = ServerComm::makeRequest(hash_url, {
"Accept: application/json"});
711 std::string osm_json;
714 std::cerr <<
"url: " << url <<
"\n";
716 if (my_cache.
inCache(hash_value) ==
true) {
718 if (my_cache.
inCache(hash_value)) {
719 osm_json = my_cache.
getDoc(hash_value);
723 std::cout <<
"Exception while reading from cache. Ignoring cache and continue." << std::endl;
727 else if (hash_value.compare(
"false") == 0 || my_cache.
inCache(hash_value) ==
false) {
729 std::cerr <<
"Hitting json URL: " << url <<
"\n";
730 osm_json = ServerComm::makeRequest(url, {
"Accept: application/json"});
732 std::cerr <<
"Hitting hash URL: " << hash_url <<
"\n";
733 hash_value = ServerComm::makeRequest(hash_url, {
"Accept: application/json"});
734 if (hash_value.compare(
"false") == 0) {
735 std::cerr <<
"Error while gathering hash data for generated map..." << std::endl;
736 std::cerr << osm_json << std::endl;
742 my_cache.
putDoc(hash_value, osm_json);
746 std::cerr <<
"Exception while storing in cache. Weird but not critical." << std::endl;
748 std::cerr <<
"Tried to store hash=" << hash_value <<
" key=" << osm_json << std::endl;
752 return getOSMDataFromJSON(osm_json);
817 const std::string& user,
819 int subassignment = 0) {
823 std::string s = this->getAssignment(user, assignment, subassignment);
825 rapidjson::Document doc;
826 doc.Parse(s.c_str());
827 if (doc.HasParseError())
828 throw "Malformed JSON";
831 const auto& assjson = doc.FindMember(
"assignmentJSON");
833 if (assjson == doc.MemberEnd())
834 throw "Malformed GraphAdjacencyList JSON: no assignmentJSON";
837 const auto& dataArray = assjson->value.FindMember(
"data");
839 if (dataArray == assjson->value.MemberEnd()
840 || dataArray->value.IsArray() ==
false)
841 throw "Malformed GraphAdjacencyList JSON: No data";
843 const auto& data = dataArray->value.GetArray()[0];
846 const auto& dataVisual = data.FindMember(
"visual");
848 if (dataVisual == data.MemberEnd() ||
849 dataVisual->value.IsString() ==
false)
850 throw "Malformed GraphAdjacencyList JSON";
852 std::string assignment_type = dataVisual->value.GetString();
854 if (assignment_type !=
"GraphAdjacencyList")
855 throw "Malformed GraphAdjacencyList JSON: Not a GraphAdjacencyList";
859 const auto& nodes = data.FindMember(
"nodes");
860 if (nodes == data.MemberEnd() ||
861 nodes->value.IsArray() ==
false)
862 throw "Malformed GraphAdjacencyList JSON: malformed nodes";
865 const auto& nodeArray = nodes->value.GetArray();
866 int nbVertex = nodeArray.Size();
867 for (
int i = 0; i < nbVertex; ++i) {
870 const auto& vertexJSONstr = nodeArray[i];
872 const auto& nameJSON = vertexJSONstr.FindMember(
"name");
873 if (nameJSON != vertexJSONstr.MemberEnd()
874 && nameJSON->value.IsString()) {
875 name = nameJSON->value.GetString();
883 const auto& links = data.FindMember(
"links");
884 if (links == data.MemberEnd() ||
885 links->value.IsArray() ==
false)
886 throw "Malformed GraphAdjacencyList JSON: malformed links";
888 const auto& linkArray = links->value.GetArray();
889 int nbLink = linkArray.Size();
890 for (
int i = 0; i < nbLink; ++i) {
896 const auto& linkJSONstr = linkArray[i];
899 const auto& nameJSON = linkJSONstr.FindMember(
"label");
900 if (nameJSON != linkJSONstr.MemberEnd()
901 && nameJSON->value.IsString()) {
902 name = nameJSON->value.GetString();
906 const auto& srcJSON = linkJSONstr.FindMember(
"source");
907 if (srcJSON == linkJSONstr.MemberEnd()
908 || srcJSON->value.IsInt() ==
false) {
909 throw "Malformed GraphAdjacencyList JSON: malformed link";
911 src = srcJSON->value.GetInt();
915 const auto& dstJSON = linkJSONstr.FindMember(
"target");
916 if (dstJSON == linkJSONstr.MemberEnd()
917 || dstJSON->value.IsInt() ==
false) {
918 throw "Malformed GraphAdjacencyList JSON: malformed link";
920 dest = dstJSON->value.GetInt();
923 const auto& wgtJSON = linkJSONstr.FindMember(
"weight");
924 if (wgtJSON == linkJSONstr.MemberEnd()
925 || wgtJSON->value.IsInt() ==
false) {
926 throw "Malformed GraphAdjacencyList JSON: malformed link";
928 wgt = wgtJSON->value.GetInt();
948 int subassignment = 0) {
950 std::string s = this->getAssignment(user, assignment, subassignment);
952 rapidjson::Document doc;
953 doc.Parse(s.c_str());
954 if (doc.HasParseError())
955 throw "Malformed JSON";
958 std::string assignment_type = doc[
"assignment_type"].GetString();
960 if (assignment_type !=
"ColorGrid")
961 throw "Malformed ColorGrid JSON: Not a ColorGrid";
964 throw "Malformed JSON: Not a Bridges assignment?";
969 auto& data = doc[
"data"][0];
971 std::string encoding = data[
"encoding"].GetString();
972 if (encoding !=
"RAW" && encoding !=
"RLE")
973 throw "Malformed ColorGrid JSON: encoding not supported";
977 const auto& dimensions = data[
"dimensions"];
978 int dimx = dimensions[0].GetInt();
979 int dimy = dimensions[1].GetInt();
982 std::cerr <<
"Dimensions: " << dimx <<
"x" << dimy << std::endl;
985 std::string base64_encoded_assignment = data[
"nodes"][0].GetString();
993 if (encoding ==
"RAW") {
995 std::cerr <<
"decoding RAW" << std::endl;
997 std::cerr <<
"length: " << decoded.size() << std::endl;
998 if (decoded.size() < dimx * dimy * 4)
999 throw "Malformed ColorGrid JSON: nodes is smaller than expected";
1008 for (
int x = 0; x < dimx; ++x) {
1009 for (
int y = 0; y < dimy; ++y) {
1011 (
int)decoded[base + 1],
1012 (
int)decoded[base + 2],
1013 (
int)decoded[base + 3]
1021 else if (encoding ==
"RLE") {
1023 std::cerr <<
"Decoding RLE" << std::endl;
1025 int currentInDecoded = 0;
1026 int currentInCG = 0;
1027 while (currentInDecoded != decoded.size()) {
1028 if (currentInDecoded + 5 > decoded.size())
1029 throw "Malformed ColorGrid JSON: nodes is not a multiple of 5";
1033 int repeat = (
BYTE) decoded[currentInDecoded++];
1034 int r = (
BYTE) decoded[currentInDecoded++];
1035 int g = (
BYTE) decoded[currentInDecoded++];
1036 int b = (
BYTE) decoded[currentInDecoded++];
1037 int a = (
BYTE) decoded[currentInDecoded++];
1040 std::cerr <<
"indecoded: " << currentInDecoded
1041 <<
" repeat: " << (
int)repeat
1042 <<
" color(" << (int)r <<
"," << (
int)g <<
"," << (int)b <<
"," << (
int)a <<
")" 1047 while (repeat >= 0) {
1048 int posX = currentInCG / dimy;
1049 int posY = currentInCG % dimy;
1050 if (posX >= dimx || posY >= dimy) {
1052 std::cerr << posX <<
" " << dimx <<
" " << posY <<
" " << dimy << std::endl;
1053 throw "Malformed ColorGrid JSON: Too much data in nodes";
1055 cg.
set(posX, posY, c);
1062 std::cerr <<
"written " << currentInCG <<
" pixels" << std::endl;
1063 if (currentInCG != dimx * dimy)
1064 throw "Malformed ColorGrid JSON: Not enough data in nodes";
1070 throw "Malformed ColorGrid JSON";
1083 std::string getAssignment(std::string user,
1085 int subassignment = 0) {
1086 std::vector<std::string> headers;
1088 std::stringstream ss;
1092 ss << bridges_inst->getServerURL();
1094 ss << bridges::Bridges::getDefaultServerURL();
1095 ss <<
"/assignmentJSON/" 1096 << assignment <<
".";
1097 ss << std::setfill(
'0') << std::setw(2) << subassignment;
1100 std::string url = ss.str();
1104 std::string s = bridges::ServerComm::makeRequest(url, headers);
1110 void removeFirstOccurence (std::string & str,
const std::string & toRemove) {
1111 size_t pos = str.find(toRemove);
1112 if (pos != std::string::npos) {
1113 str.erase(pos, toRemove.length());
1126 void getWikidataActorMovieDirect (
int yearbegin,
int yearend, std::vector<MovieActorWikidata>& vout) {
1127 std::string codename =
"wikidata-actormovie-" + std::to_string(yearbegin) +
"-" + std::to_string(yearend);
1129 bool from_cache =
false;
1131 if (my_cache.
inCache(codename)) {
1132 json = my_cache.
getDoc(codename);
1138 std::cout <<
"Exception while reading from cache. Ignoring cache and continue." << std::endl;
1143 std::vector<std::string> http_headers;
1144 http_headers.push_back(
"User-Agent: bridges-cxx");
1145 http_headers.push_back(
"Accept: application/json");
1147 string url =
"https://query.wikidata.org/sparql?";
1156 std::string sparqlquery =
"SELECT ?movie ?movieLabel ?actor ?actorLabel WHERE \ 1158 ?movie wdt:P31 wd:Q11424.\ 1159 ?movie wdt:P161 ?actor.\ 1160 ?movie wdt:P364 wd:Q1860.\ 1161 ?movie wdt:P577 ?date.\ 1162 FILTER(YEAR(?date) >= " + std::to_string(yearbegin) +
" && YEAR(?date) <= " + std::to_string(yearend) +
").\ 1163 SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\". } \ 1165 url +=
"query=" + ServerComm::encodeURLPart(sparqlquery);
1167 url +=
"format=json";
1170 json = ServerComm::makeRequest(url, http_headers);
1173 my_cache.
putDoc(codename, json);
1177 std::cerr <<
"Exception while storing in cache. Weird but not critical." << std::endl;
1182 using namespace rapidjson;
1183 rapidjson::Document doc;
1184 doc.Parse(json.c_str());
1185 if (doc.HasParseError())
1186 throw "Malformed JSON";
1189 const auto& resultsArray = doc[
"results"][
"bindings"].GetArray();
1191 for (
auto& mak_json : resultsArray) {
1197 std::string actoruri = mak_json[
"actor"][
"value"].GetString();
1198 std::string movieuri = mak_json[
"movie"][
"value"].GetString();
1199 removeFirstOccurence (actoruri,
"http://www.wikidata.org/entity/");
1201 removeFirstOccurence (movieuri,
"http://www.wikidata.org/entity/");
1206 mak.
setActorName(mak_json[
"actorLabel"][
"value"].GetString());
1207 mak.
setMovieName(mak_json[
"movieLabel"][
"value"].GetString());
1208 vout.push_back(mak);
1213 throw "Malformed JSON: Not from wikidata?";
1237 std::vector<MovieActorWikidata> ret;
1238 for (
int y = yearbegin; y <= yearend; ++y) {
1239 cout <<
"getting year " << y << endl;
1240 getWikidataActorMovieDirect (y, y, ret);
1258 double latitMin,
double longitMin,
1259 double latitMax,
double longitMax,
double res = 0.0166) {
1264 "http://bridges-data-server-elevation.bridgesuncc.org/";
1266 string elev_str =
"elevation?";
1269 "&minLon=" + std::to_string(longitMin) +
1270 "&minLat=" + std::to_string(latitMin) +
1271 "&maxLon=" + std::to_string(longitMax) +
1272 "&maxLat=" + std::to_string(latitMax);
1274 string resn_str =
"&resX=" + std::to_string(res)
1275 +
"&resY=" + std::to_string(res);
1277 string elev_data_url =
1278 server_str + elev_str + bbox_str + resn_str;
1281 cerr <<
"Hitting data URL: " << elev_data_url <<
"\n";
1282 string hash_str =
"hash?";
1283 string hash_url = server_str + hash_str + bbox_str + resn_str;
1286 cerr <<
"Hitting hash URL: " << hash_url <<
"\n";
1289 string hash_value = ServerComm::makeRequest(hash_url,
1290 {
"Accept: application/json"});
1295 if (my_cache.
inCache(hash_value)) {
1297 elev_json = my_cache.
getDoc(hash_value);
1301 cout <<
"Exception while reading from cache. Ignoring cache." << std::endl;
1307 cerr <<
"Hitting json URL: " << elev_data_url <<
"\n";
1310 elev_json = ServerComm::makeRequest(elev_data_url,
1311 {
"Accept: application/json"});
1314 cerr <<
"Hitting elev data URL: " << elev_data_url <<
"\n";
1316 string hash_value = ServerComm::makeRequest(hash_url,
1317 {
"Accept: application/json"});
1319 if (hash_value !=
"false") {
1322 my_cache.
putDoc(hash_value, elev_json);
1326 cerr <<
"Exception while storing in cache. Weird but not critical." 1331 return getElevationDataFromJSON(elev_json);
1339 stringstream ss(elev_json);
1341 int rows, cols, elev_val;
1342 double ll_x, ll_y, cell_size;
1346 ss >> tmp >> cols >> tmp >> rows >>
1347 tmp >> ll_x >> tmp >> ll_y >>
1358 for (
int i = 0; i < rows; i++) {
1359 for (
int j = 0; j < cols; j++) {
1361 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:32
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 Data source object containing sonnets, poems and plays.
Definition: Shakespeare.h:31
virtual void putDoc(const std::string &hash_value, const std::string &content) override
Definition: Cache.h:172
std::vector< MovieActorWikidata > getWikidataActorMovie(int yearbegin, int yearend)
This function returns the Movie and Actors playing in them between two years.
Definition: DataSource.h:1226
This is a helper class for accessing actor-movie data from Wikidata.
Definition: MovieActorWikidata.h:15
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()
Get meta data of the IGN games collection.
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:56
A Song object, used along with the Songs data source.
Definition: Song.h:24
long OSMVertexID
Definition: OSMVertex.h:30
vector< Song > getSongData()
Get data of the songs (including lyrics) using the Genius API https://docs.genius.com/ Valid endpoints: https://bridgesdata.herokuapp.com/api/songs/.
Definition: DataSource.h:364
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:946
void setName(const string &n)
change the name of the dataset
Definition: OSMData.h:224
void setAgeAdjustedCI_Lower(double ci_l)
Definition: CancerIncidence.h:90
void setCount(int c)
Set cancer incidence count.
Definition: CancerIncidence.h:286
virtual std::string getDoc(const std::string &hash_value) override
Definition: Cache.h:156
ElevationData getElevationDataFromJSON(string elev_json)
Definition: DataSource.h:1335
vector< ActorMovieIMDB > getActorMovieIMDBData(int number=0)
Get ActorMovie IMDB Data Data is retrieved, formatted into a list of ActorMovieIMDB objects...
Definition: DataSource.h:132
This class represents Color, and supports rgba, hexadecimal and named color values.
Definition: Color.h:51
void getAmenityData(const std::string &location, const std::string &amenity)
Definition: DataSource.h:672
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())
Adds a vertex to the graph.
Definition: GraphAdjList.h:174
void setActorURI(std::string au)
Definition: MovieActorWikidata.h:40
void setLocationY(double locY)
Set location (Y coord)
Definition: CancerIncidence.h:321
vector< EarthquakeUSGS > getEarthquakeUSGSData(int number=0)
Get USGS earthquake data USGS Tweet data (https://earthquake.usgs.gov/earthquakes/map/) retrieved...
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
ElevationData getElevationData(double latitMin, double longitMin, double latitMax, double longitMax, double res=0.0166)
Definition: DataSource.h:1257
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:183
void setMovieName(std::string mn)
Definition: MovieActorWikidata.h:48
void setVertices(const vector< OSMVertex > &verts)
replace the vertices stored by this new set.
Definition: OSMData.h:269
vector< GutenbergBook > getGutenbergBookData(int num=0)
Get meta data of the Gutenberg book collection. This function retrieves, and formats the data into a ...
Definition: DataSource.h:404
A class to hold actor movie data – using IMDB dataset.
Definition: ActorMovieIMDB.h:23
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)
Retrieves the CDC dataset of Cancer Incidence. Data is retrieved into a vector of records See CancerI...
Definition: DataSource.h:466
unsigned char BYTE
Definition: base64.h:44
Class that hold elevation data.
Definition: ElevationData.h:23
bridges::GraphAdjList< int, std::string > getGraphFromAssignment(const std::string &user, int assignment, int subassignment=0)
old interface for the OSM data set.
Definition: DataSource.h:816
void getAmenityData(double minLat, double minLon, double maxLat, double maxLon, std::string amenity)
Definition: DataSource.h:668
Song getSong(string songTitle, string artistName)
Get data of a particular songs (including lyrics) using the Genius API (https://docs.genius.com/), given the song title and artist name. Valid endpoints: http://bridgesdata.herokuapp.com/api/songs/find/ Valid queryParams: song title, artist name.
Definition: DataSource.h:309
Class that hold Open Street Map Data.
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)
Set the grid value for the (row, col) element.
Definition: Grid.h:192
OSMData getOSMData(double lat_min, double long_min, double lat_max, double long_max, string level="default")
Get OpenStreetMap data given a bounding rectangle of lat/long values.
Definition: DataSource.h:593
void setxll(int x_ll)
Definition: ElevationData.h:166
OSMData getOSMData(string location, string level="default")
Definition: DataSource.h:695
DataSource(bridges::Bridges &br)
Definition: DataSource.h:78
void setCellSize(int cell_size)
Definition: ElevationData.h:201
void setAgeAdjustedRate(double aar)
Definition: CancerIncidence.h:69
virtual bool inCache(const std::string &hash_value) override
Definition: Cache.h:165
void setEdges(const vector< OSMEdge > &e)
set edges
Definition: OSMData.h:307
A Game object, used along with the Games data source.
Definition: Game.h:29
A class representing the attributes for cancer incidence.
Definition: CancerIncidence.h:26
OSMData getOSMDataFromJSON(const string &osm_json)
Retrieves the Open Street Map data from a prebuilt JSON of OSM dataset.
Definition: DataSource.h:518
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:131
vector< ActorMovieIMDB > getActorMovieIMDBData2()
Get ActorMovie IMDB Data Data is retrieved, formatted into a list of ActorMovieIMDB objects...
Definition: DataSource.h:166
void addEdge(const K &src, const K &dest, const E2 &data=E2())
Add an edge with data.
Definition: GraphAdjList.h:197
Class that hold Open Street Map vertices.
Definition: OSMVertex.h:28
vector< BYTE > decode(string const &encoded_string)
Definition: base64.h:103