mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-11-09 21:51:29 +08:00
renamed function
This commit is contained in:
parent
1f4df9199d
commit
7f734e7d3f
9 changed files with 42 additions and 42 deletions
|
|
@ -138,7 +138,7 @@ function buildPbHtml(
|
|||
dateText = format(date, "dd MMM yyyy");
|
||||
}
|
||||
|
||||
let speedString: number | string = typingSpeedUnit.convert(pbData.wpm);
|
||||
let speedString: number | string = typingSpeedUnit.fromWpm(pbData.wpm);
|
||||
if (Config.alwaysShowDecimalPlaces) {
|
||||
speedString = Misc.roundTo2(speedString).toFixed(2);
|
||||
} else {
|
||||
|
|
@ -146,7 +146,7 @@ function buildPbHtml(
|
|||
}
|
||||
speedString += ` ${speedUnit}`;
|
||||
|
||||
let rawString: number | string = typingSpeedUnit.convert(pbData.raw);
|
||||
let rawString: number | string = typingSpeedUnit.fromWpm(pbData.raw);
|
||||
if (Config.alwaysShowDecimalPlaces) {
|
||||
rawString = Misc.roundTo2(rawString).toFixed(2);
|
||||
} else {
|
||||
|
|
@ -180,7 +180,7 @@ function buildPbHtml(
|
|||
|
||||
retval = `<div class="quick">
|
||||
<div class="test">${modeString}</div>
|
||||
<div class="wpm">${Math.round(typingSpeedUnit.convert(pbData.wpm))}</div>
|
||||
<div class="wpm">${Math.round(typingSpeedUnit.fromWpm(pbData.wpm))}</div>
|
||||
<div class="acc">${
|
||||
pbData.acc === undefined ? "-" : Math.floor(pbData.acc) + "%"
|
||||
}</div>
|
||||
|
|
|
|||
|
|
@ -187,9 +187,9 @@ function updateFooter(lb: LbKey): void {
|
|||
<tr>
|
||||
<td>${entry.rank}</td>
|
||||
<td><span class="top">You</span>${toppercent ? toppercent : ""}</td>
|
||||
<td class="alignRight">${typingSpeedUnit.convert(entry.wpm).toFixed(2)}<br>
|
||||
<td class="alignRight">${typingSpeedUnit.fromWpm(entry.wpm).toFixed(2)}<br>
|
||||
<div class="sub">${entry.acc.toFixed(2)}%</div></td>
|
||||
<td class="alignRight">${typingSpeedUnit.convert(entry.raw).toFixed(2)}<br>
|
||||
<td class="alignRight">${typingSpeedUnit.fromWpm(entry.raw).toFixed(2)}<br>
|
||||
<div class="sub">${
|
||||
!entry.consistency || entry.consistency === "-"
|
||||
? "-"
|
||||
|
|
@ -341,9 +341,9 @@ async function fillTable(lb: LbKey, prepend?: number): Promise<void> {
|
|||
${entry.badgeId ? getBadgeHTMLbyId(entry.badgeId) : ""}
|
||||
</div>
|
||||
</td>
|
||||
<td class="alignRight">${typingSpeedUnit.convert(entry.wpm).toFixed(2)}<br>
|
||||
<td class="alignRight">${typingSpeedUnit.fromWpm(entry.wpm).toFixed(2)}<br>
|
||||
<div class="sub">${entry.acc.toFixed(2)}%</div></td>
|
||||
<td class="alignRight">${typingSpeedUnit.convert(entry.raw).toFixed(2)}<br>
|
||||
<td class="alignRight">${typingSpeedUnit.fromWpm(entry.raw).toFixed(2)}<br>
|
||||
<div class="sub">${
|
||||
!entry.consistency || entry.consistency === "-"
|
||||
? "-"
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ function loadMoreLines(lineIndex?: number): void {
|
|||
|
||||
let raw;
|
||||
try {
|
||||
raw = typingSpeedUnit.convert(result.rawWpm).toFixed(2);
|
||||
raw = typingSpeedUnit.fromWpm(result.rawWpm).toFixed(2);
|
||||
if (raw === undefined) {
|
||||
raw = "-";
|
||||
}
|
||||
|
|
@ -161,7 +161,7 @@ function loadMoreLines(lineIndex?: number): void {
|
|||
$(".pageAccount .history table tbody").append(`
|
||||
<tr class="resultRow" id="result-${i}">
|
||||
<td>${pb}</td>
|
||||
<td>${typingSpeedUnit.convert(result.wpm).toFixed(2)}</td>
|
||||
<td>${typingSpeedUnit.fromWpm(result.wpm).toFixed(2)}</td>
|
||||
<td>${raw}</td>
|
||||
<td>${result.acc.toFixed(2)}%</td>
|
||||
<td>${consistency}</td>
|
||||
|
|
@ -538,7 +538,7 @@ async function fillContent(): Promise<void> {
|
|||
|
||||
const bucketSize = typingSpeedUnit.histogramDataBucketSize;
|
||||
const bucket = Math.floor(
|
||||
typingSpeedUnit.convert(result.wpm) / bucketSize
|
||||
typingSpeedUnit.fromWpm(result.wpm) / bucketSize
|
||||
);
|
||||
|
||||
//grow array if needed
|
||||
|
|
@ -619,8 +619,8 @@ async function fillContent(): Promise<void> {
|
|||
|
||||
chartData.push({
|
||||
x: filteredResults.length,
|
||||
y: Misc.roundTo2(typingSpeedUnit.convert(result.wpm)),
|
||||
wpm: Misc.roundTo2(typingSpeedUnit.convert(result.wpm)),
|
||||
y: Misc.roundTo2(typingSpeedUnit.fromWpm(result.wpm)),
|
||||
wpm: Misc.roundTo2(typingSpeedUnit.fromWpm(result.wpm)),
|
||||
acc: result.acc,
|
||||
mode: result.mode,
|
||||
mode2: result.mode2,
|
||||
|
|
@ -628,7 +628,7 @@ async function fillContent(): Promise<void> {
|
|||
language: result.language,
|
||||
timestamp: result.timestamp,
|
||||
difficulty: result.difficulty,
|
||||
raw: Misc.roundTo2(typingSpeedUnit.convert(result.rawWpm)),
|
||||
raw: Misc.roundTo2(typingSpeedUnit.fromWpm(result.rawWpm)),
|
||||
isPb: result.isPb ?? false,
|
||||
});
|
||||
|
||||
|
|
@ -683,7 +683,7 @@ async function fillContent(): Promise<void> {
|
|||
activityChartData_avgWpm.push({
|
||||
x: dateInt,
|
||||
y: Misc.roundTo2(
|
||||
typingSpeedUnit.convert(activityChartData[dateInt].totalWpm) /
|
||||
typingSpeedUnit.fromWpm(activityChartData[dateInt].totalWpm) /
|
||||
activityChartData[dateInt].amount
|
||||
),
|
||||
});
|
||||
|
|
@ -844,7 +844,7 @@ async function fillContent(): Promise<void> {
|
|||
Misc.secondsToString(Math.round(totalSecondsFiltered), true, true)
|
||||
);
|
||||
|
||||
let highestSpeed: number | string = typingSpeedUnit.convert(topWpm);
|
||||
let highestSpeed: number | string = typingSpeedUnit.fromWpm(topWpm);
|
||||
|
||||
if (Config.alwaysShowDecimalPlaces) {
|
||||
highestSpeed = Misc.roundTo2(highestSpeed).toFixed(2);
|
||||
|
|
@ -857,7 +857,7 @@ async function fillContent(): Promise<void> {
|
|||
$(".pageAccount .highestWpm .title").text(`highest ${speedUnit}`);
|
||||
$(".pageAccount .highestWpm .val").text(highestSpeed);
|
||||
|
||||
let averageSpeed: number | string = typingSpeedUnit.convert(totalWpm);
|
||||
let averageSpeed: number | string = typingSpeedUnit.fromWpm(totalWpm);
|
||||
if (Config.alwaysShowDecimalPlaces) {
|
||||
averageSpeed = Misc.roundTo2(averageSpeed / testCount).toFixed(2);
|
||||
} else {
|
||||
|
|
@ -868,7 +868,7 @@ async function fillContent(): Promise<void> {
|
|||
$(".pageAccount .averageWpm .val").text(averageSpeed);
|
||||
|
||||
let averageSpeedLast10: number | string =
|
||||
typingSpeedUnit.convert(wpmLast10total);
|
||||
typingSpeedUnit.fromWpm(wpmLast10total);
|
||||
if (Config.alwaysShowDecimalPlaces) {
|
||||
averageSpeedLast10 = Misc.roundTo2(averageSpeedLast10 / last10).toFixed(2);
|
||||
} else {
|
||||
|
|
@ -880,7 +880,7 @@ async function fillContent(): Promise<void> {
|
|||
);
|
||||
$(".pageAccount .averageWpm10 .val").text(averageSpeedLast10);
|
||||
|
||||
let highestRawSpeed: number | string = typingSpeedUnit.convert(rawWpm.max);
|
||||
let highestRawSpeed: number | string = typingSpeedUnit.fromWpm(rawWpm.max);
|
||||
if (Config.alwaysShowDecimalPlaces) {
|
||||
highestRawSpeed = Misc.roundTo2(highestRawSpeed).toFixed(2);
|
||||
} else {
|
||||
|
|
@ -890,7 +890,7 @@ async function fillContent(): Promise<void> {
|
|||
$(".pageAccount .highestRaw .title").text(`highest raw ${speedUnit}`);
|
||||
$(".pageAccount .highestRaw .val").text(highestRawSpeed);
|
||||
|
||||
let averageRawSpeed: number | string = typingSpeedUnit.convert(rawWpm.total);
|
||||
let averageRawSpeed: number | string = typingSpeedUnit.fromWpm(rawWpm.total);
|
||||
if (Config.alwaysShowDecimalPlaces) {
|
||||
averageRawSpeed = Misc.roundTo2(averageRawSpeed / rawWpm.count).toFixed(2);
|
||||
} else {
|
||||
|
|
@ -900,7 +900,7 @@ async function fillContent(): Promise<void> {
|
|||
$(".pageAccount .averageRaw .title").text(`average raw ${speedUnit}`);
|
||||
$(".pageAccount .averageRaw .val").text(averageRawSpeed);
|
||||
|
||||
let averageRawSpeedLast10: number | string = typingSpeedUnit.convert(
|
||||
let averageRawSpeedLast10: number | string = typingSpeedUnit.fromWpm(
|
||||
rawWpm.last10Total
|
||||
);
|
||||
if (Config.alwaysShowDecimalPlaces) {
|
||||
|
|
@ -1007,7 +1007,7 @@ async function fillContent(): Promise<void> {
|
|||
|
||||
$(".pageAccount .group.chart .below .text").text(
|
||||
`Speed change per hour spent typing: ${
|
||||
plus + Misc.roundTo2(typingSpeedUnit.convert(wpmChangePerHour))
|
||||
plus + Misc.roundTo2(typingSpeedUnit.fromWpm(wpmChangePerHour))
|
||||
} ${Config.typingSpeedUnit}`
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { get as getTypingSpeedUnit } from "../utils/typing-speed-units";
|
|||
|
||||
export async function update(burst: number): Promise<void> {
|
||||
if (!Config.showLiveBurst) return;
|
||||
burst = Math.round(getTypingSpeedUnit(Config.typingSpeedUnit).convert(burst));
|
||||
burst = Math.round(getTypingSpeedUnit(Config.typingSpeedUnit).fromWpm(burst));
|
||||
(document.querySelector("#miniTimerAndLiveWpm .burst") as Element).innerHTML =
|
||||
burst.toString();
|
||||
(document.querySelector("#liveBurst") as Element).innerHTML =
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export function update(wpm: number, raw: number): void {
|
|||
number = raw;
|
||||
}
|
||||
number = Math.round(
|
||||
getTypingSpeedUnit(Config.typingSpeedUnit).convert(number)
|
||||
getTypingSpeedUnit(Config.typingSpeedUnit).fromWpm(number)
|
||||
);
|
||||
miniLiveWpmElement.innerHTML = number.toString();
|
||||
liveWpmElement.innerHTML = number.toString();
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ async function updateGraph(): Promise<void> {
|
|||
|
||||
const chartData1 = [
|
||||
...TestInput.wpmHistory.map((a) =>
|
||||
Misc.roundTo2(typingSpeedUnit.convert(a))
|
||||
Misc.roundTo2(typingSpeedUnit.fromWpm(a))
|
||||
),
|
||||
];
|
||||
|
||||
|
|
@ -72,7 +72,7 @@ async function updateGraph(): Promise<void> {
|
|||
|
||||
const chartData2 = [
|
||||
...result.chartData.raw.map((a) =>
|
||||
Misc.roundTo2(typingSpeedUnit.convert(a))
|
||||
Misc.roundTo2(typingSpeedUnit.fromWpm(a))
|
||||
),
|
||||
];
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ export async function updateGraphPBLine(): Promise<void> {
|
|||
);
|
||||
if (lpb === 0) return;
|
||||
const typingSpeedUnit = getTypingSpeedUnit(Config.typingSpeedUnit);
|
||||
const chartlpb = Misc.roundTo2(typingSpeedUnit.convert(lpb)).toFixed(2);
|
||||
const chartlpb = Misc.roundTo2(typingSpeedUnit.fromWpm(lpb)).toFixed(2);
|
||||
resultAnnotation.push({
|
||||
display: true,
|
||||
type: "line",
|
||||
|
|
@ -198,7 +198,7 @@ export async function updateGraphPBLine(): Promise<void> {
|
|||
content: `PB: ${chartlpb}`,
|
||||
},
|
||||
});
|
||||
const lpbRange = typingSpeedUnit.convert(20);
|
||||
const lpbRange = typingSpeedUnit.fromWpm(20);
|
||||
if (
|
||||
maxChartVal >= parseFloat(chartlpb) - lpbRange &&
|
||||
maxChartVal <= parseFloat(chartlpb) + lpbRange
|
||||
|
|
@ -222,11 +222,11 @@ function updateWpmAndAcc(): void {
|
|||
$("#result .stats .wpm .bottom").text("Infinite");
|
||||
} else {
|
||||
$("#result .stats .wpm .bottom").text(
|
||||
Misc.roundTo2(typingSpeedUnit.convert(result.wpm)).toFixed(2)
|
||||
Misc.roundTo2(typingSpeedUnit.fromWpm(result.wpm)).toFixed(2)
|
||||
);
|
||||
}
|
||||
$("#result .stats .raw .bottom").text(
|
||||
Misc.roundTo2(typingSpeedUnit.convert(result.rawWpm)).toFixed(2)
|
||||
Misc.roundTo2(typingSpeedUnit.fromWpm(result.rawWpm)).toFixed(2)
|
||||
);
|
||||
|
||||
if (Config.typingSpeedUnit != "wpm") {
|
||||
|
|
@ -272,11 +272,11 @@ function updateWpmAndAcc(): void {
|
|||
$("#result .stats .wpm .bottom").text("Infinite");
|
||||
} else {
|
||||
$("#result .stats .wpm .bottom").text(
|
||||
Math.round(typingSpeedUnit.convert(result.wpm))
|
||||
Math.round(typingSpeedUnit.fromWpm(result.wpm))
|
||||
);
|
||||
}
|
||||
$("#result .stats .raw .bottom").text(
|
||||
Math.round(typingSpeedUnit.convert(result.rawWpm))
|
||||
Math.round(typingSpeedUnit.fromWpm(result.rawWpm))
|
||||
);
|
||||
$("#result .stats .raw .bottom").attr("aria-label", rawWpmHover);
|
||||
|
||||
|
|
@ -415,7 +415,7 @@ export async function updateCrown(): Promise<void> {
|
|||
pbDiff = Math.abs(result.wpm - lpb);
|
||||
$("#result .stats .wpm .crown").attr(
|
||||
"aria-label",
|
||||
"+" + Misc.roundTo2(typingSpeedUnit.convert(pbDiff))
|
||||
"+" + Misc.roundTo2(typingSpeedUnit.fromWpm(pbDiff))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -506,7 +506,7 @@ async function updateTags(dontSave: boolean): Promise<void> {
|
|||
type: "line",
|
||||
id: "tpb",
|
||||
scaleID: "wpm",
|
||||
value: typingSpeedUnit.convert(tpb),
|
||||
value: typingSpeedUnit.fromWpm(tpb),
|
||||
borderColor: themecolors["sub"],
|
||||
borderWidth: 1,
|
||||
borderDash: [2, 2],
|
||||
|
|
@ -526,7 +526,7 @@ async function updateTags(dontSave: boolean): Promise<void> {
|
|||
xAdjust: labelAdjust,
|
||||
enabled: true,
|
||||
content: `${tag.display} PB: ${Misc.roundTo2(
|
||||
typingSpeedUnit.convert(tpb)
|
||||
typingSpeedUnit.fromWpm(tpb)
|
||||
).toFixed(2)}`,
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1246,7 +1246,7 @@ $(".pageTest #resultWordsHistory").on("mouseenter", ".words .word", (e) => {
|
|||
</div>
|
||||
<div class="speed">
|
||||
${Math.round(
|
||||
getTypingSpeedUnit(Config.typingSpeedUnit).convert(burst)
|
||||
getTypingSpeedUnit(Config.typingSpeedUnit).fromWpm(burst)
|
||||
)}${Config.typingSpeedUnit}
|
||||
</div>
|
||||
</div>`
|
||||
|
|
|
|||
2
frontend/src/ts/types/types.d.ts
vendored
2
frontend/src/ts/types/types.d.ts
vendored
|
|
@ -884,7 +884,7 @@ declare namespace MonkeyTypes {
|
|||
|
||||
type TypingSpeedUnit = "wpm" | "cpm" | "wps" | "cps" | "wph";
|
||||
interface TypingSpeedUnitSettings {
|
||||
convert: (number) => number;
|
||||
fromWpm: (number) => number;
|
||||
convertWithUnitSuffix: (number) => string;
|
||||
fullUnitString: string;
|
||||
histogramDataBucketSize: number;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ const typingSpeedUnits: Record<
|
|||
MonkeyTypes.TypingSpeedUnitSettings
|
||||
> = {
|
||||
wpm: {
|
||||
convert: (wpm: number) => wpm,
|
||||
fromWpm: (wpm: number) => wpm,
|
||||
convertWithUnitSuffix: (wpm: number) => {
|
||||
return convertTypingSpeedWithUnitSuffix("wpm", wpm);
|
||||
},
|
||||
|
|
@ -14,7 +14,7 @@ const typingSpeedUnits: Record<
|
|||
historyStepSize: 10,
|
||||
},
|
||||
cpm: {
|
||||
convert: (wpm: number) => wpm * 5,
|
||||
fromWpm: (wpm: number) => wpm * 5,
|
||||
convertWithUnitSuffix: (wpm: number) => {
|
||||
return convertTypingSpeedWithUnitSuffix("cpm", wpm);
|
||||
},
|
||||
|
|
@ -23,7 +23,7 @@ const typingSpeedUnits: Record<
|
|||
historyStepSize: 100,
|
||||
},
|
||||
wps: {
|
||||
convert: (wpm: number) => wpm / 60,
|
||||
fromWpm: (wpm: number) => wpm / 60,
|
||||
convertWithUnitSuffix: (wpm: number) => {
|
||||
return convertTypingSpeedWithUnitSuffix("wps", wpm);
|
||||
},
|
||||
|
|
@ -32,7 +32,7 @@ const typingSpeedUnits: Record<
|
|||
historyStepSize: 2,
|
||||
},
|
||||
cps: {
|
||||
convert: (wpm: number) => (wpm * 5) / 60,
|
||||
fromWpm: (wpm: number) => (wpm * 5) / 60,
|
||||
convertWithUnitSuffix: (wpm: number) => {
|
||||
return convertTypingSpeedWithUnitSuffix("cps", wpm);
|
||||
},
|
||||
|
|
@ -41,7 +41,7 @@ const typingSpeedUnits: Record<
|
|||
historyStepSize: 5,
|
||||
},
|
||||
wph: {
|
||||
convert: (wpm: number) => wpm * 60,
|
||||
fromWpm: (wpm: number) => wpm * 60,
|
||||
convertWithUnitSuffix: (wpm: number) => {
|
||||
return convertTypingSpeedWithUnitSuffix("wph", wpm);
|
||||
},
|
||||
|
|
@ -62,5 +62,5 @@ function convertTypingSpeedWithUnitSuffix(
|
|||
unit: MonkeyTypes.TypingSpeedUnit,
|
||||
wpm: number
|
||||
): string {
|
||||
return roundTo2(get(unit).convert(wpm)).toFixed(2) + " " + unit;
|
||||
return roundTo2(get(unit).fromWpm(wpm)).toFixed(2) + " " + unit;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue