MCPcopy Create free account
hub / github.com/GeoDaCenter/geoda / CorrectCatClassifFromTable

Method CorrectCatClassifFromTable

Explore/CatClassification.cpp:1634–1809  ·  view source on GitHub ↗

Modify CatClassifDef so that it is consistent with data in the TableInterface. Some things that might require changes to CatClassifDef data: - associated variable no longer exists - values and range of associated variable has changed Additionally, in case the user has manually edited the meta-data in the project configuration file, we attempt to make data self-consistent. If any changes made

Source from the content-addressed store, hash-verified

1632 will be left as they were.
1633 */
1634bool CatClassification::CorrectCatClassifFromTable(CatClassifDef& _cc,
1635 TableInterface* table_int,
1636 bool auto_label)
1637{
1638 if (!table_int) return false;
1639
1640 int num_obs = table_int->GetNumberRows();
1641 CatClassifDef cc;
1642 cc = _cc;
1643
1644 std::vector<wxString> user_def_labels = cc.names;
1645
1646 // correct cc.uniform_dist_min, cc.uniform_dist_max
1647 if (cc.uniform_dist_min > cc.uniform_dist_max) {
1648 double t = cc.uniform_dist_min;
1649 cc.uniform_dist_min = cc.uniform_dist_max;
1650 cc.uniform_dist_max = t;
1651 }
1652 if (cc.breaks.size() > 0) {
1653 std::sort(cc.breaks.begin(), cc.breaks.end());
1654 // use min/max breaks as min/max for uniform dist
1655 if (cc.uniform_dist_min > cc.breaks[0]) {
1656 cc.uniform_dist_min = cc.breaks[0];
1657 }
1658 if (cc.uniform_dist_max < cc.breaks[cc.breaks.size()-1]) {
1659 cc.uniform_dist_max = cc.breaks[cc.breaks.size()-1];
1660 }
1661 }
1662
1663
1664 int col = -1, tm = 0;
1665 // ensure that assoc_db_fld_name exists in table
1666 bool field_removed = cc.assoc_db_fld_name != "";
1667 field_removed = field_removed && (!table_int->DbColNmToColAndTm(cc.assoc_db_fld_name, col, tm) || !table_int->IsColNumeric(col));
1668 if (field_removed) cc.assoc_db_fld_name = "";
1669
1670 bool uni_dist_mode = cc.assoc_db_fld_name.IsEmpty();
1671
1672 Gda::dbl_int_pair_vec_type data(num_obs);
1673 std::vector<bool> data_undef(num_obs, false);
1674
1675 if (uni_dist_mode) {
1676 // fill data with uniform distribution
1677 double delta = ((cc.uniform_dist_max-cc.uniform_dist_min) /
1678 (double) num_obs);
1679 for (int i=0; i<num_obs; ++i) {
1680 double di = (double) i;
1681 data[i].first = cc.uniform_dist_min + di*delta;
1682 data[i].second = i;
1683 }
1684
1685 } else {
1686 std::vector<double> v;
1687 table_int->GetColData(col, tm, v);
1688 table_int->GetColUndefined(col, tm, data_undef);
1689 for (int i=0; i<num_obs; ++i) {
1690 data[i].first = v[i];
1691 data[i].second = i;

Callers

nothing calls this directly

Calls 10

DbColNmToColAndTmMethod · 0.80
IsColNumericMethod · 0.80
GetColUndefinedMethod · 0.80
GetMinMaxValsMethod · 0.80
sortFunction · 0.50
GetNumberRowsMethod · 0.45
sizeMethod · 0.45
IsEmptyMethod · 0.45
GetColDataMethod · 0.45

Tested by

no test coverage detected