TEST_F(EventsDatabaseTests, test_record_indexing) {
  auto sub = std::make_shared<DBFakeEventSubscriber>();
  auto status = sub->testAdd(2);
  status = sub->testAdd(11);
  status = sub->testAdd(61);
  status = sub->testAdd((1 * 3600) + 1);
  status = sub->testAdd((2 * 3600) + 1);

  // An "all" range, will pick up everything in the largest index.
  auto indexes = sub->getIndexes(0, 3 * 3600);
  auto output = boost::algorithm::join(indexes, ", ");
  EXPECT_EQ("60.0, 60.1, 60.60, 60.120", output);

  // Restrict range to "most specific", which is an index by 10.
  indexes = sub->getIndexes(0, 5);
  output = boost::algorithm::join(indexes, ", ");
  // The order 10, 0th index include results with t = [0, 10).
  EXPECT_EQ("60.0", output);

  // Add specific indexes to the upper bound.
  status = sub->testAdd((2 * 3600) + 11);
  status = sub->testAdd((2 * 3600) + 61);
  indexes = sub->getIndexes(2 * 3600, (2 * 3600) + 62);
  output = boost::algorithm::join(indexes, ", ");
  EXPECT_EQ("60.120, 60.121", output);

  // Request specific lower and upper bounding.
  indexes = sub->getIndexes(2, (2 * 3600) + 62);
  output = boost::algorithm::join(indexes, ", ");
  EXPECT_EQ("60.0, 60.1, 60.60, 60.120, 60.121", output);
}
Exemple #2
0
void Octree::insert(std::shared_ptr<Collidable > collidable)
{
	if (childNode[0] != nullptr) { //child node exists. Recurse into children
		std::vector<int> indexes = getIndexes(collidable);
		for (auto indexIt =indexes.begin(); indexIt!=indexes.end(); indexIt++) {
			childNode[*indexIt]->insert(collidable);
		}
	}
	else {
		//arrived at leaf
		
		
		this->objects.push_back(collidable);

		if (this->objects.size() > MAX_OBJECTS && level < MAX_LEVELS) { //check for leave
			split();
			
			auto objectsIt = objects.begin();
			for (; objectsIt != objects.end(); objectsIt++) {
				std::vector<int> indexList = getIndexes(*objectsIt);
				for (auto indexIt = indexList.begin(); indexIt != indexList.end(); indexIt++) {
					childNode[*indexIt]->insert(*objectsIt);
				}
			}
			objects.clear();
		}
	}
}
TEST_F(EventsDatabaseTests, test_record_expiration) {
  auto sub = std::make_shared<FakeEventSubscriber>();

  // No expiration
  auto indexes = sub->getIndexes(0, 60);
  auto records = sub->getRecords(indexes);
  EXPECT_EQ(records.size(), 3); // 1, 2, 11

  sub->expire_events_ = true;
  sub->expire_time_ = 10;
  indexes = sub->getIndexes(0, 60);
  records = sub->getRecords(indexes);
  EXPECT_EQ(records.size(), 1); // 11
}
Exemple #4
0
void EventSubscriberPlugin::expireCheck(bool cleanup) {
  auto data_key = "data." + dbNamespace();
  auto eid_key = "eid." + dbNamespace();
  // Min key will be the last surviving key.
  size_t min_key = 0;

  {
    auto limit = getEventsMax();
    std::vector<std::string> keys;
    scanDatabaseKeys(kEvents, keys, data_key);
    if (keys.size() <= limit) {
      return;
    }

    // There is an overflow of events buffered for this subscriber.
    LOG(WARNING) << "Expiring events for subscriber: " << getName()
                 << " (limit " << limit << ")";
    VLOG(1) << "Subscriber events " << getName() << " exceeded limit " << limit
            << " by: " << keys.size() - limit;
    // Inspect the N-FLAGS_events_max -th event's value and expire before the
    // time within the content.
    std::string last_key;
    getDatabaseValue(kEvents, eid_key, last_key);
    // The EID is the next-index.
    // EID - events_max is the most last-recent event to keep.
    min_key = boost::lexical_cast<size_t>(last_key) - getEventsMax();

    if (cleanup) {
      // Scan each of the keys in keys, if their ID portion is < min_key.
      // Nix them, this requires lots of conversions, use with care.
      for (const auto& key : keys) {
        if (std::stoul(key.substr(key.rfind('.') + 1)) < min_key) {
          deleteDatabaseValue(kEvents, key);
        }
      }
    }
  }

  // Convert the key index into a time using the content.
  // The last-recent event is fetched and the corresponding time is used as
  // the expiration time for the subscriber.
  std::string content;
  getDatabaseValue(kEvents, data_key + "." + std::to_string(min_key), content);

  // Decode the value into a row structure to extract the time.
  Row r;
  if (!deserializeRowJSON(content, r) || r.count("time") == 0) {
    return;
  }

  // The last time will become the implicit expiration time.
  size_t last_time = boost::lexical_cast<size_t>(r.at("time"));
  if (last_time > 0) {
    expire_time_ = last_time;
  }

  // Finally, attempt an index query to trigger expirations.
  // In this case the result set is not used.
  getIndexes(expire_time_, 0);
}
Exemple #5
0
FourTree::Indexes FourTree::getIndexes(Entity* ptr)
{
	sf::FloatRect boundingRect = ptr->comp<BoxCollisionComponent>()->getTransfromedRect();

	sf::Vector2f ptrPosition = ptr->comp<TransformableComponent>()->getWorldPosition(true);

	return getIndexes(ptrPosition, boundingRect);
}
TEST_F(EventsDatabaseTests, test_record_range) {
  auto sub = std::make_shared<DBFakeEventSubscriber>();
  auto status = sub->testAdd(1);
  status = sub->testAdd(2);
  status = sub->testAdd(11);
  status = sub->testAdd(61);
  status = sub->testAdd((1 * 3600) + 1);
  status = sub->testAdd((2 * 3600) + 1);

  // Search within a specific record range.
  auto indexes = sub->getIndexes(0, 10);
  EXPECT_EQ(1U, indexes.size());
  auto records = sub->getRecords(indexes);
  // This will return 3 results, ::get filters records by an absolute range.
  EXPECT_EQ(3U, records.size()); // 1, 2, 11

  // Search within a large bound.
  indexes = sub->getIndexes(3, 3601);
  // This will include the 0-10 bucket meaning 1, 2 will show up.
  records = sub->getRecords(indexes);
  EXPECT_EQ(5U, records.size()); // 1, 2, 11, 61, 3601

  // Get all of the records.
  indexes = sub->getIndexes(0, 3 * 3600);
  records = sub->getRecords(indexes);
  EXPECT_EQ(6U, records.size()); // 1, 2, 11, 61, 3601, 7201

  // stop = 0 is an alias for everything.
  indexes = sub->getIndexes(0, 0);
  records = sub->getRecords(indexes);
  EXPECT_EQ(6U, records.size());

  for (size_t j = 0; j < 30; j++) {
    // 110 is 10 below an index (60.2).
    sub->testAdd(110 + static_cast<int>(j));
  }

  indexes = sub->getIndexes(110, 0);
  auto output = boost::algorithm::join(indexes, ", ");
  EXPECT_EQ("60.1, 60.2, 60.60, 60.120", output);
  records = sub->getRecords(indexes);
  EXPECT_EQ(33U, records.size()); // (61) 110 - 139 + 3601, 7201
}
Exemple #7
0
int Simbox::getIndex(double x, double y, double z) const

{
  int index = IMISSING;
  int i, j, k;
  getIndexes(x,y,z,i,j,k);
  if(k != IMISSING && j != IMISSING && i != IMISSING)
    index = int(i+j*nx_+k*nx_*ny_);
  return(index);
}
    int parzenWindowEstimator::computeResponse(const std::vector<double> x)
    {
        std::vector<int> b;

        if (getIndexes(x,b))
        {
            return int(getF_X_scaled(x));
        }

        return 0;
    }
 bool parzenWindowEstimator::removeSample(const std::vector<double> x)
 {
     std::vector<int> b;
     
     if (getIndexes(x,b))
     {
         negHist(b[0],b[1]) += 1;
         return true;
     }
     else
         return false;
 }
TEST_F(EventsDatabaseTests, test_record_expiration) {
  auto sub = std::make_shared<DBFakeEventSubscriber>();

  // No expiration
  auto indexes = sub->getIndexes(0, 5000);
  auto records = sub->getRecords(indexes);
  EXPECT_EQ(records.size(), 5U); // 1, 2, 11, 61, 3601

  sub->expire_events_ = true;
  sub->expire_time_ = 10;
  indexes = sub->getIndexes(0, 5000);
  records = sub->getRecords(indexes);
  EXPECT_EQ(records.size(), 3U); // 11, 61, 3601

  indexes = sub->getIndexes(0, 5000, 0);
  records = sub->getRecords(indexes);
  EXPECT_EQ(records.size(), 3U); // 11, 61, 3601

  indexes = sub->getIndexes(0, 5000, 1);
  records = sub->getRecords(indexes);
  EXPECT_EQ(records.size(), 3U); // 11, 61, 3601

  indexes = sub->getIndexes(0, 5000, 2);
  records = sub->getRecords(indexes);
  EXPECT_EQ(records.size(), 3U); // 11, 61, 3601

  // Check that get/deletes did not act on cache.
  // This implies that RocksDB is flushing the requested delete records.
  sub->expire_time_ = 0;
  indexes = sub->getIndexes(0, 5000);
  records = sub->getRecords(indexes);
  EXPECT_EQ(records.size(), 3U); // 11, 61, 3601
}
 bool parzenWindowEstimator::addSample(const std::vector<double> x)
 {
     std::vector<int> b;
     
     if (getIndexes(x,b))
     {
         printf("adding sample %i %i from %g %g\n",b[0],b[1],x[0],x[1]);
         posHist(b[0],b[1]) += 1;
         return true;
     }
     else
         return false;
 }
Exemple #12
0
QueryData EventSubscriberPlugin::get(EventTime start, EventTime stop) {
  QueryData results;

  // Get the records for this time range.
  auto indexes = getIndexes(start, stop);
  auto records = getRecords(indexes);

  std::string events_key = "data." + dbNamespace();
  std::vector<std::string> mapped_records;
  for (const auto& record : records) {
    if (record.second >= start && (record.second <= stop || stop == 0)) {
      mapped_records.push_back(events_key + "." + record.first);
    }
  }

  if (FLAGS_events_optimize && !records.empty()) {
    // If records were returned save the ordered-last as the optimization EID.
    unsigned long int eidr = 0;
    if (safeStrtoul(records.back().first, 10, eidr)) {
      optimize_eid_ = static_cast<size_t>(eidr);
      auto index_key = "optimize_id." + dbNamespace();
      setDatabaseValue(kEvents, index_key, records.back().first);
    }
  }

  // Select mapped_records using event_ids as keys.
  std::string data_value;
  for (const auto& record : mapped_records) {
    Row r;
    auto status = getDatabaseValue(kEvents, record, data_value);
    if (data_value.length() == 0) {
      // There is no record here, interesting error case.
      continue;
    }
    status = deserializeRowJSON(data_value, r);
    data_value.clear();
    if (status.ok()) {
      results.push_back(std::move(r));
    }
  }

  if (getEventsExpiry() > 0) {
    // Set the expire time to NOW - "configured lifetime".
    // Index retrieval will apply the constraints checking and auto-expire.
    expire_time_ = getUnixTime() - getEventsExpiry();
  }

  return results;
}
TEST_F(EventsDatabaseTests, test_record_range) {
  auto sub = std::make_shared<DBFakeEventSubscriber>();

  // Search within a specific record range.
  auto indexes = sub->getIndexes(0, 10);
  auto records = sub->getRecords(indexes);
  EXPECT_EQ(records.size(), 2U); // 1, 2

  // Search within a large bound.
  indexes = sub->getIndexes(3, 3601);
  // This will include the 0-10 bucket meaning 1, 2 will show up.
  records = sub->getRecords(indexes);
  EXPECT_EQ(records.size(), 5U); // 1, 2, 11, 61, 3601

  // Get all of the records.
  indexes = sub->getIndexes(0, 3 * 3600);
  records = sub->getRecords(indexes);
  EXPECT_EQ(records.size(), 8U); // 1, 2, 11, 61, 3601, 7201, 7211, 7261

  // stop = 0 is an alias for everything.
  indexes = sub->getIndexes(0, 0);
  records = sub->getRecords(indexes);
  EXPECT_EQ(records.size(), 8U);
}
Exemple #14
0
    void DBClientWithCommands::reIndex( const string& ns ) {
        list<BSONObj> all;
        auto_ptr<DBClientCursor> i = getIndexes( ns );
        while ( i->more() ) {
            all.push_back( i->next().getOwned() );
        }

        dropIndexes( ns );

        for ( list<BSONObj>::iterator i=all.begin(); i!=all.end(); i++ ) {
            BSONObj o = *i;
            insert( Namespace( ns.c_str() ).getSisterNS( "system.indexes" ).c_str() , o );
        }

    }
Exemple #15
0
void FourTree::insert(Entity *ptr)
{
	if (isSpilt){
		Indexes indexes = getIndexes(ptr);

		if (!indexes.empty()){
			for (int i : indexes)
				mNodes[i]->insert(ptr);
			return;
		}
	}


	mEntities.push_back(ptr);
	//std::cout << "wee";
	//if this level reaches it max objects, seperate it into 4 more cells
	if (!isSpilt && mEntities.size() > mMaxObjects && mCurrentLevel < mMaxLevels){
		//if (mNodes[0] == NULL)
			//split();
		isSpilt = true;

		int i = 0;
		while (i < mEntities.size()){
			
			Indexes indexes = getIndexes(mEntities[i]);
			if (!indexes.empty()){
				Entity *newEntity = deleteFromContainer(mEntities[i]);
				for (int i : indexes)
					mNodes[i]->insert(newEntity);
			}
			else
				i++;

		}
	}
}
Exemple #16
0
QueryData EventSubscriberPlugin::get(EventTime start, EventTime stop) {
  QueryData results;
  Status status;

  std::shared_ptr<DBHandle> db;
  try {
    db = DBHandle::getInstance();
  } catch (const std::runtime_error& e) {
    LOG(ERROR) << "Cannot retrieve subscriber results database is locked";
    return results;
  }

  // Get the records for this time range.
  auto indexes = getIndexes(start, stop);
  auto records = getRecords(indexes);

  std::vector<EventRecord> mapped_records;
  for (const auto& record : records) {
    if (record.second >= start && (record.second <= stop || stop == 0)) {
      mapped_records.push_back(record);
    }
  }

  std::string events_key = "data." + dbNamespace();
  if (FLAGS_events_expiry > 0) {
    // Set the expire time to NOW - "configured lifetime".
    // Index retrieval will apply the constraints checking and auto-expire.
    expire_time_ = getUnixTime() - FLAGS_events_expiry;
  }

  // Select mapped_records using event_ids as keys.
  std::string data_value;
  for (const auto& record : mapped_records) {
    Row r;
    status = db->Get(kEvents, events_key + "." + record.first, data_value);
    if (data_value.length() == 0) {
      // THere is no record here, interesting error case.
      continue;
    }
    status = deserializeRowJSON(data_value, r);
    if (status.ok()) {
      results.push_back(r);
    }
  }
  return results;
}
/**
 * void mrc_binning(MRC *mrc, int binning, int skip_avg)
 */
void mrc_binning(MRC *mrc, int binning, int skip_avg) {

	float *data_array_src ;
	float f_val;

	long	ij, IJ;

	int *indexes;
	int	i, j,
		n_w, w,
		n_h, h,
		binningsize,
		index;

	if (binning>1) {
		
 		binningsize = binning*binning;
		indexes = malloc(sizeof(int)*binningsize);
		data_array_src = (float *)mrc->pbyData;
		w = mrc->header.nx;
		h = mrc->header.ny;
		n_w = w/binning;
		n_h = h/binning;

		for (j=0; j<n_h; j++) {
			for (i=0; i<n_w; i++) {
				ij = i + j*n_w;
				IJ = i*binning + j*w*binning;
				if (skip_avg) {
					f_val = data_array_src[IJ];
				} else {
					getIndexes(indexes, binning, IJ, w);
					for (f_val=0, index=0; index<binningsize; index++)
						f_val += data_array_src[indexes[index]];
					f_val /= binningsize;
				}
				data_array_src[ij] = f_val;
			}
		}
		mrc->header.nx=n_w;
		mrc->header.ny=n_h;
		free(indexes);
	}
}
Exemple #18
0
void EventSubscriberPlugin::expireCheck() {
  auto db = DBHandle::getInstance();
  auto data_key = "data." + dbNamespace();
  auto eid_key = "eid." + dbNamespace();

  std::vector<std::string> keys;
  db->ScanPrefix(kEvents, keys, data_key);
  if (keys.size() <= FLAGS_events_max) {
    return;
  }

  // There is an overflow of events buffered for this subscriber.
  LOG(WARNING) << "Expiring events for subscriber: " << getName() << " limit ("
               << FLAGS_events_max << ") exceeded: " << keys.size();
  // Inspect the N-FLAGS_events_max -th event's value and expire before the
  // time within the content.
  std::string last_key;
  db->Get(kEvents, eid_key, last_key);
  // The EID is the next-index.
  size_t max_key = boost::lexical_cast<size_t>(last_key) - FLAGS_events_max - 1;

  // Convert the key index into a time using the content.
  std::string content;
  db->Get(kEvents, data_key + "." + std::to_string(max_key), content);

  // Decode the value into a row structure to extract the time.
  Row r;
  if (!deserializeRowJSON(content, r) || r.count("time") == 0) {
    return;
  }

  // The last time will become the implicit expiration time.
  size_t last_time = boost::lexical_cast<size_t>(r.at("time"));
  if (last_time > 0) {
    expire_time_ = last_time;
  }

  // Finally, attempt an index query to trigger expirations.
  // In this case the result set is not used.
  getIndexes(expire_time_ - 1, -1);
}
Exemple #19
0
unsigned char * NBase58Decode(unsigned char *input, int inLen) {
    if(inLen == 0)
        return NULL;

    unsigned char *input58 = malloc(inLen);
    unsigned char *indexes = getIndexes();

    int i=0;
    for(; i<inLen; i++) {
        input58[i] = indexes[input[i]];
    }

    //count leading zeros
    int z = -1;
    while(z<inLen && input58[++z] == 0x00)
        ;

    unsigned char *temp = malloc(inLen);
    int j = inLen;

    int startAt = z;
    while(startAt < inLen) {
        char mod = divmod256(input58, inLen, startAt);
        if(input58[startAt] == 0)
            ++startAt;

        temp[--j] = mod;
    }

    free(input58);

    while(j<inLen && temp[j] == 0)		j++;

    int len = inLen - j + z;
    unsigned char *out = malloc(len + 1);
    out[len] = 0;
    memcpy(out, temp + j - z, len);
    free(temp);

    return out;
}
Exemple #20
0
void FourTree::getObjects(std::vector<Entity*>& entities, const RotatedRect& rotatedRect,
	std::vector<sf::FloatRect>& finalIndexesWorldBound)
{
	Indexes indexes;
	if (isSpilt)
		indexes = getIndexes(rotatedRect);

	if (!isSpilt)
		finalIndexesWorldBound.push_back(this->getWorldBounds());
	

	if (!indexes.empty() && isSpilt){
		for (int i : indexes)
			mNodes[i]->getObjects(entities, rotatedRect, finalIndexesWorldBound);
		return;
	}

	for (Entity *entity : mEntities){
		if (std::find(entities.begin(), entities.end(), entity) == entities.end())
			entities.push_back(entity);
	}
}
Exemple #21
0
QueryData EventSubscriberPlugin::get(EventTime start, EventTime stop) {
  QueryData results;

  // Get the records for this time range.
  auto db = DBHandle::getInstance();
  auto indexes = getIndexes(start, stop);
  auto records = getRecords(indexes);
  std::string events_key = "data." + dbNamespace();

  std::vector<std::string> mapped_records;
  for (const auto& record : records) {
    if (record.second >= start && (record.second <= stop || stop == 0)) {
      mapped_records.push_back(events_key + "." + record.first);
    }
  }

  // Select mapped_records using event_ids as keys.
  std::string data_value;
  for (const auto& record : mapped_records) {
    Row r;
    auto status = db->Get(kEvents, record, data_value);
    if (data_value.length() == 0) {
      // There is no record here, interesting error case.
      continue;
    }
    status = deserializeRowJSON(data_value, r);
    data_value.clear();
    if (status.ok()) {
      results.push_back(std::move(r));
    }
  }

  if (FLAGS_events_expiry > 0) {
    // Set the expire time to NOW - "configured lifetime".
    // Index retrieval will apply the constraints checking and auto-expire.
    expire_time_ = getUnixTime() - FLAGS_events_expiry;
  }
  return results;
}
TEST_F(EventsDatabaseTests, test_record_indexing) {
  auto sub = std::make_shared<DBFakeEventSubscriber>();
  auto status = sub->testAdd(2);
  status = sub->testAdd(11);
  status = sub->testAdd(61);
  status = sub->testAdd((1 * 3600) + 1);
  status = sub->testAdd((2 * 3600) + 1);

  // An "all" range, will pick up everything in the largest index.
  auto indexes = sub->getIndexes(0, 3 * 3600);
  auto output = boost::algorithm::join(indexes, ", ");
  EXPECT_EQ(output, "3600.0, 3600.1, 3600.2");

  // Restrict range to "most specific", which is an index by 10.
  indexes = sub->getIndexes(0, 5);
  output = boost::algorithm::join(indexes, ", ");
  // The order 10, 0th index include results with t = [0, 10).
  EXPECT_EQ(output, "10.0");

  // Get a mix of indexes for the lower bounding.
  indexes = sub->getIndexes(2, (3 * 3600));
  output = boost::algorithm::join(indexes, ", ");
  EXPECT_EQ(output, "10.0, 10.1, 3600.1, 3600.2, 60.1");

  // Rare, but test ONLY intermediate indexes.
  // Provide an optional third parameter to getIndexes: 1 = 10,(60),3600.
  indexes = sub->getIndexes(2, (3 * 3600), 1);
  output = boost::algorithm::join(indexes, ", ");
  EXPECT_EQ(output, "60.0, 60.1, 60.120, 60.60");

  // Add specific indexes to the upper bound.
  status = sub->testAdd((2 * 3600) + 11);
  status = sub->testAdd((2 * 3600) + 61);
  indexes = sub->getIndexes(2 * 3600, (2 * 3600) + 62);
  output = boost::algorithm::join(indexes, ", ");
  EXPECT_EQ(output, "10.726, 60.120");

  // Request specific lower and upper bounding.
  indexes = sub->getIndexes(2, (2 * 3600) + 62);
  output = boost::algorithm::join(indexes, ", ");
  EXPECT_EQ(output, "10.0, 10.1, 10.726, 3600.1, 60.1, 60.120");
}
TEST_F(EventsDatabaseTests, test_record_indexing) {
  auto sub = std::make_shared<FakeEventSubscriber>();
  auto status = sub->testAdd(2);
  status = sub->testAdd(11);
  status = sub->testAdd(61);
  status = sub->testAdd((1 * 3600) + 1);
  status = sub->testAdd((2 * 3600) + 1);

  // An "all" range, will pick up everything in the largest index.
  auto indexes = sub->getIndexes(0, 3 * 3600);
  auto output = boost::algorithm::join(indexes, ", ");
  EXPECT_EQ(output, "3600.0, 3600.1, 3600.2");

  // Restrict range to "most specific".
  indexes = sub->getIndexes(0, 5);
  output = boost::algorithm::join(indexes, ", ");
  EXPECT_EQ(output, "10.0");

  // Get a mix of indexes for the lower bounding.
  indexes = sub->getIndexes(2, (3 * 3600));
  output = boost::algorithm::join(indexes, ", ");
  EXPECT_EQ(output, "3600.1, 3600.2, 60.1, 10.0, 10.1");

  // Rare, but test ONLY intermediate indexes.
  indexes = sub->getIndexes(2, (3 * 3600), 1);
  output = boost::algorithm::join(indexes, ", ");
  EXPECT_EQ(output, "60.0, 60.1, 60.60, 60.120");

  // Add specific indexes to the upper bound.
  status = sub->testAdd((2 * 3600) + 11);
  status = sub->testAdd((2 * 3600) + 61);
  indexes = sub->getIndexes(2 * 3600, (2 * 3600) + 62);
  output = boost::algorithm::join(indexes, ", ");
  EXPECT_EQ(output, "60.120, 10.726");

  // Request specific lower and upper bounding.
  indexes = sub->getIndexes(2, (2 * 3600) + 62);
  output = boost::algorithm::join(indexes, ", ");
  EXPECT_EQ(output, "3600.1, 60.1, 60.120, 10.0, 10.1, 10.726");
}
Exemple #24
0
void HAlarm::filterTargets()
{
   // setUI();

   // seleziono le righe del modello
    bool usaidgruppo=ui->tvMain->model()->index(ui->tvMain->selectionModel()->currentIndex().row(),6).data(0).toBool();
    qDebug()<<"usaidgruppo: "<<QString::number(usaidgruppo);
    int colonnaconids;
    int number=0;
    QString idsindb;



    if (usaidgruppo)
    {
       colonnaconids=4;
    }
    else
    {
        colonnaconids=3;
    }




    idsindb=ui->tvMain->model()->index(ui->tvMain->selectionModel()->currentIndex().row(),colonnaconids).data(0).toString();
 qDebug()<<"idsindb"<<idsindb<<ui->tvMain->model()->index(ui->tvMain->selectionModel()->currentIndex().row(),colonnaconids).data(0).toString();
    QStringList indexes=getIndexes(idsindb);

    QString filter;
    if(action =="n")
    {

    indexes=getIndexes(idsindb);
    number=indexes.count();
qDebug()<<"indexes,count: "<<number;

         if (number>=1)
         {
                filter="ID IN (";

                    for (int f=0;f<number;f++)
                    {
                       QString fid=indexes.at(f);

                       fid=fid.replace("-",",");

                       qDebug()<<"fid: "<<fid;

                       filter += fid;

                       if(f<indexes.count()-1)
                       {
                           filter +=",";
                       }
                    }

                    filter +=")";
         }
        else
        {
            filter="";
        }
    }
    else
    {
        indexes=QStringList();
       // filter="";
    }


    qDebug()<<"filtertargets: action: "<<action<<"filter: "<<filter<<"number: "<<number;

    QSqlTableModel* lvmod=static_cast<QSqlTableModel*> (ui->lvTarget->model());
    lvmod->setFilter(filter);
    lvmod->select();





}