"sampling" filter

"sampling" filter

Post by Dan Dorroug » Thu, 01 May 1997 04:00:00



I have an application in which it is required that "sampling filter" be
applied
to a data set. For example, select every 10th record or select 10% or the
records randomly or select a maximum of 10,000 records.

The following code, which was intended to implement the
"sample selection" filter, does not work. It does not work because
Table_MailingListFilterRecord gets called many times, but after the
first pass through the data, it is getting called only on records
that were previously accepted for the "selection set". Thus, if during
the first pass, only every tenth record was selected, during the next
pass only every one hundredth record gets selected and during the
third pass only every one thousandth record gets selected, etc.
There are actually other filtering conditions which may be applied on
a record-by-record basis, but those conditions work ok and have
been omitted from this code fragment.

I would be grateful if anyone has suggestions for how to make this
work.

procedure TMailList_Form.Table_MailingListFilterRecord(DataSet: TDataSet;
  var Accept: Boolean);
begin { TMailList_Form.Table_MailingListFilterRecord }
    begin
      if fDOSAMP_N then         { true if we are sampling every N'th rec }
        Accept := (fRecords_Scanned mod fSAMPLE_N) = 0 else
      if fDOSAMP_PCT then       { true if we are sampling a percentage of
recs }
        Accept := RANDOM <= (fSAMPLE_PCT / 100);
      if fDOSAMP_MAX then       { true if we have a max record count }
        Accept := fRecords_Accepted < fSAMPLE_MAX;
    end;

  Inc(fRecords_Scanned);
  if Accept then
    inc(fRecords_Accepted);
end;  { TMailList_Form.Table_MailingListFilterRecord }