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);
|
||||
if (totalGrams > 0) avgCostPerGram = totalSpend / totalGrams;
|
||||
} else {
|
||||
const totalGrams = items.reduce((s, i) => s + i.countOriginal * i.unitWeight, 0);
|
||||
if (totalGrams > 0) avgCostPerGram = totalSpend / totalGrams;
|
||||
const totalCount = items.reduce((s, i) => s + i.countOriginal, 0);
|
||||
if (totalCount > 0) avgCostPerGram = totalSpend / totalCount;
|
||||
}
|
||||
|
||||
const rated = items.filter((i) => i.rating != null);
|
||||
@@ -62,7 +62,7 @@ export function SkuDetail({
|
||||
|
||||
const totalGramsConsumed = consumed.reduce((s, i) => {
|
||||
if (i.kind === "bulk") return s + i.weight;
|
||||
return s + i.countOriginal * i.unitWeight;
|
||||
return s + i.countOriginal;
|
||||
}, 0);
|
||||
const totalDaysConsumed = lifespans.reduce((a, b) => a + b, 0);
|
||||
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);
|
||||
if (totalGrams > 0) avgCostPerGram = totalSpend / totalGrams;
|
||||
} else if (cfg && p.kind === "discrete") {
|
||||
const totalGrams = items.reduce((s, i) => s + i.countOriginal * i.unitWeight, 0);
|
||||
if (totalGrams > 0) avgCostPerGram = totalSpend / totalGrams;
|
||||
const totalCount = items.reduce((s, i) => s + i.countOriginal, 0);
|
||||
if (totalCount > 0) avgCostPerGram = totalSpend / totalCount;
|
||||
}
|
||||
|
||||
const dates = items.map((i) => i.purchaseDate).sort();
|
||||
|
||||
Reference in New Issue
Block a user