From fd43873af5de2d892ada1fe2691272992decaf4f Mon Sep 17 00:00:00 2001 From: Xun Li Date: Fri, 29 Apr 2016 21:49:10 -0700 Subject: [PATCH 1/9] #407 make OK buttons consistent --- DialogTools/ExportCsvDlg.cpp | 2 +- DialogTools/RegressionDlg.cpp | 2 +- DialogTools/SelectWeightsDlg.cpp | 4 ++-- DialogTools/VariableSettingsDlg.cpp | 2 +- DialogTools/WeightsManDlg.cpp | 2 +- GeoDa.cpp | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/DialogTools/ExportCsvDlg.cpp b/DialogTools/ExportCsvDlg.cpp index 1491a64f2..8b88cb847 100644 --- a/DialogTools/ExportCsvDlg.cpp +++ b/DialogTools/ExportCsvDlg.cpp @@ -82,7 +82,7 @@ void ExportCsvDlg::OnOkClick( wxCommandEvent& event ) // Prompt for overwrite permission if (wxFileExists(new_csv)) { wxString msg; - msg << new_csv << " already exists. Ok to overwrite?"; + msg << new_csv << " already exists. OK to overwrite?"; wxMessageDialog dlg (this, msg, "Overwrite?", wxYES_NO | wxCANCEL | wxNO_DEFAULT); if (dlg.ShowModal() != wxID_YES) return; diff --git a/DialogTools/RegressionDlg.cpp b/DialogTools/RegressionDlg.cpp index 02485b100..96ff0c398 100644 --- a/DialogTools/RegressionDlg.cpp +++ b/DialogTools/RegressionDlg.cpp @@ -700,7 +700,7 @@ void RegressionDlg::OnSaveToTxtFileClick( wxCommandEvent& event ) // Prompt for overwrite permission if (wxFileExists(new_txt)) { wxString msg; - msg << new_txt << " already exists. Ok to overwrite?"; + msg << new_txt << " already exists. OK to overwrite?"; wxMessageDialog dlg (this, msg, "Overwrite?", wxYES_NO | wxCANCEL | wxNO_DEFAULT); if (dlg.ShowModal() != wxID_YES) return; diff --git a/DialogTools/SelectWeightsDlg.cpp b/DialogTools/SelectWeightsDlg.cpp index 171e40486..ea94e3a86 100644 --- a/DialogTools/SelectWeightsDlg.cpp +++ b/DialogTools/SelectWeightsDlg.cpp @@ -53,7 +53,7 @@ w_man_int(project->GetWManInt()), w_list(0), ok_btn(0), cancel_btn(0) void SelectWeightsDlg::InitNoWeights() { panel = new wxPanel(this); - ok_btn = new wxButton(panel, XRCID("wxID_OK"), "Ok", + ok_btn = new wxButton(panel, XRCID("wxID_OK"), "OK", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); Connect(XRCID("wxID_OK"), wxEVT_BUTTON, wxCommandEventHandler(SelectWeightsDlg::OnOkClick)); @@ -86,7 +86,7 @@ void SelectWeightsDlg::InitNormal() panel->SetBackgroundColour(*wxWHITE); SetBackgroundColour(*wxWHITE); - ok_btn = new wxButton(panel, XRCID("wxID_OK"), "Ok", + ok_btn = new wxButton(panel, XRCID("wxID_OK"), "OK", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); cancel_btn = new wxButton(panel, XRCID("wxID_CANCEL"), "Cancel", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT); diff --git a/DialogTools/VariableSettingsDlg.cpp b/DialogTools/VariableSettingsDlg.cpp index c6c9e3445..65cd816c4 100644 --- a/DialogTools/VariableSettingsDlg.cpp +++ b/DialogTools/VariableSettingsDlg.cpp @@ -118,7 +118,7 @@ void DiffMoranVarSettingDlg::CreateControls() panel->SetSizer(vbox); - wxButton *okButton = new wxButton(this, wxID_OK, wxT("Ok"), wxDefaultPosition, wxSize(70, 30)); + wxButton *okButton = new wxButton(this, wxID_OK, wxT("OK"), wxDefaultPosition, wxSize(70, 30)); wxButton *closeButton = new wxButton(this, wxID_EXIT, wxT("Close"), wxDefaultPosition, wxSize(70, 30)); hbox2->Add(okButton, 1); diff --git a/DialogTools/WeightsManDlg.cpp b/DialogTools/WeightsManDlg.cpp index c3d82516e..310eba20f 100644 --- a/DialogTools/WeightsManDlg.cpp +++ b/DialogTools/WeightsManDlg.cpp @@ -316,7 +316,7 @@ void WeightsManFrame::OnRemoveBtn(wxCommandEvent& ev) msg << " other " << (nb==1 ? "view" : "views"); msg << " open that depend" << (nb==1 ? "s" : ""); msg << " on this matrix. "; - msg << "Ok to close " << (nb==1 ? "this view" : "these views"); + msg << "OK to close " << (nb==1 ? "this view" : "these views"); msg << " and remove?"; wxMessageDialog dlg(this, msg, "Notice", wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION); diff --git a/GeoDa.cpp b/GeoDa.cpp index 5c3350cda..cbb2ddd5e 100644 --- a/GeoDa.cpp +++ b/GeoDa.cpp @@ -1676,7 +1676,7 @@ void GdaFrame::OnClose(wxCloseEvent& event) msg << "To save your work, go to File > Save"; } else { title = "Exit?"; - msg = "Ok to Exit?"; + msg = "OK to Exit?"; } if (IsProjectOpen()) { From 3423cc50b59ac805f6c6d8f9bcbd883f5e26d6aa Mon Sep 17 00:00:00 2001 From: Xun Li Date: Sun, 1 May 2016 09:43:43 -0700 Subject: [PATCH 2/9] averages chart: interface formatting issue #411 the group summary table in the averages chart bumps the selected period to the second line when "unselected" is chosen in both time periods; for selected it lines up very nicely. looks like an extra space may be needed. --- Explore/LineChartView.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Explore/LineChartView.cpp b/Explore/LineChartView.cpp index 5d1ffd309..5bd970e17 100644 --- a/Explore/LineChartView.cpp +++ b/Explore/LineChartView.cpp @@ -171,7 +171,7 @@ has_excluded(1) btn_box->Add(btn_apply, 1, wxALIGN_CENTER | wxEXPAND | wxALL, 10); wxHtmlWindow* wv = 0; - wv = new wxHtmlWindow(lpanel, wxID_ANY, wxDefaultPosition, wxSize(220, 100)); + wv = new wxHtmlWindow(lpanel, wxID_ANY, wxDefaultPosition, wxSize(230, 100)); stats_wins.push_back(wv); wxBoxSizer* stats_box = new wxBoxSizer(wxHORIZONTAL); stats_box->Add(wv, 1, wxEXPAND | wxALL, 10); @@ -207,7 +207,7 @@ has_excluded(1) panel->SetSizer(panel_h_szr); - splitter_win->SplitVertically(lpanel, panel, 320); + splitter_win->SplitVertically(lpanel, panel, 350); wxBoxSizer* sizerAll = new wxBoxSizer(wxVERTICAL); sizerAll->Add(splitter_win, 1, wxEXPAND|wxALL); SetSizer(sizerAll); @@ -1988,7 +1988,7 @@ void LineChartFrame::UpdateStatsWinContent(int var) s<< ""; s<< ""; - s<< ""; + s<< ""; s<< ""; s<< ""; s<< ""; From 61d0c97a42abe33d21004ad43877c05ae1cdd051 Mon Sep 17 00:00:00 2001 From: Xun Li Date: Sun, 1 May 2016 09:44:17 -0700 Subject: [PATCH 3/9] update version # to 1.8.4 --- version.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/version.h b/version.h index 464d01a1b..30a5e4ad6 100644 --- a/version.h +++ b/version.h @@ -1,10 +1,10 @@ namespace Gda { const int version_major = 1; const int version_minor = 8; - const int version_build = 3; + const int version_build = 4; const int version_year = 2016; - const int version_month = 4; - const int version_day = 29; + const int version_month = 5; + const int version_day = 1; const int version_night = 0; const int version_type = 1; // 0: alpha, 1: beta, 2: release } From 3d750351afce81a58df4bfae3bc2a36769b48f11 Mon Sep 17 00:00:00 2001 From: Xun Li Date: Sun, 1 May 2016 19:41:20 -0700 Subject: [PATCH 4/9] add PERIOD in averages chart save dummy #408 averages chart save dummy needs both space and time ID #408 --- Explore/LineChartView.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Explore/LineChartView.cpp b/Explore/LineChartView.cpp index 5bd970e17..f70be6bc1 100644 --- a/Explore/LineChartView.cpp +++ b/Explore/LineChartView.cpp @@ -811,6 +811,9 @@ void LineChartFrame::OnSaveDummyTable(wxCommandEvent& event) const std::vector& hs(highlight_state->GetHighlight()); int n_obs = project->GetNumRecords(); + std::vector tm_strs; + table_int->GetTimeStrings(tm_strs); + //double** var_stack_array = new double*[nTests]; //double *dummy_select_stack = NULL; //double *dummy_time_stack = NULL; @@ -823,6 +826,7 @@ void LineChartFrame::OnSaveDummyTable(wxCommandEvent& event) std::vector interaction_stack; std::vector id_stack; std::vector newids; + std::vector period_stack; var_stack_array.resize(nTests); @@ -873,6 +877,7 @@ void LineChartFrame::OnSaveDummyTable(wxCommandEvent& event) var_stack_array[i].resize(n); dummy_select_stack.resize(n); + period_stack.resize(n); id_stack.resize(n); int idx = 0; @@ -882,6 +887,7 @@ void LineChartFrame::OnSaveDummyTable(wxCommandEvent& event) var_stack_array[i][idx] = Y[t][j]; dummy_select_stack[idx] = hs[j] == true ? 1 : 0; id_stack[idx] = j; + period_stack[idx] = tm_strs[t]; newids.push_back(idx+1); idx += 1; } @@ -915,6 +921,7 @@ void LineChartFrame::OnSaveDummyTable(wxCommandEvent& event) var_stack_array[i].resize(n); dummy_time_stack.resize(n); + period_stack.resize(n); id_stack.resize(n); int idx = 0; @@ -925,6 +932,7 @@ void LineChartFrame::OnSaveDummyTable(wxCommandEvent& event) var_stack_array[i][idx] = Y[t][j]; dummy_time_stack[idx] = tms_subset0[t] == true ? 0 : 1; id_stack[idx] = j; + period_stack[idx] = tm_strs[t]; newids.push_back(idx+1); idx += 1; } @@ -974,6 +982,7 @@ void LineChartFrame::OnSaveDummyTable(wxCommandEvent& event) dummy_select_stack.push_back(hs[j] == true ? 1 : 0); dummy_time_stack.push_back(tms_subset0[t] == true ? 0 : 1); interaction_stack.push_back(dummy_select_stack[idx] * dummy_time_stack[idx]); + period_stack.push_back(tm_strs[t]); id_stack.push_back(j); newids.push_back(idx+1); idx += 1; @@ -1027,6 +1036,14 @@ void LineChartFrame::OnSaveDummyTable(wxCommandEvent& event) } } + if (!period_stack.empty()) { + int n = period_stack.size(); + if (mem_table_int == NULL) mem_table_int = new OGRTable(n); + OGRColumn* period_col = new OGRColumnString("PERIOD", 50, 0, n); + period_col->UpdateData(period_stack); + mem_table_int->AddOGRColumn(period_col); + } + if (!dummy_time_stack.empty()) { int n = dummy_time_stack.size(); if (mem_table_int == NULL) mem_table_int = new OGRTable(n); From f3bba5b554d43bacbac7f3ebeb18f84dc1a07091 Mon Sep 17 00:00:00 2001 From: Xun Li Date: Sun, 1 May 2016 20:04:36 -0700 Subject: [PATCH 5/9] averages chart: number of observations in save dummy file is incorrect #410 --- Explore/LineChartView.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Explore/LineChartView.cpp b/Explore/LineChartView.cpp index f70be6bc1..5dfea8828 100644 --- a/Explore/LineChartView.cpp +++ b/Explore/LineChartView.cpp @@ -977,7 +977,7 @@ void LineChartFrame::OnSaveDummyTable(wxCommandEvent& event) for (int t=0; tUpdateData(period_stack); mem_table_int->AddOGRColumn(period_col); } @@ -1073,7 +1073,13 @@ void LineChartFrame::OnSaveDummyTable(wxCommandEvent& event) wxString col_name(var_man.GetName(i)); int n = var_stack_array[i].size(); if (mem_table_int == NULL) mem_table_int = new OGRTable(n); - OGRColumn* var_col = new OGRColumnDouble(col_name, 18, 9, n); + int col_idx = table_int->FindColId(col_name); + GdaConst::FieldType f_type = table_int->GetColType(col_idx, 0); + OGRColumn* var_col; + if (f_type == GdaConst::long64_type) + var_col = new OGRColumnInteger(col_name, 18, 0, n); + else + var_col = new OGRColumnDouble(col_name, 18, 9, n); var_col->UpdateData(var_stack_array[i]); mem_table_int->AddOGRColumn(var_col); } From 0333bc769276b0a03c9ceb07ac6b7085b205778f Mon Sep 17 00:00:00 2001 From: Xun Li Date: Sun, 1 May 2016 20:34:35 -0700 Subject: [PATCH 6/9] fix DID bug: no DID on non-time variable --- Explore/LineChartView.cpp | 80 +++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/Explore/LineChartView.cpp b/Explore/LineChartView.cpp index 5dfea8828..2df3e6610 100644 --- a/Explore/LineChartView.cpp +++ b/Explore/LineChartView.cpp @@ -1177,35 +1177,43 @@ void LineChartFrame::RunDIDTest() } } + // start regression + int nX = 0; + double* y; + double **x; + + if (compare_regimes) { m_Xnames.push_back("SPACE_DUMMY"); - int nX = m_Xnames.size(); + nX = m_Xnames.size(); - int n = 0; - for (size_t t=0; tGetTableInt(); + int col = table_int->FindColId(m_Yname); + + if (!table_int->IsColTimeVariant(col)) { + for (int j=0; jGetTableName(), wxEmptyString, &m_DR, m_obs, nX, do_white_test); m_yhat1 = m_DR.GetYHAT(); - delete[] y; - for (int t=0; tGetTableName(), wxEmptyString, &m_DR, m_obs, nX, do_white_test); m_yhat1 = m_DR.GetYHAT(); - delete[] y; - for (int t=0; tGetTableName(), wxEmptyString, &m_DR, m_obs, nX, do_white_test); m_yhat1 = m_DR.GetYHAT(); - delete[] y; - for (int t=0; t Date: Sun, 1 May 2016 23:10:05 -0700 Subject: [PATCH 7/9] save DID results to file #409 --- DialogTools/RegressionReportDlg.cpp | 14 +- Explore/LineChartView.cpp | 275 ++++++++++++++++------------ Explore/LineChartView.h | 3 + 3 files changed, 177 insertions(+), 115 deletions(-) diff --git a/DialogTools/RegressionReportDlg.cpp b/DialogTools/RegressionReportDlg.cpp index 3e2da59f1..45b21e2e0 100644 --- a/DialogTools/RegressionReportDlg.cpp +++ b/DialogTools/RegressionReportDlg.cpp @@ -88,6 +88,16 @@ void RegressionReportDlg::CreateControls() vbox->Add(m_textbox, 1, wxEXPAND|wxALL|wxALIGN_CENTRE); panel->SetSizer(vbox); + + + //wxBitmap edit = wxArtProvider::GetBitmap(wxART_PRINT); + //wxBitmap save = wxArtProvider::GetBitmap(wxART_FILE_SAVE); + //wxToolBar *toolbar = CreateToolBar(); + //toolbar->AddTool(wxID_EDIT, "Change Font", edit); + //toolbar->AddTool(wxID_SAVE, "Save Regression Results", save); + //toolbar->Realize(); + //Connect(wxID_EDIT, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(RegressionReportDlg::OnFontChanged)); + //Connect(wxID_SAVE, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(RegressionReportDlg::OnFontChanged)); Center(); } @@ -105,7 +115,7 @@ void RegressionReportDlg::SetReport(const wxString report) void RegressionReportDlg::OnMouseEvent(wxMouseEvent& event) { - if (event.RightUp()) + if (event.RightDown()) PopupMenu(wxXmlResource::Get()-> LoadMenu("ID_REPORT_VIEW_MENU_CONTEXT"), event.GetPosition().x, event.GetPosition().y); @@ -114,7 +124,7 @@ void RegressionReportDlg::OnMouseEvent(wxMouseEvent& event) void RegressionReportDlg::OnFontChanged(wxCommandEvent& event) { wxFontData data; - wxFontDialog dlg(this, data); + wxFontDialog dlg(NULL, data); wxTextAttr attr; if (dlg.ShowModal() == wxID_OK) diff --git a/Explore/LineChartView.cpp b/Explore/LineChartView.cpp index 2df3e6610..5aacf4755 100644 --- a/Explore/LineChartView.cpp +++ b/Explore/LineChartView.cpp @@ -167,9 +167,14 @@ has_excluded(1) wxButton* btn_save_dummy = new wxButton(lpanel, wxID_ANY, "Save Dummy"); wxButton* btn_apply = new wxButton(lpanel, wxID_ANY, "Run Diff-in-Diff Test"); wxBoxSizer* btn_box = new wxBoxSizer(wxHORIZONTAL); - btn_box->Add(btn_save_dummy, 1, wxALIGN_CENTER |wxEXPAND| wxALL, 10); btn_box->Add(btn_apply, 1, wxALIGN_CENTER | wxEXPAND | wxALL, 10); - + btn_box->Add(btn_save_dummy, 1, wxALIGN_CENTER |wxEXPAND| wxALL, 10); + + chk_save_did = new wxCheckBox(lpanel, wxID_ANY, "Save Test Results"); + wxBoxSizer* chk_box = new wxBoxSizer(wxHORIZONTAL); + chk_box->Add(chk_save_did, 1, wxALIGN_LEFT |wxLEFT, 10); + + wxHtmlWindow* wv = 0; wv = new wxHtmlWindow(lpanel, wxID_ANY, wxDefaultPosition, wxSize(230, 100)); stats_wins.push_back(wv); @@ -182,6 +187,7 @@ has_excluded(1) rbox->Add(tests_sizer, 0, wxALIGN_TOP | wxALL, 20); //rbox->Add(chk_run_test, 0, wxALIGN_TOP | wxLEFT | wxRIGHT | wxBOTTOM, 20); rbox->Add(btn_box, 0, wxALIGN_TOP | wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10); + rbox->Add(chk_box, 0, wxALIGN_TOP | wxEXPAND | wxLEFT | wxRIGHT , 10); rbox->Add(stats_box, 1, wxALIGN_TOP | wxEXPAND | wxALL, 10); lpanel->SetSizerAndFit(rbox); @@ -803,14 +809,16 @@ void LineChartFrame::OnAdjustYAxisPrecision(wxCommandEvent& event) Refresh(); } -void LineChartFrame::OnSaveDummyTable(wxCommandEvent& event) +void LineChartFrame::SaveDataAndResults(bool save_weights, bool save_did, + double* m_yhat1, double* m_resid1) { - LOG_MSG("Start LineChartFrame::OnSaveDummyTable"); int nTests = var_man.GetVarsCount(); + nTests = 1; // only handle one variable at a time + TableInterface* table_int = project->GetTableInt(); const std::vector& hs(highlight_state->GetHighlight()); int n_obs = project->GetNumRecords(); - + std::vector tm_strs; table_int->GetTimeStrings(tm_strs); @@ -827,13 +835,13 @@ void LineChartFrame::OnSaveDummyTable(wxCommandEvent& event) std::vector id_stack; std::vector newids; std::vector period_stack; - + var_stack_array.resize(nTests); for (int i=0; iGetSelection(); wxString col_name = variable_names[variable_selection]; - + TableInterface* table_int = project->GetTableInt(); int col = table_int->FindColId(col_name); @@ -864,8 +872,8 @@ void LineChartFrame::OnSaveDummyTable(wxCommandEvent& event) } } else { - - for (size_t t=0; tGetSelection() == 0 ? true : false; - + int idx = 0; for (int t=0; tUpdateData(newids); @@ -1005,7 +1014,7 @@ void LineChartFrame::OnSaveDummyTable(wxCommandEvent& event) } if (!id_stack.empty()) { - int n = id_stack.size(); + n = id_stack.size(); if (mem_table_int == NULL) mem_table_int = new OGRTable(n); bool using_default_id = true; @@ -1022,7 +1031,7 @@ void LineChartFrame::OnSaveDummyTable(wxCommandEvent& event) int c_id = table_int->FindColId(gw->id_field); if (c_id > 0) { table_int->GetColData(c_id, 1, id_vec); - + vector new_id_vec; for (int ii=0; iiUpdateData(period_stack); mem_table_int->AddOGRColumn(period_col); } + if (!var_stack_array.empty()) { + for (size_t i=0; iFindColId(col_name); + GdaConst::FieldType f_type = table_int->GetColType(col_idx, 0); + OGRColumn* var_col; + if (f_type == GdaConst::long64_type) + var_col = new OGRColumnInteger(col_name, 18, 0, n); + else + var_col = new OGRColumnDouble(col_name, 18, 9, n); + var_col->UpdateData(var_stack_array[i]); + mem_table_int->AddOGRColumn(var_col); + } + } + if (!dummy_time_stack.empty()) { - int n = dummy_time_stack.size(); + n = dummy_time_stack.size(); if (mem_table_int == NULL) mem_table_int = new OGRTable(n); OGRColumn* time_col = new OGRColumnInteger("TIME", 18, 0, n); time_col->UpdateData(dummy_time_stack); @@ -1053,66 +1079,78 @@ void LineChartFrame::OnSaveDummyTable(wxCommandEvent& event) } if (!dummy_select_stack.empty()) { - int n = dummy_select_stack.size(); + n = dummy_select_stack.size(); if (mem_table_int == NULL) mem_table_int = new OGRTable(n); OGRColumn* select_col = new OGRColumnInteger("SPACE", 18, 0, n); select_col->UpdateData(dummy_select_stack); mem_table_int->AddOGRColumn(select_col); } - + if (!interaction_stack.empty()) { - int n = interaction_stack.size(); + n = interaction_stack.size(); if (mem_table_int == NULL) mem_table_int = new OGRTable(n); OGRColumn* interact_col = new OGRColumnInteger("INTERACT", 18, 0, n); interact_col->UpdateData(interaction_stack); mem_table_int->AddOGRColumn(interact_col); } + - if (!var_stack_array.empty()) { - for (size_t i=0; i yhat; + std::vector resid; + for (int m=0; mFindColId(col_name); - GdaConst::FieldType f_type = table_int->GetColType(col_idx, 0); - OGRColumn* var_col; - if (f_type == GdaConst::long64_type) - var_col = new OGRColumnInteger(col_name, 18, 0, n); - else - var_col = new OGRColumnDouble(col_name, 18, 9, n); - var_col->UpdateData(var_stack_array[i]); - mem_table_int->AddOGRColumn(var_col); + OGRColumn* pred_col = new OGRColumnDouble("OLS_PREDIC", 18, 9, n); + pred_col->UpdateData(yhat); + mem_table_int->AddOGRColumn(pred_col); + OGRColumn* resi_col = new OGRColumnDouble("OLS_RESIDU", 18, 9, n); + resi_col->UpdateData(resid); + mem_table_int->AddOGRColumn(resi_col); + } } // export ExportDataDlg dlg(this, (TableInterface*)mem_table_int); if (dlg.ShowModal() == wxID_OK) { - wxString ds_name = dlg.GetDatasourceName(); - wxFileName wx_fn(ds_name); - - // save weights - // Get default GalWeight* - // change to space-time weights - WeightsManInterface* wmi = NULL; - if (project && project->GetWManInt()) { - wmi = project->GetWManInt(); - boost::uuids::uuid default_wid = wmi->GetDefault(); - if (!default_wid.is_nil()) { - GeoDaWeight* w = wmi->GetWeights(default_wid); - if (w->weight_type == GeoDaWeight::gal_type) { - wx_fn.SetExt("gal"); - } else if (w->weight_type == GeoDaWeight::gwt_type) { - wx_fn.SetExt("gwt"); + if (save_weights) { + wxString ds_name = dlg.GetDatasourceName(); + wxFileName wx_fn(ds_name); + + // save weights + // Get default GalWeight* + // change to space-time weights + WeightsManInterface* wmi = NULL; + if (project && project->GetWManInt()) { + wmi = project->GetWManInt(); + boost::uuids::uuid default_wid = wmi->GetDefault(); + if (!default_wid.is_nil()) { + GeoDaWeight* w = wmi->GetWeights(default_wid); + if (w->weight_type == GeoDaWeight::gal_type) { + wx_fn.SetExt("gal"); + } else if (w->weight_type == GeoDaWeight::gwt_type) { + wx_fn.SetExt("gwt"); + } + wxString ofn(wx_fn.GetFullPath()); + w->SaveDIDWeights(project, n_obs, newids, id_stack, ofn); } - wxString ofn(wx_fn.GetFullPath()); - w->SaveDIDWeights(project, n_obs, newids, id_stack, ofn); } } } // clean memory delete mem_table_int; + +} +void LineChartFrame::OnSaveDummyTable(wxCommandEvent& event) +{ + LOG_MSG("Start LineChartFrame::OnSaveDummyTable"); + bool save_w = true; + SaveDataAndResults(save_w); LOG_MSG("End LineChartFrame::OnSaveDummyTable"); } @@ -1181,10 +1219,11 @@ void LineChartFrame::RunDIDTest() int nX = 0; double* y; double **x; + DiagnosticReport* m_DR; if (compare_regimes) { - m_Xnames.push_back("SPACE_DUMMY"); + m_Xnames.push_back("SPACE"); nX = m_Xnames.size(); int n = m_obs; @@ -1218,29 +1257,27 @@ void LineChartFrame::RunDIDTest() } } - DiagnosticReport m_DR(n, nX, m_constant_term, true, RegressModel); + m_DR = new DiagnosticReport(n, nX, m_constant_term, true, RegressModel); for (int i = 0; i < nX; i++) { - m_DR.SetXVarNames(i, m_Xnames[i]); + m_DR->SetXVarNames(i, m_Xnames[i]); } - m_DR.SetMeanY(ComputeMean(y, n)); - m_DR.SetSDevY(ComputeSdev(y, n)); + m_DR->SetMeanY(ComputeMean(y, n)); + m_DR->SetSDevY(ComputeSdev(y, n)); - classicalRegression(NULL, n, y, n, x, nX, &m_DR, + classicalRegression(NULL, n, y, n, x, nX, m_DR, m_constant_term, true, m_gauge, do_white_test); - m_resid1= m_DR.GetResidual(); - printAndShowClassicalResults(row_nm, y, table_int->GetTableName(), wxEmptyString, &m_DR, m_obs, nX, do_white_test); - m_yhat1 = m_DR.GetYHAT(); - - m_DR.release_Var(); + m_resid1= m_DR->GetResidual(); + printAndShowClassicalResults(row_nm, y, table_int->GetTableName(), wxEmptyString, m_DR, m_obs, nX, do_white_test); + m_yhat1 = m_DR->GetYHAT(); wxDateTime now = wxDateTime::Now(); logReport = ">>" + now.FormatDate() + " " + now.FormatTime() + "\nREGRESSION (DIFF-IN-DIFF, COMPARE REGIMES) \n----------\n" + logReport; } else if (compare_time_periods) { - m_Xnames.push_back("PERIOD_DUMMY"); + m_Xnames.push_back("TIME"); nX = m_Xnames.size(); int n1 = 0, n2 = 0; @@ -1284,30 +1321,29 @@ void LineChartFrame::RunDIDTest() } } - DiagnosticReport m_DR(n, nX, m_constant_term, true, RegressModel); + m_DR = new DiagnosticReport(n, nX, m_constant_term, true, RegressModel); for (int i = 0; i < nX; i++) { - m_DR.SetXVarNames(i, m_Xnames[i]); + m_DR->SetXVarNames(i, m_Xnames[i]); } - m_DR.SetMeanY(ComputeMean(y, n)); - m_DR.SetSDevY(ComputeSdev(y, n)); + m_DR->SetMeanY(ComputeMean(y, n)); + m_DR->SetSDevY(ComputeSdev(y, n)); - classicalRegression(NULL, n, y, n, x, nX, &m_DR, + classicalRegression(NULL, n, y, n, x, nX, m_DR, m_constant_term, true, m_gauge, do_white_test); - m_resid1= m_DR.GetResidual(); - printAndShowClassicalResults(row_nm, y, table_int->GetTableName(), wxEmptyString, &m_DR, m_obs, nX, do_white_test); - m_yhat1 = m_DR.GetYHAT(); + m_resid1= m_DR->GetResidual(); + printAndShowClassicalResults(row_nm, y, table_int->GetTableName(), wxEmptyString, m_DR, m_obs, nX, do_white_test); + m_yhat1 = m_DR->GetYHAT(); - m_DR.release_Var(); wxDateTime now = wxDateTime::Now(); logReport = ">>" + now.FormatDate() + " " + now.FormatTime() + "\nREGRESSION (DIFF-IN-DIFF, COMPARE TIME PERIOD) \n----------\n" + logReport; } else if (compare_r_and_t) { - m_Xnames.push_back("SPACE_DUMMY"); - m_Xnames.push_back("PERIOD_DUMMY"); - m_Xnames.push_back("INTERACTION"); + m_Xnames.push_back("SPACE"); + m_Xnames.push_back("TIME"); + m_Xnames.push_back("INTERACT"); nX = m_Xnames.size(); int n1 = 0, n2 = 0; @@ -1352,42 +1388,55 @@ void LineChartFrame::RunDIDTest() } } - DiagnosticReport m_DR(n, nX, m_constant_term, true, RegressModel); + m_DR = new DiagnosticReport(n, nX, m_constant_term, true, RegressModel); for (int i = 0; i < nX; i++) { - m_DR.SetXVarNames(i, m_Xnames[i]); + m_DR->SetXVarNames(i, m_Xnames[i]); } - m_DR.SetMeanY(ComputeMean(y, n)); - m_DR.SetSDevY(ComputeSdev(y, n)); + m_DR->SetMeanY(ComputeMean(y, n)); + m_DR->SetSDevY(ComputeSdev(y, n)); - classicalRegression(NULL, n, y, n, x, nX, &m_DR, + classicalRegression(NULL, n, y, n, x, nX, m_DR, m_constant_term, true, m_gauge, do_white_test); - m_resid1= m_DR.GetResidual(); - printAndShowClassicalResults(row_nm, y, table_int->GetTableName(), wxEmptyString, &m_DR, m_obs, nX, do_white_test); - m_yhat1 = m_DR.GetYHAT(); + m_resid1= m_DR->GetResidual(); + printAndShowClassicalResults(row_nm, y, table_int->GetTableName(), wxEmptyString, m_DR, m_obs, nX, do_white_test); + m_yhat1 = m_DR->GetYHAT(); - m_DR.release_Var(); wxDateTime now = wxDateTime::Now(); logReport = ">>" + now.FormatDate() + " " + now.FormatTime() + "\nREGRESSION (DIFF-IN-DIFF, COMPARE REGIMES AND TIME PERIOD) \n----------\n" + logReport; } - delete[] y; - for (int t=0; tConnect(wxEVT_DESTROY, wxWindowDestroyEventHandler(LineChartFrame::OnReportClose), NULL, this); + + } else { regReportDlg->AddNewReport(logReport); } regReportDlg->Show(true); regReportDlg->m_textbox->SetSelection(0, 0); + if (chk_save_did && chk_save_did->IsChecked()) { + wxMessageDialog saveDlg(this, "Do you want to save the results of Diff-in-Diff test?\n\nNote: the results can only be saved into an external data file, due to the change of cross-sectional observations in a space-time context.", "Save Diff-in-Diff Test Results", wxYES_NO | wxICON_QUESTION); + if (saveDlg.ShowModal() == wxID_YES) { + bool save_w = false; + bool save_did = true; + SaveDataAndResults(save_w, save_did, m_yhat1, m_resid1); + } + } + + delete[] y; + for (int t=0; trelease_Var(); + delete m_DR; } LOG_MSG("End LineChartFrame::RunDIDTest"); diff --git a/Explore/LineChartView.h b/Explore/LineChartView.h index 1408ee1a1..82abd635e 100644 --- a/Explore/LineChartView.h +++ b/Explore/LineChartView.h @@ -145,6 +145,8 @@ public HighlightStateObserver, public LineChartCanvasCallbackInt protected: + void SaveDataAndResults(bool save_weights, bool save_did=false, + double* m_yhat1=0, double* m_resid1=0); void SetupPanelForNumVariables(int num_vars); void UpdateMessageWin(); void UpdateTitleWin(); @@ -168,6 +170,7 @@ public HighlightStateObserver, public LineChartCanvasCallbackInt wxChoice* choice_time1; wxChoice* choice_time2; //wxCheckBox* chk_run_test; + wxCheckBox* chk_save_did; int has_selection; int has_excluded; From 31f74fae07d5f3f3a24040b6817cb7b3b54ef7d5 Mon Sep 17 00:00:00 2001 From: Xun Li Date: Sun, 1 May 2016 23:29:46 -0700 Subject: [PATCH 8/9] Neighborless observations: No weights with 0 connections and add flag #400 --- DialogTools/CreatingWeightDlg.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/DialogTools/CreatingWeightDlg.cpp b/DialogTools/CreatingWeightDlg.cpp index 3c25720dd..3cea4596e 100644 --- a/DialogTools/CreatingWeightDlg.cpp +++ b/DialogTools/CreatingWeightDlg.cpp @@ -389,15 +389,23 @@ void CreatingWeightDlg::OnCreateClick( wxCommandEvent& event ) } gal = PolysToContigWeights(project->main_data, !is_rook, precision_threshold); } - - if (!gal) { + + bool empty_w = true; + bool has_island = false; + + for (size_t i=0; i0) { + empty_w = false; + } else { + has_island = true; + } + } + + if (empty_w) { // could be an empty weights file, and should prompt user // to setup Precision Threshold - wxString msg("GeoDa can't find weights information from " - "shapes. You can try to set a precision " - "threshold value to find neighbor shapes " - "using a fuzzy matching approach."); - wxMessageDialog dlg(NULL, msg, "Empty Contiguity Weights Created", wxOK | wxICON_WARNING); + wxString msg("None of your observations have neighbors. This could be related to digitizing problems, which can be fixed by adjusting the precision threshold."); + wxMessageDialog dlg(NULL, msg, "Empty Contiguity Weights", wxOK | wxICON_WARNING); dlg.ShowModal(); m_cbx_precision_threshold->SetValue(true); @@ -420,6 +428,13 @@ void CreatingWeightDlg::OnCreateClick( wxCommandEvent& event ) m_txt_precision_threshold->SetValue(tmpTxt); break; } + if (has_island) { + wxString msg("There is at least one neighborless observation. Check the weights histogram and linked map to see if the islands are real or not. If not, adjust the distance threshold (points) or the precision threshold (polygons)."); + wxMessageDialog dlg(NULL, msg, "Neighborless Observation", wxOK | wxICON_WARNING); + dlg.ShowModal(); + } + + if (m_ooC > 1) { Gda::MakeHigherOrdContiguity(m_ooC, m_num_obs, gal, m_check1); WriteWeightFile(gal, 0, project->GetProjectTitle(), outputfile, id, wmi); From 8b926ab2f67b61afc80cfdebebd037a0d321419a Mon Sep 17 00:00:00 2001 From: Xun Li Date: Mon, 2 May 2016 00:09:42 -0700 Subject: [PATCH 9/9] update UI for win LineChart --- Explore/LineChartView.cpp | 4 ++-- Explore/LineChartView.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Explore/LineChartView.cpp b/Explore/LineChartView.cpp index 5aacf4755..b256b725f 100644 --- a/Explore/LineChartView.cpp +++ b/Explore/LineChartView.cpp @@ -196,7 +196,7 @@ has_excluded(1) panel->SetBackgroundColour(*wxWHITE); panel->Bind(wxEVT_RIGHT_UP, &LineChartFrame::OnMouseEvent, this); - message_win = new wxHtmlWindow(panel, wxID_ANY, wxDefaultPosition, wxSize(400,-1)); + message_win = new wxHtmlWindow(panel, wxID_ANY, wxDefaultPosition, wxSize(380,-1)); message_win->Bind(wxEVT_RIGHT_UP, &LineChartFrame::OnMouseEvent, this); bag_szr = new wxGridBagSizer(0, 0); // 0 vgap, 0 hgap @@ -213,7 +213,7 @@ has_excluded(1) panel->SetSizer(panel_h_szr); - splitter_win->SplitVertically(lpanel, panel, 350); + splitter_win->SplitVertically(lpanel, panel, 380); wxBoxSizer* sizerAll = new wxBoxSizer(wxVERTICAL); sizerAll->Add(splitter_win, 1, wxEXPAND|wxALL); SetSizer(sizerAll); diff --git a/Explore/LineChartView.h b/Explore/LineChartView.h index 82abd635e..068cc779c 100644 --- a/Explore/LineChartView.h +++ b/Explore/LineChartView.h @@ -103,7 +103,7 @@ public HighlightStateObserver, public LineChartCanvasCallbackInt LineChartFrame(wxFrame *parent, Project* project, const wxString& title = "Averages Chart", const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize); + const wxSize& size = wxSize(680,420)); virtual ~LineChartFrame(); virtual void OnActivate(wxActivateEvent& event);
GroupGroup Obs.  Mean  S.D.