示例#1
0
FB::VariantMap UploadQueue::getStatusDict(bool include_filenames) {
    FB::VariantMap d;
    // whole-queue stats
    d["queue_name"] = name;
    d["current_queue_bytes_remaining"] = current_queue_bytes;
    d["total_queue_bytes"] = total_queue_bytes;
    d["total_queue_files"] = total_queue_files;
    d["current_queue_files_remaining"] = files_waiting;
    d["batches_remaining"] = ceil(static_cast<float>(files_waiting) / static_cast<float>(batch_size));
    d["status"] = "Uploading";

    // this-batch stats
    if (include_filenames) {
        FB::VariantList cf;
        for (std::set<std::wstring>::const_iterator it = current_upload_files.begin();
            it != current_upload_files.end(); ++it)  {
                cf.push_back(*it);
        }
        d["current_files"] = cf;
    }
    d["current_batch_bytes_total"] = current_batch_bytes;

    double current_batch_pct_complete = 0.0;

    if (current_upload_request) {
        HTTP::Status st = current_upload_request->getStatus();
        FB::VariantMap status(st.asDict());
        d.insert(status.begin(), status.end());
        if (st.send_total) {
            current_batch_pct_complete = static_cast<double>(st.bytes_sent)
                / static_cast<double>(st.send_total);
        }
    }

    d["current_batch_pct_complete"] = current_batch_pct_complete;
    d["overall_progress_pct"] = static_cast<double>(
        (total_queue_bytes - (current_queue_bytes + current_batch_bytes))
            + (current_batch_pct_complete *  current_batch_bytes))
        / static_cast<double>(total_queue_bytes);

    return d;
}