Page 1 of 2

Help with ascan

PostPosted: Thu May 12, 2022 8:30 pm
by Silvio.Falconi
I have to look for a number how many times it is repeated in the same position

since the search in an archive is very slow I thought of using an array but I have difficulty in counting the number in the same position

first I convert the archive to an array

Code: Select all  Expand view
Local aData := oDbf:dbftoarray()


I have an array of 57 columns and 10078 rows

to give an example I have to look for the number 34 in the first position, which in the archive is the third field

? freq(oDbf,34,1,10078)

freq(oDbf,numero,npos,nRowMax)

nRowMax is the maximum number record where I have to look for it
Code: Select all  Expand view


Function test()
   local oDbf
   local cDir := ".\data\"
   oDbf:= TDatabase():Open( ,cDir+"
demo", "DBFCDX", .T. )

   ? freq(oDbf,34,1,10078)
return nil

Function freq(oDbf,numero,npos,nRowMax)
     Local aData := oDbf:dbftoarray()
     Local nColMax  := 57
     LOCAL k, j, nPosi
     LOCAL nCount   := 0

      For k = 1 to  nRowMax
            FOR j = 1 TO nColMax
                nPosi := AScan( aData, { |a|  a[ nPos+2 ]  = numero } )
                 IF nPosi = nPos+2
                      // increase Counter
                        nCount:=nCount + 1
                      ENDIF
                 NEXT
            NEXT
 ? nCount
 return nil



any help pls

Re: Help with ascan

PostPosted: Fri May 13, 2022 6:08 am
by Antonio Linares
Dear Silvio,

Could you provide us the DBF ?

What problem or error do you have ?

Re: Help with ascan

PostPosted: Fri May 13, 2022 6:50 am
by Silvio.Falconi
Antonio,
see on your e-mail

Re: Help with ascan

PostPosted: Fri May 13, 2022 7:27 am
by Otto
Hello Silvio,

can't see the e-mail,



Best regards,
Otto

Re: Help with ascan

PostPosted: Fri May 13, 2022 7:43 am
by Antonio Linares
Dear Silvio,

If you need fastest speed then forget about for ... next loops

use AEval() and AScan() only

If that is not fast enough, then you have to code it in pure C language. C language is the fastest speed you will ever get.

Re: Help with ascan

PostPosted: Fri May 13, 2022 8:15 am
by Silvio.Falconi
Otto wrote:Hello Silvio,

can't see the e-mail,



Best regards,
Otto


???

Re: Help with ascan

PostPosted: Fri May 13, 2022 8:42 am
by Silvio.Falconi
Antonio Linares wrote:Dear Silvio,

If you need fastest speed then forget about for ... next loops

use AEval() and AScan() only

If that is not fast enough, then you have to code it in pure C language. C language is the fastest speed you will ever get.


Antonio,

I not understood

If I make
number:= 34
cFilter := "oDbf:Ba1=" +number
oDbf:setFilter(cFilter)
nFreq:= oDbf:keycount()

It immediately gives me the frequency value in fast mode for 1 number

Is it possible that if I do a search for 90 numbers it will take a long time?

Re: Help with ascan

PostPosted: Fri May 13, 2022 9:50 am
by Otto
Dear Antonio,

I was thinking today that you could possibly make a good solution with HASHs.

But with Silvio it is usually so that he does not provide the necessary documents.

Now with mod harbour I use HASHs eg at the "controller".
The code is actually very clear.
But I have no speed tests yet.
Can you maybe say something about speed?

E.g. I would have thought of element["91"] += 1 etc..

Best regards,
Otto

Re: Help with ascan

PostPosted: Fri May 13, 2022 10:59 am
by Silvio.Falconi
Otto wrote:Dear Antonio,

I was thinking today that you could possibly make a good solution with HASHs.

But with Silvio it is usually so that he does not provide the necessary documents.

Now with mod harbour I use HASHs eg at the "controller".
The code is actually very clear.
But I have no speed tests yet.
Can you maybe say something about speed?

E.g. I would have thought of element["91"] += 1 etc..

Best regards,
Otto



>But with Silvio it is usually so that he does not provide the necessary documents.

what documents do you need?
I sent the archive dbf to Antonio, I did not get a clear answer from you that you were willing to help me otherwise I would have sent you everything you need

Re: Help with ascan

PostPosted: Fri May 13, 2022 2:42 pm
by Antonio Linares
Dear Silvio,

If you are looking for speed then forget, completely, about filters...

Re: Help with ascan

PostPosted: Fri May 13, 2022 5:18 pm
by nageswaragunupudi
Code: Select all  Expand view
Function test()
   local oDbf
   local cDir := ".\data\"
   local aData

   oDbf:= TDatabase():Open( ,cDir+"
demo", "DBFCDX", .T. )
   aData := oDbf:DbfToArray()
   
   ? freq(oDbf, 34, 1 ) // Frequency of number 34 in position 1 (field 3)

return nil

Function freq( aData, numero, npos )

   local nCount   := 0

   nPos  += 2
   AEval( aData, { |a| If( a[ nPos ] == numero, nCount++, nil ) } )

return nCount

Re: Help with ascan

PostPosted: Fri May 13, 2022 5:44 pm
by Silvio.Falconi
nageswaragunupudi wrote:
Code: Select all  Expand view
Function test()
   local oDbf
   local cDir := ".\data\"
   local aData

   oDbf:= TDatabase():Open( ,cDir+"
demo", "DBFCDX", .T. )
   aData := oDbf:DbfToArray()
   
   ? freq(oDbf, 34, 1 ) // Frequency of number 34 in position 1 (field 3)

return nil

Function freq( aData, numero, npos )

   local nCount   := 0

   nPos  += 2
   AEval( aData, { |a| If( a[ nPos ] == numero, nCount++, nil ) } )

return nCount



thanks Maestro but give me error

Called from: test.prg => (b)FREQ( 18 )
Called from: => AEVAL( 0 )
Called from: test.prg => FREQ( 18 )
Called from: test.prg => TEST( 9 )

Re: Help with ascan

PostPosted: Fri May 13, 2022 5:52 pm
by Otto
Hi Max,
Thanks for the speed test with the HASH variant.
Best regards and a nice weekend,
Otto

Re: Help with ascan

PostPosted: Fri May 13, 2022 6:43 pm
by Silvio.Falconi
Otto wrote:Hi Max,
Thanks for the speed test with the HASH variant.
Best regards and a nice weekend,
Otto


perhaps U wrong topic ..... :)

Re: Help with ascan

PostPosted: Fri May 13, 2022 6:51 pm
by Silvio.Falconi
nageswaragunupudi wrote:
Code: Select all  Expand view
Function test()
   local oDbf
   local cDir := ".\data\"
   local aData

   oDbf:= TDatabase():Open( ,cDir+"
demo", "DBFCDX", .T. )
   aData := oDbf:DbfToArray()
   
   ? freq(oDbf, 34, 1 ) // Frequency of number 34 in position 1 (field 3)

return nil

Function freq( aData, numero, npos )

   local nCount   := 0

   nPos  += 2
   AEval( aData, { |a| If( a[ nPos ] == numero, nCount++, nil ) } )

return nCount




Nages,
run ok thanks

a question....to calculate the delay of a number it is the opposite in the sense that you start from the bottom of the archive and go backwards until you find the number
how I translate it

i try to make
oRit:= TDatabase():Open( , cDir+"lotto", "DBFCDX", .T. )
oRit:setorder(0)
oRitardo:gobottom()
nUltimo:= oRitardo:recno()
aTemp:=oRit:dbftoarray()

ritardo:= Rit( aTemp, number, npos,nUltimo )


Function Rit( aData, numero, npos, nLast )
local nCount := -1
nPos += 2
AEval( aData, { |a| If( a[npos] == numero, nCount++, nil ) },nLast )
return nCount