[Solved] Show ETA On a Mysql function

Post

Posted
Rating:
#1 (In Topic #963)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
Hi All

I have the following MySQL Function that I use to copy my Product table from the Server to the Local System's database

Code (gambas)

  1.     Dim DataResult As Result
  2.  
  3.     Global.DisplaySystemMessage("Processing Please wait...")
  4.    
  5.     i = 1
  6.  
  7.     $Query = Null
  8.     $Query &= "Select "
  9.     $Query &= "barcodenumber, "
  10.     $Query &= "posdescription, "
  11.     $Query &= "shelfedgelabeldescription, "
  12.     $Query &= "salelocation, "
  13.     $Query &= "subcatnumber, "
  14.     $Query &= "agerestricted, "
  15.     $Query &= "agelimit, "
  16.     $Query &= "pricetype, "
  17.     $Query &= "retailprice, "
  18.     $Query &= "retailvatprice, "
  19.     $Query &= "vatcode, "
  20.     $Query &= "stockcontrolyn, "
  21.     $Query &= "trackcolor, "
  22.     $Query &= "tracksize, "
  23.     $Query &= "print_guarantee_message, "
  24.     $Query &= "print_guarantee_code, "
  25.     $Query &= "displaymessage, "
  26.     $Query &= "messagenumber, "
  27.     $Query &= "sendtoppr, "
  28.     $Query &= "requestserial, "
  29.     $Query &= "itemnotallowed, "
  30.     $Query &= "itemnotallowed_reason, "
  31.     $Query &= "restrict_product_qty, "
  32.     $Query &= "product_qty_allowed, "
  33.     $Query &= "discount_not_allowed, "
  34.     $Query &= "no_refund_allowed, "
  35.     $Query &= "healthy_start_voucher_ok, "
  36.     $Query &= "ask_for_qty_before_selling, "
  37.     $Query &= "priceoverride_not_allowed "
  38.     $Query &= "from producttable "
  39.     $Query &= "order by barcodenumber ASC;"
  40.  
  41.     DataResult = Global.$DBCon.Exec($Query)
  42.  
  43.     If DataResult.Available = True Then
  44.         Global.AddToListBox("Downloading data from the product table")
  45.          
  46.         With FMain.ProgressBar1
  47.             .Value = 1
  48.             .Visible = True
  49.         End With
  50.  
  51.         For Each DataResult
  52.             LocalSQL = Null
  53.             LocalSQL &= "Insert into producttable ("
  54.             LocalSQL &= "barcodenumber, "
  55.             LocalSQL &= "posdescription, "
  56.             LocalSQL &= "shelfedgelabeldescription, "
  57.             LocalSQL &= "salelocation, "
  58.             LocalSQL &= "subcatnumber, "
  59.             LocalSQL &= "agerestricted, "
  60.             LocalSQL &= "agelimit, "
  61.             LocalSQL &= "pricetype, "
  62.             LocalSQL &= "retailprice, "
  63.             LocalSQL &= "retailvatprice, "
  64.             LocalSQL &= "vatcode, "
  65.             LocalSQL &= "stockcontrolyn, "
  66.             LocalSQL &= "trackcolor, "
  67.             LocalSQL &= "tracksize, "
  68.             LocalSQL &= "print_guarantee_message, "
  69.             LocalSQL &= "print_guarantee_code, "
  70.             LocalSQL &= "displaymessage, "
  71.             LocalSQL &= "messagenumber, "
  72.             LocalSQL &= "sendtoppr, "
  73.             LocalSQL &= "requestserial, "
  74.             LocalSQL &= "itemnotallowed, "
  75.             LocalSQL &= "itemnotallowed_reason, "
  76.             LocalSQL &= "restrict_product_qty, "
  77.             LocalSQL &= "product_qty_allowed, "
  78.             LocalSQL &= "discount_not_allowed, "
  79.             LocalSQL &= "no_refund_allowed, "
  80.             LocalSQL &= "healthy_start_voucher_ok, "
  81.             LocalSQL &= "ask_for_qty_before_selling, "
  82.             LocalSQL &= "priceoverride_not_allowed) "
  83.             LocalSQL &= "VALUES ('"
  84.             LocalSQL &= DataResult!barcodenumber & "','"
  85.             LocalSQL &= Replace(Replace(DataResult!posdescription, "'", "''"), ",", ",,") & "','"
  86.             LocalSQL &= Replace(Replace(DataResult!shelfedgelabeldescription, "'", "''"), ",", ",,") & "','"
  87.             LocalSQL &= DataResult!salelocation & "','"
  88.             LocalSQL &= DataResult!subcatnumber & "','"
  89.             LocalSQL &= DataResult!agerestricted & "','"
  90.             LocalSQL &= DataResult!agelimit & "','"
  91.             LocalSQL &= DataResult!pricetype & "','"
  92.             LocalSQL &= DataResult!retailprice & "','"
  93.             LocalSQL &= DataResult!retailvatprice & "','"
  94.             LocalSQL &= DataResult!vatcode & "','"
  95.             LocalSQL &= DataResult!stockcontrolyn & "','"
  96.             LocalSQL &= DataResult!trackcolor & "','"
  97.             LocalSQL &= DataResult!tracksize & "','"
  98.             LocalSQL &= DataResult!print_guarantee_message & "','"
  99.             LocalSQL &= DataResult!print_guarantee_code & "','"
  100.             LocalSQL &= DataResult!displaymessage & "','"
  101.             LocalSQL &= DataResult!messagenumber & "','"
  102.             LocalSQL &= DataResult!sendtoppr & "','"
  103.             LocalSQL &= DataResult!requestserial & "','"
  104.             LocalSQL &= DataResult!itemnotallowed & "','"
  105.             LocalSQL &= Replace(Replace(DataResult!itemnotallowed_reason, "'", "''"), ",", ",,") & "','"
  106.             LocalSQL &= DataResult!restrict_product_qty & "','"
  107.             LocalSQL &= DataResult!product_qty_allowed & "','"
  108.             LocalSQL &= DataResult!discount_not_allowed & "','"
  109.             LocalSQL &= DataResult!no_refund_allowed & "','"
  110.             LocalSQL &= DataResult!healthy_start_voucher_ok & "','"
  111.             LocalSQL &= DataResult!ask_for_qty_before_selling & "','"
  112.             LocalSQL &= DataResult!priceoverride_not_allowed & "')"
  113.  
  114.             DatabaseFunctions.SendToLocalDatabase(LocalSQL)
  115.             Dim RemaingValue As Integer = DataResult.Count - I
  116.  
  117.             FMain.ProgressBar1.Value = i / DataResult.Count
  118.             Global.DisplaySystemMessage("Processing Record " & Trim(Format(i, "###,###,##0")) & " of " & Trim(Format(DataResult.Count, "###,###,##0")) & " Reaming to Process " & Trim(Format(RemaingValue, "###,###,##0")))
  119.             i += 1
  120.         Next
  121.        
  122.         If DataResult.Count = 1 Then
  123.             Global.AddToListBox("Downloaded a total of " & DataResult.Count & " record")
  124.         Else
  125.             Global.AddToListBox("Downloaded a total of " & DataResult.Count & " records")
  126.         End If
  127.  
  128.     Else
  129.         Global.AddToListBox("Nothing to Download from the product table")
  130.     End If
  131.    
  132.     With FMain.ProgressBar1
  133.         .Value = 0
  134.         .Visible = False
  135.     End With
  136.  
  137.     ShowDottedLine
  138.    

Does anyone know how I can show a ETA on the screen (example Processing Record 1  of  12,999 & " Reaming to Process 12,998 (ETA 05:00 Mins)

or could someone point me in the direction so I can read up on how to show a Est time remaining

I was working on 2 seconds a record so that would be 12999 *2 = 25,998 then divide by 60 (minute) = 433.3 would that be mins or hours ?
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
The theory is that in data processes that take a long time, there can be many factors that will effect the actual time taken.
The source(Server)  or recipient(Workstation), may have other background tasks that can take up cycle time and so your
solution for an ETC (Estimated time of completion) needs to be self adjusting.


START = Now() 'Get the start time.
Read a set number of records                                             ' say 2 records ?
END = Now()
DURATION = DateDiff(START,END,Gb.Second)                'Record how long this takes in seconds - you could change to Gb.Milliseconds to suit?

ETC = DURATION * Records Remaining                            'In seconds

Update Progress bar with records read and ETC converted to readable time.

That's the theory anyway…

Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#3
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
 Hi Quincunxian

Thank you for that example I will see what I can can come up with

if i have something say like 56,003 seconds how would i convert that into minutes so I could display it on screen
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
 You need to understand query planning.
For each query you send to the database it has to a) parse the query and formulate the most efficient approach, b) process the query and c) output a response. Around this wrap the latency due to network/other processes being scheduled etc. so
  1. Updating the local database record by record is the most inefficient way to do this possibly imaginable as a) and c) are repeated each time
  2. Basing a guestimate on one or two records will be inaccurate as in that case a) can sometimes be the major "cost" of the entire transaction.

thatbruce

Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’

AndyGable said

Hi Quincunxian

Thank you for that example I will see what I can can come up with

if i have something say like 56,003 seconds how would i convert that into minutes so I could display it on screen

you can use \ and % operators
\ gives the division without the remainder
% gives the remainder

the following will give a string like 15h33m23s for the 56003 seconds and omit showing any zero numbers

Code (gambas)

  1.  
  2. Public Sub SecsToMins(iSecs As Integer) As String
  3.  
  4.   Dim h, m, s As Integer, sStr As String
  5.  
  6.   m = iSecs \ 60
  7.   s = iSecs % 60
  8.  
  9.   If m >= 60 Then
  10.     h = m \ 60
  11.     m = m % 60
  12.  
  13.   If h Then sStr = h & "h"
  14.   If m Then sStr &= m & "m"
  15.   If s Then sStr &= s & "s"
  16.   Return sStr
  17.  
  18.  
  19.  
Online now: No Back to the top

Post

Posted
Rating:
#6
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’

BruceSteers said

AndyGable said

Hi Quincunxian

Thank you for that example I will see what I can can come up with

if i have something say like 56,003 seconds how would i convert that into minutes so I could display it on screen

you can use \ and $ operators
\ gives the division without the remainder
% gives the remainder

the following will give a string like 15h33m23s for the 56003 seconds and omit showing any zero numbers

Code (gambas)

  1.  
  2. Public Sub SecsToMins(iSecs As Integer) As String
  3.  
  4.   Dim h, m, s As Integer, sStr As String
  5.  
  6.   m = iSecs \ 60
  7.   s = iSecs % 60
  8.  
  9.   If m >= 60 Then
  10.     h = m \ 60
  11.     m = m % 60
  12.  
  13.   If h Then sStr = h & "h"
  14.   If m Then sStr &= m & "m"
  15.   If s Then sStr &= s & "s"
  16.   Return sStr
  17.  
  18.  
  19.  

Bruce that was just what I needed
<IMG src="https://www.algpos.co.uk/webimage/DataSyncScreenShot.png"> </IMG>

I know this is not fully accuate but it is just a guide :D and it works great thanks
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Regular
Cedron is in the usergroup ‘Regular’

AndyGable said

if i have something say like 56,003 seconds how would i convert that into minutes so I could display it on screen

Here is an alternative way:

Code (gambas)

  1.     Dim d As Date = 56003 / 86400  ' Seconds per Day
  2.     Print Format(d, "hh:nn:ss")
  3.  

.... and carry a big stick!
Online now: No Back to the top
1 guest and 0 members have just viewed this.