Skip to content

Commit 0357168

Browse files
committed
add refactoring
1 parent 762a9fe commit 0357168

14 files changed

Lines changed: 184 additions & 75 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "svelte-starter",
2+
"name": "formulacode-www",
33
"version": "5.15.1",
44
"scripts": {
55
"deleteImgs": "node tasks/deleteNonAnimalImgs.js",

src/actions/keepWithinBox.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ function getXY(node) {
55
.map((d) => +d.replace(/[^0-9.]/g, ""));
66
}
77

8-
// TODO top and bottom
8+
// TODO: Top and bottom bounds not implemented - currently only handles left/right edges
9+
// This is sufficient for current use case (horizontal scroll positioning)
10+
// If vertical bounds are needed, add similar logic for top/bottom edges
911
export default function keepWithinBox(node, params = {}) {
1012
function check({ width }) {
1113
const { top, left, right, bottom } = node.getBoundingClientRect();

src/components/AgentAdvantageTable.svelte

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { onMount } from "svelte";
33
import { browser } from "$app/environment";
44
import { bigScatterData } from "$stores/misc.js";
5+
import { LEVEL_DISPLAY_LABELS, LEVEL_ORDER, CELL_NEUTRAL_RANGE } from "$utils/constants.js";
56
67
// Lazy-load grid only in browser to avoid SSR 'document' errors
78
let GridComponent = null;
@@ -12,15 +13,9 @@
1213
}
1314
});
1415
15-
// Map of level names for display
16-
const levelLabels = {
17-
"param-level": "Level 0: Params",
18-
"func-level": "Level 1: Functions",
19-
"class-level": "Level 2: Classes",
20-
"module-level": "Level 3: Modules"
21-
};
22-
23-
const levelOrder = ["param-level", "func-level", "class-level", "module-level"];
16+
// Use centralized level labels and order
17+
const levelLabels = LEVEL_DISPLAY_LABELS;
18+
const levelOrder = LEVEL_ORDER;
2419
2520
// Helper to calculate median
2621
function calculateMedian(values) {
@@ -45,7 +40,7 @@
4540
return 'cell-neutral';
4641
}
4742
const numValue = parseFloat(value);
48-
if (numValue >= 0.95 && numValue <= 1.05) {
43+
if (numValue >= CELL_NEUTRAL_RANGE.MIN && numValue <= CELL_NEUTRAL_RANGE.MAX) {
4944
return 'cell-neutral';
5045
}
5146
if (numValue < 1.00) {
@@ -151,16 +146,16 @@
151146
152147
/* wx-svelte-grid custom theme */
153148
.advantage-table-wrapper :global(.wx-grid) {
154-
--wx-background: #181a1f;
155-
--wx-color: #CFCABF;
149+
--wx-background: var(--wine-black);
150+
--wx-color: var(--wine-tan);
156151
--wx-border: #3a3d45;
157152
--wx-font-family: var(--sans);
158153
font-size: 16px;
159154
}
160155
161156
.advantage-table-wrapper :global(.wx-header) {
162157
background: #2a2d35;
163-
color: #CFCABF;
158+
color: var(--wine-tan);
164159
font-weight: 700;
165160
}
166161
@@ -174,16 +169,16 @@
174169
175170
/* Cell styling based on value */
176171
.advantage-table-wrapper :global(.cell-neutral) {
177-
background-color: rgba(207, 202, 191, 0.05);
178-
color: #CFCABF;
172+
background-color: var(--wine-tan-transparent);
173+
color: var(--wine-tan);
179174
padding: 0.25rem 0.5rem;
180175
border-radius: 3px;
181176
display: inline-block;
182177
}
183178
184179
.advantage-table-wrapper :global(.cell-negative) {
185180
background-color: rgba(232, 69, 69, 0.15);
186-
color: #e84545;
181+
color: var(--score-bad);
187182
font-weight: 600;
188183
padding: 0.25rem 0.5rem;
189184
border-radius: 3px;
@@ -192,7 +187,7 @@
192187
193188
.advantage-table-wrapper :global(.cell-positive) {
194189
background-color: rgba(15, 157, 88, 0.15);
195-
color: #0f9d58;
190+
color: var(--score-good);
196191
font-weight: 600;
197192
padding: 0.25rem 0.5rem;
198193
border-radius: 3px;
@@ -205,7 +200,7 @@
205200
}
206201
207202
.grid-fallback {
208-
color: #CFCABF;
203+
color: var(--wine-tan);
209204
opacity: 0.7;
210205
padding: 0.5rem 0;
211206
}

src/components/GPTExamples.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { fade } from 'svelte/transition';
33
import Icon from "$components/helpers/Icon.svelte";
44
import { useLazyImage as lazyImage } from 'svelte-lazy-image';
5+
import { SCROLL_STEPS } from "$utils/agents.js";
56
67
export let exampleType;
78
export let scrollIndex;
@@ -48,7 +49,7 @@
4849
{#if exampleType == "correct"}
4950
<div class="example-wrapper">
5051
{#each correctData as example, i}
51-
{#if scrollIndex == 3}
52+
{#if scrollIndex == SCROLL_STEPS.GPT_EXAMPLE_1}
5253
<div class="example" in:fade={{ duration: 250, delay: i * 250 }} out:fade={{duration: 250}}>
5354
<img src={`./assets/images/vivinoLabels/img_${example.img}.png`} alt="Wine label" use:lazyImage />
5455
<div class="correct-icon">
@@ -64,7 +65,7 @@
6465
{:else}
6566
<div class="example-wrapper">
6667
{#each wrongData as example, i}
67-
{#if scrollIndex == 4}
68+
{#if scrollIndex == SCROLL_STEPS.GPT_EXAMPLE_2}
6869
<div class="example" in:fade={{ duration: 250, delay: i * 250 }} out:fade={{duration: 250}}>
6970
<img src={`./assets/images/vivinoLabels/img_${example.img}.png`} alt="Wine label" use:lazyImage />
7071
<div class="wrong-icon">

src/components/Intro.Agents.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script>
22
import { createEventDispatcher, onMount } from "svelte";
33
import { agentSelected, uniqueAgents, agentStats } from "$stores/misc.js";
4+
import { AGENT_NAMES, SCROLL_STEPS } from "$utils/agents.js";
45
import claudeSVG from "$svg/claude.svg";
56
import openaiSVG from "$svg/openai.svg";
67
import humanSVG from "$svg/human.svg";
@@ -14,8 +15,8 @@
1415
if (!str) return "";
1516
const lower = str.toLowerCase();
1617
if (lower === "gpt-5") return "GPT‑5";
17-
if (lower === "claude") return "Claude Sonnet 4.0";
18-
if (lower === "oracle") return "Oracle (Human)";
18+
if (lower === "claude") return AGENT_NAMES["terminus-2,claude"] || "Claude Sonnet 4.0";
19+
if (lower === "oracle") return AGENT_NAMES["terminus-2,oracle"] || "Oracle";
1920
return str.charAt(0).toUpperCase() + str.slice(1);
2021
};
2122
@@ -55,7 +56,7 @@
5556
})
5657
.filter(Boolean);
5758
58-
$: visible = scrollIndex === undefined || scrollIndex <= 1;
59+
$: visible = scrollIndex === undefined || scrollIndex <= SCROLL_STEPS.AGENTS_VISIBLE_UNTIL;
5960
$: selectedId = $agentSelected;
6061
6162
function handleSelect(agent) {

src/components/Intro.CDF.svelte

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { LayerCake, Svg } from "layercake";
33
import { scaleLinear } from "d3-scale";
44
import { agentSelected, bigScatterData } from "$stores/misc.js";
5-
import { AGENT_IDS } from "$utils/agents.js";
5+
import { AGENT_IDS, AGENT_COLORS, AGENT_NAMES_SHORT, SCROLL_STEPS } from "$utils/agents.js";
66
import AxisX from "$components/layercake/AxisX.svg.svelte";
77
import AxisY from "$components/layercake/AxisY.svg.svelte";
88
import CDFLines from "$components/layercake/CDF.svg.svelte";
@@ -15,18 +15,8 @@
1515
// Use the bigScatterData store which contains the full website_data.csv
1616
$: data = $bigScatterData && Array.isArray($bigScatterData) ? $bigScatterData : [];
1717
18-
// Agent colors
19-
const AGENT_COLORS = {
20-
[AGENT_IDS.CLAUDE]: "#F7B956", // wine-gold
21-
[AGENT_IDS.GPT5]: "#4477AA", // category-blue
22-
[AGENT_IDS.HUMAN]: "#66CCEE" // category-cyan
23-
};
24-
25-
const AGENT_NAMES = {
26-
[AGENT_IDS.CLAUDE]: "Claude",
27-
[AGENT_IDS.GPT5]: "GPT-5",
28-
[AGENT_IDS.HUMAN]: "Oracle"
29-
};
18+
// Use centralized agent names (short version for compact display)
19+
const AGENT_NAMES = AGENT_NAMES_SHORT;
3020
3121
// Calculate CDF data for each agent
3222
function calculateCDF(agentId, dataset) {
@@ -82,8 +72,7 @@
8272
$: selectedAgent = $agentSelected;
8373
8474
// Visibility based on scroll position
85-
// Show CDF starting from step 4 (after methodology explanation) through step 5
86-
$: visible = scrollIndex >= 4 && scrollIndex <= 6;
75+
$: visible = scrollIndex >= SCROLL_STEPS.CDF_START && scrollIndex <= SCROLL_STEPS.CDF_END;
8776
$: transform = visible ? 'translate(-50%, -50%) scale(1)' : 'translate(-50%, -50%) scale(0.85)';
8877
$: opacity = visible ? 1 : 0;
8978
$: paddingStyle = `

src/components/PaperHeader.svelte

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import { getContext } from "svelte";
33
import Icon from "$components/helpers/Icon.svelte";
44
import leaderboardData from "$data/leaderboard.json";
5+
import { LEVEL_DISPLAY_LABELS, LEVEL_ORDER } from "$utils/constants.js";
6+
import { formatAdvantage, getCellClass } from "$utils/formatting.js";
57
68
const copy = getContext("copy") || {};
79
const headerCopy = copy.paperHeader || {};
@@ -55,21 +57,12 @@
5557
? abstractConfig.paragraphs
5658
: defaultAbstractParagraphs;
5759
58-
// Hardcoded leaderboard data matching main Leaderboard.svelte structure
60+
// Leaderboard data
5961
const leaderboardTitle = headerCopy.leaderboard.title;
6062
const leaderboardDescription = headerCopy.leaderboard.description;
6163
62-
// Level display labels - matching main Leaderboard
63-
const LEVEL_DISPLAY_LABELS = {
64-
"no-aggregation": "L0: No Aggregation",
65-
"param-level": "L1: Parameter",
66-
"func-level": "L2: Function",
67-
"class-level": "L3: Class",
68-
"module-level": "L4: Module",
69-
};
70-
71-
// Hardcoded levels in order
72-
const levels = ["param-level", "func-level", "class-level", "module-level"];
64+
// Use centralized level order
65+
const levels = LEVEL_ORDER;
7366
7467
// Hardcoded table data - example data, replace with actual values
7568
const tableData = Array.isArray(leaderboardData?.tableData) ? leaderboardData.tableData : [];
@@ -83,19 +76,6 @@
8376
hero?.body ||
8477
(hero?.cta && hero.cta.label)
8578
);
86-
87-
// Helper functions matching main Leaderboard.svelte
88-
function formatAdvantage(value) {
89-
if (value === null || value === undefined) return "";
90-
return value.toFixed(4);
91-
}
92-
93-
function getCellClass(value) {
94-
if (value === null || value === undefined) return "";
95-
if (value >= 0.1) return "high";
96-
if (value >= 0) return "medium";
97-
return "low";
98-
}
9979
</script>
10080
10181
<section class="paper-header">
@@ -431,7 +411,7 @@
431411
}
432412
433413
.header-leaderboard tbody tr:hover {
434-
background: rgba(207, 202, 191, 0.05);
414+
background: var(--wine-tan-transparent);
435415
}
436416
437417
.header-leaderboard td {
@@ -455,20 +435,20 @@
455435
.header-leaderboard .overall-cell {
456436
font-weight: 700;
457437
font-size: var(--16px);
458-
background: rgba(207, 202, 191, 0.05);
438+
background: var(--wine-tan-transparent);
459439
}
460440
461-
/* Color coding for scores - matching main Leaderboard.svelte */
441+
/* Color coding for scores */
462442
.header-leaderboard .score-cell.high {
463-
color: #0f9d58;
443+
color: var(--score-good);
464444
}
465445
466446
.header-leaderboard .score-cell.medium {
467447
color: #d8d8d8;
468448
}
469449
470450
.header-leaderboard .score-cell.low {
471-
color: #e84545;
451+
color: var(--score-bad);
472452
}
473453
474454
.paper-hero {

src/components/SpinningBottle.svelte

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import { createEventDispatcher } from "svelte";
33
import { bottleSelected, animalSelected } from "$stores/misc.js";
44
import viewport from "$stores/viewport.js";
5-
5+
import { SCROLL_STEPS } from "$utils/agents.js";
6+
67
export let bottleIndex;
78
export let wineData;
89
export let bottlePosLeft;
@@ -110,11 +111,11 @@
110111
}
111112
112113
$: transitionDelay = $bottleSelected == false
113-
? (3 - 1 - bottleIndex) * 50
114-
: bottleIndex == 4
115-
? 0
114+
? (3 - 1 - bottleIndex) * 50
115+
: bottleIndex == 4
116+
? 0
116117
: bottleIndex * 50;
117-
$: if (scrollIndex >= 2) { shouldSpin = [true,true,true,true]; }
118+
$: if (scrollIndex >= SCROLL_STEPS.SPINNING_BOTTLE_START) { shouldSpin = [true,true,true,true]; }
118119
$: if (outroVisible == false || outroVisible == undefined) { spin4 = true };
119120
</script>
120121

src/data/results.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"leaderboard": [
3+
{
4+
"id": "1",
5+
"agent": "terminus-2,gpt-5",
6+
"displayName": "GPT-5",
7+
"levels": {
8+
"param-level": 0.1500,
9+
"func-level": 0.1200,
10+
"class-level": 0.0800,
11+
"module-level": 0.0500
12+
},
13+
"overall": 0.1000
14+
},
15+
{
16+
"id": "2",
17+
"agent": "terminus-2,claude",
18+
"displayName": "Claude Sonnet 4.0",
19+
"levels": {
20+
"param-level": 0.1300,
21+
"func-level": 0.1000,
22+
"class-level": 0.0600,
23+
"module-level": 0.0300
24+
},
25+
"overall": 0.0800
26+
},
27+
{
28+
"id": "3",
29+
"agent": "terminus-2,oracle",
30+
"displayName": "Oracle (Human)",
31+
"levels": {
32+
"param-level": 0.2500,
33+
"func-level": 0.2200,
34+
"class-level": 0.1800,
35+
"module-level": 0.1500
36+
},
37+
"overall": 0.2000
38+
}
39+
],
40+
"colorThresholds": {
41+
"high": 0.1,
42+
"medium": 0
43+
}
44+
}

src/styles/variables.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
--wine-blue: #38425D;
1111
--wine--light-blue: #475171;
1212
--wine-tan: #CFCABF;
13+
--wine-tan-transparent: rgba(207, 202, 191, 0.05);
1314
--wine-dark-tan: #9A968E;
1415
--wine-red: #7b0439;
1516
--wine-gold: #F7B956;
1617
--wine-dark-gold: #e7a53b;
1718
--wine-green: #3E5C4B;
19+
--score-good: #0f9d58;
20+
--score-bad: #e84545;
1821
--category-blue: #4477AA;
1922
--category-red: #EE6677;
2023
--category-green: #228833;

0 commit comments

Comments
 (0)