Search in sources :

Example 6 with DownloadManagerStats

use of com.biglybt.core.download.DownloadManagerStats in project BiglyBT by BiglySoftware.

the class DownloadActivityView method fillPanel.

public void fillPanel() {
    Utils.disposeComposite(panel, false);
    GridData gridData;
    ValueFormater formatter = new ValueFormater() {

        @Override
        public String format(int value) {
            return DisplayFormatters.formatByteCountToKiBEtcPerSec(value);
        }
    };
    final ValueSourceImpl[] sources = { new ValueSourceImpl("Up", 0, colors, true, false, false) {

        @Override
        public int getValue() {
            DownloadManager dm = manager;
            if (dm == null) {
                return (0);
            }
            DownloadManagerStats stats = manager.getStats();
            return ((int) (stats.getDataSendRate()));
        }
    }, new ValueSourceImpl("Up Smooth", 1, colors, true, false, true) {

        @Override
        public int getValue() {
            DownloadManager dm = manager;
            if (dm == null) {
                return (0);
            }
            DownloadManagerStats stats = manager.getStats();
            return ((int) (stats.getSmoothedDataSendRate()));
        }
    }, new ValueSourceImpl("Down", 2, colors, false, false, false) {

        @Override
        public int getValue() {
            DownloadManager dm = manager;
            if (dm == null) {
                return (0);
            }
            DownloadManagerStats stats = manager.getStats();
            return ((int) (stats.getDataReceiveRate()));
        }
    }, new ValueSourceImpl("Down Smooth", 3, colors, false, false, true) {

        @Override
        public int getValue() {
            DownloadManager dm = manager;
            if (dm == null) {
                return (0);
            }
            DownloadManagerStats stats = manager.getStats();
            return ((int) (stats.getSmoothedDataReceiveRate()));
        }
    }, new ValueSourceImpl("Swarm Peer Average", 4, colors, false, true, false) {

        @Override
        public int getValue() {
            DownloadManager dm = manager;
            if (dm == null) {
                return (0);
            }
            return ((int) (manager.getStats().getTotalAveragePerPeer()));
        }
    } };
    final MultiPlotGraphic f_mpg = mpg = MultiPlotGraphic.getInstance(sources, formatter);
    String[] color_configs = new String[] { "DownloadActivityView.legend.up", "DownloadActivityView.legend.up_smooth", "DownloadActivityView.legend.down", "DownloadActivityView.legend.down_smooth", "DownloadActivityView.legend.peeraverage" };
    Legend.LegendListener legend_listener = new Legend.LegendListener() {

        private int hover_index = -1;

        @Override
        public void hoverChange(boolean entry, int index) {
            if (hover_index != -1) {
                sources[hover_index].setHover(false);
            }
            if (entry) {
                hover_index = index;
                sources[index].setHover(true);
            }
            f_mpg.refresh(true);
        }

        @Override
        public void visibilityChange(boolean visible, int index) {
            sources[index].setVisible(visible);
            f_mpg.refresh(true);
        }
    };
    if (!legend_at_bottom) {
        gridData = new GridData(GridData.FILL_VERTICAL);
        gridData.verticalAlignment = SWT.CENTER;
        Legend.createLegendComposite(panel, colors, color_configs, null, gridData, false, legend_listener);
    }
    Composite gSpeed = new Composite(panel, SWT.NULL);
    gridData = new GridData(GridData.FILL_BOTH);
    gSpeed.setLayoutData(gridData);
    gSpeed.setLayout(new GridLayout());
    if (legend_at_bottom) {
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        Legend.createLegendComposite(panel, colors, color_configs, null, gridData, true, legend_listener);
    }
    Canvas speedCanvas = new Canvas(gSpeed, SWT.NO_BACKGROUND);
    gridData = new GridData(GridData.FILL_BOTH);
    speedCanvas.setLayoutData(gridData);
    mpg.initialize(speedCanvas, false);
}
Also used : Legend(com.biglybt.ui.swt.components.Legend) MultiPlotGraphic(com.biglybt.ui.swt.components.graphics.MultiPlotGraphic) Composite(org.eclipse.swt.widgets.Composite) Canvas(org.eclipse.swt.widgets.Canvas) ValueFormater(com.biglybt.ui.swt.components.graphics.ValueFormater) DownloadManager(com.biglybt.core.download.DownloadManager) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats)

Example 7 with DownloadManagerStats

use of com.biglybt.core.download.DownloadManagerStats in project BiglyBT by BiglySoftware.

the class DownloadActivityView method dataSourceChanged.

public void dataSourceChanged(Object newDataSource) {
    if (!comp_focused) {
        focus_pending_ds = newDataSource;
        return;
    }
    DownloadManager newManager = ViewUtils.getDownloadManagerFromDataSource(newDataSource);
    if (newManager == manager) {
        return;
    }
    manager = newManager;
    Utils.execSWTThread(new AERunnable() {

        @Override
        public void runSupport() {
            if (panel == null || panel.isDisposed()) {
                return;
            }
            Utils.disposeComposite(panel, false);
            if (manager != null) {
                fillPanel();
                parent.layout(true, true);
            } else {
                ViewUtils.setViewRequiresOneDownload(panel);
            }
        }
    });
    if (manager == null) {
        mpg.setActive(false);
        mpg.reset(new int[5][0]);
    } else {
        DownloadManagerStats stats = manager.getStats();
        stats.setRecentHistoryRetention(true);
        int[][] _history = stats.getRecentHistory();
        // reconstitute the smoothed values to the best of our ability (good enough unless we decide we want
        // to throw more memory at remembering this more accurately...)
        int[] send_history = _history[0];
        int[] recv_history = _history[1];
        int history_secs = send_history.length;
        int[] smoothed_send = new int[history_secs];
        int[] smoothed_recv = new int[history_secs];
        MovingImmediateAverage send_average = GeneralUtils.getSmoothAverage();
        MovingImmediateAverage recv_average = GeneralUtils.getSmoothAverage();
        int smooth_interval = GeneralUtils.getSmoothUpdateInterval();
        int current_smooth_send = 0;
        int current_smooth_recv = 0;
        int pending_smooth_send = 0;
        int pending_smooth_recv = 0;
        for (int i = 0; i < history_secs; i++) {
            pending_smooth_send += send_history[i];
            pending_smooth_recv += recv_history[i];
            if (i % smooth_interval == 0) {
                current_smooth_send = (int) (send_average.update(pending_smooth_send) / smooth_interval);
                current_smooth_recv = (int) (recv_average.update(pending_smooth_recv) / smooth_interval);
                pending_smooth_send = 0;
                pending_smooth_recv = 0;
            }
            smoothed_send[i] = current_smooth_send;
            smoothed_recv[i] = current_smooth_recv;
        }
        int[][] history = { send_history, smoothed_send, recv_history, smoothed_recv, _history[2] };
        mpg.reset(history);
        mpg.setActive(true);
    }
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats) DownloadManager(com.biglybt.core.download.DownloadManager) MovingImmediateAverage(com.biglybt.core.util.average.MovingImmediateAverage)

Example 8 with DownloadManagerStats

use of com.biglybt.core.download.DownloadManagerStats in project BiglyBT by BiglySoftware.

the class GeneralView method refresh.

public void refresh() {
    if (gFile == null || gFile.isDisposed() || manager == null)
        return;
    loopFactor++;
    if ((loopFactor % graphicsUpdate) == 0) {
        updateAvailability();
        availabilityImage.redraw();
        updatePiecesInfo(false);
        piecesImage.redraw();
    }
    DiskManager dm = manager.getDiskManager();
    String remaining;
    String eta = DisplayFormatters.formatETA(manager.getStats().getSmoothedETA());
    if (dm != null) {
        long rem = dm.getRemainingExcludingDND();
        String data_rem = DisplayFormatters.formatByteCountToKiBEtc(rem);
        if (rem > 0) {
            remaining = eta + (eta.length() == 0 ? "" : " ") + data_rem;
        } else {
            if (eta.length() == 0) {
                remaining = data_rem;
            } else {
                remaining = eta;
            }
        }
    } else {
        // only got eta value, just use that
        remaining = eta;
    }
    setTime(manager.getStats().getElapsedTime(), remaining);
    TRTrackerScraperResponse hd = manager.getTrackerScrapeResponse();
    String seeds_str = manager.getNbSeeds() + " " + MessageText.getString("GeneralView.label.connected");
    String peers_str = manager.getNbPeers() + " " + MessageText.getString("GeneralView.label.connected");
    String completed;
    if (hd != null && hd.isValid()) {
        seeds_str += " ( " + hd.getSeeds() + " " + MessageText.getString("GeneralView.label.in_swarm") + " )";
        peers_str += " ( " + hd.getPeers() + " " + MessageText.getString("GeneralView.label.in_swarm") + " )";
        completed = hd.getCompleted() > -1 ? Integer.toString(hd.getCompleted()) : "?";
    } else {
        completed = "?";
    }
    String _shareRatio = "";
    int sr = manager.getStats().getShareRatio();
    if (sr == -1)
        _shareRatio = Constants.INFINITY_STRING;
    if (sr > 0) {
        String partial = "" + sr % 1000;
        while (partial.length() < 3) partial = "0" + partial;
        _shareRatio = (sr / 1000) + "." + partial;
    }
    DownloadManagerStats stats = manager.getStats();
    String swarm_speed = DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getTotalAverage()) + " ( " + DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getTotalAveragePerPeer()) + " " + MessageText.getString("GeneralView.label.averagespeed") + " )";
    String swarm_completion = "";
    String distributedCopies = "0.000";
    String piecesDoneAndSum = "" + manager.getNbPieces();
    PEPeerManager pm = manager.getPeerManager();
    if (pm != null) {
        int comp = pm.getAverageCompletionInThousandNotation();
        if (comp >= 0) {
            swarm_completion = DisplayFormatters.formatPercentFromThousands(comp);
        }
        piecesDoneAndSum = pm.getPiecePicker().getNbPiecesDone() + "/" + piecesDoneAndSum;
        distributedCopies = new DecimalFormat("0.000").format(pm.getPiecePicker().getMinAvailability() - pm.getNbSeeds() - (pm.isSeeding() && stats.getDownloadCompleted(false) == 1000 ? 1 : 0));
    }
    int kInB = DisplayFormatters.getKinB();
    setStats(DisplayFormatters.formatDownloaded(stats), DisplayFormatters.formatByteCountToKiBEtc(stats.getTotalDataBytesSent()), DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataReceiveRate()), DisplayFormatters.formatByteCountToKiBEtcPerSec(stats.getDataSendRate()), swarm_speed, "" + manager.getStats().getDownloadRateLimitBytesPerSecond() / kInB, "" + (manager.getStats().getUploadRateLimitBytesPerSecond() / kInB), seeds_str, peers_str, completed, DisplayFormatters.formatHashFails(manager), _shareRatio, swarm_completion, distributedCopies);
    TOTorrent torrent = manager.getTorrent();
    String creation_date = DisplayFormatters.formatDate(manager.getTorrentCreationDate() * 1000);
    byte[] created_by = torrent == null ? null : torrent.getCreatedBy();
    if (created_by != null) {
        try {
            creation_date = MessageText.getString("GeneralView.torrent_created_on_and_by", new String[] { creation_date, new String(created_by, Constants.DEFAULT_ENCODING) });
        } catch (java.io.UnsupportedEncodingException e) {
        /* forget it */
        }
    }
    setInfos(manager.getDisplayName(), DisplayFormatters.formatByteCountToKiBEtc(manager.getSize()), DisplayFormatters.formatDownloadStatus(manager), manager.getState() == DownloadManager.STATE_ERROR, manager.getSaveLocation().toString(), TorrentUtils.nicePrintTorrentHash(torrent), piecesDoneAndSum, manager.getPieceLength(), manager.getTorrentComment(), creation_date, manager.getDownloadState().getUserComment(), MessageText.getString("GeneralView." + (torrent != null && torrent.getPrivate() ? "yes" : "no")));
    // the initial layout fails.
    if (loopFactor == 2) {
        getComposite().layout(true);
    }
}
Also used : TRTrackerScraperResponse(com.biglybt.core.tracker.client.TRTrackerScraperResponse) DecimalFormat(java.text.DecimalFormat) TOTorrent(com.biglybt.core.torrent.TOTorrent) PEPeerManager(com.biglybt.core.peer.PEPeerManager) DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats) DiskManager(com.biglybt.core.disk.DiskManager)

Example 9 with DownloadManagerStats

use of com.biglybt.core.download.DownloadManagerStats in project BiglyBT by BiglySoftware.

the class TorrentOptionsView method refresh.

private void refresh() {
    if (agg_size == null || managers.length == 0 || managers[0].getDownloadManager() == null) {
        return;
    }
    long total_size = 0;
    long total_remaining = 0;
    long total_good_downloaded = 0;
    long total_downloaded = 0;
    long total_uploaded = 0;
    long total_data_up_speed = 0;
    long total_prot_up_speed = 0;
    long total_data_down_speed = 0;
    long total_prot_down_speed = 0;
    for (int i = 0; i < managers.length; i++) {
        DownloadManagerOptionsHandler dm = managers[i];
        DownloadManagerStats stats = dm.getDownloadManager().getStats();
        total_size += stats.getSizeExcludingDND();
        total_remaining += stats.getRemainingExcludingDND();
        long good_received = stats.getTotalGoodDataBytesReceived();
        long received = stats.getTotalDataBytesReceived();
        long sent = stats.getTotalDataBytesSent();
        total_good_downloaded += good_received;
        total_downloaded += received;
        total_uploaded += sent;
        total_data_up_speed += stats.getDataSendRate();
        total_prot_up_speed += stats.getProtocolSendRate();
        total_data_down_speed += stats.getDataReceiveRate();
        total_prot_down_speed += stats.getProtocolReceiveRate();
    }
    agg_size.setText(DisplayFormatters.formatByteCountToKiBEtc(total_size));
    agg_remaining.setText(DisplayFormatters.formatByteCountToKiBEtc(total_remaining));
    agg_uploaded.setText(DisplayFormatters.formatByteCountToKiBEtc(total_uploaded));
    agg_downloaded.setText(DisplayFormatters.formatByteCountToKiBEtc(total_downloaded));
    agg_upload_speed.setText(DisplayFormatters.formatDataProtByteCountToKiBEtc(total_data_up_speed, total_prot_up_speed));
    agg_download_speed.setText(DisplayFormatters.formatDataProtByteCountToKiBEtc(total_data_down_speed, total_prot_down_speed));
    long sr;
    if (total_good_downloaded == 0) {
        if (total_uploaded == 0) {
            sr = 1000;
        } else {
            sr = -1;
        }
    } else {
        sr = 1000 * total_uploaded / total_good_downloaded;
    }
    String share_ratio_str;
    if (sr == -1) {
        share_ratio_str = Constants.INFINITY_STRING;
    } else {
        String partial = "" + sr % 1000;
        while (partial.length() < 3) {
            partial = "0" + partial;
        }
        share_ratio_str = (sr / 1000) + "." + partial;
    }
    agg_share_ratio.setText(share_ratio_str);
}
Also used : DownloadManagerOptionsHandler(com.biglybt.core.download.DownloadManagerOptionsHandler) DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats)

Example 10 with DownloadManagerStats

use of com.biglybt.core.download.DownloadManagerStats in project BiglyBT by BiglySoftware.

the class DiskManagerUtil method storeFilePriorities.

protected static void storeFilePriorities(DownloadManager download_manager, DiskManagerFileInfo[] files) {
    if (files == null)
        return;
    // bit confusing this: priorities are stored as
    // >= 1   : priority, 1 = high, 2 = higher etc
    // 0      : skipped
    // -1     : normal priority
    // <= -2  : negative priority , so -2 -> priority -1, -3 -> priority -2 etc
    List file_priorities = new ArrayList(files.length);
    for (int i = 0; i < files.length; i++) {
        DiskManagerFileInfo file = files[i];
        if (file == null)
            return;
        boolean skipped = file.isSkipped();
        int priority = file.getPriority();
        int value;
        if (skipped) {
            value = 0;
        } else if (priority > 0) {
            value = priority;
        } else {
            value = priority - 1;
            if (value > 0) {
                value = Integer.MIN_VALUE;
            }
        }
        file_priorities.add(i, Long.valueOf(value));
    }
    download_manager.setUserData("file_priorities", file_priorities);
    if (files.length > 0 && !(files[0] instanceof DiskManagerFileInfoImpl)) {
        long skipped_file_set_size = 0;
        long skipped_but_downloaded = 0;
        for (int i = 0; i < files.length; i++) {
            DiskManagerFileInfo file = files[i];
            if (file.isSkipped()) {
                skipped_file_set_size += file.getLength();
                skipped_but_downloaded += file.getDownloaded();
            }
        }
        DownloadManagerStats stats = download_manager.getStats();
        if (stats instanceof DownloadManagerStatsImpl) {
            ((DownloadManagerStatsImpl) stats).setSkippedFileStats(skipped_file_set_size, skipped_but_downloaded);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) DownloadManagerStatsImpl(com.biglybt.core.download.impl.DownloadManagerStatsImpl) ArrayList(java.util.ArrayList) List(java.util.List) DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats)

Aggregations

DownloadManagerStats (com.biglybt.core.download.DownloadManagerStats)17 DownloadManager (com.biglybt.core.download.DownloadManager)12 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)4 List (java.util.List)4 PEPeerManager (com.biglybt.core.peer.PEPeerManager)3 ArrayList (java.util.ArrayList)3 Category (com.biglybt.core.category.Category)2 DiskManager (com.biglybt.core.disk.DiskManager)2 DownloadManagerStatsImpl (com.biglybt.core.download.impl.DownloadManagerStatsImpl)2 GlobalManager (com.biglybt.core.global.GlobalManager)2 GlobalManagerStats (com.biglybt.core.global.GlobalManagerStats)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 Core (com.biglybt.core.Core)1 CoreRunningListener (com.biglybt.core.CoreRunningListener)1 ParameterListener (com.biglybt.core.config.ParameterListener)1 DownloadManagerListener (com.biglybt.core.download.DownloadManagerListener)1 DownloadManagerOptionsHandler (com.biglybt.core.download.DownloadManagerOptionsHandler)1 GlobalManagerEvent (com.biglybt.core.global.GlobalManagerEvent)1 GlobalManagerEventListener (com.biglybt.core.global.GlobalManagerEventListener)1 GlobalManagerListener (com.biglybt.core.global.GlobalManagerListener)1