Skip to content

Commit 980c512

Browse files
committed
Minor refactoring
1 parent c47d002 commit 980c512

8 files changed

+34
-34
lines changed

src/models.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export interface TradingState {
8888
observations: Observation;
8989
}
9090

91-
export interface SandboxLogRow {
91+
export interface AlgorithmDataRow {
9292
state: TradingState;
9393
orders: Record<ProsperitySymbol, Order[]>;
9494
conversions: number;
@@ -100,7 +100,7 @@ export interface SandboxLogRow {
100100
export interface Algorithm {
101101
summary?: AlgorithmSummary;
102102
activityLogs: ActivityLogRow[];
103-
sandboxLogs: SandboxLogRow[];
103+
data: AlgorithmDataRow[];
104104
}
105105

106106
export type CompressedListing = [symbol: ProsperitySymbol, product: Product, denomination: Product];
@@ -144,7 +144,7 @@ export type CompressedTradingState = [
144144

145145
export type CompressedOrder = [symbol: ProsperitySymbol, price: number, quantity: number];
146146

147-
export type CompressedSandboxLogRow = [
147+
export type CompressedAlgorithmDataRow = [
148148
state: CompressedTradingState,
149149
orders: CompressedOrder[],
150150
conversions: number,

src/pages/visualizer/OrdersTable.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Table } from '@mantine/core';
22
import { ReactNode } from 'react';
3-
import { SandboxLogRow } from '../../models.ts';
3+
import { AlgorithmDataRow } from '../../models.ts';
44
import { getAskColor, getBidColor } from '../../utils/colors.ts';
55
import { formatNumber } from '../../utils/format.ts';
66
import { SimpleTable } from './SimpleTable.tsx';
77

88
export interface OrdersTableProps {
9-
orders: SandboxLogRow['orders'];
9+
orders: AlgorithmDataRow['orders'];
1010
}
1111

1212
export function OrdersTable({ orders }: OrdersTableProps): ReactNode {

src/pages/visualizer/PositionChart.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ function getLimit(algorithm: Algorithm, symbol: ProsperitySymbol): number {
1717
// This code will be hit when a new product is added to the competition and the visualizer isn't updated yet
1818
// In that case the visualizer doesn't know the real limit yet, so we make a guess based on the algorithm's positions
1919

20-
const product = algorithm.sandboxLogs[0].state.listings[symbol].product;
20+
const product = algorithm.data[0].state.listings[symbol].product;
2121

22-
const positions = algorithm.sandboxLogs.map(row => row.state.position[product] || 0);
22+
const positions = algorithm.data.map(row => row.state.position[product] || 0);
2323
const minPosition = Math.min(...positions);
2424
const maxPosition = Math.max(...positions);
2525

@@ -29,7 +29,7 @@ function getLimit(algorithm: Algorithm, symbol: ProsperitySymbol): number {
2929
export function PositionChart(): ReactNode {
3030
const algorithm = useStore(state => state.algorithm)!;
3131

32-
const symbols = Object.keys(algorithm.sandboxLogs[0].state.listings).sort((a, b) => a.localeCompare(b));
32+
const symbols = Object.keys(algorithm.data[0].state.listings).sort((a, b) => a.localeCompare(b));
3333

3434
const limits: Record<string, number> = {};
3535
for (const symbol of symbols) {
@@ -41,7 +41,7 @@ export function PositionChart(): ReactNode {
4141
data[symbol] = [];
4242
}
4343

44-
for (const row of algorithm.sandboxLogs) {
44+
for (const row of algorithm.data) {
4545
for (const symbol of symbols) {
4646
const position = row.state.position[symbol] || 0;
4747
data[symbol].push([row.state.timestamp, (position / limits[symbol]) * 100]);

src/pages/visualizer/ProfitLossChart.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function ProfitLossChart(): ReactNode {
2323
},
2424
];
2525

26-
Object.keys(algorithm.sandboxLogs[0].state.listings)
26+
Object.keys(algorithm.data[0].state.listings)
2727
.sort((a, b) => a.localeCompare(b))
2828
.forEach(symbol => {
2929
const data = [];

src/pages/visualizer/SandboxLogDetail.tsx src/pages/visualizer/TimestampDetail.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Grid, Text, Title } from '@mantine/core';
22
import { ReactNode } from 'react';
33
import { ScrollableCodeHighlight } from '../../components/ScrollableCodeHighlight.tsx';
4-
import { SandboxLogRow } from '../../models.ts';
4+
import { AlgorithmDataRow } from '../../models.ts';
55
import { useStore } from '../../store.ts';
66
import { formatNumber } from '../../utils/format.ts';
77
import { ListingsTable } from './ListingsTable.tsx';
@@ -11,13 +11,13 @@ import { PositionTable } from './PositionTable.tsx';
1111
import { ProfitLossTable } from './ProfitLossTable.tsx';
1212
import { TradesTable } from './TradesTable.tsx';
1313

14-
export interface SandboxLogDetailProps {
15-
row: SandboxLogRow;
14+
export interface TimestampDetailProps {
15+
row: AlgorithmDataRow;
1616
}
1717

18-
export function SandboxLogDetail({
18+
export function TimestampDetail({
1919
row: { state, orders, conversions, traderData, algorithmLogs, sandboxLogs },
20-
}: SandboxLogDetailProps): ReactNode {
20+
}: TimestampDetailProps): ReactNode {
2121
const algorithm = useStore(state => state.algorithm)!;
2222

2323
const profitLoss = algorithm.activityLogs

src/pages/visualizer/SandboxLogsCard.tsx src/pages/visualizer/TimestampsCard.tsx

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { Slider, SliderProps, Text } from '@mantine/core';
22
import { useHotkeys } from '@mantine/hooks';
33
import { ReactNode, useState } from 'react';
4-
import { SandboxLogRow } from '../../models.ts';
4+
import { AlgorithmDataRow } from '../../models.ts';
55
import { useStore } from '../../store.ts';
66
import { formatNumber } from '../../utils/format.ts';
7-
import { SandboxLogDetail } from './SandboxLogDetail.tsx';
7+
import { TimestampDetail } from './TimestampDetail.tsx';
88
import { VisualizerCard } from './VisualizerCard.tsx';
99

10-
export function SandboxLogsCard(): ReactNode {
10+
export function TimestampsCard(): ReactNode {
1111
const algorithm = useStore(state => state.algorithm)!;
1212

13-
const rowsByTimestamp: Record<number, SandboxLogRow> = {};
14-
for (const row of algorithm.sandboxLogs) {
13+
const rowsByTimestamp: Record<number, AlgorithmDataRow> = {};
14+
for (const row of algorithm.data) {
1515
rowsByTimestamp[row.state.timestamp] = row;
1616
}
1717

18-
const timestampMin = algorithm.sandboxLogs[0].state.timestamp;
19-
const timestampMax = algorithm.sandboxLogs[algorithm.sandboxLogs.length - 1].state.timestamp;
20-
const timestampStep = algorithm.sandboxLogs[1].state.timestamp - algorithm.sandboxLogs[0].state.timestamp;
18+
const timestampMin = algorithm.data[0].state.timestamp;
19+
const timestampMax = algorithm.data[algorithm.data.length - 1].state.timestamp;
20+
const timestampStep = algorithm.data[1].state.timestamp - algorithm.data[0].state.timestamp;
2121

2222
const [timestamp, setTimestamp] = useState(timestampMin);
2323

@@ -35,7 +35,7 @@ export function SandboxLogsCard(): ReactNode {
3535
]);
3636

3737
return (
38-
<VisualizerCard title="Sandbox logs">
38+
<VisualizerCard title="Timestamps">
3939
<Slider
4040
min={timestampMin}
4141
max={timestampMax}
@@ -48,7 +48,7 @@ export function SandboxLogsCard(): ReactNode {
4848
/>
4949

5050
{rowsByTimestamp[timestamp] ? (
51-
<SandboxLogDetail row={rowsByTimestamp[timestamp]} />
51+
<TimestampDetail row={rowsByTimestamp[timestamp]} />
5252
) : (
5353
<Text>No logs found for timestamp {formatNumber(timestamp)}</Text>
5454
)}

src/pages/visualizer/VisualizerPage.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { AlgorithmSummaryCard } from './AlgorithmSummaryCard.tsx';
77
import { PositionChart } from './PositionChart.tsx';
88
import { PriceChart } from './PriceChart.tsx';
99
import { ProfitLossChart } from './ProfitLossChart.tsx';
10-
import { SandboxLogsCard } from './SandboxLogsCard.tsx';
10+
import { TimestampsCard } from './TimestampsCard.tsx';
1111
import { VisualizerCard } from './VisualizerCard.tsx';
1212
import { VolumeChart } from './VolumeChart.tsx';
1313

@@ -27,7 +27,7 @@ export function VisualizerPage(): ReactNode {
2727
}
2828

2929
const symbolColumns: ReactNode[] = [];
30-
Object.keys(algorithm.sandboxLogs[0].state.listings)
30+
Object.keys(algorithm.data[0].state.listings)
3131
.sort((a, b) => a.localeCompare(b))
3232
.forEach((symbol, i) => {
3333
symbolColumns.push(
@@ -61,7 +61,7 @@ export function VisualizerPage(): ReactNode {
6161
</Grid.Col>
6262
{symbolColumns}
6363
<Grid.Col span={12}>
64-
<SandboxLogsCard />
64+
<TimestampsCard />
6565
</Grid.Col>
6666
{algorithm.summary && (
6767
<Grid.Col span={12}>

src/utils/algorithm.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {
22
ActivityLogRow,
33
Algorithm,
4+
AlgorithmDataRow,
45
AlgorithmSummary,
6+
CompressedAlgorithmDataRow,
57
CompressedListing,
68
CompressedObservations,
79
CompressedOrder,
810
CompressedOrderDepth,
9-
CompressedSandboxLogRow,
1011
CompressedTrade,
1112
CompressedTradingState,
1213
ConversionObservation,
@@ -16,7 +17,6 @@ import {
1617
OrderDepth,
1718
Product,
1819
ProsperitySymbol,
19-
SandboxLogRow,
2020
Trade,
2121
TradingState,
2222
} from '../models.ts';
@@ -172,7 +172,7 @@ function decompressOrders(compressed: CompressedOrder[]): Record<ProsperitySymbo
172172
return orders;
173173
}
174174

175-
function decompressSandboxLogRow(compressed: CompressedSandboxLogRow, sandboxLogs: string): SandboxLogRow {
175+
function decompressSandboxLogRow(compressed: CompressedAlgorithmDataRow, sandboxLogs: string): AlgorithmDataRow {
176176
return {
177177
state: decompressState(compressed[0]),
178178
orders: decompressOrders(compressed[1]),
@@ -183,13 +183,13 @@ function decompressSandboxLogRow(compressed: CompressedSandboxLogRow, sandboxLog
183183
};
184184
}
185185

186-
function getSandboxLogs(logLines: string[]): SandboxLogRow[] {
186+
function getSandboxLogs(logLines: string[]): AlgorithmDataRow[] {
187187
const headerIndex = logLines.indexOf('Sandbox logs:');
188188
if (headerIndex === -1) {
189189
return [];
190190
}
191191

192-
const rows: SandboxLogRow[] = [];
192+
const rows: AlgorithmDataRow[] = [];
193193
let nextSandboxLogs = '';
194194

195195
const sandboxLogPrefix = ' "sandboxLog": ';
@@ -239,7 +239,7 @@ export function parseAlgorithmLogs(logs: string, summary?: AlgorithmSummary): Al
239239
return {
240240
summary,
241241
activityLogs,
242-
sandboxLogs,
242+
data: sandboxLogs,
243243
};
244244
}
245245

0 commit comments

Comments
 (0)