Skip to content

Commit 6f8b804

Browse files
committed
Merge remote-tracking branch 'origin/main' into ph/txWorkerRedis
2 parents 228640c + a4b8e38 commit 6f8b804

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

src/server/routes/system/queue.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Static, Type } from "@sinclair/typebox";
22
import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { TransactionDB } from "../../../db/transactions/db";
5+
import { getPercentile } from "../../../utils/math";
56
import { MinedTransaction } from "../../../utils/transaction/types";
67
import { MineTransactionQueue } from "../../../worker/queues/mineTransactionQueue";
78
import { SendTransactionQueue } from "../../../worker/queues/sendTransactionQueue";

src/server/routes/transaction/syncRetry.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ export async function syncRetryTransaction(fastify: FastifyInstance) {
117117
await TransactionDB.set(sentTransaction);
118118
await MineTransactionQueue.add({ queueId: sentTransaction.queueId });
119119
await enqueueTransactionWebhook(sentTransaction);
120-
await _reportUsageSuccess(sentTransaction);
121120

122121
reply.status(StatusCodes.OK).send({
123122
result: {

src/tests/math.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { describe, expect, it } from "vitest";
2+
import { getPercentile } from "../utils/math";
3+
4+
describe("getPercentile", () => {
5+
it("should correctly calculate the p50 (median) of a sorted array", () => {
6+
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
7+
expect(getPercentile(numbers, 50)).toBe(5);
8+
});
9+
10+
it("should correctly calculate the p90 of a sorted array", () => {
11+
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
12+
expect(getPercentile(numbers, 90)).toBe(9);
13+
});
14+
15+
it("should handle arrays with even number of elements", () => {
16+
const numbers = [10, 20, 30, 40, 50, 60, 70, 80];
17+
expect(getPercentile(numbers, 50)).toBe(40);
18+
});
19+
20+
it("should handle single element array", () => {
21+
const numbers = [1];
22+
expect(getPercentile(numbers, 50)).toBe(1);
23+
});
24+
25+
it("should handle empty array", () => {
26+
const numbers: number[] = [];
27+
expect(getPercentile(numbers, 50)).toBe(0);
28+
});
29+
});

src/utils/math.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const getPercentile = (arr: number[], percentile: number): number => {
2+
if (arr.length === 0) {
3+
return 0;
4+
}
5+
6+
arr.sort((a, b) => a - b);
7+
const index = Math.floor((percentile / 100) * (arr.length - 1));
8+
return arr[index];
9+
};

0 commit comments

Comments
 (0)