Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve readability of the daily burnt BSQ chart #3890

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.common.util;

import java.util.DoubleSummaryStatistics;

/* Adds logic to DoubleSummaryStatistics for keeping track of sum of squares
* and computing population variance and population standard deviation.
* Kahan summation algorithm (for `getSumOfSquares`) sourced from the DoubleSummaryStatistics class.
* Incremental variance algorithm sourced from https://math.stackexchange.com/a/1379804/316756
*/
public class DoubleSummaryStatisticsWithStdDev extends DoubleSummaryStatistics {
private double sumOfSquares;
private double sumOfSquaresCompensation; // Low order bits of sum of squares
private double simpleSumOfSquares; // Used to compute right sum of squares for non-finite inputs

@Override
public void accept(double value) {
super.accept(value);
double valueSquared = value * value;
simpleSumOfSquares += valueSquared;
sumOfSquaresWithCompensation(valueSquared);
}

public void combine(DoubleSummaryStatisticsWithStdDev other) {
super.combine(other);
simpleSumOfSquares += other.simpleSumOfSquares;
sumOfSquaresWithCompensation(other.sumOfSquares);
sumOfSquaresWithCompensation(other.sumOfSquaresCompensation);
}

/* Incorporate a new squared double value using Kahan summation /
* compensated summation.
*/
private void sumOfSquaresWithCompensation(double valueSquared) {
double tmp = valueSquared - sumOfSquaresCompensation;
double velvel = sumOfSquares + tmp; // Little wolf of rounding error
sumOfSquaresCompensation = (velvel - sumOfSquares) - tmp;
sumOfSquares = velvel;
}

private double getSumOfSquares() {
// Better error bounds to add both terms as the final sum of squares
double tmp = sumOfSquares + sumOfSquaresCompensation;
if (Double.isNaN(tmp) && Double.isInfinite(simpleSumOfSquares))
// If the compensated sum of squares is spuriously NaN from
// accumulating one or more same-signed infinite values,
// return the correctly-signed infinity stored in
// simpleSumOfSquares.
return simpleSumOfSquares;
else
return tmp;
}

private double getVariance() {
double sumOfSquares = getSumOfSquares();
long count = getCount();
double mean = getAverage();
return (sumOfSquares / count) - (mean * mean);
}

public final double getStandardDeviation() {
double variance = getVariance();
return Math.sqrt(variance);
}

}
2 changes: 2 additions & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2251,6 +2251,8 @@ dao.factsAndFigures.supply.compRequestIssueAmount=BSQ issued for compensation re
dao.factsAndFigures.supply.reimbursementAmount=BSQ issued for reimbursement requests

dao.factsAndFigures.supply.burnt=BSQ burnt
dao.factsAndFigures.supply.burntMovingAverage=15 days moving average
dao.factsAndFigures.supply.burntZoomToInliers=Zoom to inliers

dao.factsAndFigures.supply.locked=Global state of locked BSQ
dao.factsAndFigures.supply.totalLockedUpAmount=Locked up in bonds
Expand Down
11 changes: 11 additions & 0 deletions desktop/src/main/java/bisq/desktop/bisq.css
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,17 @@ textfield */
-fx-stroke: -bs-buy;
}

/* The .chart-line-symbol rules change the color of the legend symbol */
#charts-dao .default-color0.chart-series-line { -fx-stroke: -bs-chart-dao-line1; }
#charts-dao .default-color0.chart-line-symbol { -fx-background-color: -bs-chart-dao-line1, -bs-background-color; }

#charts-dao .default-color1.chart-series-line { -fx-stroke: -bs-chart-dao-line2; }
#charts-dao .default-color1.chart-line-symbol { -fx-background-color: -bs-chart-dao-line2, -bs-background-color; }

#charts-dao .chart-series-line {
-fx-stroke-width: 1px;
}

#charts .default-color0.chart-series-area-fill {
-fx-fill: -bs-sell-transparent;
}
Expand Down
Loading