FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Help with ascan
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Help with ascan
Posted: Thu May 12, 2022 08:30 PM
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 (fw): Select all Collapse
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 (fw): Select all Collapse
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
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Help with ascan
Posted: Fri May 13, 2022 06:08 AM

Dear Silvio,

Could you provide us the DBF ?

What problem or error do you have ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Help with ascan
Posted: Fri May 13, 2022 06:50 AM

Antonio,
see on your e-mail

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Help with ascan
Posted: Fri May 13, 2022 07:27 AM

Hello Silvio,

can't see the e-mail,

Best regards,
Otto

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Help with ascan
Posted: Fri May 13, 2022 07:43 AM

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.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Help with ascan
Posted: Fri May 13, 2022 08:15 AM
Otto wrote:Hello Silvio,

can't see the e-mail,



Best regards,
Otto


???
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Help with ascan
Posted: Fri May 13, 2022 08:42 AM
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?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Help with ascan
Posted: Fri May 13, 2022 09:50 AM

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

Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Help with ascan
Posted: Fri May 13, 2022 10:59 AM
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
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Help with ascan
Posted: Fri May 13, 2022 02:42 PM

Dear Silvio,

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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Help with ascan
Posted: Fri May 13, 2022 05:18 PM
Code (fw): Select all Collapse
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
Regards



G. N. Rao.

Hyderabad, India
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Help with ascan
Posted: Fri May 13, 2022 05:44 PM
nageswaragunupudi wrote:
Code (fw): Select all Collapse
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 )
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: Help with ascan
Posted: Fri May 13, 2022 05:52 PM

Hi Max,
Thanks for the speed test with the HASH variant.
Best regards and a nice weekend,
Otto

Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Help with ascan
Posted: Fri May 13, 2022 06:43 PM
Otto wrote:Hi Max,
Thanks for the speed test with the HASH variant.
Best regards and a nice weekend,
Otto


perhaps U wrong topic ..... :-)
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Help with ascan
Posted: Fri May 13, 2022 06:51 PM
nageswaragunupudi wrote:
Code (fw): Select all Collapse
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
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com