/* 测量项目other在min和max之间的人找出来,统计他们的item的值 */ void Query::query_data_by_others(Stat &stat, QString item, QString other, float min, float max) { stat.reset(); for (int i = 0; i < npeople; i++) { float other_data = get_data_by_item(&people[i], other); if (other_data <= max && other_data >= min) { float data = get_data_by_item(&people[i], item); if (data != -1) { stat.add_element(data); } } } }
void Query::query_data(Stat &stat, QString item, QString nativeplace, QString district, QString armtype, QString education, QString militaryrank) { int pm; QList<int> parameters; stat.reset(); if (item == "") return; parameters << get_value_by_key(nativeplace_map, nativeplace); parameters << get_value_by_key(district_map, district); parameters << get_value_by_key(armtype_map, armtype); parameters << get_value_by_key(education_map, education); parameters << get_value_by_key(militaryrank_map, militaryrank); pm = 0; while (pm < PARAMETER_SIZE && parameters[pm] == -1) { pm++; } if (pm == PARAMETER_SIZE) { for (int i = 0; i < this->npeople; i++) { People *p = &people[i]; float item_data = get_data_by_item(p, item); if (item_data > 0) { stat.add_element(item_data); } } } else { List *l = find_list(parameters[pm], pm); People *p = l->first; while (p) { bool all_parameter_match = true; for (int ii = pm + 1; ii < PARAMETER_SIZE; ii++) { if (parameters[ii] != -1 && !match_parameter(p, ii, parameters[ii])) { all_parameter_match = false; break; } } float item_data = get_data_by_item(p, item); if (all_parameter_match && item_data > 0) { stat.add_element(item_data); } p = p->next[pm]; } } }