bertrandmartel / speed-test-lib

:cloud: JSpeedTest : speed test client library for Java/Android
MIT License
381 stars 119 forks source link

upload and download speed is off #65

Open ferily7 opened 6 years ago

ferily7 commented 6 years ago

Hello,

I'm trying to calculate the upload and download speed using the function startUploadRepeat and startDownloadRepeat and converting it from bits to mbps. However, when I run my application and try to calculate the two speeds, the numbers are super off? The upload speed is like 0.1 and the download speed is in the 100 range. I'm using report.getTransferRateBit() to get the rate and dividing it by 1,000,000 but the numbers are still extremely off. Can anyone help me with this? Here is my code:

        SpeedTestSocket socketDown = new SpeedTestSocket();
        socketDown.startUploadRepeat(server.getUrl(),
                15000, 1000000, new IRepeatListener() {
                    @Override
                    public void onCompletion(final SpeedTestReport report) {
                        BigDecimal rate = report.getTransferRateBit();
                        BigDecimal divisor = BigDecimal.valueOf(1000000);
                        rate = rate.divide(divisor);
                        download.add(rate);
                        String rateString = "";
                        rateString = rateString + rate;
                        data.setDownload(rateString);
                        uploadData();
                        double num = 0.0000;
                        BigDecimal total = new BigDecimal(0.0000000);
                        for(BigDecimal value: download) {
                            num++;
                            total = total.add(value);
                        }
                        double dbTotal = total.doubleValue();
                        final double average = dbTotal / num;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                TextView downText = findViewById(R.id.textViewTableDown);
                                downText.setText("" + average);
                                changeButton();
                            }
                        });
                        Log.v("test", "DOWNLOAD SPEED: " + rateString);

                    }

                    @Override
                    public void onReport(final SpeedTestReport report) {
                        BigDecimal rate = report.getTransferRateBit();
                        BigDecimal divisor = BigDecimal.valueOf(1000000);
                        rate = rate.divide(divisor);
                        download.add(rate);
                        String rateString = "";
                        rateString = rateString + rate;
                        data.setDownload(rateString);
                        Log.v("test", "DOWNLOAD SPEED, R: " + rateString);
                    }
                });

Also I'm putting all of this data in firebase, which is what the uploadData() function does. Any help will be greatly appreciated.

lr2bmail commented 5 years ago

same after updating my phone to android 8.1.0