PDA

View Full Version : QHttp::dataSendProgress transfer speed Kb sec.



patrik08
5th March 2007, 10:26
I mesure the time wo file upload go up on send process....

void QHttp::dataSendProgress ( int done, int total ) [signal]
Warning: done and total are not necessarily the size in bytes, since for large files these values might need to be "scaled" to avoid overflow.
is this Byte or bit done???? or random nummer to only qscrollbar

or better use qint64 QHttp::read ( char * data, qint64 maxlen ) ?

gostart.start();
/* header set QTime gostart; gostart.start(); */
uint mmse = gostart.elapsed(); /* millisecond*/

to become speed ...... kb sec how i must calc i have time && size...?


float kilobite = bytesRead * 8;
float speedwork = kilobite / mmse;

or

float speedwork = bytesRead / mmse;




if i but BiteorMega( incomming done QHttp::dataSendProgress ) direct the ammount of MB is correct .....


and i mesure time && MB so......




QString TimeaGo( int ms , int sek )
{
QString elapstime;
QString elapettime,ssec,smin,shor,speeder;
int sec_el;

if (ms > 0) {
sec_el = ms / 1000;
}

if (sek > 0) {
sec_el = sek;
}

if (ms < 1 && sek < 1) {
return elapstime;
}



int min_el = 0;
int hor_el = 0;
int timebreak = 0;
for (int i = 0; i < sec_el; ++i) {
timebreak++;
if (timebreak == 60) {
timebreak = 0;
min_el++;
}
if (min_el == 60) {
min_el = 0;
hor_el++;
}
if (hor_el == 24) {
hor_el = 0;
/* day 1 */
}

}

if (timebreak < 10) {
ssec = QString("0%1").arg(timebreak);
} else {
ssec = QString("%1").arg(timebreak);
}
if (min_el < 10) {
smin = QString("0%1").arg(min_el);
} else {
smin = QString("%1").arg(min_el);
}
if (hor_el < 10) {
shor = QString("0%1").arg(hor_el);
} else {
shor = QString("%1").arg(hor_el);
}

elapstime = QString("%1:%2:%3").arg(shor).arg(smin).arg(ssec);
return elapstime;
}


QString BiteorMega( int peso )
{

/*
on Byte are 8 bit
on Kilobyte are 1024 Byte.
*/

QString humanread;
double canno = peso / 1024;
int sale = canno;
if (peso > 0) {
if (canno < 1) {
sale = 1;
}
}

if (sale < 1025) {
humanread = QString("KB %1").arg(sale);
return humanread;
}

float megad = sale / 1024;

if (megad < 1025) {
humanread = QString("MB %1").arg(megad);
return humanread;
} else {
/* maybe impossibel upload GBs */
humanread = QString("GB 1+");
}

return humanread;
}

wysota
5th March 2007, 10:53
What is the actual question? :)
For relatively short files the progress will be measured in bytes, but you can't rely on that to be always the case, as for example file sizes larger than 2GB can't be stored with ints, so in that case the result will be scaled.

patrik08
5th March 2007, 11:24
What is the actual question? :)
For relatively short files the progress will be measured in bytes, but you can't rely on that to be always the case, as for example file sizes larger than 2GB can't be stored with ints, so in that case the result will be scaled.

I suppose http://doc.trolltech.com/4.2/qiodevice.html#pos
have moore precision on uload??? or is this mistake?

QFile * locfile
BeamUpFile = locfile;
QFileInfo info(locfile);
qint64 filezsize = info.size();
qint64 filereadnow = BeamUpFile->pos();

wysota
5th March 2007, 11:50
This only works for random access devices. A socket is not a random access device.

patrik08
5th March 2007, 12:05
This only works for random access devices. A socket is not a random access device.

Hmmm... and How to become the corect size read status? on upload?

wysota
5th March 2007, 12:11
Either calculate it yourself or use the progress signals regardless of their precision.

patrik08
5th March 2007, 17:36
Either calculate it yourself or use the progress signals regardless of their precision.

qint64 filereadnow = BeamUpFile->pos(); /* pointer to qfile upload qt4.2 */
work perfekt i tested on a iso file upload 698MB on my LAN
result ... http://qt-webdav.svn.sourceforge.net/viewvc/qt-webdav/webdavdir/dav/davput.h?view=markup

wysota
5th March 2007, 17:43
Have you taken into consideration that the size pos() returns doesn't mean the position of the stream being sent but rather the one being read from the file? There is also some amount of data that is currently buffered along the way (file buffer, socket buffer, system buffer, NIC buffer, possibly more).

patrik08
5th March 2007, 18:02
Have you taken into consideration that the size pos() returns doesn't mean the position of the stream being sent but rather the one being read from the file? There is also some amount of data that is currently buffered along the way (file buffer, socket buffer, system buffer, NIC buffer, possibly more).


I suppose QIODevice read fast or not fast in to speed tat socket can send....
on dataSendProgress(int done , int) on done is 3% the same value as QIODevice :: pos() at end is the same .... but QIODevice :: pos() go moore as 2GB....


And How calculate you the Time to complete upload? && Speed?

wysota
5th March 2007, 20:10
And How calculate you the Time to complete upload? && Speed?

speed = (length*percentage_completed) / time_elapsed
time remaining = (1 - percentage_completed) * length/speed or 100*(1-percentage_completed)*time_elapsed
percentage_completed = done/total (taken from QHttp progress signals)

division used here (/) is a floating point operator.

Example:

length = 1000000B
time_elapsed = 5s
done = 1000
total = 100000

hence:
percentage_completed = 0.01 (=10000B)
speed = (10^6*10^-2)/5s = 10000/5 = 2000B/s
time remaining = (1-0.01) * 10^6/2000 = 0.99 * 500 = 495s
time remaining (alternative) = 100 * 0.99 * 5 = 99 * 5 = 495s


BTW. 1% * 3GB = 3MB - buffers are not that large therefore you won't notice a difference with such big values here. But if you try sending a small file (100kB) through an extremely slow link, the file read buffer and socket write buffer positions might be quite different.

patrik08
5th March 2007, 20:30
speed = (length*percentage_completed) / time_elapsed

division used here (/) is a floating point operator.
different.

double can go to .arg(22.22) or accept .arg float as double?
not run....
QString str = QString("speed Kb/s: %1").arg(d, 0, 'f', 0);

How can .arg() print only 2 decimal??
QChar & fillChar 0



double d = 12.34;
QString str = QString("delta: %1").arg(d, 0, 'E', 3);
// str == "delta: 1.234E+01"

wysota
5th March 2007, 22:59
I don't understand the question.

patrik08
6th March 2007, 01:12
I don't understand the question.

How display decimal numer on .arg ....?

double nummer = .33 ;

QString("Cent: %1").arg(nummer); /* comming 0 */

QString str = QString("delta: %1").arg(d, 0, 'E', 3);
i am confused on E g f..... i can only display decimal point on console app...
and i like display double nummer = .33 on .arg() ....

wysota
6th March 2007, 10:12
Are you sure "nummer" is double? Or maybe you're using a comma instead of a dot while initialising the variable?

The following:

#include <QString>
#include <QtDebug>

int main(){
qDebug() << QString("Value: %1").arg((double).33);
return 0;
}

returns:

"Value: 0.33"

patrik08
6th March 2007, 23:34
Are you sure "nummer" is double? Or maybe you're using a comma instead of a dot while initialising the variable?

The following:

#include <QString>
#include <QtDebug>

int main(){
qDebug() << QString("Value: %1").arg((double).33);
return 0;
}

returns:

is a float speed kbs .... convertet on double the first value .... why? .... on wayting the first second ;) to calculate the speed upload..... to display speed each millisecond break my eyes && compiler... ... and i print only speed each sec. much tanks...:o