Skip to content

Commit

Permalink
Remove debugging messages and handle zero rate utilities #1968
Browse files Browse the repository at this point in the history
Working without issue on Windows
  • Loading branch information
sjanzou committed Jan 29, 2025
1 parent 8d4f328 commit b9f16fb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 42 deletions.
37 changes: 1 addition & 36 deletions src/geotools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,8 @@ bool GeoTools::GeocodeDeveloper(const wxString& address, double* lat, double* lo

wxEasyCurl curl;
wxBusyCursor curs;
wxMessageBox(url, "geocode developer URL");


// SAM issue 1968
/* works from command line and fails in curl.get with invalid key
url.Replace("&", "\\&");
wxMessageBox(url, "updated geocode developer URL");
*/
curl.AddHttpHeader("Content-Type: application/json");
curl.AddHttpHeader("Accept: application/json");

Expand All @@ -212,32 +207,10 @@ bool GeoTools::GeocodeDeveloper(const wxString& address, double* lat, double* lo
rapidjson::GenericDocument < rapidjson::UTF16<> > reader;
wxString str = curl.GetDataAsString();

// str.Replace("\"", "\\\"");

// std::string str = curl.GetDataAsString().ToStdString();

wxMessageBox(str, "geocode developer URL return string");


// rapidjson::StringStream is(str.c_str());

// doc.ParseStream(is);


// rapidjson::ParseResult ok = reader.Parse((const char*)str.c_str());
// rapidjson::ParseResult ok = reader.ParseStream(is);
rapidjson::ParseResult ok = reader.Parse(str.c_str());


/*
ParseResult ok = doc.Parse("[42]");
if (!ok) {
fprintf(stderr, "JSON parse error: %s (%u)",
GetParseError_En(ok.Code()), ok.Offset());
exit(EXIT_FAILURE);
}
example for "denver, co"
{"info":
{"statuscode":0,"copyright":
Expand Down Expand Up @@ -276,7 +249,6 @@ bool GeoTools::GeocodeDeveloper(const wxString& address, double* lat, double* lo
}
// check status code
success = false;//overrides success of retrieving data
wxMessageBox(str, "geocode developer reset status code ");

if (reader.HasMember(L"info")) {
if (reader[L"info"].HasMember(L"statuscode")) {
Expand All @@ -293,16 +265,13 @@ bool GeoTools::GeocodeDeveloper(const wxString& address, double* lat, double* lo
if (!success)
return false;

wxMessageBox(str, "geocode developer success to tz ");


if (tz != 0)
{
success = false;

curl = wxEasyCurl();
// curl.AddHttpHeader("Content-Type: application/json");
// curl.AddHttpHeader("Accept: application/json");



Expand All @@ -314,8 +283,6 @@ bool GeoTools::GeocodeDeveloper(const wxString& address, double* lat, double* lo
curl.AddHttpHeader("Accept: application/json");


wxMessageBox(url, "geocode developer bing tz URL");

if (showprogress)
{
if (!curl.Get(url, "Geocoding address '" + address + "'..."))
Expand All @@ -328,8 +295,6 @@ bool GeoTools::GeocodeDeveloper(const wxString& address, double* lat, double* lo

str = curl.GetDataAsString();

wxMessageBox(str, "geocode developer bing tz URL return string");

reader.Parse(str.c_str());

if (!reader.HasParseError()) {
Expand Down
20 changes: 15 additions & 5 deletions src/urdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,8 +1281,9 @@ int OpenEIUtilityRateDialog::ShowModal()
return wxDialog::ShowModal();
}

void OpenEIUtilityRateDialog::QueryRates(const wxString &utility_name)
bool OpenEIUtilityRateDialog::QueryRates(const wxString &utility_name)
{
bool ret = true;
wxBusyInfo busy("Getting available rates...", this);
lblStatus->SetLabel("Loading rates...");

Expand All @@ -1293,8 +1294,10 @@ void OpenEIUtilityRateDialog::QueryRates(const wxString &utility_name)
if (!api.QueryUtilityRates(utility_name, mUtilityRates, &err))
{
busy.~wxBusyInfo();
wxMessageBox("Utility Rate Query Error\n\n" + err, "URDB Download Message");
return;
// wxMessageBox("Utility Rate Query Error\n\n" + err, "URDB Download Message");
// return false;
ret = false;
mUtilityRates.clear();
}

lblRateStatus->SetLabel(wxString::Format("%d rates available for %s", (int)mUtilityRates.size(), utility_name));
Expand All @@ -1305,6 +1308,7 @@ void OpenEIUtilityRateDialog::QueryRates(const wxString &utility_name)
lblStatus->SetLabel("Ready.");

UpdateRateList();
return true;
}

void OpenEIUtilityRateDialog::UpdateRateList()
Expand Down Expand Up @@ -1414,8 +1418,14 @@ void OpenEIUtilityRateDialog::OnEvent(wxCommandEvent &evt)
UpdateRateList();
break;
case ID_lstUtilities:
QueryRates( lstUtilities->GetStringSelection() );
lblUtilityCount->SetLabel(wxString::Format("%d utilities", (int)lstUtilities->Count()));
if (QueryRates(lstUtilities->GetStringSelection())) {
lblUtilityCount->SetLabel(wxString::Format("%d utilities", (int)lstUtilities->Count()));
}
else {
lstRates->Clear();
mGUIDList.Clear();
mUtilityRates.clear();
}
break;
case ID_lstRates:
UpdateRateData();
Expand Down
2 changes: 1 addition & 1 deletion src/urdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class OpenEIUtilityRateDialog : public wxDialog
void StartHttp();
void QueryUtilities();
void QueryUtilitiesByZipCode();
void QueryRates(const wxString &utility_name);
bool QueryRates(const wxString &utility_name);
void OnEvent(wxCommandEvent &evt);
void OnTimer(wxTimerEvent &evt);
void UpdateRateList();
Expand Down

0 comments on commit b9f16fb

Please sign in to comment.