Skip to content

Commit

Permalink
Merge pull request #4 from lixun910/dev1.9
Browse files Browse the repository at this point in the history
1.8.5 patch
  • Loading branch information
lixun910 committed May 4, 2016
2 parents 84b2fe8 + 175464b commit bdfce7e
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 21 deletions.
66 changes: 58 additions & 8 deletions DialogTools/RegressionReportDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

// For compilers that support precompilation, includes <wx/wx.h>.
#include <wx/wxprec.h>
#include <wx/wfstream.h>
#include <wx/txtstrm.h>

#ifndef WX_PRECOMP
#include <wx/wx.h>
Expand Down Expand Up @@ -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();
}
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions DialogTools/RegressionReportDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 8 additions & 7 deletions Explore/LineChartView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,9 @@ void LineChartFrame::RunDIDTest()
int n = m_obs;
y = new double[n];
x = new double* [2];
for (int t=0; t<nX; t++) x[t] = new double[n];

for (int t=0; t<nX; t++)
x[t] = new double[n];

int idx = 0;

Expand Down Expand Up @@ -1270,7 +1272,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();
Expand Down Expand Up @@ -1309,13 +1311,12 @@ void LineChartFrame::RunDIDTest()
}

int idx = 0;

for (int t=0; t<n_ts; t++) {
if (tms_subset0[t] || tms_subset1[t]) {
for (int j=0; j<m_obs; j++) {
y[idx] = Y[t][j];
x[0][idx] = 1.0; //constant
x[1][idx] = tms_subset0[t] == true ? 1 : 0; // DUMMY_PERIOD
x[1][idx] = tms_subset0[t] == true ? 0 : 1; // DUMMY_PERIOD
idx += 1;
}
}
Expand All @@ -1334,7 +1335,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();
Expand Down Expand Up @@ -1381,7 +1382,7 @@ void LineChartFrame::RunDIDTest()
y[idx] = Y[t][j];
x[0][idx] = 1.0; //constant
x[1][idx] = hs[j] == true ? 1.0 : 0.0; // DUMMY_SELECT
x[2][idx] = tms_subset0[t] == true ? 1 : 0; // DUMMY_PERIOD
x[2][idx] = tms_subset0[t] == true ? 0 : 1; // DUMMY_PERIOD
x[3][idx] = x[1][idx] * x[2][idx];
idx += 1;
}
Expand All @@ -1400,7 +1401,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();


Expand Down
28 changes: 27 additions & 1 deletion Explore/LisaMapNewView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,18 @@ void LisaMapFrame::OnSigFilter0001(wxCommandEvent& event)

void LisaMapFrame::OnSaveLisa(wxCommandEvent& event)
{

int t = template_canvas->cat_data.GetCurrentCanvasTmStep();
std::vector<SaveToTableEntry> data(3);
LisaMapCanvas* lc = (LisaMapCanvas*)template_canvas;

std::vector<SaveToTableEntry> data;

if (lc->is_diff) {
data.resize(4);
} else {
data.resize(3);
}

std::vector<double> tempLocalMoran(lisa_coord->num_obs);
for (int i=0, iend=lisa_coord->num_obs; i<iend; i++) {
tempLocalMoran[i] = lisa_coord->local_moran_vecs[t][i];
Expand All @@ -623,15 +633,31 @@ void LisaMapFrame::OnSaveLisa(wxCommandEvent& event)
data[1].type = GdaConst::long64_type;

std::vector<double> sig(lisa_coord->num_obs);
std::vector<double> diff(lisa_coord->num_obs);

for (int i=0, iend=lisa_coord->num_obs; i<iend; i++) {
sig[i] = p[i];


if (lc->is_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;
data[2].label = "Significances";
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));
Expand Down
3 changes: 2 additions & 1 deletion Explore/LisaMapNewView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down
28 changes: 26 additions & 2 deletions Explore/LisaScatterPlotView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,15 +479,32 @@ void LisaScatterPlotCanvas::SaveMoranI()
wxString title = "Save Results: Moran's I";
std::vector<double> std_data(num_obs);
std::vector<double> lag(num_obs);

std::vector<double> 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; i<num_obs; i++) {
std_data[i] = x_data[xt][i];
lag[i] = y_data[yt][i];

if (is_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];
}
}
std::vector<SaveToTableEntry> data(2);

std::vector<SaveToTableEntry> 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";
Expand All @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions SampleData/proj_nat_st.gda
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@
<var>FH80</var>
<var>FH90</var>
</group>
<var>LISA_I</var>
<var>LISA_CL</var>
<var>LISA_P</var>
<var>DIFF_VAL</var>
</variable_order>
<custom_classifications/>
<weights_entries>
Expand Down
4 changes: 2 additions & 2 deletions version.h
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit bdfce7e

Please sign in to comment.