Working on stuff

This commit is contained in:
Christopher Cookman 2024-09-03 16:16:18 -06:00
parent 6dd31f7d04
commit 6719f452d1
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42
3 changed files with 91 additions and 1 deletions

73
PayoutTest.js Normal file
View file

@ -0,0 +1,73 @@
require("dotenv").config();
const noblox = require('noblox.js');
const payoutPercentages = {
"Honeywell Vista Device Pack": .6
}
noblox.setCookie(process.env.COOKIE).then(() => {
noblox.getGroupTransactions(process.env.GROUPID, "Sale").then((transactions) => {
// Calculate the first and last days of the previous month
const now = new Date();
const firstDayOfLastMonth = new Date(now.getFullYear(), now.getMonth() - 1, 1);
const lastDayOfLastMonth = new Date(now.getFullYear(), now.getMonth(), 0); // Last day of the previous month
// Filter transactions to those within the previous month
const previousMonthTransactions = transactions.filter((transaction) => {
const transactionDate = new Date(transaction.created);
//console.log(transaction)
return transactionDate >= firstDayOfLastMonth && transactionDate <= lastDayOfLastMonth && transaction.currency.amount > 0;
});
console.log(previousMonthTransactions);
// Calculate total revenue
const totalRevenue = previousMonthTransactions.reduce((acc, transaction) => acc + transaction.currency.amount, 0);
// Calculate total revenue per product
const totalRevPerProduct = previousMonthTransactions.reduce((acc, transaction) => {
if (!acc[transaction.details.name]) {
acc[transaction.details.name] = 0;
}
acc[transaction.details.name] += transaction.currency.amount;
return acc;
}, {});
// Calculate percentage to pay out per product
const payouts = Object.keys(totalRevPerProduct).reduce((acc, product) => {
if (!payoutPercentages[product]) {
acc[product] = 0;
} else {
acc[product] = Math.floor(totalRevPerProduct[product] * payoutPercentages[product]);
}
return acc;
}, {});
// Get list of people that bought products
const buyers = previousMonthTransactions.reduce((acc, transaction) => {
if (!acc[transaction.agent.id]) {
acc[transaction.agent.id] = {
name: transaction.agent.name,
total: 0,
products: []
};
}
acc[transaction.agent.id].total += transaction.currency.amount;
acc[transaction.agent.id].products.push({
name: transaction.details.name,
amount: transaction.currency.amount
});
return acc;
}, {});
console.log("Buyers");
console.log(JSON.stringify(buyers, null, 2));
console.log("Rev");
console.log(totalRevPerProduct);
console.log("Payouts");
console.log(payouts);
console.log(`Total Revenue: ${totalRevenue}`);
// Print a single line for every transaction
});
});

12
PublicAssets.js Normal file
View file

@ -0,0 +1,12 @@
require("dotenv").config();
const noblox = require('noblox.js');
const payoutPercentages = {
"Honeywell Vista Device Pack": .6
}
noblox.setCookie(process.env.COOKIE).then(() => {
noblox.getGroupAssets(process.env.GROUPID, "Model").then((assets) => {
console.log(assets)
});
});

7
package-lock.json generated
View file

@ -1,16 +1,21 @@
{
"name": "roblortest",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "roblortest",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"colors": "^1.4.0",
"crypto": "^1.0.1",
"discord.js": "^14.15.3",
"dotenv": "^16.4.5",
"noblox.js": "^6.0.2"
}
},
"devDependencies": {}
},
"node_modules/@discordjs/builders": {
"version": "1.8.2",