FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour calculate the frequency of a number
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
calculate the frequency of a number
Posted: 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




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 (fw): Select all Collapse
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 (fw): Select all Collapse
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 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: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: calculate the frequency of a number
Posted: Wed May 11, 2022 01: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
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: calculate the frequency of a number
Posted: Wed May 11, 2022 06: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 (fw): Select all Collapse
 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 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: calculate the frequency of a number
Posted: Fri May 27, 2022 07: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 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: calculate the frequency of a number
Posted: Fri May 27, 2022 07:39 AM

Silvio,
Can you show your code?
LG
Otto

Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: calculate the frequency of a number
Posted: Fri May 27, 2022 10:49 AM
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: calculate the frequency of a number
Posted: Fri May 27, 2022 06: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




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




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 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

Continue the discussion