44 static bool profile() {
49 static string getDefaultServerURL() {
50 return "http://bridges-cs.herokuapp.com";
54 bool jsonFlag =
false;
57 bool element_labelFlag =
false, link_labelFlag =
false;
59 bool post_visualization_link =
true;
61 string user_name = string(),
66 string description = string();
68 string title = string();
70 unsigned int assn_num = 0;
74 string server_url =
"http://bridges-cs.herokuapp.com";
76 string BASE_URL = server_url +
"/assignments/";
79 string map_overlay_options[3] = {
"cartesian",
"albersusa",
"equirectangular"};
80 bool map_overlay =
false;
81 string coord_system_type =
"cartesian";
84 vector<double> wc_window;
86 unsigned int lastAssignNum = 0, subAssignNum = 0;
106 Bridges (
const string& name,
const string& key) {
129 Bridges (
unsigned int num,
const string& name,
const string& key) {
145 element_labelFlag = flag;
156 link_labelFlag = flag;
166 return element_labelFlag;
176 return link_labelFlag;
199 post_visualization_link = link_url;
231 char* force = getenv(
"FORCE_BRIDGES_USERNAME");
232 if (force !=
nullptr) {
257 char* force = getenv(
"FORCE_BRIDGES_APIKEY");
258 if (force !=
nullptr) {
282 char* force = getenv(
"FORCE_BRIDGES_ASSIGNMENT");
283 if (force !=
nullptr) {
284 num = std::atoi(force);
289 if (assn_num != lastAssignNum) {
290 lastAssignNum = assn_num;
350 setDataStructure(&ds);
376 char* force = getenv(
"FORCE_BRIDGES_APISERVER");
377 if (force !=
nullptr) {
381 if (server_type ==
"live")
382 server_url =
"http://bridges-cs.herokuapp.com";
383 else if (server_type ==
"clone")
384 server_url =
"http://bridges-clone.herokuapp.com";
385 else if (server_type ==
"games")
386 server_url =
"http://bridges-games.herokuapp.com";
387 else if (server_type ==
"local")
388 server_url =
"http://127.0.0.1:3000";
390 BASE_URL = server_url +
"/assignments/";
401 map_overlay = overlay_flag;
413 void setMap(
string my_map,
string info) {
428 std::transform(coord.begin(), coord.end(), coord.begin(), ::tolower);
429 if (coord ==
"cartesian" || coord ==
"albersusa" || coord ==
"equirectangular" 430 || coord ==
"window")
431 coord_system_type = coord;
433 cout <<
"Unrecognized coordinate system \'" + coord +
"\', defaulting to " 434 <<
"cartesian. Options:";
435 for (
auto proj : map_overlay_options)
437 coord_system_type =
"cartesian";
448 return coord_system_type;
461 void setWindow (
int xmin,
int xmax,
int ymin,
int ymax) {
462 setWindow(
double(xmin),
double(xmax),
double(ymin),
double(ymax));
475 void setWindow (
double xmin,
double xmax,
double ymin,
double ymax) {
477 wc_window.push_back(xmin);
478 wc_window.push_back(xmax);
479 wc_window.push_back(ymin);
480 wc_window.push_back(ymax);
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();
501 if (getAssignment() != lastAssignNum) {
502 lastAssignNum = getAssignment();
505 if (subAssignNum == 99) {
506 cout <<
"#sub-assignments limit(99) exceeded, visualization not generated .." 511 cerr <<
"Error: Data Structure handle null! Visualization not generated.";
520 jsonbuild_start = std::chrono::system_clock::now();
522 string ds_json = getJSONHeader() + ds_handle->getDataStructureRepresentation();
524 jsonbuild_end = std::chrono::system_clock::now();
530 cout <<
"JSON[" + ds_handle->
getDStype() +
"]:\t" << ds_json << endl;
534 httprequest_start = std::chrono::system_clock::now();
537 ServerComm::makeRequest(BASE_URL + to_string(getAssignment()) +
"." +
538 (subAssignNum > 9 ?
"" :
"0") + to_string(subAssignNum) +
"?apikey=" + getApiKey() +
539 "&username=" + getUserName(), {
"Content-Type: text/plain"}, ds_json);
541 if (post_visualization_link) {
542 cout <<
"Success: Assignment posted to the server. " << endl
543 <<
"Check out your visualization at:" << endl << endl
544 << BASE_URL + to_string(getAssignment()) +
"/" + getUserName() << endl << endl;
548 catch (
const string& error_str) {
549 cerr <<
"\nPosting assignment to the server failed!" << endl
550 << error_str << endl << endl;
551 cerr <<
"Provided Bridges Credentials:" << endl <<
552 "\t User Name: " << getUserName() << endl <<
553 "\t API Key: " << getApiKey() << endl <<
554 "\t Assignment Number: " << getAssignment() << endl;
557 cerr <<
"\nPosting assignment to the server failed!" << endl;
559 cerr <<
"Provided Bridges Credentials are incorrect:" << endl <<
560 "\t ServerURL: "<< getServerURL() <<endl<<
561 "\t User Name: " << getUserName() << endl <<
562 "\t API Key: " << getApiKey() << endl <<
563 "\t Assignment Number: " << getAssignment() << endl;
566 cerr<<
"Assignment is too large."<<endl;
567 cerr<<
"In general the assignment should be smaller than 16MB once serialized to JSON."<<endl;
570 std::cerr<<he.
what()<<endl;
574 httprequest_end = std::chrono::system_clock::now();
579 end = std::chrono::system_clock::now();
581 std::chrono::duration<double> totaltime = end - start;
582 std::chrono::duration<double> jsonbuildtime = jsonbuild_end - jsonbuild_start;
583 std::chrono::duration<double> httptime = httprequest_end - httprequest_start;
584 std::cerr <<
"total visualize() time:" << totaltime.count() <<
" seconds" 585 <<
" (including JSON build time: " << jsonbuildtime.count() <<
" seconds" 586 <<
" and HTTP request time: " << httptime.count() <<
" seconds)." 592 string getServerURL()
const {
597 string getJSONHeader () {
607 QUOTE +
"element_label_flag" +
QUOTE +
COLON + ((element_labelFlag) ?
"true" :
"false") +
COMMA +
612 if (wc_window.size() == 4) {
614 json_header += std::to_string(wc_window[0]) +
COMMA +
615 std::to_string(wc_window[1]) +
COMMA +
616 std::to_string(wc_window[2]) +
COMMA + std::to_string(wc_window[3]);
void visualize()
Definition: Bridges.h:489
virtual const char * what() const noexcept
Definition: ServerComm.h:35
This is the superclass of all data structure types in BRIDGES.
Definition: DataStructure.h:73
void setDescription(const string &descr)
Definition: Bridges.h:327
long httpcode
Definition: ServerComm.h:19
void setElementLabelFlag(bool flag)
Flag that controls if labels of elements (nodes) are to be turned on.
Definition: Bridges.h:144
virtual const string getDStype() const =0
void setCoordSystemType(string coord)
Definition: Bridges.h:427
void setWindow(int xmin, int xmax, int ymin, int ymax)
Definition: Bridges.h:461
void setMap(string my_map, string info)
Sets the type of map overlay to use.
Definition: Bridges.h:413
const string COLON
Definition: DataStructure.h:51
Bridges(unsigned int num, const string &name, const string &key)
constructor to bridges
Definition: Bridges.h:129
void setTitle(const string &t)
Definition: Bridges.h:312
const string OPEN_BOX
Definition: DataStructure.h:54
const string & getCoordSystemType()
Definition: Bridges.h:447
const string & getDescription() const
Definition: Bridges.h:320
void setDataStructure(DataStructure *ds)
Definition: Bridges.h:338
void setAssignment(unsigned int num)
Definition: Bridges.h:281
This is meant to be an internal class, not something that the library user will use.
Definition: SocketConnection.h:48
Bridges(const string &name, const string &key)
constructor to bridges
Definition: Bridges.h:106
void setDataStructure(DataStructure &ds)
Definition: Bridges.h:349
This class contains methods to connect and transmit a user's data structure representation to the Bri...
Definition: Bridges.h:42
void setUserName(string name)
Set user name.
Definition: Bridges.h:230
void postVisualizationLink(bool link_url)
Definition: Bridges.h:198
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 OPEN_CURLY
Definition: DataStructure.h:52
const string & getTitle() const
Definition: Bridges.h:301
const string CLOSE_BOX
Definition: DataStructure.h:55
void setMapOverlay(bool overlay_flag)
Turns on map overlay for subsequent visualizations - used with location specific datasets.
Definition: Bridges.h:400
bool getElementLabelFlag() const
status of flag for element labels
Definition: Bridges.h:165
Bridges()
Definition: Bridges.h:91
const string & getApiKey() const
Definition: Bridges.h:243
DataStructure * getDataStructure()
Definition: Bridges.h:359
void setApiKey(string key)
Set API key credentials.
Definition: Bridges.h:256
const string & getUserName() const
Definition: Bridges.h:218
bool getJSONFlag() const
Definition: Bridges.h:185
void setLinkLabelFlag(bool flag)
Flag that controls if labels of links(edges) are to be turned on/off.
Definition: Bridges.h:155
Definition: ServerComm.h:17
const string COMMA
Definition: DataStructure.h:50
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:475
const string QUOTE
Definition: DataStructure.h:49
bool getLinkLabelFlag() const
Return status of flag for link labels.
Definition: Bridges.h:175
void setServer(string server_type)
Definition: Bridges.h:375
void setJSONFlag(bool flag)
Definition: Bridges.h:207
unsigned int getAssignment() const
Definition: Bridges.h:269
std::string JSONencode(const T &d)
Definition: JSONutil.h:37