vault backup: 2023-11-16 10:35:29

This commit is contained in:
Paul Trowbridge 2023-11-16 10:35:29 -05:00
parent 56d139c22d
commit 8a9102dbca
2 changed files with 8 additions and 4 deletions

2
api.ts
View File

@ -52,7 +52,7 @@ router.get('/dseg_price/:billcode/:shipcode/:stlc/:dseg/:qty', async (ctx) => {
const { billcode, shipcode, stlc, dseg, qty } = ctx.params; const { billcode, shipcode, stlc, dseg, qty } = ctx.params;
const result = await client.queryObject({args: [billcode, shipcode, stlc, dseg, qty], text: query_dseg} ); const result = await client.queryObject({args: [billcode, shipcode, stlc, dseg, qty], text: query_dseg} );
const ag = apply_guidance(result.rows[0]["doc"]); const ag = apply_guidance(result.rows[0]["doc"]);
ctx.response.body = ag.guidance.FinalReason; ctx.response.body = ag.guidance.finalPrice.Snapped;
}); });
app.use(router.routes()); app.use(router.routes());

View File

@ -41,7 +41,11 @@ export function apply_guidance(doc: any) {
} }
function pp(value) { function pp(value) {
return (value * 1000).toFixed(2); // Multiplies by 1000 and rounds to the nearest 2 decimals
var result = Math.round(value * 1000 * 100) / 100;
// Converts the number to a string with commas for thousand separators
return result.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2});
} }
// --------------------extract incoming data------------------------------------------------------ // --------------------extract incoming data------------------------------------------------------
@ -84,9 +88,9 @@ export function apply_guidance(doc: any) {
let custSeason = earlyCustSeason; let custSeason = earlyCustSeason;
let custReason = bridgePremium let custReason = bridgePremium
? `${custSeason} (similar ${altHist} price ${pp(earlyCustPrice)} x ${bridgePremium} = ${pp(bridgedPrice)})${custAddReason}` ? `${custSeason} (similar ${altHist} price ${pp(earlyCustPrice)} x ${bridgePremium} = ${pp(bridgedPrice)})${custAddReason}`
: `${custSeason} + price ${pp(custPrice)}${custAddReason}`; : `${custSeason} price ${pp(custPrice)}${custAddReason}`;
let markPrice = earlyMarkPrice * (1 + markAdder); let markPrice = earlyMarkPrice * (1 + markAdder);
let markReason = `${earlyMarkSeason} ASP + ${pp(earlyMarkPrice)}${markAddReason}`; let markReason = `${earlyMarkSeason} ASP ${pp(earlyMarkPrice)}${markAddReason}`;
let targPrice = targetPrice * (1 + markAdder); let targPrice = targetPrice * (1 + markAdder);
let targReason = `Target price ${pp(targetPrice)}${markAddReason}`; let targReason = `Target price ${pp(targetPrice)}${markAddReason}`;
let listPrice = listUSD; let listPrice = listUSD;