Add pts/W column
This commit is contained in:
@@ -94,6 +94,39 @@ export const ShortSummaryTable = ({ force, primaryColor, name, points }) => {
|
|||||||
}))
|
}))
|
||||||
.sort((a, b) => a.save - b.save);
|
.sort((a, b) => a.save - b.save);
|
||||||
|
|
||||||
|
const totalArmyWounds = sortedUnits.reduce((sum, unit) => {
|
||||||
|
return (
|
||||||
|
sum +
|
||||||
|
(unit.modelStats?.reduce((wSum, stat) => {
|
||||||
|
const modelName = unit.models?.reduce(
|
||||||
|
(bestMatch, model) => {
|
||||||
|
const similarity = (str1, str2) => {
|
||||||
|
let matches = 0;
|
||||||
|
for (
|
||||||
|
let i = 0;
|
||||||
|
i < Math.min(str1.length, str2.length);
|
||||||
|
i++
|
||||||
|
) {
|
||||||
|
if (str1[i] === str2[i]) matches++;
|
||||||
|
}
|
||||||
|
return matches;
|
||||||
|
};
|
||||||
|
const currentSimilarity = similarity(stat.name, model.name);
|
||||||
|
return currentSimilarity > similarity(stat.name, bestMatch.name)
|
||||||
|
? model
|
||||||
|
: bestMatch;
|
||||||
|
},
|
||||||
|
unit.models[0],
|
||||||
|
);
|
||||||
|
const modelCount =
|
||||||
|
unit.modelStats?.length === 1
|
||||||
|
? unit?.models?.reduce((s, m) => s + m.count, 0) || 1
|
||||||
|
: modelName?.count || 1;
|
||||||
|
return wSum + (stat.wounds || 0) * modelCount;
|
||||||
|
}, 0) || 0)
|
||||||
|
);
|
||||||
|
}, 0);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="flex justify-end gap-3">
|
<div className="flex justify-end gap-3">
|
||||||
@@ -178,7 +211,17 @@ export const ShortSummaryTable = ({ force, primaryColor, name, points }) => {
|
|||||||
fontWeight: 600,
|
fontWeight: 600,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Cost (pts)
|
Pts/W
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="table-cell border border-[var(--primary-color)] px-4 py-1 text-right"
|
||||||
|
style={{
|
||||||
|
fontSize: "1.1em",
|
||||||
|
color: "#fff",
|
||||||
|
fontWeight: 600,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Pts
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -201,8 +244,40 @@ export const ShortSummaryTable = ({ force, primaryColor, name, points }) => {
|
|||||||
// sum of all counts of the models
|
// sum of all counts of the models
|
||||||
count =
|
count =
|
||||||
models?.reduce((sum, model) => sum + model.count, 0) || 1;
|
models?.reduce((sum, model) => sum + model.count, 0) || 1;
|
||||||
}
|
} const totalWounds = unit.modelStats?.reduce((sum, stat) => {
|
||||||
return (
|
const modelName = unit.models?.reduce(
|
||||||
|
(bestMatch, model) => {
|
||||||
|
const similarity = (str1, str2) => {
|
||||||
|
let matches = 0;
|
||||||
|
for (
|
||||||
|
let i = 0;
|
||||||
|
i < Math.min(str1.length, str2.length);
|
||||||
|
i++
|
||||||
|
) {
|
||||||
|
if (str1[i] === str2[i]) matches++;
|
||||||
|
}
|
||||||
|
return matches;
|
||||||
|
};
|
||||||
|
const currentSimilarity = similarity(
|
||||||
|
stat.name,
|
||||||
|
model.name,
|
||||||
|
);
|
||||||
|
return currentSimilarity >
|
||||||
|
similarity(stat.name, bestMatch.name)
|
||||||
|
? model
|
||||||
|
: bestMatch;
|
||||||
|
},
|
||||||
|
unit.models[0],
|
||||||
|
);
|
||||||
|
const modelCount =
|
||||||
|
unit.modelStats?.length === 1
|
||||||
|
? models?.reduce(
|
||||||
|
(sum, model) => sum + model.count,
|
||||||
|
0,
|
||||||
|
) || 1
|
||||||
|
: modelName?.count || 1;
|
||||||
|
return sum + (stat.wounds || 0) * modelCount;
|
||||||
|
}, 0) || 0; return (
|
||||||
<div
|
<div
|
||||||
key={name + index}
|
key={name + index}
|
||||||
className={`table-row ${index % 2 === 0 ? "" : "bg-[#c4c4c480]"}`}
|
className={`table-row ${index % 2 === 0 ? "" : "bg-[#c4c4c480]"}`}
|
||||||
@@ -229,43 +304,7 @@ export const ShortSummaryTable = ({ force, primaryColor, name, points }) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="table-cell border border-dotted border-[#9e9fa1] px-4 py-1 text-right">
|
<div className="table-cell border border-dotted border-[#9e9fa1] px-4 py-1 text-right">
|
||||||
{unit.modelStats?.reduce((sum, stat, index) => {
|
{totalWounds}
|
||||||
const modelName = unit.models?.reduce(
|
|
||||||
(bestMatch, model) => {
|
|
||||||
const similarity = (str1, str2) => {
|
|
||||||
let matches = 0;
|
|
||||||
for (
|
|
||||||
let i = 0;
|
|
||||||
i < Math.min(str1.length, str2.length);
|
|
||||||
i++
|
|
||||||
) {
|
|
||||||
if (str1[i] === str2[i]) matches++; // Match only if characters are at the same position
|
|
||||||
}
|
|
||||||
return matches;
|
|
||||||
};
|
|
||||||
const currentSimilarity = similarity(
|
|
||||||
stat.name,
|
|
||||||
model.name,
|
|
||||||
);
|
|
||||||
|
|
||||||
return currentSimilarity >
|
|
||||||
similarity(stat.name, bestMatch.name)
|
|
||||||
? model
|
|
||||||
: bestMatch;
|
|
||||||
},
|
|
||||||
unit.models[0],
|
|
||||||
);
|
|
||||||
|
|
||||||
const modelCount =
|
|
||||||
unit.modelStats?.length === 1
|
|
||||||
? // sum of all counts of the models
|
|
||||||
models?.reduce(
|
|
||||||
(sum, model) => sum + model.count,
|
|
||||||
0,
|
|
||||||
) || 1
|
|
||||||
: modelName?.count || 1;
|
|
||||||
return sum + (stat.wounds || 0) * modelCount;
|
|
||||||
}, 0)}
|
|
||||||
</div>
|
</div>
|
||||||
<div className="table-cell border border-dotted border-[#9e9fa1] px-4 py-1 text-right">
|
<div className="table-cell border border-dotted border-[#9e9fa1] px-4 py-1 text-right">
|
||||||
{unit.modelStats?.reduce((sum, stat, index) => {
|
{unit.modelStats?.reduce((sum, stat, index) => {
|
||||||
@@ -306,12 +345,15 @@ export const ShortSummaryTable = ({ force, primaryColor, name, points }) => {
|
|||||||
return sum + (stat.oc || 0) * modelCount;
|
return sum + (stat.oc || 0) * modelCount;
|
||||||
}, 0)}
|
}, 0)}
|
||||||
</div>
|
</div>
|
||||||
|
<div className="table-cell border border-dotted border-[#9e9fa1] px-4 py-1 text-right">
|
||||||
|
{totalWounds > 0 ? (cost.points / totalWounds).toFixed(1) : "—"}
|
||||||
|
</div>
|
||||||
<div className="table-cell border border-dotted border-[#9e9fa1] px-4 py-1 text-right">
|
<div className="table-cell border border-dotted border-[#9e9fa1] px-4 py-1 text-right">
|
||||||
{cost.points} pts
|
{cost.points} pts
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
<div className="table-row bg-[var(--primary-color)] font-bold text-white">
|
<div className="table-row bg-[var(--primary-color)] font-bold text-white">
|
||||||
<div className="table-cell border border-[var(--primary-color)] px-4 py-1">
|
<div className="table-cell border border-[var(--primary-color)] px-4 py-1">
|
||||||
{sortedUnits.length} Units
|
{sortedUnits.length} Units
|
||||||
@@ -406,8 +448,14 @@ export const ShortSummaryTable = ({ force, primaryColor, name, points }) => {
|
|||||||
);
|
);
|
||||||
}, 0)}
|
}, 0)}
|
||||||
</div>
|
</div>
|
||||||
<div className="table-cell border border-[var(--primary-color)] px-4 py-1 text-right">
|
<div className="table-cell border border-[var(--primary-color)] px-4 py-1 text-right"> {totalArmyWounds > 0
|
||||||
{sortedUnits.reduce((sum, unit) => sum + unit.cost.points, 0)}{" "}
|
? (
|
||||||
|
sortedUnits.reduce((sum, unit) => sum + unit.cost.points, 0) /
|
||||||
|
totalArmyWounds
|
||||||
|
).toFixed(1)
|
||||||
|
: "—"}
|
||||||
|
</div>
|
||||||
|
<div className="table-cell border border-[var(--primary-color)] px-4 py-1 text-right"> {sortedUnits.reduce((sum, unit) => sum + unit.cost.points, 0)}{" "}
|
||||||
pts
|
pts
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user