@@ -6071,15 +6071,36 @@ static void fcall_reopt_size_battery(lk::invoke_t& cxt)
60716071 wxString post_url = SamApp::WebApi (" reopt_post" );
60726072 post_url.Replace (" <SAMAPIKEY>" , wxString (sam_api_key));
60736073
6074- // reopt_jsonpost = "'" + reopt_jsonpost + "'"; // Not valid JSON on Windows
60756074
60766075 wxEasyCurl curl;
6077- // curl.AddHttpHeader("Accept: application/json");
6078- // curl.AddHttpHeader("Content-Type: application/json");
60796076 curl.AddHttpHeader (" Content-Type: application/json" );
6080- // curl.AddHttpHeader("Accept: application/json");
6077+ curl.AddHttpHeader (" Accept: application/json" );
60816078 curl.SetPostData (reopt_jsonpost);
60826079
6080+ /*
6081+ auto ElectricLoad = reopt_scenario->lookup("ElectricLoad");
6082+ ElectricLoad->empty_hash();
6083+ ElectricLoad->hash_item("doe_reference_name", "SmallOffice");
6084+ // ElectricLoad->hash_item("annual_kwh", 100000.0);
6085+ lk::vardata_t monthly_load;
6086+ monthly_load.empty_vector();
6087+ monthly_load.vec_append(sam_case->Values(0).Get("energy_1")->Value());
6088+ monthly_load.vec_append(sam_case->Values(0).Get("energy_2")->Value());
6089+ monthly_load.vec_append(sam_case->Values(0).Get("energy_3")->Value());
6090+ monthly_load.vec_append(sam_case->Values(0).Get("energy_4")->Value());
6091+ monthly_load.vec_append(sam_case->Values(0).Get("energy_5")->Value());
6092+ monthly_load.vec_append(sam_case->Values(0).Get("energy_6")->Value());
6093+ monthly_load.vec_append(sam_case->Values(0).Get("energy_7")->Value());
6094+ monthly_load.vec_append(sam_case->Values(0).Get("energy_8")->Value());
6095+ monthly_load.vec_append(sam_case->Values(0).Get("energy_9")->Value());
6096+ monthly_load.vec_append(sam_case->Values(0).Get("energy_10")->Value());
6097+ monthly_load.vec_append(sam_case->Values(0).Get("energy_11")->Value());
6098+ monthly_load.vec_append(sam_case->Values(0).Get("energy_12")->Value());
6099+ ElectricLoad->hash_item("monthly_totals_kwh", monthly_load);
6100+ // ElectricLoad->assign("{ \"doe_reference_name\": \"MidriseApartment\",\"annual_kwh\" : 1000000.0 }, ");
6101+ reopt_jsonpost = lk::json_write(*reopt_scenario);
6102+ cxt.result().hash_item("scenario", reopt_jsonpost);
6103+ */
60836104 // write to file for SAM issue 1830
60846105 wxString filename = SamApp::GetAppPath () + " /reopt_jsonpost.json" ;
60856106 wxFile file (filename, wxFile::write);
@@ -6107,14 +6128,73 @@ static void fcall_reopt_size_battery(lk::invoke_t& cxt)
61076128
61086129 // get the run_uuid to poll for result, checking the status
61096130 // examine raw string
6110- wxMessageBox (" curl = " + curl.GetDataAsString (), " CURL result" );
6131+ // wxMessageBox("curl = " + curl.GetDataAsString(), "CURL result");
61116132
61126133 // handle errors instead of hard crash SAM 1830
61136134 auto strData = curl.GetDataAsString ();
61146135 if (strData.Find (" error" ) != wxNOT_FOUND) {
6115- pdlg.Close ();
6116- cxt.result ().hash_item (" error" , strData);
6117- return ;
6136+ // content-length issue on Linux 135832 runs and 140778 fails
6137+ // if failing with "Request Rejected" title, then run with monthly scaled load per
6138+ // https://nrel.github.io/REopt.jl/stable/reopt/inputs/#ElectricLoad
6139+ if (strData.Find (" Request Rejected" ) != wxNOT_FOUND) {
6140+ // TODO: extra prompt to let user know what is going on???
6141+ auto ElectricLoad = reopt_scenario->lookup (" ElectricLoad" );
6142+ ElectricLoad->empty_hash ();
6143+ if (sam_case->GetFinancing () == " Residential" )
6144+ ElectricLoad->hash_item (" doe_reference_name" , " SmallOffice" );
6145+ else
6146+ ElectricLoad->hash_item (" doe_reference_name" , " LargeOffice" );
6147+ // ElectricLoad->hash_item("annual_kwh", 100000.0);
6148+ lk::vardata_t monthly_load;
6149+ monthly_load.empty_vector ();
6150+ monthly_load.vec_append (sam_case->Values (0 ).Get (" energy_1" )->Value ());
6151+ monthly_load.vec_append (sam_case->Values (0 ).Get (" energy_2" )->Value ());
6152+ monthly_load.vec_append (sam_case->Values (0 ).Get (" energy_3" )->Value ());
6153+ monthly_load.vec_append (sam_case->Values (0 ).Get (" energy_4" )->Value ());
6154+ monthly_load.vec_append (sam_case->Values (0 ).Get (" energy_5" )->Value ());
6155+ monthly_load.vec_append (sam_case->Values (0 ).Get (" energy_6" )->Value ());
6156+ monthly_load.vec_append (sam_case->Values (0 ).Get (" energy_7" )->Value ());
6157+ monthly_load.vec_append (sam_case->Values (0 ).Get (" energy_8" )->Value ());
6158+ monthly_load.vec_append (sam_case->Values (0 ).Get (" energy_9" )->Value ());
6159+ monthly_load.vec_append (sam_case->Values (0 ).Get (" energy_10" )->Value ());
6160+ monthly_load.vec_append (sam_case->Values (0 ).Get (" energy_11" )->Value ());
6161+ monthly_load.vec_append (sam_case->Values (0 ).Get (" energy_12" )->Value ());
6162+ ElectricLoad->hash_item (" monthly_totals_kwh" , monthly_load);
6163+ // ElectricLoad->assign("{ \"doe_reference_name\": \"MidriseApartment\",\"annual_kwh\" : 1000000.0 }, ");
6164+ reopt_jsonpost = lk::json_write (*reopt_scenario);
6165+ cxt.result ().hash_item (" scenario" , reopt_jsonpost);
6166+ curl.SetPostData (reopt_jsonpost);
6167+ // TODO: remove after review
6168+ // write to file for SAM issue 1830
6169+ filename = SamApp::GetAppPath () + " /reopt_jsonpost2.json" ;
6170+ wxFile file (filename, wxFile::write);
6171+ if (!file.IsOpened ()) {
6172+ wxLogError (" Could not open file for writing!" );
6173+ return ;
6174+ }
6175+ file.Write (reopt_jsonpost);
6176+ file.Close ();
6177+
6178+
6179+
6180+ if (!curl.Get (post_url, msg))
6181+ {
6182+ pdlg.Close ();
6183+ cxt.result ().assign (msg);
6184+ return ;
6185+ }
6186+ strData = curl.GetDataAsString ();
6187+ if (strData.Find (" error" ) != wxNOT_FOUND) {
6188+ pdlg.Close ();
6189+ cxt.result ().hash_item (" error" , strData);
6190+ return ;
6191+ }
6192+ }
6193+ else {
6194+ pdlg.Close ();
6195+ cxt.result ().hash_item (" error" , strData);
6196+ return ;
6197+ }
61186198 }
61196199
61206200
0 commit comments