Skip to content

Commit

Permalink
spanning tree save issue
Browse files Browse the repository at this point in the history
skater spanning tree weights properties incorrect GeoDaCenter#1765
skater spanning tree gwt format incorrect GeoDaCenter#1764
no id variable for gwt skater spanning tree GeoDaCenter#1763
  • Loading branch information
lixun910 committed Dec 4, 2018
1 parent 25ed408 commit 13ae484
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 24 deletions.
4 changes: 2 additions & 2 deletions DataViewer/OGRTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1582,7 +1582,7 @@ int OGRTable::FindOGRColId(int wxgrid_col_pos, int time)
int OGRTable::FindOGRColId(const wxString& name)
{
for (size_t i=0; i < org_var_names.size(); i++ ) {
if (name == org_var_names[i] ) {
if (name.CmpNoCase(org_var_names[i]) == 0 ) {
return i;
}
}
Expand All @@ -1601,7 +1601,7 @@ OGRColumn* OGRTable::FindOGRColumn(const wxString& name)
if (name.IsEmpty()) return NULL;

for (size_t i=0; i<org_var_names.size(); i++ ) {
if (name == org_var_names[i] ) {
if ( name.CmpNoCase(org_var_names[i]) == 0 ) {
return columns[i];
}
}
Expand Down
6 changes: 3 additions & 3 deletions DataViewer/VarOrderPtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,17 @@ bool VarOrderPtree::CorrectVarGroups(const std::map<wxString,
LOG_MSG("Entering VarOrderPtree::CorrectVarGroups");
bool changed = false;
set<wxString> ds_var_set;
BOOST_FOREACH(const wxString &v, ds_var_list) { ds_var_set.insert(v); }
BOOST_FOREACH(const wxString &v, ds_var_list) { ds_var_set.insert(v.Lower()); }

set<wxString> var_set;
set<wxString> group_nm_set;
BOOST_FOREACH(const VarGroup& e, var_grps) {
if (e.vars.size() == 0) {
var_set.insert(e.name);
var_set.insert(e.name.Lower());
} else {
group_nm_set.insert(e.name);
BOOST_FOREACH(const wxString& v, e.vars) {
if (!v.empty()) var_set.insert(v);
if (!v.empty()) var_set.insert(v.Lower());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion DialogTools/AbstractClusterDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ double AbstractClusterDlg::CreateSummary(const vector<vector<int> >& solution, c
summary << _printConfiguration();

// auto weighting
if (m_use_centroids->IsChecked()) {
if (m_use_centroids != NULL && m_use_centroids->IsChecked()) {
wxString w_val = m_wc_txt->GetValue();
double w_valf = 0;
if (w_val.ToDouble(&w_valf)) {
Expand Down
41 changes: 34 additions & 7 deletions DialogTools/RedcapDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,31 @@ void RedcapDlg::OnSaveTree(wxCommandEvent& event )
{
if (weights && redcap) {
wxString filter = "GWT|*.gwt";
wxFileDialog dialog(NULL, _("Save Spanning Tree to a Weights File"), wxEmptyString,
wxFileDialog dialog(NULL, _("Save Spanning Tree to a Weights File"),
wxEmptyString,
wxEmptyString, filter,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal() != wxID_OK)
if (dialog.ShowModal() != wxID_OK) {
return;
}
// get info from input weights
vector<boost::uuids::uuid> weights_ids;
WeightsManInterface* w_man_int = project->GetWManInt();
w_man_int->GetIds(weights_ids);
int sel = combo_weights->GetSelection();
if (sel < 0) sel = 0;
if (sel >= weights_ids.size()) sel = weights_ids.size()-1;
boost::uuids::uuid w_id = weights_ids[sel];
GalWeight* gw = w_man_int->GetGal(w_id);
GeoDaWeight* gdw = (GeoDaWeight*)gw;
wxString id = gdw->GetIDName();
int col = table_int->FindColId(id);
if (col < 0) {
return;
}
vector<wxString> ids;
table_int->GetColData(col, 0, ids);

wxFileName fname = wxFileName(dialog.GetPath());
wxString new_main_dir = fname.GetPathWithSep();
wxString new_main_name = fname.GetName();
Expand All @@ -402,20 +422,27 @@ void RedcapDlg::OnSaveTree(wxCommandEvent& event )
file.Clear();

wxString header;
header << "0 " << project->GetNumRecords() << " " << project->GetProjectTitle();
header << "0 " << project->GetNumRecords() << " " << project->GetProjectTitle() << " " << id;
file.AddLine(header);


for (int i=0; i<redcap->ordered_edges.size(); i++) {
wxString line;
line << redcap->ordered_edges[i]->orig->id+1<< " " << redcap->ordered_edges[i]->dest->id +1<< " " << redcap->ordered_edges[i]->length ;
file.AddLine(line);
int from_idx = redcap->ordered_edges[i]->orig->id;
int to_idx = redcap->ordered_edges[i]->dest->id;
double cost = redcap->ordered_edges[i]->length;
wxString line1;
line1 << ids[from_idx] << " " << ids[to_idx] << " " << cost;
file.AddLine(line1);
wxString line2;
line2 << ids[to_idx] << " " << ids[from_idx] << " " << cost;
file.AddLine(line2);
}
file.Write();
file.Close();

// Load the weights file into Weights Manager
WeightsManInterface* w_man_int = project->GetWManInt();
WeightUtils::LoadGwtInMan(w_man_int, new_txt, table_int);
WeightUtils::LoadGwtInMan(w_man_int, new_txt, table_int, id);
}
}

Expand Down
39 changes: 32 additions & 7 deletions DialogTools/SkaterDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,31 @@ void SkaterDlg::OnSaveTree(wxCommandEvent& event )
{
if (skater) {
wxString filter = "GWT|*.gwt";
wxFileDialog dialog(NULL, _("Save Spanning Tree to a Weights File"), wxEmptyString,
wxFileDialog dialog(NULL, _("Save Spanning Tree to a Weights File"),
wxEmptyString,
wxEmptyString, filter,
wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if (dialog.ShowModal() != wxID_OK) {
return;
}
// get info from input weights
vector<boost::uuids::uuid> weights_ids;
WeightsManInterface* w_man_int = project->GetWManInt();
w_man_int->GetIds(weights_ids);
int sel = combo_weights->GetSelection();
if (sel < 0) sel = 0;
if (sel >= weights_ids.size()) sel = weights_ids.size()-1;
boost::uuids::uuid w_id = weights_ids[sel];
GalWeight* gw = w_man_int->GetGal(w_id);
GeoDaWeight* gdw = (GeoDaWeight*)gw;
wxString id = gdw->GetIDName();
int col = table_int->FindColId(id);
if (col < 0) {
return;
}
vector<wxString> ids;
table_int->GetColData(col, 0, ids);

wxFileName fname = wxFileName(dialog.GetPath());
wxString new_main_dir = fname.GetPathWithSep();
wxString new_main_name = fname.GetName();
Expand All @@ -241,20 +260,26 @@ void SkaterDlg::OnSaveTree(wxCommandEvent& event )
file.Clear();

wxString header;
header << "0 " << project->GetNumRecords() << " " << project->GetProjectTitle();
header << "0 " << project->GetNumRecords() << " " << project->GetProjectTitle() << " " << id;
file.AddLine(header);


for (int i=0; i<skater->ordered_edges.size(); i++) {
wxString line;
line << skater->ordered_edges[i]->orig->id+1<< " " << skater->ordered_edges[i]->dest->id +1<< " " << skater->ordered_edges[i]->length ;
file.AddLine(line);
int from_idx = skater->ordered_edges[i]->orig->id;
int to_idx = skater->ordered_edges[i]->dest->id;
double cost = skater->ordered_edges[i]->length;
wxString line1;
line1 << ids[from_idx] << " " << ids[to_idx] << " " << cost;
file.AddLine(line1);
wxString line2;
line2 << ids[to_idx] << " " << ids[from_idx] << " " << cost;
file.AddLine(line2);
}
file.Write();
file.Close();

// Load the weights file into Weights Manager
WeightsManInterface* w_man_int = project->GetWManInt();
WeightUtils::LoadGwtInMan(w_man_int, new_txt, table_int);
WeightUtils::LoadGwtInMan(w_man_int, new_txt, table_int, id);
}
}

Expand Down
7 changes: 5 additions & 2 deletions ShapeOperations/WeightUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ GalElement* WeightUtils::Gwt2Gal(GwtElement* Gwt, long obs)
}


void WeightUtils::LoadGwtInMan(WeightsManInterface* w_man_int, wxString filepath, TableInterface* table_int)
void WeightUtils::LoadGwtInMan(WeightsManInterface* w_man_int, wxString filepath, TableInterface* table_int, wxString id_field)
{
int rows = table_int->GetNumberRows();

Expand All @@ -872,10 +872,13 @@ void WeightUtils::LoadGwtInMan(WeightsManInterface* w_man_int, wxString filepath
w->num_obs = rows;
w->wflnm = filepath;
w->gal = tempGal;
w->id_field = "unknown";
w->id_field = id_field;
w->is_symmetric = true;

w->GetNbrStats();
wmi.num_obs = w->GetNumObs();
wmi.id_var = id_field;
wmi.SetSymmetric(w->is_symmetric);
wmi.SetMinNumNbrs(w->GetMinNumNbrs());
wmi.SetMaxNumNbrs(w->GetMaxNumNbrs());
wmi.SetMeanNumNbrs(w->GetMeanNumNbrs());
Expand Down
2 changes: 1 addition & 1 deletion ShapeOperations/WeightUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace WeightUtils {
TableInterface* table_int);
GwtElement* ReadGwt(const wxString& w_fname, TableInterface* table_int);
GalElement* Gwt2Gal(GwtElement* Gwt, long obs);
void LoadGwtInMan(WeightsManInterface* w_man_int, wxString filepath, TableInterface* table_int);
void LoadGwtInMan(WeightsManInterface* w_man_int, wxString filepath, TableInterface* table_int, wxString id_field);
}

#endif
5 changes: 5 additions & 0 deletions VarCalc/WeightsMetaInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ void WeightsMetaInfo::SetToCustom(const wxString& idv)
id_var = idv;
}

void WeightsMetaInfo::SetSymmetric(bool is_sym)
{
sym_type = is_sym ? SYM_symmetric : SYM_unknown;
}

void WeightsMetaInfo::SetToRook(const wxString& idv, long order_, bool inc_lower_orders_)
{
SetToDefaults();
Expand Down
2 changes: 1 addition & 1 deletion VarCalc/WeightsMetaInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ struct WeightsMetaInfo
void SetMaxNumNbrs(int val);
void SetMeanNumNbrs(double val);
void SetMedianNumNbrs(double val);

void SetSymmetric(bool is_sym);
};

#endif
Expand Down

0 comments on commit 13ae484

Please sign in to comment.