From 06dc9110abc46af95cc6a82bf3b2a5751fffdf4c Mon Sep 17 00:00:00 2001 From: Xun Li Date: Wed, 4 May 2016 14:09:37 -0700 Subject: [PATCH 1/5] #415 number of observations in DID regression incorrect --- Explore/LineChartView.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Explore/LineChartView.cpp b/Explore/LineChartView.cpp index b256b725f..0e9768439 100644 --- a/Explore/LineChartView.cpp +++ b/Explore/LineChartView.cpp @@ -1270,7 +1270,7 @@ void LineChartFrame::RunDIDTest() do_white_test); m_resid1= m_DR->GetResidual(); - printAndShowClassicalResults(row_nm, y, table_int->GetTableName(), wxEmptyString, m_DR, m_obs, nX, do_white_test); + printAndShowClassicalResults(row_nm, y, table_int->GetTableName(), wxEmptyString, m_DR, n, nX, do_white_test); m_yhat1 = m_DR->GetYHAT(); wxDateTime now = wxDateTime::Now(); @@ -1334,7 +1334,7 @@ void LineChartFrame::RunDIDTest() do_white_test); m_resid1= m_DR->GetResidual(); - printAndShowClassicalResults(row_nm, y, table_int->GetTableName(), wxEmptyString, m_DR, m_obs, nX, do_white_test); + printAndShowClassicalResults(row_nm, y, table_int->GetTableName(), wxEmptyString, m_DR, n, nX, do_white_test); m_yhat1 = m_DR->GetYHAT(); wxDateTime now = wxDateTime::Now(); @@ -1400,7 +1400,7 @@ void LineChartFrame::RunDIDTest() do_white_test); m_resid1= m_DR->GetResidual(); - printAndShowClassicalResults(row_nm, y, table_int->GetTableName(), wxEmptyString, m_DR, m_obs, nX, do_white_test); + printAndShowClassicalResults(row_nm, y, table_int->GetTableName(), wxEmptyString, m_DR, n, nX, do_white_test); m_yhat1 = m_DR->GetYHAT(); From c48880f4fc777131154c5496ce4abea22e49bce5 Mon Sep 17 00:00:00 2001 From: Xun Li Date: Wed, 4 May 2016 14:24:17 -0700 Subject: [PATCH 2/5] #416 DID regression results may be incorrect --- Explore/LineChartView.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Explore/LineChartView.cpp b/Explore/LineChartView.cpp index 0e9768439..697a6fb66 100644 --- a/Explore/LineChartView.cpp +++ b/Explore/LineChartView.cpp @@ -1229,7 +1229,9 @@ void LineChartFrame::RunDIDTest() int n = m_obs; y = new double[n]; x = new double* [2]; - for (int t=0; t Date: Wed, 4 May 2016 14:33:45 -0700 Subject: [PATCH 3/5] #409 save DID regression results to file --- DialogTools/RegressionReportDlg.cpp | 66 +++++++++++++++++++++++++---- DialogTools/RegressionReportDlg.h | 1 + 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/DialogTools/RegressionReportDlg.cpp b/DialogTools/RegressionReportDlg.cpp index 45b21e2e0..ac251769d 100644 --- a/DialogTools/RegressionReportDlg.cpp +++ b/DialogTools/RegressionReportDlg.cpp @@ -19,6 +19,8 @@ // For compilers that support precompilation, includes . #include +#include +#include #ifndef WX_PRECOMP #include @@ -90,14 +92,13 @@ void RegressionReportDlg::CreateControls() 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)); + + wxBitmap save = wxArtProvider::GetBitmap(wxART_FILE_SAVE); + wxToolBar *toolbar = CreateToolBar(); + + toolbar->AddTool(wxID_SAVE, "Save Regression Results", save); + toolbar->Realize(); + Connect(wxID_SAVE, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(RegressionReportDlg::OnSaveToFile)); Center(); } @@ -121,6 +122,55 @@ void RegressionReportDlg::OnMouseEvent(wxMouseEvent& event) event.GetPosition().x, event.GetPosition().y); } +void RegressionReportDlg::OnSaveToFile(wxCommandEvent& event) +{ + wxFileDialog dlg( this, "Regression Output Text File", wxEmptyString, + wxEmptyString, + "TXT files (*.txt)|*.txt", + wxFD_SAVE ); + if (dlg.ShowModal() != wxID_OK) return; + + wxFileName new_txt_fname(dlg.GetPath()); + wxString new_main_dir = new_txt_fname.GetPathWithSep(); + wxString new_main_name = new_txt_fname.GetName(); + wxString new_txt = new_main_dir + new_main_name + ".txt"; + + // Prompt for overwrite permission + if (wxFileExists(new_txt)) { + wxString msg; + msg << new_txt << " already exists. OK to overwrite?"; + wxMessageDialog dlg (this, msg, "Overwrite?", + wxYES_NO | wxCANCEL | wxNO_DEFAULT); + if (dlg.ShowModal() != wxID_YES) return; + } + + bool failed = false; + // Automatically overwrite existing csv since we have + // permission to overwrite. + + if (wxFileExists(new_txt) && !wxRemoveFile(new_txt)) failed = true; + + if (!failed) { + // write logReport to a text file + wxFFileOutputStream output(new_txt); + if (output.IsOk()) { + wxTextOutputStream txt_out( output ); + txt_out << m_textbox->GetValue(); + txt_out.Flush(); + output.Close(); + } else { + failed = true; + } + } + + if (failed) { + wxString msg; + msg << "Unable to overwrite " << new_txt; + wxMessageDialog dlg (this, msg, "Error", wxOK | wxICON_ERROR); + dlg.ShowModal(); + } +} + void RegressionReportDlg::OnFontChanged(wxCommandEvent& event) { wxFontData data; diff --git a/DialogTools/RegressionReportDlg.h b/DialogTools/RegressionReportDlg.h index b8da14178..4f54f4ddc 100644 --- a/DialogTools/RegressionReportDlg.h +++ b/DialogTools/RegressionReportDlg.h @@ -47,6 +47,7 @@ class RegressionReportDlg: public wxFrame void OnClose(wxCloseEvent& event); void OnMouseEvent(wxMouseEvent& event); void OnFontChanged(wxCommandEvent& event); + void OnSaveToFile(wxCommandEvent& event); void AddNewReport(const wxString report); void SetReport(const wxString report); From 8acab6390eaee191df1e07fd421b6a0b0a49c790 Mon Sep 17 00:00:00 2001 From: Xun Li Date: Wed, 4 May 2016 14:58:34 -0700 Subject: [PATCH 4/5] #406 save time differences in differential Moran --- Explore/LisaMapNewView.cpp | 28 +++++++++++++++++++++++++++- Explore/LisaMapNewView.h | 3 ++- Explore/LisaScatterPlotView.cpp | 28 ++++++++++++++++++++++++++-- SampleData/proj_nat_st.gda | 4 ++++ 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/Explore/LisaMapNewView.cpp b/Explore/LisaMapNewView.cpp index df9ecd7fe..5dc088f79 100644 --- a/Explore/LisaMapNewView.cpp +++ b/Explore/LisaMapNewView.cpp @@ -595,8 +595,18 @@ void LisaMapFrame::OnSigFilter0001(wxCommandEvent& event) void LisaMapFrame::OnSaveLisa(wxCommandEvent& event) { + int t = template_canvas->cat_data.GetCurrentCanvasTmStep(); - std::vector data(3); + LisaMapCanvas* lc = (LisaMapCanvas*)template_canvas; + + std::vector data; + + if (lc->is_diff) { + data.resize(4); + } else { + data.resize(3); + } + std::vector tempLocalMoran(lisa_coord->num_obs); for (int i=0, iend=lisa_coord->num_obs; ilocal_moran_vecs[t][i]; @@ -623,8 +633,17 @@ void LisaMapFrame::OnSaveLisa(wxCommandEvent& event) data[1].type = GdaConst::long64_type; std::vector sig(lisa_coord->num_obs); + std::vector diff(lisa_coord->num_obs); + for (int i=0, iend=lisa_coord->num_obs; iis_diff ) { + int t0 = lisa_coord->var_info[0].time; + int t1 = lisa_coord->var_info[1].time; + diff[i] = lisa_coord->data[0][t0][i] - lisa_coord->data[0][t1][i]; + } } data[2].d_val = &sig; @@ -632,6 +651,13 @@ void LisaMapFrame::OnSaveLisa(wxCommandEvent& event) data[2].field_default = "LISA_P"; data[2].type = GdaConst::double_type; + if (lc->is_diff) { + data[3].d_val = &diff; + data[3].label = "Diff Values"; + data[3].field_default = "DIFF_VAL"; + data[3].type = GdaConst::double_type; + } + SaveToTableDlg dlg(project, this, data, "Save Results: LISA", wxDefaultPosition, wxSize(400,400)); diff --git a/Explore/LisaMapNewView.h b/Explore/LisaMapNewView.h index 75edd7522..33c7ee4f7 100644 --- a/Explore/LisaMapNewView.h +++ b/Explore/LisaMapNewView.h @@ -50,12 +50,13 @@ class LisaMapCanvas : public MapCanvas virtual void CreateAndUpdateCategories(); virtual void TimeSyncVariableToggle(int var_index); + bool is_diff; + protected: LisaCoordinator* lisa_coord; bool is_clust; // true = Cluster Map, false = Significance Map bool is_bi; // true = Bivariate, false = Univariate bool is_rate; // true = Moran Empirical Bayes Rate Smoothing - bool is_diff; DECLARE_EVENT_TABLE() }; diff --git a/Explore/LisaScatterPlotView.cpp b/Explore/LisaScatterPlotView.cpp index b29600a88..9bfc3dcb8 100644 --- a/Explore/LisaScatterPlotView.cpp +++ b/Explore/LisaScatterPlotView.cpp @@ -479,15 +479,32 @@ void LisaScatterPlotCanvas::SaveMoranI() wxString title = "Save Results: Moran's I"; std::vector std_data(num_obs); std::vector lag(num_obs); - + std::vector diff(num_obs); + + int xt = sp_var_info[0].time-sp_var_info[0].time_min; int yt = sp_var_info[1].time-sp_var_info[1].time_min; + for (int i=0; ivar_info[0].time; + int t1 = lisa_coord->var_info[1].time; + diff[i] = lisa_coord->data[0][t0][i] - lisa_coord->data[0][t1][i]; + } } - std::vector data(2); + + std::vector data; + + if (is_diff) { + data.resize(3); + } else { + data.resize(2); + } + data[0].d_val = &std_data; data[0].label = "Standardized Data"; data[0].field_default = "MORAN_STD"; @@ -496,6 +513,13 @@ void LisaScatterPlotCanvas::SaveMoranI() data[1].label = "Spatial Lag"; data[1].field_default = "MORAN_LAG"; data[1].type = GdaConst::double_type; + + if (is_diff) { + data[2].d_val = &diff; + data[2].label = "Diff Values"; + data[2].field_default = "DIFF_VAL"; + data[2].type = GdaConst::double_type; + } SaveToTableDlg dlg(project, this, data, title, wxDefaultPosition, wxSize(400,400)); diff --git a/SampleData/proj_nat_st.gda b/SampleData/proj_nat_st.gda index d9c8d5cd2..297921c8d 100644 --- a/SampleData/proj_nat_st.gda +++ b/SampleData/proj_nat_st.gda @@ -130,6 +130,10 @@ FH80 FH90 + LISA_I + LISA_CL + LISA_P + DIFF_VAL From 175464bc827bd17efff080294e7731d3e58629d3 Mon Sep 17 00:00:00 2001 From: Xun Li Date: Wed, 4 May 2016 15:00:03 -0700 Subject: [PATCH 5/5] update version 1.8.5 Still for 1.8.4 release, but just for testing --- version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/version.h b/version.h index 30a5e4ad6..cfc03d2df 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 = 4; + const int version_build = 5; const int version_year = 2016; const int version_month = 5; - const int version_day = 1; + const int version_day = 4; const int version_night = 0; const int version_type = 1; // 0: alpha, 1: beta, 2: release }