45 static bool profile() {
49 static string getDefaultServerURL() {
50 return "http://bridges-cs.herokuapp.com";
53 bool jsonFlag =
false;
56 bool element_labelFlag =
false, link_labelFlag =
false;
58 bool post_visualization_link =
true;
60 string user_name = string(),
65 string description = string();
67 string title = string();
69 unsigned int assn_num = 0;
73 string server_url =
"http://bridges-cs.herokuapp.com";
75 string BASE_URL = server_url +
"/assignments/";
78 string map_overlay_options[3] = {
"cartesian",
"albersusa",
"equirectangular"};
79 bool map_overlay =
false;
80 string coord_system_type =
"cartesian";
83 vector<double> wc_window;
85 unsigned int lastAssignNum = 0, subAssignNum = 0;
104 Bridges (
const string& name,
const string& key) {
127 Bridges (
unsigned int num,
const string& name,
const string& key) {
143 element_labelFlag = flag;
154 link_labelFlag = flag;
164 return element_labelFlag;
174 return link_labelFlag;
197 post_visualization_link = link_url;
229 char* force = getenv(
"FORCE_BRIDGES_USERNAME");
230 if (force !=
nullptr) {
255 char* force = getenv(
"FORCE_BRIDGES_APIKEY");
256 if (force !=
nullptr) {
280 char* force = getenv(
"FORCE_BRIDGES_ASSIGNMENT");
281 if (force !=
nullptr) {
282 num = std::atoi(force);
287 if (assn_num != lastAssignNum) {
288 lastAssignNum = assn_num;
348 setDataStructure(&ds);
372 char* force = getenv(
"FORCE_BRIDGES_APISERVER");
373 if (force !=
nullptr) {
377 if (server_type ==
"live")
378 server_url =
"http://bridges-cs.herokuapp.com";
379 else if (server_type ==
"clone")
380 server_url =
"http://bridges-clone.herokuapp.com";
381 else if (server_type ==
"games")
382 server_url =
"http://bridges-games.herokuapp.com";
383 else if (server_type ==
"local")
384 server_url =
"http://127.0.0.1:3000";
386 BASE_URL = server_url +
"/assignments/";
397 map_overlay = overlay_flag;
409 void setMap(
string my_map,
string info) {
424 std::transform(coord.begin(), coord.end(), coord.begin(), ::tolower);
425 if (coord ==
"cartesian" || coord ==
"albersusa" || coord ==
"equirectangular"
426 || coord ==
"window")
427 coord_system_type = coord;
429 cout <<
"Unrecognized coordinate system \'" + coord +
"\', defaulting to "
430 <<
"cartesian. Options:";
431 for (
auto proj : map_overlay_options)
433 coord_system_type =
"cartesian";
444 return coord_system_type;
457 void setWindow (
int xmin,
int xmax,
int ymin,
int ymax) {
458 setWindow(
double(xmin),
double(xmax),
double(ymin),
double(ymax));
471 void setWindow (
double xmin,
double xmax,
double ymin,
double ymax) {
473 wc_window.push_back(xmin);
474 wc_window.push_back(xmax);
475 wc_window.push_back(ymin);
476 wc_window.push_back(ymax);
480 return BASE_URL + to_string(getAssignment()) +
"/" + getUserName();
490 std::chrono::time_point<std::chrono::system_clock> start;
491 std::chrono::time_point<std::chrono::system_clock> end;
492 std::chrono::time_point<std::chrono::system_clock> jsonbuild_start;
493 std::chrono::time_point<std::chrono::system_clock> jsonbuild_end;
494 std::chrono::time_point<std::chrono::system_clock> httprequest_start;
495 std::chrono::time_point<std::chrono::system_clock> httprequest_end;
498 start = std::chrono::system_clock::now();
500 if (getAssignment() != lastAssignNum) {
501 lastAssignNum = getAssignment();
504 if (subAssignNum == 99) {
505 cout <<
"#sub-assignments limit(99) exceeded, visualization not generated .."
510 cerr <<
"Error: Data Structure handle null! Visualization not generated.";
519 jsonbuild_start = std::chrono::system_clock::now();
524 string ds_part_json = ds_handle->getDataStructureRepresentation();
526 ds_part_json.erase(0, 1);
527 ds_json = getJSONHeader() + ds_part_json;
530 ds_json = getJSONHeader() + ds_handle->getDataStructureRepresentation();
532 jsonbuild_end = std::chrono::system_clock::now();
538 cout <<
"JSON[" + ds_handle->
getDStype() +
"]:\t" << ds_json << endl;
542 httprequest_start = std::chrono::system_clock::now();
545 ServerComm::makeRequest(BASE_URL + to_string(getAssignment()) +
"." +
546 (subAssignNum > 9 ?
"" :
"0") + to_string(subAssignNum) +
"?apikey=" + getApiKey() +
547 "&username=" + getUserName(), {
"Content-Type: text/plain"}, ds_json);
549 if (post_visualization_link) {
550 cout <<
"Success: Assignment posted to the server. " << endl
551 <<
"Check out your visualization at:" << endl << endl
552 << getVisualizeURL() << endl << endl;
556 catch (
const string& error_str) {
557 cerr <<
"\nPosting assignment to the server failed!" << endl
558 << error_str << endl << endl;
559 cerr <<
"Provided Bridges Credentials:" << endl <<
560 "\t User Name: " << getUserName() << endl <<
561 "\t API Key: " << getApiKey() << endl <<
562 "\t Assignment Number: " << getAssignment() << endl;
565 cerr <<
"\nPosting assignment to the server failed!" << endl;
567 cerr <<
"Provided Bridges Credentials are incorrect:" << endl <<
568 "\t ServerURL: " << getServerURL() << endl <<
569 "\t User Name: " << getUserName() << endl <<
570 "\t API Key: " << getApiKey() << endl <<
571 "\t Assignment Number: " << getAssignment() << endl;
574 cerr <<
"Assignment is too large." << endl;
575 cerr <<
"In general the assignment should be smaller than 16MB once serialized to JSON." << endl;
578 std::cerr << he.
what() << endl;
582 httprequest_end = std::chrono::system_clock::now();
585 end = std::chrono::system_clock::now();
587 std::chrono::duration<double> totaltime = end - start;
588 std::chrono::duration<double> jsonbuildtime = jsonbuild_end - jsonbuild_start;
589 std::chrono::duration<double> httptime = httprequest_end - httprequest_start;
590 std::cerr <<
"total visualize() time:" << totaltime.count() <<
" seconds"
591 <<
" (including JSON build time: " << jsonbuildtime.count() <<
" seconds"
592 <<
" and HTTP request time: " << httptime.count() <<
" seconds)."
598 string getServerURL()
const {
602 string getJSONHeader () {
612 QUOTE +
"element_label_flag" +
QUOTE +
COLON + ((element_labelFlag) ?
"true" :
"false") +
COMMA +
617 if (wc_window.size() == 4) {
619 json_header += std::to_string(wc_window[0]) +
COMMA +
620 std::to_string(wc_window[1]) +
COMMA +
621 std::to_string(wc_window[2]) +
COMMA + std::to_string(wc_window[3]);
This class contains methods to connect and transmit a user's data structure representation to the Bri...
Definition: Bridges.h:43
string getVisualizeURL() const
Definition: Bridges.h:479
void setWindow(int xmin, int xmax, int ymin, int ymax)
Definition: Bridges.h:457
bool getLinkLabelFlag() const
Return status of flag for link labels.
Definition: Bridges.h:173
Bridges(const string &name, const string &key)
constructor to bridges
Definition: Bridges.h:104
void setMapOverlay(bool overlay_flag)
Turns on map overlay for subsequent visualizations - used with location specific datasets.
Definition: Bridges.h:396
void visualize()
Definition: Bridges.h:489
void setUserName(string name)
Set user name.
Definition: Bridges.h:228
bool getElementLabelFlag() const
status of flag for element labels
Definition: Bridges.h:163
void setDataStructure(DataStructure &ds)
Definition: Bridges.h:347
void setServer(string server_type)
Definition: Bridges.h:371
void setApiKey(string key)
Set API key credentials.
Definition: Bridges.h:254
DataStructure * getDataStructure()
Definition: Bridges.h:356
void setDataStructure(DataStructure *ds)
Definition: Bridges.h:336
void postVisualizationLink(bool link_url)
Definition: Bridges.h:196
const string & getTitle() const
Definition: Bridges.h:299
const string & getApiKey() const
Definition: Bridges.h:241
void setWindow(double xmin, double xmax, double ymin, double ymax)
sets the world coordinate window defining the space of the user defined objects (or nodes)
Definition: Bridges.h:471
void setDescription(const string &descr)
Definition: Bridges.h:325
unsigned int getAssignment() const
Definition: Bridges.h:267
Bridges(unsigned int num, const string &name, const string &key)
constructor to bridges
Definition: Bridges.h:127
Bridges()
Definition: Bridges.h:89
const string & getCoordSystemType()
Definition: Bridges.h:443
void setLinkLabelFlag(bool flag)
Flag that controls if labels of links(edges) are to be turned on/off.
Definition: Bridges.h:153
void setTitle(const string &t)
Definition: Bridges.h:310
void setAssignment(unsigned int num)
Definition: Bridges.h:279
void setMap(string my_map, string info)
Sets the type of map overlay to use.
Definition: Bridges.h:409
void setCoordSystemType(string coord)
Definition: Bridges.h:423
const string & getUserName() const
Definition: Bridges.h:216
void setJSONFlag(bool flag)
Definition: Bridges.h:205
bool getJSONFlag() const
Definition: Bridges.h:183
const string & getDescription() const
Definition: Bridges.h:318
void setElementLabelFlag(bool flag)
Flag that controls if labels of elements (nodes) are to be turned on.
Definition: Bridges.h:142
This is the superclass of all data structure types in BRIDGES.
Definition: DataStructure.h:73
virtual const string getDStype() const =0
This is meant to be an internal class, not something that the library user will use.
Definition: SocketConnection.h:48
std::string JSONencode(const T &d)
Definition: JSONutil.h:36
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
const string COLON
Definition: DataStructure.h:51
const string OPEN_BOX
Definition: DataStructure.h:54
const string COMMA
Definition: DataStructure.h:50
const string OPEN_CURLY
Definition: DataStructure.h:52
const string CLOSE_BOX
Definition: DataStructure.h:55
const string QUOTE
Definition: DataStructure.h:49
Definition: ServerComm.h:17
virtual const char * what() const noexcept
Definition: ServerComm.h:35
long httpcode
Definition: ServerComm.h:19