calculate the frequency of a number

calculate the frequency of a number

Postby Silvio.Falconi » Tue May 10, 2022 10:11 pm

I have to calculate the frequency of a number that is, I'll explain
I have these ninety numbers

Image


For each number I must calculate the frequency
that is, how many times this number is repeated in the archive and in the same position, compared to the number of records where I have positioned myself

Code: Select all  Expand view
EstrattoFrequenza(nNumber,nWheel,npos,nrecord)


with this function I pass the following parameters

nNumber the number to search
nWheel a number (from 1 to 11)
npos the position ( from 1 to 5)
nrecord the number of record where I have positioned myself



Of course I am using tdatabase

the function
Code: Select all  Expand view
Function EstrattoFrequenza(nNumber,nWheel,nPos,nRecord)
local oFreq,primo
local frequency:=0
local r1,r2,r3,r4,r5
local cDir := ".\data\"
local lFound:=.f.


//take the field I need

do case
      case nWheel = 1
         r1:= "
BA1"
         r2:= "
BA2"
         r3:= "
BA3"
         r4:= "
BA4"
         r5:= "
BA5"
            case nWheel = 2
         r1:= "
CA1"
         r2:= "
CA2"
         r3:= "
CA3"
         r4:= "
CA4"
         r5:= "
CA5"
           case nWheel = 3
         r1:= "
FI1"
         r2:= "
FI2"
         r3:= "
FI3"
         r4:= "
FI4"
         r5:= "
FI5"
          case nWheel = 4
         r1:= "
GE1"
         r2:= "
GE2"
         r3:= "
GE3"
         r4:= "
GE4"
         r5:= "
GE5"
       case nWheel = 5
         r1:= "
MI1"
         r2:= "
MI2"
         r3:= "
MI3"
         r4:= "
MI4"
         r5:= "
MI5"
         case nWheel = 6
         r1:= "
NA1"
         r2:= "
NA2"
         r3:= "
NA3"
         r4:= "
NA4"
         r5:= "
NA5"
       case nWheel = 7
         r1:= "
PA1"
         r2:= "
PA2"
         r3:= "
PA3"
         r4:= "
PA4"
         r5:= "
PA5"
      case nWheel = 8
         r1:= "
RM1"
         r2:= "
RM2"
         r3:= "
RM3"
         r4:= "
RM4"
         r5:= "
RM5"
       case nWheel = 9
         r1:= "
TO1"
         r2:= "
TO2"
         r3:= "
TO3"
         r4:= "
TO4"
         r5:= "
TO5"
      case nWheel = 10
         r1:= "
VE1"
         r2:= "
VE2"
         r3:= "
VE3"
         r4:= "
VE4"
         r5:= "
VE5"
      case nWheel = 11
         r1:= "
NZ1"
         r2:= "
NZ2"
         r3:= "
NZ3"
         r4:= "
NZ4"
         r5:= "
NZ5"
  endcase

         
   oFreq:=TDatabase():Open( , cDir+"
demo", "DBFCDX", .T. )
   oFreq:setorder(0)
   oFreq:goTop()
 

         do while (oFreq:RecNo() != nRecord .AND. !lFound)
   

        //position
            Do case
         case nPos=1
              If oFreq:&r1 = nNumber
                 lFound:=.t.
              Endif
         case nPos=2
             If oFreq:&r2 = nNumber
                lFound:=.t.
             Endif
         case nPos=3
             If oFreq:&r3 = nNumber
                lFound:=.t.
             Endif
         case nPos=4
             If oFreq:&r4 = nNumber
                lFound:=.t.
             Endif
         case nPos=5
             If oFreq:&r5 = nNumber
                lFound:=.t.
              Endif
         Endcase



           IF lFound
              frequency:= frequency+1
           Endif

           
        oFreq:skip(1)
        Enddo
       oFreq:close()
return frequency



I tried to make a function but the calculation slows down the display a lot and I really don't know how to solve to speed up the calculation
Any suggestion ? 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: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: calculate the frequency of a number

Postby James Bott » Wed May 11, 2022 1:11 am

Read the database once while copying all the data into a multidimensional array.

Then calculate the frequency using the array.
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: calculate the frequency of a number

Postby Silvio.Falconi » Wed May 11, 2022 6:19 am

James Bott wrote:Read the database once while copying all the data into a multidimensional array.

Then calculate the frequency using the array.


that is in practice how should I do?
if I asked in the forum it means that I don't know how to do it
I cannot use ascan() on all fields because I have to determine if it is in the first position or the second or the third or the fourth or the fifth

this is my structure and the records are 10078

Code: Select all  Expand view


 local aFields := { { "DATA", "D", 8, 0 },;
                   { "CONCORSO", "C", 3, 0 },;
                   { "BA1", "N", 2, 0 },;
                   { "BA2", "N", 2, 0 },;
                   { "BA3", "N", 2, 0 },;
                   { "BA4", "N", 2, 0 },;
                   { "BA5", "N", 2, 0 },;
                   { "CA1", "N", 2, 0 },;
                   { "CA2", "N", 2, 0 },;
                   { "CA3", "N", 2, 0 },;
                   { "CA4", "N", 2, 0 },;
                   { "CA5", "N", 2, 0 },;
                   { "FI1", "N", 2, 0 },;
                   { "FI2", "N", 2, 0 },;
                   { "FI3", "N", 2, 0 },;
                   { "FI4", "N", 2, 0 },;
                   { "FI5", "N", 2, 0 },;
                   { "GE1", "N", 2, 0 },;
                   { "GE2", "N", 2, 0 },;
                   { "GE3", "N", 2, 0 },;
                   { "GE4", "N", 2, 0 },;
                   { "GE5", "N", 2, 0 },;
                   { "MI1", "N", 2, 0 },;
                   { "MI2", "N", 2, 0 },;
                   { "MI3", "N", 2, 0 },;
                   { "MI4", "N", 2, 0 },;
                   { "MI5", "N", 2, 0 },;
                   { "NA1", "N", 2, 0 },;
                   { "NA2", "N", 2, 0 },;
                   { "NA3", "N", 2, 0 },;
                   { "NA4", "N", 2, 0 },;
                   { "NA5", "N", 2, 0 },;
                   { "PA1", "N", 2, 0 },;
                   { "PA2", "N", 2, 0 },;
                   { "PA3", "N", 2, 0 },;
                   { "PA4", "N", 2, 0 },;
                   { "PA5", "N", 2, 0 },;
                   { "RM1", "N", 2, 0 },;
                   { "RM2", "N", 2, 0 },;
                   { "RM3", "N", 2, 0 },;
                   { "RM4", "N", 2, 0 },;
                   { "RM5", "N", 2, 0 },;
                   { "TO1", "N", 2, 0 },;
                   { "TO2", "N", 2, 0 },;
                   { "TO3", "N", 2, 0 },;
                   { "TO4", "N", 2, 0 },;
                   { "TO5", "N", 2, 0 },;
                   { "VE1", "N", 2, 0 },;
                   { "VE2", "N", 2, 0 },;
                   { "VE3", "N", 2, 0 },;
                   { "VE4", "N", 2, 0 },;
                   { "VE5", "N", 2, 0 },;
                   { "NZ1", "N", 2, 0 },;
                   { "NZ2", "N", 2, 0 },;
                   { "NZ3", "N", 2, 0 },;
                   { "NZ4", "N", 2, 0 },;
                   { "NZ5", "N", 2, 0 } }


 




I try to make on dbu a filter sample BA1=numero and it is fast , when I try to make it on prg it is slow
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: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: calculate the frequency of a number

Postby Silvio.Falconi » Fri May 27, 2022 7:18 am

James Bott wrote:Read the database once while copying all the data into a multidimensional array.

Then calculate the frequency using the array.



I made it but the time is big
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: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: calculate the frequency of a number

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

Silvio,
Can you show your code?
LG
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: calculate the frequency of a number

Postby Silvio.Falconi » Fri May 27, 2022 10:49 am

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: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: calculate the frequency of a number

Postby Silvio.Falconi » Fri May 27, 2022 6:17 pm

Otto wrote:Silvio,
Can you show your code?
LG
Otto


Do you saw the code ?

LG ?

It is not here to discuss how to do the calculation because finding the frequency of a number is quickly done.

this is one of last draws

Image


the frequency is calculated by counting how many times a number has come out over a period of time, in my case from 1871 to today
Nages has calculated the relative frequency that is the frequency of a number in the same position, then there is the maximum frequency by counting the times in the fields of the same wheel or if we were to find the frequency of a number in the Bari wheel we will look for it in BA1, Ba2, Ba3 , Ba4 and Ba5.

the frequency

Image


My problem is to replace another one, if I do a do while loop inside the lotto.dbf archive it will take several seconds (0,8363636363636364) and since the procedure must find the frequency of 55 numbers the seconds will be 46/47 .

So at the suggestion of many people including James Bott I tried to find the frequency of a number by transforming the dbf archive into an array but unfortunately the result does not change I always have to wait several seconds.
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: 7061
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 80 guests