Fix avg/ct and consumption rate for discrete products (edibles)
Build and push image / build (push) Successful in 1m0s
Build and push image / build (push) Successful in 1m0s
Both metrics multiplied countOriginal by unitWeight, producing weight-based values labeled as per-count. For edibles where unitWeight is in mg, this yielded $0.02/ct and 18.18 ct/day. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -43,8 +43,8 @@ export function SkuDetail({
|
|||||||
const totalGrams = items.reduce((s, i) => s + i.weight, 0);
|
const totalGrams = items.reduce((s, i) => s + i.weight, 0);
|
||||||
if (totalGrams > 0) avgCostPerGram = totalSpend / totalGrams;
|
if (totalGrams > 0) avgCostPerGram = totalSpend / totalGrams;
|
||||||
} else {
|
} else {
|
||||||
const totalGrams = items.reduce((s, i) => s + i.countOriginal * i.unitWeight, 0);
|
const totalCount = items.reduce((s, i) => s + i.countOriginal, 0);
|
||||||
if (totalGrams > 0) avgCostPerGram = totalSpend / totalGrams;
|
if (totalCount > 0) avgCostPerGram = totalSpend / totalCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rated = items.filter((i) => i.rating != null);
|
const rated = items.filter((i) => i.rating != null);
|
||||||
@@ -62,7 +62,7 @@ export function SkuDetail({
|
|||||||
|
|
||||||
const totalGramsConsumed = consumed.reduce((s, i) => {
|
const totalGramsConsumed = consumed.reduce((s, i) => {
|
||||||
if (i.kind === "bulk") return s + i.weight;
|
if (i.kind === "bulk") return s + i.weight;
|
||||||
return s + i.countOriginal * i.unitWeight;
|
return s + i.countOriginal;
|
||||||
}, 0);
|
}, 0);
|
||||||
const totalDaysConsumed = lifespans.reduce((a, b) => a + b, 0);
|
const totalDaysConsumed = lifespans.reduce((a, b) => a + b, 0);
|
||||||
const consumptionRate = totalDaysConsumed > 0 ? totalGramsConsumed / totalDaysConsumed : null;
|
const consumptionRate = totalDaysConsumed > 0 ? totalGramsConsumed / totalDaysConsumed : null;
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ function buildSkuRows(data: Bootstrap): SkuRow[] {
|
|||||||
const totalGrams = items.reduce((s, i) => s + i.weight, 0);
|
const totalGrams = items.reduce((s, i) => s + i.weight, 0);
|
||||||
if (totalGrams > 0) avgCostPerGram = totalSpend / totalGrams;
|
if (totalGrams > 0) avgCostPerGram = totalSpend / totalGrams;
|
||||||
} else if (cfg && p.kind === "discrete") {
|
} else if (cfg && p.kind === "discrete") {
|
||||||
const totalGrams = items.reduce((s, i) => s + i.countOriginal * i.unitWeight, 0);
|
const totalCount = items.reduce((s, i) => s + i.countOriginal, 0);
|
||||||
if (totalGrams > 0) avgCostPerGram = totalSpend / totalGrams;
|
if (totalCount > 0) avgCostPerGram = totalSpend / totalCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dates = items.map((i) => i.purchaseDate).sort();
|
const dates = items.map((i) => i.purchaseDate).sort();
|
||||||
|
|||||||
Reference in New Issue
Block a user