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

chore: Refine report with biz2 #109

Merged
merged 1 commit into from
Dec 19, 2023
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
7 changes: 5 additions & 2 deletions report/src/config/.env.local
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
RECEIPTS_COSMOS_CONN_STRING=xxx
RECEIPTS_COSMOS_CONN_STRING=x
RECEIPT_COSMOS_DB_NAME=db
RECEIPT_COSMOS_DB_CONTAINER_NAME=receipts
RECEIPT_MESSAGE_ERRORS_COSMOS_DB_CONTAINER_NAME=receipts-message-errors

BIZ_COSMOS_CONN_STRING=x
BIZ_COSMOS_DB_NAME=db
BIZ_COSMOS_DB_CONTAINER_NAME=biz-events
91 changes: 53 additions & 38 deletions report/src/utils/report.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs');

const { getReceiptsStatusCount } = require("./utils");
const { getReceiptsStatusCount, getBizCount } = require("./utils");

// const from = "2023-11-23T00:00:00";
// const to = "2023-11-25T23:59:59";
Expand All @@ -11,8 +11,8 @@ yesterday.setDate(yesterday.getDate() - 1)
// console.log(yesterday);

function padTo2Digits(num) {
return num.toString().padStart(2, '0');
}
return num.toString().padStart(2, '0');
}

// function formatDate(date) {
// return (
Expand All @@ -30,45 +30,52 @@ function padTo2Digits(num) {
// );
// }
function formatDate(date) {
return (
return (
[
date.getFullYear(),
padTo2Digits(date.getMonth() + 1),
padTo2Digits(date.getDate()),
date.getFullYear(),
padTo2Digits(date.getMonth() + 1),
padTo2Digits(date.getDate()),
].join('-')
);
);
}

// console.log(formatDate(new Date()));
yesterday_=formatDate(yesterday);
yesterday_ = formatDate(yesterday);
// console.log(formatDate(yesterday));


const res = getReceiptsStatusCount(yesterday_+"T00:00:00",yesterday_+"T23:59:59");

const dictionary = {
"NOT_QUEUE_SENT" : "🟢",
"INSERTED" : "🟡",
"RETRY" : "🟡",
"GENERATED" : "🟡",
"SIGNED" : "🟡",
"FAILED" : "🔴",
"IO_NOTIFIED" : "🟢",
"IO_ERROR_TO_NOTIFY" : "🔴",
"IO_NOTIFIER_RETRY" : "🟡",
"UNABLE_TO_SEND" : "🔴",
"NOT_TO_NOTIFY" : "🟢",
// Start function
const start = async function (a, b) {
const resBiz = await getBizCount(yesterday_ + "T00:00:00", yesterday_ + "T23:59:59");
const totBiz = resBiz.resources[0].num;
// console.log(totBiz);

// >>>>>>>>>>>>> start-RECEIPTs
const res = getReceiptsStatusCount(yesterday_ + "T00:00:00", yesterday_ + "T23:59:59");

const dictionary = {
"NOT_QUEUE_SENT": "🟢",
"INSERTED": "🟡",
"RETRY": "🟡",
"GENERATED": "🟡",
"SIGNED": "🟡",
"FAILED": "🔴",
"IO_NOTIFIED": "🟢",
"IO_ERROR_TO_NOTIFY": "🔴",
"IO_NOTIFIER_RETRY": "🟡",
"UNABLE_TO_SEND": "🔴",
"NOT_TO_NOTIFY": "🟢",
"TO_REVIEW": "🔴"
}


// let report_ = '{"title":"","detail":[]}'
let report_ = '{"text":""}'
// let report_ = '{"title":"","detail":[]}'
let report_ = '{"text":""}'

report=JSON.parse(report_);
report = JSON.parse(report_);

report.text = `📈 _Riepilogo del_ *${yesterday_}*\n`
let p = res.then(function(result) {
report.text = `📈 _Riepilogo del_ *${yesterday_}*\n`
let p = res.then(function (result) {
// console.log(result.resources.forEach(e => {
// console.log(`> ${dictionary[e.status]} ${e.num.toString().padEnd(8, ' ')}\t ${e.status} `);
// }))
Expand All @@ -79,21 +86,23 @@ let p = res.then(function(result) {
dic_sum[element.status] = element.num;
});
// console.log(dic_sum);
report.text+=`Pagamenti effettuati sul nodo: \`${sum.toLocaleString('it-IT')}\` \n`;
report.text += `Pagamenti effettuati sul nodo 🪢 : \`${totBiz.toLocaleString('it-IT')}\` \n`;
report.text += `Pagamenti con CF debitore/pagatore noto: \`${sum.toLocaleString('it-IT')}\` \n`;
// :large_green_circle: Ricevute inviate su IO: YY% · numeroAssolutoB
report.text+=`🟢 Ricevute inviate su IO: *${(100*dic_sum["IO_NOTIFIED"]/sum).toFixed(2)}%* - \`${dic_sum["IO_NOTIFIED"]?.toLocaleString('it-IT')}\` \n`;
report.text += `🟢 Ricevute inviate su IO: *${(100 * dic_sum["IO_NOTIFIED"] / sum).toFixed(2)}%* - \`${dic_sum["IO_NOTIFIED"]?.toLocaleString('it-IT')}\` \n`;
// :white_circle: Ricevute di debitori non presenti su IO: ZZ% · numeroAssolutoC
report.text+=`⚪️ Ricevute di debitori/pagatori non presenti su IO: *${(100*dic_sum["NOT_TO_NOTIFY"]/sum).toFixed(2)}%* - \`${dic_sum["NOT_TO_NOTIFY"]?.toLocaleString('it-IT')}\` \n`;
report.text += `⚪️ Ricevute di debitori/pagatori non presenti su IO: *${(100 * dic_sum["NOT_TO_NOTIFY"] / sum).toFixed(2)}%* - \`${dic_sum["NOT_TO_NOTIFY"]?.toLocaleString('it-IT')}\` \n`;
// :large_yellow_circle: Ricevute in attesa di essere inviate: QQ% · numeroAssolutoD
let GENERATED_INSERTED = dic_sum["GENERATED"] + dic_sum["INSERTED"];
report.text+=`🟡 Ricevute in attesa di essere inviate: *${(100*GENERATED_INSERTED/sum).toFixed(2)}%* - \`${GENERATED_INSERTED.toLocaleString('it-IT')}\` \n`;
report.text += `🟡 Ricevute in attesa di essere inviate: *${(100 * GENERATED_INSERTED / sum).toFixed(2)}%* - \`${GENERATED_INSERTED.toLocaleString('it-IT')}\` \n`;
// :red_circle: Ricevute non inviate a causa di un errore: NN% · numeroAssolutoE (edited)
let errori = (dic_sum["NOT_QUEUE_SENT"] != undefined ? dic_sum["NOT_QUEUE_SENT"] : 0) +
(dic_sum["FAILED"] != undefined ? dic_sum["FAILED"] : 0) +
(dic_sum["IO_ERROR_TO_NOTIFY"] != undefined ? dic_sum["IO_ERROR_TO_NOTIFY"] : 0) +
(dic_sum["UNABLE_TO_SEND"] != undefined ? dic_sum["UNABLE_TO_SEND"] : 0) +
(dic_sum["TO_REVIEW"] !=undefined ? dic_sum["TO_REVIEW"] : 0);
report.text+=`🔴 Ricevute non inviate a causa di un errore: *${(100*errori/sum).toFixed(2)}%* - \`${errori.toLocaleString('it-IT')}\` \n`;
(dic_sum["FAILED"] != undefined ? dic_sum["FAILED"] : 0) +
(dic_sum["IO_ERROR_TO_NOTIFY"] != undefined ? dic_sum["IO_ERROR_TO_NOTIFY"] : 0) +
(dic_sum["UNABLE_TO_SEND"] != undefined ? dic_sum["UNABLE_TO_SEND"] : 0) +
(dic_sum["TO_REVIEW"] != undefined ? dic_sum["TO_REVIEW"] : 0);
report.text += `🔴 Ricevute non inviate a causa di un errore: *${(100 * errori / sum).toFixed(2)}%* - \`${errori.toLocaleString('it-IT')}\` \n`;


// result.resources.forEach(e => {
// // report["detail"].push( {"status": `${dictionary[e.status]} ${e.status}`, "num":`${e.num}` });
Expand All @@ -105,6 +114,12 @@ let p = res.then(function(result) {
fs.writeFileSync('report.json', JSON.stringify(report));


})
});
// >>>>>>>>>>>>> stop-RECEIPTs

};

start();



32 changes: 26 additions & 6 deletions report/src/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
const { CosmosClient } = require("@azure/cosmos");
const { get } = require("http");

// receipt
const cosmos_db_conn_string = process.env.RECEIPTS_COSMOS_CONN_STRING || "";
const databaseId = process.env.RECEIPT_COSMOS_DB_NAME;
const receiptContainerId = process.env.RECEIPT_COSMOS_DB_CONTAINER_NAME;
const errorReceiptContainerId = process.env.RECEIPT_MESSAGE_ERRORS_COSMOS_DB_CONTAINER_NAME;

const client = new CosmosClient(cosmos_db_conn_string);
const receiptContainer = client.database(databaseId).container(receiptContainerId);
// const errorReceiptContainer = client.database(databaseId).container(errorReceiptContainerId);

//biz
const biz_cosmos_db_conn_string = process.env.BIZ_COSMOS_CONN_STRING || "";
const biz_databaseId = process.env.BIZ_COSMOS_DB_NAME;
const bizContainerId = process.env.BIZ_COSMOS_DB_CONTAINER_NAME;
const biz_client = new CosmosClient(biz_cosmos_db_conn_string);
const bizContainer = biz_client.database(biz_databaseId).container(bizContainerId);


async function getReceiptsStatusCount(data_from, data_to) {
return await receiptContainer.items
.query({
query: `SELECT count(1) as num,c.status FROM c WHERE
c.inserted_at >= DateTimeToTimestamp(@datefrom)
and c.inserted_at < DateTimeToTimestamp(@dateto)
and c.inserted_at <= DateTimeToTimestamp(@dateto)
GROUP BY c.status`,
parameters: [
{ name: "@datefrom", value: data_from },
Expand All @@ -26,6 +31,21 @@ async function getReceiptsStatusCount(data_from, data_to) {
.fetchAll();
}


async function getBizCount(data_from, data_to) {
return await bizContainer.items
.query({
query: `SELECT count(1) as num FROM c WHERE c.eventStatus = "DONE"
and c.timestamp >= DateTimeToTimestamp(@datefrom)
and c.timestamp <= DateTimeToTimestamp(@dateto)`,
parameters: [
{ name: "@datefrom", value: data_from },
{ name: "@dateto", value: data_to },
]
})
.fetchAll();
}

module.exports = {
getReceiptsStatusCount
}
getReceiptsStatusCount, getBizCount
}
Loading