Help with ascan

Help with ascan

Postby Silvio.Falconi » Thu May 12, 2022 8: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: Select all  Expand view  RUN
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  RUN


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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7072
Joined: Thu Oct 18, 2012 7:17 pm

Re: Help with ascan

Postby Antonio Linares » Fri May 13, 2022 6:08 am

Dear Silvio,

Could you provide us the DBF ?

What problem or error do you have ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Help with ascan

Postby Silvio.Falconi » Fri May 13, 2022 6:50 am

Antonio,
see on your e-mail
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7072
Joined: Thu Oct 18, 2012 7:17 pm

Re: Help with ascan

Postby Otto » Fri May 13, 2022 7:27 am

Hello Silvio,

can't see the e-mail,



Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6341
Joined: Fri Oct 07, 2005 7:07 pm

Re: Help with ascan

Postby Antonio Linares » Fri May 13, 2022 7: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Help with ascan

Postby Silvio.Falconi » Fri May 13, 2022 8: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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7072
Joined: Thu Oct 18, 2012 7:17 pm

Re: Help with ascan

Postby Silvio.Falconi » Fri May 13, 2022 8: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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7072
Joined: Thu Oct 18, 2012 7:17 pm

Re: Help with ascan

Postby Otto » Fri May 13, 2022 9: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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6341
Joined: Fri Oct 07, 2005 7:07 pm

Re: Help with ascan

Postby Silvio.Falconi » 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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7072
Joined: Thu Oct 18, 2012 7:17 pm

Re: Help with ascan

Postby Antonio Linares » Fri May 13, 2022 2:42 pm

Dear Silvio,

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

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Help with ascan

Postby nageswaragunupudi » Fri May 13, 2022 5:18 pm

Code: Select all  Expand view  RUN
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
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Help with ascan

Postby Silvio.Falconi » Fri May 13, 2022 5:44 pm

nageswaragunupudi wrote:
Code: Select all  Expand view  RUN
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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7072
Joined: Thu Oct 18, 2012 7:17 pm

Re: Help with ascan

Postby Otto » Fri May 13, 2022 5:52 pm

Hi Max,
Thanks for the speed test with the HASH variant.
Best regards and a nice weekend,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6341
Joined: Fri Oct 07, 2005 7:07 pm

Re: Help with ascan

Postby Silvio.Falconi » Fri May 13, 2022 6: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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7072
Joined: Thu Oct 18, 2012 7:17 pm

Re: Help with ascan

Postby Silvio.Falconi » Fri May 13, 2022 6:51 pm

nageswaragunupudi wrote:
Code: Select all  Expand view  RUN
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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7072
Joined: Thu Oct 18, 2012 7:17 pm

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 34 guests