UPlanet(*)

This commit is contained in:
fred 2024-02-04 15:09:16 +01:00
parent 5b44be85a5
commit 18e91e7e2b
4 changed files with 67 additions and 77 deletions

View File

@ -43,16 +43,29 @@
</p> </p>
</form> </form>
<section id="export-button"> <section id="totals">
<button id="exportButton">Export PDF</button> <div id="totalExpenses">Total Dépenses: <span id="totalExpensesAmount"></span> Ğ1</div>
<div id="totalIncomes">Total Revenus: <span id="totalIncomesAmount"></span> Ğ1</div>
</section> </section>
<section id="expenses"> <section id="expenses">
</section> </section>
<section id="txExpensesList">
<h2>Dépenses</h2>
<ul id="expensesList"></ul>
</section>
<section id="incomes"> <section id="incomes">
</section> </section>
<section id="txIncomesList">
<h2>Revenus</h2>
<ul id="incomesList"></ul>
</section>
<footer> <footer>
<blockquote> <blockquote>
Follow the money Follow the money

View File

@ -45,8 +45,8 @@ export const Treemap = (
link, // given a leaf node d, its link (if any) link, // given a leaf node d, its link (if any)
linkTarget = "_blank", // the target attribute for links (if any) linkTarget = "_blank", // the target attribute for links (if any)
tile = d3.treemapBinary, // treemap strategy tile = d3.treemapBinary, // treemap strategy
width = 640, // outer width, in pixels width = 480, // outer width, in pixels
height = 400, // outer height, in pixels height = 360, // outer height, in pixels
margin = 0, // shorthand for margins margin = 0, // shorthand for margins
marginTop = margin, // top margin, in pixels marginTop = margin, // top margin, in pixels
marginRight = margin, // right margin, in pixels marginRight = margin, // right margin, in pixels
@ -241,8 +241,8 @@ export const fetchExpenses = async (pubkey, minTime, limit = MAX_NB_TX) => {
const data = await response.json(); const data = await response.json();
console.log('node for the expenses of :\n', pubkey, '\n', node); console.log('node for the expenses of :\n', pubkey, '\n', node);
console.log('expenses data :\n', data);
// expensesByRecipient initialize table
let expensesByRecipient = {}; let expensesByRecipient = {};
let totalAmount = 0; let totalAmount = 0;
@ -250,6 +250,9 @@ export const fetchExpenses = async (pubkey, minTime, limit = MAX_NB_TX) => {
const tx = hit._source; const tx = hit._source;
// tx expense example : Object { amount: 18000, medianTime: 1670155095, recipient: "9e7rdkfNQetyyKudJz9aRSQQV6HeebeZFsj3Ha5MsMZ1", comment: "Bolso cartera marron" }
console.log('tx expense :\n', tx);
if (!(tx.recipient in expensesByRecipient)) { if (!(tx.recipient in expensesByRecipient)) {
expensesByRecipient[tx.recipient] = 0; expensesByRecipient[tx.recipient] = 0;
@ -257,12 +260,6 @@ export const fetchExpenses = async (pubkey, minTime, limit = MAX_NB_TX) => {
expensesByRecipient[tx.recipient] += tx.amount/100; expensesByRecipient[tx.recipient] += tx.amount/100;
// incomesByIssuer initialize table
expensesByRecipient[tx.medianTime] = tx.medianTime;
expensesByRecipient[tx.amout] = tx.amount;
expensesByRecipient[tx.recipient] = tx.recipient;
expensesByRecipient[tx.comment] = tx.comment;
totalAmount += tx.amount; totalAmount += tx.amount;
} }
@ -335,8 +332,8 @@ export const fetchIncomes = async (pubkey, minTime, limit = MAX_NB_TX) => {
const data = await response.json(); const data = await response.json();
console.log('node for the incomes of :\n', pubkey, '\n', node); console.log('node for the incomes of :\n', pubkey, '\n', node);
console.log('incomes data :\n', data);
// incomesByIssuer initialize table
let incomesByIssuer = {}; let incomesByIssuer = {};
let totalAmount = 0; let totalAmount = 0;
@ -344,6 +341,9 @@ export const fetchIncomes = async (pubkey, minTime, limit = MAX_NB_TX) => {
const tx = hit._source; const tx = hit._source;
// tx income example : Object { amount: 40000, medianTime: 1693753222, comment: "Huevos gotas", issuer: "HpztnzdDP1FEiS4bnXVzQ3BQBAfRiMUMhHK7xzTGsVqe" }
console.log('tx income :\n', tx);
if (!(tx.issuer in incomesByIssuer)) { if (!(tx.issuer in incomesByIssuer)) {
incomesByIssuer[tx.issuer] = 0; incomesByIssuer[tx.issuer] = 0;
@ -351,12 +351,6 @@ export const fetchIncomes = async (pubkey, minTime, limit = MAX_NB_TX) => {
incomesByIssuer[tx.issuer] += tx.amount/100; incomesByIssuer[tx.issuer] += tx.amount/100;
// incomesByIssuer initialize table
incomesByIssuer[tx.medianTime] = tx.medianTime;
incomesByIssuer[tx.amout] = tx.amount;
incomesByIssuer[tx.issuer] = tx.issuer;
incomesByIssuer[tx.comment] = tx.comment;
totalAmount += tx.amount; totalAmount += tx.amount;
} }
@ -557,6 +551,19 @@ export const displayExpenses = (expensesByRecipient, expensesTotalAmount, recipi
svgContainer.append(chart); svgContainer.append(chart);
screenElt.scrollIntoView({behavior: 'smooth'}, true); screenElt.scrollIntoView({behavior: 'smooth'}, true);
// Display transaction list
const expensesList = document.getElementById("expensesList");
expensesList.innerHTML = "";
for (const recipient in expensesByRecipient) {
const listItem = document.createElement("li");
listItem.textContent = `To: ${recipientsCesiumProfiles[recipient]?.title || recipient}, Amount: ${expensesByRecipient[recipient]} Ğ1`;
expensesList.appendChild(listItem);
}
// Display total expenses
const totalExpensesAmount = document.getElementById("totalExpensesAmount");
totalExpensesAmount.textContent = expensesTotalAmount.toFixed(2);
}; };
export const displayIncomes = (incomesByIssuer, incomesTotalAmount, issuersCesiumProfiles, chartColors, currentPubkey, currentProfile) => { export const displayIncomes = (incomesByIssuer, incomesTotalAmount, issuersCesiumProfiles, chartColors, currentPubkey, currentProfile) => {
@ -620,6 +627,19 @@ export const displayIncomes = (incomesByIssuer, incomesTotalAmount, issuersCesiu
svgContainer.append(chart); svgContainer.append(chart);
screenElt.scrollIntoView({behavior: 'smooth'}, true); screenElt.scrollIntoView({behavior: 'smooth'}, true);
// Display transaction list
const incomesList = document.getElementById("incomesList");
incomesList.innerHTML = "";
for (const issuer in incomesByIssuer) {
const listItem = document.createElement("li");
listItem.textContent = `From: ${issuersCesiumProfiles[issuer]?.title || issuer}, Amount: ${incomesByIssuer[issuer]} Ğ1`;
incomesList.appendChild(listItem);
}
// Display total incomes
const totalIncomesAmount = document.getElementById("totalIncomesAmount");
totalIncomesAmount.textContent = incomesTotalAmount.toFixed(2);
}; };
@ -642,8 +662,8 @@ const treemapIt = async (pubkey, minTime, maxNbTx = MAX_NB_TX) => {
let nbRecipients = Object.keys(expensesByRecipient).length; let nbRecipients = Object.keys(expensesByRecipient).length;
let nbIssuers = Object.keys(incomesByIssuer).length; let nbIssuers = Object.keys(incomesByIssuer).length;
console.log("nb recipients :\n", nbRecipients); console.log("nb Expences recipients :\n", nbRecipients);
console.log("nb Issuers :\n", nbIssuers); console.log("nb Income Issuers :\n", nbIssuers);
let recipientsList = Object.keys(expensesByRecipient); let recipientsList = Object.keys(expensesByRecipient);
let recipientsCesiumProfiles = await fetchCesiumProfiles(recipientsList, maxNbTx); let recipientsCesiumProfiles = await fetchCesiumProfiles(recipientsList, maxNbTx);
@ -782,49 +802,4 @@ window.addEventListener('DOMContentLoaded', (loadEvent) => {
minDateElt.value = dateStr; minDateElt.value = dateStr;
// Add an event listener to the export button
const exportButton = document.getElementById('exportButton');
exportButton.addEventListener('click', async () => {
try {
const pubkey = document.querySelector('input[name="pubkey"]').value;
const { expensesTotalAmount, expensesByRecipient } = await fetchExpenses(pubkey, minTime, txLimit);
const { incomesTotalAmount, incomesByIssuer } = await fetchIncomes(pubkey, minTime, txLimit);
// Combine expenses and incomes into a single list ordered by date
const combinedTransactions = [];
for (const recipient in expensesByRecipient) {
combinedTransactions.push({
medianTime: expensesByRecipient[medianTime],
type: 'Expense',
amount: expensesByRecipient[amount],
recipient: expensesByRecipient[recipient],
});
}
for (const issuer in incomesByIssuer) {
combinedTransactions.push({
medianTime: incomesByIssuer[medianTime],
type: 'Income',
amount: incomesByIssuer[amount],
issuer: incomesByIssuer[issuer],
});
}
// Sort the transactions by date
combinedTransactions.sort((a, b) => new Date(a.medianTime) - new Date(b.medianTime));
// Create a PDF with the combined transactions
exportToPDF(combinedTransactions);
} catch (error) {
console.error(`Error exporting transactions to PDF: ${error}`);
}
});
}); });

View File

@ -183,7 +183,7 @@ console.log(station)
--> -->
<button style="position: fixed; top: 10px; left: 10px;" onclick="document.getElementById('console').style.visibility = (document.getElementById('console').style.visibility === 'visible' ? 'hidden' : 'visible');">(?)</button> <button style="position: fixed; top: 10px; left: 10px;" onclick="document.getElementById('console').style.visibility = (document.getElementById('console').style.visibility === 'visible' ? 'hidden' : 'visible');">(?)</button>
<div id="console"> <a href="https://pad.p2p.legal/p/UPlanet_HELP" target="aframe">HELP</a> ___ <a href="https://zen.g1sms.fr" target="aframe">Discover Ẑen</a> ___ <button onclick="document.getElementById('console').style.visibility = 'hidden';"> X </button> <div id="console"> <a href="https://pad.p2p.legal/p/UPlanet_HELP" target="aframe"><img width=20 src="/ipfs/QmY1BbaSHLj5vmtB6QmFenqma6qajkky3QRBJEMWaZnA49" ></a> ___<a href="https://chaton.g1sms.fr" target="aframe">Dragons</a> are keeping <a href="https://zen.g1sms.fr" target="aframe">Ẑen UPlanet(*)</a> ___ <button onclick="document.getElementById('console').style.visibility = 'hidden';"> X </button>
<iframe name="aframe" id="aframe" src="https://pad.p2p.legal/p/UPlanet_HELP" width="100%" height="100%"></iframe> <iframe name="aframe" id="aframe" src="https://pad.p2p.legal/p/UPlanet_HELP" width="100%" height="100%"></iframe>
</div> </div>

File diff suppressed because one or more lines are too long