traffic decimal part
This commit is contained in:
@@ -38,8 +38,10 @@ namespace c {
|
||||
const QString HA_PAGE_TITLE = "{{PAGE_TITLE}}";
|
||||
const QString HA_CUSTOM_CSS = "{{CUSTOM_CSS}}";
|
||||
const QString HA_DAILY_UPLOAD = "{{DAILY_UPLOAD}}";
|
||||
const QString HA_DAILY_UPLOAD_DECIMAL = "{{DAILY_UPLOAD_DECIMAL}}";
|
||||
const QString HA_DAILY_UPLOAD_MEASURE = "{{DAILY_UPLOAD_MEASURE}}";
|
||||
const QString HA_DAILY_DOWNLOAD = "{{DAILY_DOWNLOAD}}";
|
||||
const QString HA_DAILY_DOWNLOAD_DECIMAL = "{{DAILY_DOWNLOAD_DECIMAL}}";
|
||||
const QString HA_DAILY_DOWNLOAD_MEASURE = "{{DAILY_DOWNLOAD_MEASURE}}";
|
||||
const QString HA_TOTAL_UPLOAD = "{{TOTAL_UPLOAD}}";
|
||||
const QString HA_TOTAL_DOWNLOAD = "{{TOTAL_DOWNLOAD}}";
|
||||
|
||||
@@ -40,8 +40,10 @@ namespace c /* for Constants */ {
|
||||
extern const QString HA_PAGE_TITLE;
|
||||
extern const QString HA_CUSTOM_CSS;
|
||||
extern const QString HA_DAILY_UPLOAD;
|
||||
extern const QString HA_DAILY_UPLOAD_DECIMAL;
|
||||
extern const QString HA_DAILY_UPLOAD_MEASURE;
|
||||
extern const QString HA_DAILY_DOWNLOAD;
|
||||
extern const QString HA_DAILY_DOWNLOAD_DECIMAL;
|
||||
extern const QString HA_DAILY_DOWNLOAD_MEASURE;
|
||||
extern const QString HA_TOTAL_UPLOAD;
|
||||
extern const QString HA_TOTAL_DOWNLOAD;
|
||||
|
||||
@@ -37,6 +37,9 @@
|
||||
<div class="handledTraffic__number">
|
||||
{{DAILY_UPLOAD}}
|
||||
</div>
|
||||
<div class="handledTraffic__decimal">
|
||||
{{DAILY_UPLOAD_DECIMAL}}
|
||||
</div>
|
||||
<div class="handledTraffic__measure">
|
||||
{{DAILY_UPLOAD_MEASURE}}
|
||||
</div>
|
||||
@@ -68,6 +71,9 @@
|
||||
<div class="handledTraffic__number">
|
||||
{{DAILY_DOWNLOAD}}
|
||||
</div>
|
||||
<div class="handledTraffic__decimal">
|
||||
{{DAILY_DOWNLOAD_DECIMAL}}
|
||||
</div>
|
||||
<div class="handledTraffic__measure">
|
||||
{{DAILY_DOWNLOAD_MEASURE}}
|
||||
</div>
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
*{box-sizing:border-box;outline:none;z-index:1}*:hover{outline:none}*:focus{outline:none}html{width:100%;font-size:16px;scroll-behavior:smooth}body{overflow-y:scroll;height:100%;line-height:1.42;margin:0;background-color:#fff;color:#000;height:100vh;font-family:monospace;font-size:16px}main{display:flex;flex-flow:column nowrap;align-items:stretch;justify-content:flex-start}ul,ol{padding:0;margin:0}li{list-style:none}a{text-decoration:none;color:inherit}a:hover{text-decoration:none}button{cursor:pointer;background-color:rgba(0,0,0,0);border:0px solid rgba(0,0,0,0);padding:0}button:focus,input:focus,a:focus,textarea:focus{text-decoration:none}button,input,textarea{font-family:inherit;font-size:inherit}textarea{resize:none}p{margin:0}h1,h2,h3,h4,h5{margin-top:0;margin-bottom:0;font-weight:normal;font-size:100%}img{display:block;max-width:100%;height:auto}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit}table{border-collapse:collapse}input[type=checkbox]{margin:0}.wrapper{height:100%;padding:16px 0;flex:1}.container{max-width:648px;margin:0 auto;padding:0 5px}.section{margin-bottom:35px}.section__title{margin-bottom:10px;font-size:20px;font-weight:bold}.proxyService__title{text-align:center;font-size:50px;padding:12px 0;font-weight:bold}.handledTraffic{width:100%}.handledTraffic__blocks{width:100%;display:flex;flex-flow:row nowrap;align-items:start;justify-content:center;gap:10px}.handledTraffic__block{width:calc(50% - 5px)}.handledTraffic__block_download .handledTraffic__svg{fill:#91fd91}.handledTraffic__block_upload .handledTraffic__svg{fill:#ff6f6f}.handledTraffic__title{text-transform:uppercase;font-weight:bold;background-color:#ddd;padding:3px 5px;font-size:20px}.handledTraffic__amount{display:flex;flex-flow:row nowrap;align-items:stretch;justify-content:center;background-color:#aaa;padding:10px;border-top:1px solid #000;border-bottom:1px solid #000}.handledTraffic__icon{text-align:center;display:flex;flex-flow:column nowrap;align-items:center;justify-content:center;padding:3px 8px;margin-right:5px}.handledTraffic__icon .handledTraffic__svg{height:35px}.handledTraffic__number{line-height:1;font-size:56px;font-weight:bold;text-transform:uppercase;margin-right:8px}.handledTraffic__measure{font-size:18px;font-weight:bold;align-self:end}.handledTraffic__total{background-color:#ddd;padding:8px;font-size:16px;text-align:right}.handledTraffic__totalTitle{text-transform:uppercase;font-weight:bold}.accordeo__radio{display:none}.accordeo__radio:checked~.accordeo__dropdown{display:block}.accordeo__dropdown{display:none}.blockedDestinations__item{background-color:#ddd;overflow:hidden;white-space:nowrap;margin-bottom:5px;text-overflow:ellipsis}.blockedDestinations__url{display:block;width:100%;padding:3px 6px;cursor:pointer}.blockedDestinations__ipList{background-color:#aaa;padding-left:10px}.blockedDestinations__ipItem{padding:4px}.lastDestinations{width:100%;padding:5px 0}.lastDestinations__list{width:100%}.lastDestinations__item{width:100%;margin-bottom:5px;padding:3px 6px;overflow:hidden;text-overflow:ellipsis}.lastDestinations__item:last-child{margin-bottom:0}.lastDestinations__item_blocked{background-color:#888}.lastDestinations__item_allowed{background-color:#ddd}.topDestinations__block{margin-bottom:14px}.topDestinations__block:last-child{margin-bottom:0}.topDestinations__title{font-weight:bold;margin-bottom:10px}.topDestinations__item{padding:4px;overflow:hidden;white-space:nowrap;margin-bottom:5px;text-overflow:ellipsis;background-color:#ddd}.copyright{padding:10px 0;text-align:center;color:#888}
|
||||
*{box-sizing:border-box;outline:none;z-index:1}*:hover{outline:none}*:focus{outline:none}html{width:100%;font-size:16px;scroll-behavior:smooth}body{overflow-y:scroll;height:100%;line-height:1.42;margin:0;background-color:#fff;color:#000;height:100vh;font-family:monospace;font-size:16px}main{display:flex;flex-flow:column nowrap;align-items:stretch;justify-content:flex-start}ul,ol{padding:0;margin:0}li{list-style:none}a{text-decoration:none;color:inherit}a:hover{text-decoration:none}button{cursor:pointer;background-color:rgba(0,0,0,0);border:0px solid rgba(0,0,0,0);padding:0}button:focus,input:focus,a:focus,textarea:focus{text-decoration:none}button,input,textarea{font-family:inherit;font-size:inherit}textarea{resize:none}p{margin:0}h1,h2,h3,h4,h5{margin-top:0;margin-bottom:0;font-weight:normal;font-size:100%}img{display:block;max-width:100%;height:auto}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit}table{border-collapse:collapse}input[type=checkbox]{margin:0}.wrapper{height:100%;padding:16px 0;flex:1}.container{max-width:648px;margin:0 auto;padding:0 5px}.section{margin-bottom:35px}.section__title{margin-bottom:10px;font-size:20px;font-weight:bold}.proxyService__title{text-align:center;font-size:50px;padding:12px 0;font-weight:bold}.handledTraffic{width:100%}.handledTraffic__blocks{width:100%;display:flex;flex-flow:row nowrap;align-items:start;justify-content:center;gap:10px}.handledTraffic__block{width:calc(50% - 5px)}.handledTraffic__block_download .handledTraffic__svg{fill:#91fd91}.handledTraffic__block_upload .handledTraffic__svg{fill:#ff6f6f}.handledTraffic__title{text-transform:uppercase;font-weight:bold;background-color:#ddd;padding:3px 5px;font-size:20px}.handledTraffic__amount{display:flex;flex-flow:row nowrap;align-items:stretch;justify-content:center;background-color:#aaa;padding:10px;border-top:1px solid #000;border-bottom:1px solid #000}.handledTraffic__icon{text-align:center;display:flex;flex-flow:column nowrap;align-items:center;justify-content:center;padding:3px 8px;margin-right:8px}.handledTraffic__icon .handledTraffic__svg{height:35px}.handledTraffic__number{line-height:1;font-size:56px;font-weight:bold;text-transform:uppercase}.handledTraffic__decimal{line-height:1.3;align-self:end;font-size:28px;margin-right:12px}.handledTraffic__measure{font-size:18px;font-weight:bold;align-self:end;line-height:1.6}.handledTraffic__total{background-color:#ddd;padding:8px;font-size:16px;text-align:right}.handledTraffic__totalTitle{text-transform:uppercase;font-weight:bold}.accordeo__radio{display:none}.accordeo__radio:checked~.accordeo__dropdown{display:block}.accordeo__dropdown{display:none}.blockedDestinations__item{background-color:#ddd;overflow:hidden;white-space:nowrap;margin-bottom:5px;text-overflow:ellipsis}.blockedDestinations__url{display:block;width:100%;padding:3px 6px;cursor:pointer}.blockedDestinations__ipList{background-color:#aaa;padding-left:10px}.blockedDestinations__ipItem{padding:4px}.lastDestinations{width:100%;padding:5px 0}.lastDestinations__list{width:100%}.lastDestinations__item{width:100%;margin-bottom:5px;padding:3px 6px;overflow:hidden;text-overflow:ellipsis}.lastDestinations__item:last-child{margin-bottom:0}.lastDestinations__item_blocked{background-color:#888}.lastDestinations__item_allowed{background-color:#ddd}.topDestinations__block{margin-bottom:14px}.topDestinations__block:last-child{margin-bottom:0}.topDestinations__title{font-weight:bold;margin-bottom:10px}.topDestinations__item{padding:4px;overflow:hidden;white-space:nowrap;margin-bottom:5px;text-overflow:ellipsis;background-color:#ddd}.copyright{padding:10px 0;text-align:center;color:#888}/*# sourceMappingURL=main.min.css.map */
|
||||
+53
-28
@@ -25,7 +25,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
const QString WebPage::m_lastDestinationItemAllowed = "\
|
||||
<li class=\"lastDestinations__item lastDestinations__item_allowed\" title=\"{{VALUE}}\">\n\
|
||||
@@ -83,6 +82,13 @@ const QString WebPage::m_informationBlock = "\
|
||||
</div>\n\
|
||||
</section>\n";
|
||||
|
||||
struct HumanReadableValue
|
||||
{
|
||||
QString integer = "NaN";
|
||||
QString decimal = "0";
|
||||
QString measure = "anon";
|
||||
};
|
||||
|
||||
QByteArray WebPage::document()
|
||||
{
|
||||
QFile src(":/html/index.html");
|
||||
@@ -148,18 +154,20 @@ void WebPage::lastDestinations(QString &document)
|
||||
void WebPage::trafficBlock(QString &document)
|
||||
{
|
||||
auto dailyUpload = bytesToHumanReadableString( Statistics::dailyUpload() );
|
||||
document.replace(g::c::HA_DAILY_UPLOAD, dailyUpload.first);
|
||||
document.replace(g::c::HA_DAILY_UPLOAD_MEASURE, dailyUpload.second);
|
||||
document.replace(g::c::HA_DAILY_UPLOAD, dailyUpload.integer);
|
||||
document.replace(g::c::HA_DAILY_UPLOAD_DECIMAL, dailyUpload.decimal);
|
||||
document.replace(g::c::HA_DAILY_UPLOAD_MEASURE, dailyUpload.measure);
|
||||
|
||||
auto dailyDownload = bytesToHumanReadableString( Statistics::dailyDownload() );
|
||||
document.replace(g::c::HA_DAILY_DOWNLOAD, dailyDownload.first);
|
||||
document.replace(g::c::HA_DAILY_DOWNLOAD_MEASURE, dailyDownload.second);
|
||||
document.replace(g::c::HA_DAILY_DOWNLOAD, dailyDownload.integer);
|
||||
document.replace(g::c::HA_DAILY_DOWNLOAD_DECIMAL, dailyDownload.decimal);
|
||||
document.replace(g::c::HA_DAILY_DOWNLOAD_MEASURE, dailyDownload.measure);
|
||||
|
||||
auto totalUpload = bytesToHumanReadableString( Statistics::totalUpload() );
|
||||
document.replace(g::c::HA_TOTAL_UPLOAD, totalUpload.first + " " + totalUpload.second);
|
||||
document.replace(g::c::HA_TOTAL_UPLOAD, totalUpload.integer + " " + totalUpload.measure);
|
||||
|
||||
auto totalDownload = bytesToHumanReadableString( Statistics::totalDownload() );
|
||||
document.replace(g::c::HA_TOTAL_DOWNLOAD, totalDownload.first + " " + totalDownload.second);
|
||||
document.replace(g::c::HA_TOTAL_DOWNLOAD, totalDownload.integer + " " + totalDownload.measure);
|
||||
}
|
||||
|
||||
void WebPage::topDestinations(QString &document)
|
||||
@@ -306,47 +314,64 @@ QString WebPage::blockedDestinationItem(const QString &destination, const QStrin
|
||||
return result;
|
||||
}
|
||||
|
||||
QPair<QString, QString> WebPage::bytesToHumanReadableString(quint64 bytes)
|
||||
HumanReadableValue WebPage::bytesToHumanReadableString(quint64 bytes)
|
||||
{
|
||||
QPair<QString, QString> result;
|
||||
HumanReadableValue result;
|
||||
|
||||
constexpr const qint64 thresh = 1024;
|
||||
constexpr const quint64 BYTE = 1024;
|
||||
|
||||
if (bytes < thresh)
|
||||
if (bytes < BYTE)
|
||||
{
|
||||
result.first = QString::number(bytes);
|
||||
result.second = "B";
|
||||
result.integer = QString::number(bytes);
|
||||
result.decimal = "0";
|
||||
result.measure = "B";
|
||||
}
|
||||
|
||||
else if (bytes <= thresh*thresh)
|
||||
else if (bytes <= BYTE*BYTE)
|
||||
{
|
||||
result.first = QString::number(bytes/thresh);
|
||||
result.second = "KiB";
|
||||
result.integer = QString::number(bytes/BYTE);
|
||||
result.decimal = QString::number(bytes%BYTE);
|
||||
result.measure = "KiB";
|
||||
}
|
||||
|
||||
else if (bytes <= thresh*thresh*thresh)
|
||||
else if (bytes <= BYTE*BYTE*BYTE)
|
||||
{
|
||||
result.first = QString::number(bytes/thresh/thresh);
|
||||
result.second = "MiB";
|
||||
result.integer = QString::number(bytes /BYTE/BYTE);
|
||||
result.decimal = QString::number(bytes% (BYTE*BYTE));
|
||||
result.measure = "MiB";
|
||||
}
|
||||
|
||||
else if (bytes <= thresh*thresh*thresh*thresh)
|
||||
else if (bytes <= BYTE*BYTE*BYTE*BYTE)
|
||||
{
|
||||
result.first = QString::number(bytes/thresh/thresh/thresh);
|
||||
result.second = "GiB";
|
||||
result.integer = QString::number(bytes /BYTE/BYTE/BYTE);
|
||||
result.decimal = QString::number(bytes% (BYTE*BYTE*BYTE));
|
||||
result.measure = "GiB";
|
||||
}
|
||||
|
||||
else if (bytes <= thresh*thresh*thresh*thresh*thresh)
|
||||
else if (bytes <= BYTE*BYTE*BYTE*BYTE*BYTE)
|
||||
{
|
||||
result.first = QString::number(bytes/thresh/thresh/thresh/thresh);
|
||||
result.second = "TiB";
|
||||
result.integer = QString::number(bytes /BYTE/BYTE/BYTE/BYTE);
|
||||
result.decimal = QString::number(bytes% (BYTE*BYTE*BYTE*BYTE));
|
||||
result.measure = "TiB";
|
||||
}
|
||||
|
||||
else if (bytes <= thresh*thresh*thresh*thresh*thresh*thresh)
|
||||
else
|
||||
{
|
||||
result.first = QString::number(bytes/thresh/thresh/thresh/thresh/thresh);
|
||||
result.second = "PiB";
|
||||
result.integer = QString::number(bytes /BYTE/BYTE/BYTE/BYTE/BYTE);
|
||||
result.decimal = QString::number(bytes% (BYTE*BYTE*BYTE*BYTE*BYTE));
|
||||
result.integer = "PiB";
|
||||
}
|
||||
|
||||
if (result.decimal.size() > 2)
|
||||
{
|
||||
result.decimal = result.decimal.remove(2, result.decimal.size()-2);
|
||||
}
|
||||
else if (result.decimal.size() < 2)
|
||||
{
|
||||
result.decimal.push_back('0');
|
||||
}
|
||||
|
||||
result.decimal.push_front('.');
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
+3
-1
@@ -22,6 +22,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
#include <QByteArray>
|
||||
#include <QStringList>
|
||||
|
||||
struct HumanReadableValue;
|
||||
|
||||
class WebPage
|
||||
{
|
||||
public:
|
||||
@@ -43,7 +45,7 @@ private:
|
||||
static QString dailyTopDestinationItem(const QString& destination, quint64 count);
|
||||
static QString totalTopDestinationItem(const QString& destination, quint64 count);
|
||||
static QString blockedDestinationItem(const QString& destination, const QStringList& addresses);
|
||||
static QPair<QString, QString> bytesToHumanReadableString(quint64 bytes); // count, measure
|
||||
static HumanReadableValue bytesToHumanReadableString(quint64 bytes);
|
||||
|
||||
static const QString m_lastDestinationItemAllowed;
|
||||
static const QString m_lastDestinationItemBlocked;
|
||||
|
||||
Reference in New Issue
Block a user