Reporting fixes (#5410)

This commit is contained in:
d11n
2023-10-18 10:09:03 +02:00
committed by GitHub
parent c8ee6ead0b
commit 8dadfa2111
9 changed files with 26 additions and 28 deletions

View File

@@ -66,6 +66,10 @@ public partial class UIReportsController
decimal randomValue = ((decimal)rand.NextDouble() * range) + from; decimal randomValue = ((decimal)rand.NextDouble() * range) + from;
return decimal.Round(randomValue, precision); return decimal.Round(randomValue, precision);
} }
var fiatCurrency = rand.NextSingle() > 0.2 ? "USD" : TakeOne("JPY", "EUR", "CHF");
var cryptoCurrency = rand.NextSingle() > 0.2 ? "BTC" : TakeOne("LTC", "DOGE", "DASH");
if (f.Type == "invoice_id") if (f.Type == "invoice_id")
return Encoders.Base58.EncodeData(GenerateBytes(20)); return Encoders.Base58.EncodeData(GenerateBytes(20));
if (f.Type == "boolean") if (f.Type == "boolean")
@@ -80,9 +84,9 @@ public partial class UIReportsController
if (f.Name == "Address") if (f.Name == "Address")
return Encoders.Bech32("bc1").Encode(0, GenerateBytes(20)); return Encoders.Bech32("bc1").Encode(0, GenerateBytes(20));
if (f.Name == "Crypto") if (f.Name == "Crypto")
return rand.NextSingle() > 0.2 ? "BTC" : TakeOne("LTC", "DOGE", "DASH"); return cryptoCurrency;
if (f.Name == "CryptoAmount") if (f.Name == "CryptoAmount")
return GenerateDecimal(0.1m, 5m, 8); return DisplayFormatter.ToFormattedAmount(GenerateDecimal(0.1m, 5m, 8), cryptoCurrency);
if (f.Name == "LightningAddress") if (f.Name == "LightningAddress")
return TakeOne("satoshi", "satosan", "satoichi") + "@bitcoin.org"; return TakeOne("satoshi", "satosan", "satoichi") + "@bitcoin.org";
if (f.Name == "BalanceChange") if (f.Name == "BalanceChange")
@@ -98,24 +102,30 @@ public partial class UIReportsController
if (f.Name == "Quantity") if (f.Name == "Quantity")
return TakeOne(1, 2, 3, 4, 5); return TakeOne(1, 2, 3, 4, 5);
if (f.Name == "Currency") if (f.Name == "Currency")
return rand.NextSingle() > 0.2 ? "USD" : TakeOne("JPY", "EUR", "CHF"); return fiatCurrency;
if (f.Name == "CurrencyAmount") if (f.Name == "CurrencyAmount")
return row[fi - 1] switch {
var curr = row[fi - 1]?.ToString();
var value = curr switch
{ {
"USD" or "EUR" or "CHF" => GenerateDecimal(100.0m, 10_000m, 2), "USD" or "EUR" or "CHF" => GenerateDecimal(100.0m, 10_000m, 2),
"JPY" => GenerateDecimal(10_000m, 1000_0000, 0), "JPY" => GenerateDecimal(10_000m, 1000_0000, 0),
_ => GenerateDecimal(100.0m, 10_000m, 2) _ => GenerateDecimal(100.0m, 10_000m, 2)
}; };
return DisplayFormatter.ToFormattedAmount(value, curr);
}
if (f.Type == "tx_id") if (f.Type == "tx_id")
return Encoders.Hex.EncodeData(GenerateBytes(32)); return Encoders.Hex.EncodeData(GenerateBytes(32));
if (f.Name == "Rate") if (f.Name == "Rate")
{ {
return row[fi - 1] switch var curr = row[fi - 1]?.ToString();
var value = curr switch
{ {
"USD" or "EUR" or "CHF" => GenerateDecimal(30_000m, 60_000, 2), "USD" or "EUR" or "CHF" => GenerateDecimal(30_000m, 60_000, 2),
"JPY" => GenerateDecimal(400_0000m, 1000_0000m, 0), "JPY" => GenerateDecimal(400_0000m, 1000_0000m, 0),
_ => GenerateDecimal(30_000m, 60_000, 2) _ => GenerateDecimal(30_000m, 60_000, 2)
}; };
return DisplayFormatter.ToFormattedAmount(value, curr);
} }
return null; return null;
} }

View File

@@ -25,6 +25,7 @@ public partial class UIReportsController : Controller
ApplicationDbContextFactory dbContextFactory, ApplicationDbContextFactory dbContextFactory,
GreenfieldReportsController api, GreenfieldReportsController api,
ReportService reportService, ReportService reportService,
DisplayFormatter displayFormatter,
BTCPayServerEnvironment env) BTCPayServerEnvironment env)
{ {
Api = api; Api = api;
@@ -32,8 +33,10 @@ public partial class UIReportsController : Controller
Env = env; Env = env;
DBContextFactory = dbContextFactory; DBContextFactory = dbContextFactory;
NetworkProvider = networkProvider; NetworkProvider = networkProvider;
DisplayFormatter = displayFormatter;
} }
private BTCPayNetworkProvider NetworkProvider { get; } private BTCPayNetworkProvider NetworkProvider { get; }
private DisplayFormatter DisplayFormatter { get; }
public GreenfieldReportsController Api { get; } public GreenfieldReportsController Api { get; }
public ReportService ReportService { get; } public ReportService ReportService { get; }
public BTCPayServerEnvironment Env { get; } public BTCPayServerEnvironment Env { get; }

View File

@@ -3,14 +3,9 @@ using System;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Data;
using BTCPayServer.Services.Stores; using BTCPayServer.Services.Stores;
using BTCPayServer.Services.Wallets;
using Dapper; using Dapper;
using Microsoft.EntityFrameworkCore;
using NBitcoin; using NBitcoin;
using NBXplorer.DerivationStrategy;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;
namespace BTCPayServer.Services.Reporting; namespace BTCPayServer.Services.Reporting;
@@ -19,7 +14,6 @@ public class OnChainWalletReportProvider : ReportProvider
public OnChainWalletReportProvider( public OnChainWalletReportProvider(
NBXplorerConnectionFactory NbxplorerConnectionFactory, NBXplorerConnectionFactory NbxplorerConnectionFactory,
StoreRepository storeRepository, StoreRepository storeRepository,
DisplayFormatter displayFormatter,
BTCPayNetworkProvider networkProvider, BTCPayNetworkProvider networkProvider,
WalletRepository walletRepository) WalletRepository walletRepository)
{ {
@@ -27,10 +21,8 @@ public class OnChainWalletReportProvider : ReportProvider
StoreRepository = storeRepository; StoreRepository = storeRepository;
NetworkProvider = networkProvider; NetworkProvider = networkProvider;
WalletRepository = walletRepository; WalletRepository = walletRepository;
_displayFormatter = displayFormatter;
} }
private readonly DisplayFormatter _displayFormatter;
private NBXplorerConnectionFactory NbxplorerConnectionFactory { get; } private NBXplorerConnectionFactory NbxplorerConnectionFactory { get; }
private StoreRepository StoreRepository { get; } private StoreRepository StoreRepository { get; }
private BTCPayNetworkProvider NetworkProvider { get; } private BTCPayNetworkProvider NetworkProvider { get; }

View File

@@ -3,15 +3,9 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using BTCPayServer.Client.Models; using BTCPayServer.Client.Models;
using BTCPayServer.Data; using BTCPayServer.Data;
using BTCPayServer.Lightning;
using BTCPayServer.Payments; using BTCPayServer.Payments;
using BTCPayServer.Rating;
using BTCPayServer.Services.Invoices;
using BTCPayServer.Services.Rates;
using Dapper; using Dapper;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using NBitcoin;
using Newtonsoft.Json.Linq;
namespace BTCPayServer.Services.Reporting; namespace BTCPayServer.Services.Reporting;

View File

@@ -1,6 +1,5 @@
#nullable enable #nullable enable
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
namespace BTCPayServer.Services.Reporting namespace BTCPayServer.Services.Reporting

View File

@@ -1,9 +1,6 @@
#nullable enable #nullable enable
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Threading; using System.Threading;
using BTCPayServer.Data;
using System;
using System.Linq;
namespace BTCPayServer.Services.Reporting namespace BTCPayServer.Services.Reporting
{ {

View File

@@ -11,6 +11,6 @@ namespace BTCPayServer.Services.Reporting
set; set;
} = new List<StoreReportResponse.Field>(); } = new List<StoreReportResponse.Field>();
public List<ChartDefinition> Charts { get; set; } = new List<ChartDefinition>(); public List<ChartDefinition> Charts { get; set; } = new ();
} }
} }

View File

@@ -90,7 +90,7 @@
<table class="table table-hover w-auto"> <table class="table table-hover w-auto">
<thead class="sticky-top bg-body"> <thead class="sticky-top bg-body">
<tr> <tr>
<th v-for="field in srv.result.fields"> <th v-for="field in srv.result.fields" :class="{ 'text-end': ['integer', 'decimal', 'amount'].includes(field.type) }">
<a class="text-nowrap sort-column" <a class="text-nowrap sort-column"
href="#" href="#"
:data-field="field.name" :data-field="field.name"

View File

@@ -135,14 +135,16 @@ document.addEventListener("DOMContentLoaded", () => {
const result = str.replace(/([A-Z])/g, " $1"); const result = str.replace(/([A-Z])/g, " $1");
return result.charAt(0).toUpperCase() + result.slice(1); return result.charAt(0).toUpperCase() + result.slice(1);
}, },
displayValue(val) { displayValue
return val && typeof (val) === "object" && val.d ? new Decimal(val.v).toFixed(val.d) : val;
}
} }
}); });
fetchStoreReports(); fetchStoreReports();
}); });
function displayValue(val) {
return val && typeof val === "object" && typeof val.d === "number" ? new Decimal(val.v).toFixed(val.d) : val;
}
function updateUIDateRange() { function updateUIDateRange() {
document.getElementById("toDate")._flatpickr.setDate(moment.unix(srv.request.timePeriod.to).toDate()); document.getElementById("toDate")._flatpickr.setDate(moment.unix(srv.request.timePeriod.to).toDate());
document.getElementById("fromDate")._flatpickr.setDate(moment.unix(srv.request.timePeriod.from).toDate()); document.getElementById("fromDate")._flatpickr.setDate(moment.unix(srv.request.timePeriod.from).toDate());
@@ -167,6 +169,7 @@ function downloadCSV() {
const data = clone(origData); const data = clone(origData);
// Convert ISO8601 dates to YYYY-MM-DD HH:mm:ss so the CSV easily integrate with Excel // Convert ISO8601 dates to YYYY-MM-DD HH:mm:ss so the CSV easily integrate with Excel
modifyFields(srv.result.fields, data, 'amount', displayValue)
modifyFields(srv.result.fields, data, 'datetime', v => moment(v).format('YYYY-MM-DD hh:mm:ss')); modifyFields(srv.result.fields, data, 'datetime', v => moment(v).format('YYYY-MM-DD hh:mm:ss'));
const csv = Papa.unparse({ fields: srv.result.fields.map(f => f.name), data }); const csv = Papa.unparse({ fields: srv.result.fields.map(f => f.name), data });
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' }); const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });