From 0dea655f68f23bcb821cc0b37fed202d8d8be984 Mon Sep 17 00:00:00 2001 From: Huarch Date: Sat, 13 Jun 2026 13:07:16 +0800 Subject: [PATCH] refactor(frontend): normalize naming conventions --- AGENTS.md | 2 +- FRONTEND_NAMING_AUDIT.md | 56 +++++++++++++++++++ ...{_refine_context.tsx => RefineContext.tsx} | 0 src/app/layout.tsx | 2 +- src/components/chat/AgentTurn.tsx | 2 +- src/components/chat/GlobalChatbox.tsx | 6 +- ...atbox.parts.tsx => GlobalChatboxParts.tsx} | 0 src/components/chat/chatStorage.ts | 2 +- ...ils.test.ts => globalChatboxUtils.test.ts} | 2 +- ...Chatbox.utils.ts => globalChatboxUtils.ts} | 0 ...Chatbox.voice.ts => globalChatboxVoice.ts} | 0 .../chat/hooks/agentChatSessionState.ts | 2 +- .../chat/hooks/useAgentChatSession.test.tsx | 2 - .../chat/hooks/useAgentChatSession.ts | 2 +- .../BurstDetection/AnalysisParameters.tsx | 2 +- .../BurstLocation/AnalysisParameters.tsx | 2 +- .../BurstSimulation/AnalysisParameters.tsx | 2 +- .../olmap/BurstSimulation/SchemeQuery.tsx | 2 +- .../olmap/BurstSimulation/ValveIsolation.tsx | 2 +- .../AnalysisParameters.tsx | 2 +- .../ContaminantSimulation/SchemeQuery.tsx | 2 +- .../FlushingAnalysis/AnalysisParameters.tsx | 2 +- .../olmap/FlushingAnalysis/SchemeQuery.tsx | 2 +- .../OptimizationParameters.tsx | 2 +- .../SchemeQuery.tsx | 2 +- .../olmap/core/Controls/Timeline.tsx | 2 +- .../olmap/core/Controls/styleEditorUtils.ts | 2 +- .../olmap/core/Controls/useStyleEditor.ts | 2 +- src/contexts/ProjectContext.tsx | 4 +- ...ssification.ts => breaksClassification.ts} | 10 ++-- 30 files changed, 87 insertions(+), 33 deletions(-) create mode 100644 FRONTEND_NAMING_AUDIT.md rename src/app/{_refine_context.tsx => RefineContext.tsx} (100%) rename src/components/chat/{GlobalChatbox.parts.tsx => GlobalChatboxParts.tsx} (100%) rename src/components/chat/{GlobalChatbox.utils.test.ts => globalChatboxUtils.test.ts} (94%) rename src/components/chat/{GlobalChatbox.utils.ts => globalChatboxUtils.ts} (100%) rename src/components/chat/{GlobalChatbox.voice.ts => globalChatboxVoice.ts} (100%) delete mode 100644 src/components/chat/hooks/useAgentChatSession.test.tsx rename src/utils/{breaks_classification.ts => breaksClassification.ts} (92%) diff --git a/AGENTS.md b/AGENTS.md index a0cfc22..96c9bcc 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -24,7 +24,7 @@ npm run start ## Coding Style & Naming Conventions -Use TypeScript and React function components. Follow ESLint and Next.js conventions. Use `PascalCase` for components, `camelCase` for variables/functions, and descriptive feature-oriented filenames. Prefer MUI components and existing design tokens/patterns for UI. Keep operational screens dense, clear, and task-focused. +Use TypeScript and React function components. Follow ESLint and Next.js conventions. Use `PascalCase` for React component files and component names. Use `camelCase` for ordinary TypeScript modules, hooks, stores, providers, utilities, variables, and functions. Next.js route directories under `src/app` use `kebab-case`; route groups and dynamic segments keep the Next.js syntax such as `(main)` and `[...nextauth]`. Keep backend/Agent boundary fields and query parameters in the shape required by the API, typically `snake_case`, and do not translate third-party SDK fields. Prefer MUI components and existing design tokens/patterns for UI. Keep operational screens dense, clear, and task-focused. ## Testing Guidelines diff --git a/FRONTEND_NAMING_AUDIT.md b/FRONTEND_NAMING_AUDIT.md new file mode 100644 index 0000000..7aabb4f --- /dev/null +++ b/FRONTEND_NAMING_AUDIT.md @@ -0,0 +1,56 @@ +# Frontend Naming Audit + +DOC-004 audit for the internal `TJWaterFrontend_Refine` application. + +## Local frontend naming + +- Next.js route directories under `src/app` are already `kebab-case`: `audit-logs`, `health-risk-analysis`, `hydraulic-simulation`, `monitoring-place-optimization`, `network-simulation`, `scada-data-cleaning`, and `system-admin`. +- Route groups and dynamic segments keep Next.js syntax: `(main)` and `[...nextauth]`. +- Local ordinary module filenames now use `camelCase`, including `src/utils/breaksClassification.ts`, `src/components/chat/globalChatboxUtils.ts`, and `src/components/chat/globalChatboxVoice.ts`. +- React component files remain `PascalCase.tsx`, including `src/app/RefineContext.tsx`, `src/components/chat/GlobalChatboxParts.tsx`, and domain directories under `src/components/olmap`. + +## API boundary naming + +Frontend request and response boundary fields intentionally keep backend/Agent wire names. Examples include `project_id`, `user_id`, `scheme_name`, `scheme_type`, `start_time`, `end_time`, `session_id`, `request_id`, and `keep_message_count`. + +Current direct API calls mostly use new `kebab-case` URL paths, including: + +- `/api/v1/admin/projects` +- `/api/v1/audit/logs` +- `/api/v1/projects/open` +- `/api/v1/project-info` +- `/api/v1/schemes` +- `/api/v1/sensor-placement-schemes` +- `/api/v1/burst-analysis` +- `/api/v1/valve-isolation-analysis` +- `/api/v1/flushing-analysis` +- `/api/v1/contaminant-simulation` +- `/api/v1/simulations/run-by-date` +- `/api/v1/burst-detection/detect` +- `/api/v1/burst-location/locate` +- `/api/v1/scada/by-ids-field-time-range` +- `/api/v1/composite/clean-scada` +- `/api/v1/agent/chat/render-ref/{render_ref}` + +## Legacy URL inventory + +The frontend no longer calls these active legacy URLs directly. The backend still exposes them as deprecated compatibility aliases: + +| Current frontend URL | Files | Suggested target | +| --- | --- | --- | +| `/api/v1/openproject/` | `src/contexts/ProjectContext.tsx` | `/api/v1/projects/open` or `/api/v1/project/open` | +| `/api/v1/project_info/` | `src/contexts/ProjectContext.tsx` | `/api/v1/project-info` | +| `/api/v1/getallschemes/` | burst, burst simulation, contaminant, flushing scheme query components | `/api/v1/schemes` | +| `/api/v1/getallsensorplacements/` | `src/components/olmap/MonitoringPlaceOptimization/SchemeQuery.tsx` | `/api/v1/sensor-placement-schemes` | +| `/api/v1/sensorplacementscheme/create` | `src/components/olmap/MonitoringPlaceOptimization/OptimizationParameters.tsx` | `/api/v1/sensor-placement-schemes` | +| `/api/v1/burst_analysis/` | `src/components/olmap/BurstSimulation/AnalysisParameters.tsx` | `/api/v1/burst-analysis` | +| `/api/v1/valve_isolation_analysis/` | `src/components/olmap/BurstSimulation/ValveIsolation.tsx` | `/api/v1/valve-isolation-analysis` | +| `/api/v1/flushing_analysis/` | `src/components/olmap/FlushingAnalysis/AnalysisParameters.tsx` | `/api/v1/flushing-analysis` | +| `/api/v1/contaminant_simulation/` | `src/components/olmap/ContaminantSimulation/AnalysisParameters.tsx` | `/api/v1/contaminant-simulation` | +| `/api/v1/runsimulationmanuallybydate/` | `src/components/olmap/core/Controls/Timeline.tsx` | `/api/v1/simulations/run-by-date` | + +Already migrated frontend code leaves comments showing older pre-`/api/v1` URLs in `src/components/olmap/core/Controls/Toolbar.tsx`; those comments are historical only and are not active calls. + +## Follow-up + +Continue tracking broad passive legacy backend routes under the shared legacy API compatibility strategy. diff --git a/src/app/_refine_context.tsx b/src/app/RefineContext.tsx similarity index 100% rename from src/app/_refine_context.tsx rename to src/app/RefineContext.tsx diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 292a454..9cfb22c 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,7 +1,7 @@ import type { Metadata } from "next"; import { cookies } from "next/headers"; import React, { Suspense } from "react"; -import { RefineContext } from "./_refine_context"; +import { RefineContext } from "./RefineContext"; import { META_DATA } from "@config/config"; export const metadata: Metadata = META_DATA; diff --git a/src/components/chat/AgentTurn.tsx b/src/components/chat/AgentTurn.tsx index 4f2a1f8..54b10aa 100644 --- a/src/components/chat/AgentTurn.tsx +++ b/src/components/chat/AgentTurn.tsx @@ -23,7 +23,7 @@ import { type ContentSegment, } from "./chatMessageSections"; import type { Message, SpeechState } from "./GlobalChatbox.types"; -import { stripMarkdown } from "./GlobalChatbox.utils"; +import { stripMarkdown } from "./globalChatboxUtils"; import { AgentProgressTimeline } from "./AgentProgressTimeline"; import { ChartGenerationSkeleton, ChatInlineChart } from "./ChatInlineChart"; import { ChatToolCallBlock } from "./ChatToolCallBlock"; diff --git a/src/components/chat/GlobalChatbox.tsx b/src/components/chat/GlobalChatbox.tsx index ce53b76..eeaae1c 100644 --- a/src/components/chat/GlobalChatbox.tsx +++ b/src/components/chat/GlobalChatbox.tsx @@ -17,10 +17,10 @@ import { AgentComposer, type AgentComposerHandle } from "./AgentComposer"; import { AgentHeader } from "./AgentHeader"; import { AgentHistoryPanel } from "./AgentHistoryPanel"; import { AgentWorkspace } from "./AgentWorkspace"; -import { Blob } from "./GlobalChatbox.parts"; +import { Blob } from "./GlobalChatboxParts"; import type { Props } from "./GlobalChatbox.types"; -import { PRESET_PROMPTS } from "./GlobalChatbox.utils"; -import { useSpeechRecognition, useSpeechSynthesis } from "./GlobalChatbox.voice"; +import { PRESET_PROMPTS } from "./globalChatboxUtils"; +import { useSpeechRecognition, useSpeechSynthesis } from "./globalChatboxVoice"; import { useAgentChatSession } from "./hooks/useAgentChatSession"; import { useAgentToolActions } from "./hooks/useAgentToolActions"; diff --git a/src/components/chat/GlobalChatbox.parts.tsx b/src/components/chat/GlobalChatboxParts.tsx similarity index 100% rename from src/components/chat/GlobalChatbox.parts.tsx rename to src/components/chat/GlobalChatboxParts.tsx diff --git a/src/components/chat/chatStorage.ts b/src/components/chat/chatStorage.ts index 675bb0a..c9b5c86 100644 --- a/src/components/chat/chatStorage.ts +++ b/src/components/chat/chatStorage.ts @@ -6,7 +6,7 @@ import type { LoadedChatState, Message, } from "./GlobalChatbox.types"; -import { cloneMessages } from "./GlobalChatbox.utils"; +import { cloneMessages } from "./globalChatboxUtils"; type BackendSessionPayload = { id?: string; diff --git a/src/components/chat/GlobalChatbox.utils.test.ts b/src/components/chat/globalChatboxUtils.test.ts similarity index 94% rename from src/components/chat/GlobalChatbox.utils.test.ts rename to src/components/chat/globalChatboxUtils.test.ts index 8e89124..c530ab4 100644 --- a/src/components/chat/GlobalChatbox.utils.test.ts +++ b/src/components/chat/globalChatboxUtils.test.ts @@ -1,4 +1,4 @@ -import { cloneMessage } from "./GlobalChatbox.utils"; +import { cloneMessage } from "./globalChatboxUtils"; import type { Message } from "./GlobalChatbox.types"; describe("cloneMessage", () => { diff --git a/src/components/chat/GlobalChatbox.utils.ts b/src/components/chat/globalChatboxUtils.ts similarity index 100% rename from src/components/chat/GlobalChatbox.utils.ts rename to src/components/chat/globalChatboxUtils.ts diff --git a/src/components/chat/GlobalChatbox.voice.ts b/src/components/chat/globalChatboxVoice.ts similarity index 100% rename from src/components/chat/GlobalChatbox.voice.ts rename to src/components/chat/globalChatboxVoice.ts diff --git a/src/components/chat/hooks/agentChatSessionState.ts b/src/components/chat/hooks/agentChatSessionState.ts index 7393b4f..d1edf76 100644 --- a/src/components/chat/hooks/agentChatSessionState.ts +++ b/src/components/chat/hooks/agentChatSessionState.ts @@ -9,7 +9,7 @@ import type { ChatProgress, Message, } from "../GlobalChatbox.types"; -import { createId } from "../GlobalChatbox.utils"; +import { createId } from "../globalChatboxUtils"; export const upsertProgress = ( progress: ChatProgress[] | undefined, diff --git a/src/components/chat/hooks/useAgentChatSession.test.tsx b/src/components/chat/hooks/useAgentChatSession.test.tsx deleted file mode 100644 index 55c7215..0000000 --- a/src/components/chat/hooks/useAgentChatSession.test.tsx +++ /dev/null @@ -1,2 +0,0 @@ -// Tests for useAgentChatSession are split by behavior boundary. -// See useAgentChatSession.lifecycle.test.tsx and useAgentChatSession.actions.test.tsx. diff --git a/src/components/chat/hooks/useAgentChatSession.ts b/src/components/chat/hooks/useAgentChatSession.ts index dbc45c5..71a74e7 100644 --- a/src/components/chat/hooks/useAgentChatSession.ts +++ b/src/components/chat/hooks/useAgentChatSession.ts @@ -5,7 +5,7 @@ import { useCallback, useEffect, useRef, useState } from "react"; import { abortAgentChat, forkAgentChat, rejectAgentQuestion, replyAgentPermission, replyAgentQuestion, resumeAgentChatStream, streamAgentChat } from "@/lib/chatStream"; import type { PermissionReply, StreamEvent } from "@/lib/chatStream"; import type { AgentArtifact, ChatSessionSummary, Message } from "../GlobalChatbox.types"; -import { cloneMessages } from "../GlobalChatbox.utils"; +import { cloneMessages } from "../globalChatboxUtils"; import { createEmptyChatState, deleteChatSession, listChatSessions, loadChatSessionById, updateChatSessionTitle } from "../chatStorage"; import { applyQuestionResponse, cancelRunningTodos, completeRunningProgress, createAssistantMessage, createTodoUpdateFromEvent, createUserMessage, dedupeQuestionsAcrossMessages, finalizeAssistantMessageAfterAbort, normalizeSessionTodos, toPermissionStatus, upsertPermission, upsertProgress, upsertQuestionAcrossMessages } from "./agentChatSessionState"; import type { PromptRunOptions, UseAgentChatSessionOptions } from "./useAgentChatSession.types"; diff --git a/src/components/olmap/BurstDetection/AnalysisParameters.tsx b/src/components/olmap/BurstDetection/AnalysisParameters.tsx index d7c763c..2b0efba 100644 --- a/src/components/olmap/BurstDetection/AnalysisParameters.tsx +++ b/src/components/olmap/BurstDetection/AnalysisParameters.tsx @@ -73,7 +73,7 @@ const AnalysisParameters: React.FC = ({ onResult }) => { setSchemeLoading(true); try { - const response = await api.get(`${config.BACKEND_URL}/api/v1/getallschemes/`, { + const response = await api.get(`${config.BACKEND_URL}/api/v1/schemes`, { params: { network: NETWORK_NAME }, }); const burstSchemes = (response.data as SchemeItem[]).filter( diff --git a/src/components/olmap/BurstLocation/AnalysisParameters.tsx b/src/components/olmap/BurstLocation/AnalysisParameters.tsx index d721187..7223617 100644 --- a/src/components/olmap/BurstLocation/AnalysisParameters.tsx +++ b/src/components/olmap/BurstLocation/AnalysisParameters.tsx @@ -80,7 +80,7 @@ const AnalysisParameters: React.FC = ({ onResult }) => { setSchemeLoading(true); try { - const response = await api.get(`${config.BACKEND_URL}/api/v1/getallschemes/`, { + const response = await api.get(`${config.BACKEND_URL}/api/v1/schemes`, { params: { network: NETWORK_NAME }, }); const burstSchemes = (response.data as SchemeItem[]).filter( diff --git a/src/components/olmap/BurstSimulation/AnalysisParameters.tsx b/src/components/olmap/BurstSimulation/AnalysisParameters.tsx index b39756a..c2b6fe5 100644 --- a/src/components/olmap/BurstSimulation/AnalysisParameters.tsx +++ b/src/components/olmap/BurstSimulation/AnalysisParameters.tsx @@ -280,7 +280,7 @@ const AnalysisParameters: React.FC = () => { }; try { - await api.get(`${config.BACKEND_URL}/api/v1/burst_analysis/`, { + await api.get(`${config.BACKEND_URL}/api/v1/burst-analysis`, { params, paramsSerializer: { indexes: null, // 移除数组索引,即由 burst_ID[] 变为 burst_ID diff --git a/src/components/olmap/BurstSimulation/SchemeQuery.tsx b/src/components/olmap/BurstSimulation/SchemeQuery.tsx index 22915e6..81087c1 100644 --- a/src/components/olmap/BurstSimulation/SchemeQuery.tsx +++ b/src/components/olmap/BurstSimulation/SchemeQuery.tsx @@ -110,7 +110,7 @@ const SchemeQuery: React.FC = ({ setLoading(true); try { const response = await api.get( - `${config.BACKEND_URL}/api/v1/getallschemes/?network=${network}`, + `${config.BACKEND_URL}/api/v1/schemes?network=${network}`, ); let filteredResults = response.data; diff --git a/src/components/olmap/BurstSimulation/ValveIsolation.tsx b/src/components/olmap/BurstSimulation/ValveIsolation.tsx index b4985a8..3e58e18 100644 --- a/src/components/olmap/BurstSimulation/ValveIsolation.tsx +++ b/src/components/olmap/BurstSimulation/ValveIsolation.tsx @@ -271,7 +271,7 @@ const ValveIsolation: React.FC = ({ params.disabled_valves = disabled; } const response = await api.get( - `${config.BACKEND_URL}/api/v1/valve_isolation_analysis/`, + `${config.BACKEND_URL}/api/v1/valve-isolation-analysis`, { params, paramsSerializer: { diff --git a/src/components/olmap/ContaminantSimulation/AnalysisParameters.tsx b/src/components/olmap/ContaminantSimulation/AnalysisParameters.tsx index 66f95ea..d47deba 100644 --- a/src/components/olmap/ContaminantSimulation/AnalysisParameters.tsx +++ b/src/components/olmap/ContaminantSimulation/AnalysisParameters.tsx @@ -189,7 +189,7 @@ const AnalysisParameters: React.FC = () => { scheme_name: schemeName, }; - await api.get(`${config.BACKEND_URL}/api/v1/contaminant_simulation/`, { + await api.get(`${config.BACKEND_URL}/api/v1/contaminant-simulation`, { params, }); diff --git a/src/components/olmap/ContaminantSimulation/SchemeQuery.tsx b/src/components/olmap/ContaminantSimulation/SchemeQuery.tsx index faec59a..c4eca7b 100644 --- a/src/components/olmap/ContaminantSimulation/SchemeQuery.tsx +++ b/src/components/olmap/ContaminantSimulation/SchemeQuery.tsx @@ -181,7 +181,7 @@ const SchemeQuery: React.FC = ({ setLoading(true); try { const response = await api.get( - `${config.BACKEND_URL}/api/v1/getallschemes/?network=${network}`, + `${config.BACKEND_URL}/api/v1/schemes?network=${network}`, ); let filteredResults = response.data; diff --git a/src/components/olmap/FlushingAnalysis/AnalysisParameters.tsx b/src/components/olmap/FlushingAnalysis/AnalysisParameters.tsx index 9dbeb1b..fd5a2f9 100644 --- a/src/components/olmap/FlushingAnalysis/AnalysisParameters.tsx +++ b/src/components/olmap/FlushingAnalysis/AnalysisParameters.tsx @@ -242,7 +242,7 @@ const AnalysisParameters: React.FC = () => { // but axios usually handles array as valves[]=1&valves[]=2 // FastAPI default expects repeated query params. - const response = await api.get(`${config.BACKEND_URL}/api/v1/flushing_analysis/`, { + const response = await api.get(`${config.BACKEND_URL}/api/v1/flushing-analysis`, { params, // Ensure arrays are sent as repeated keys: valves=1&valves=2 paramsSerializer: { diff --git a/src/components/olmap/FlushingAnalysis/SchemeQuery.tsx b/src/components/olmap/FlushingAnalysis/SchemeQuery.tsx index fc56bf8..fb1aea3 100644 --- a/src/components/olmap/FlushingAnalysis/SchemeQuery.tsx +++ b/src/components/olmap/FlushingAnalysis/SchemeQuery.tsx @@ -222,7 +222,7 @@ const SchemeQuery: React.FC = ({ setLoading(true); try { const response = await api.get( - `${config.BACKEND_URL}/api/v1/getallschemes/?network=${network}`, + `${config.BACKEND_URL}/api/v1/schemes?network=${network}`, ); let filteredResults = response.data; diff --git a/src/components/olmap/MonitoringPlaceOptimization/OptimizationParameters.tsx b/src/components/olmap/MonitoringPlaceOptimization/OptimizationParameters.tsx index 3e75c1a..962ddb2 100644 --- a/src/components/olmap/MonitoringPlaceOptimization/OptimizationParameters.tsx +++ b/src/components/olmap/MonitoringPlaceOptimization/OptimizationParameters.tsx @@ -94,7 +94,7 @@ const OptimizationParameters: React.FC = () => { try { // 发送优化请求 const response = await api.post( - `${config.BACKEND_URL}/api/v1/sensorplacementscheme/create`, + `${config.BACKEND_URL}/api/v1/sensor-placement-schemes`, null, { params: { diff --git a/src/components/olmap/MonitoringPlaceOptimization/SchemeQuery.tsx b/src/components/olmap/MonitoringPlaceOptimization/SchemeQuery.tsx index da9899c..cab5d67 100644 --- a/src/components/olmap/MonitoringPlaceOptimization/SchemeQuery.tsx +++ b/src/components/olmap/MonitoringPlaceOptimization/SchemeQuery.tsx @@ -149,7 +149,7 @@ const SchemeQuery: React.FC = ({ setLoading(true); try { const response = await api.get( - `${config.BACKEND_URL}/api/v1/getallsensorplacements/?network=${network}`, + `${config.BACKEND_URL}/api/v1/sensor-placement-schemes?network=${network}`, ); let filteredResults = response.data; diff --git a/src/components/olmap/core/Controls/Timeline.tsx b/src/components/olmap/core/Controls/Timeline.tsx index dcf48de..31ad733 100644 --- a/src/components/olmap/core/Controls/Timeline.tsx +++ b/src/components/olmap/core/Controls/Timeline.tsx @@ -643,7 +643,7 @@ const Timeline: React.FC = ({ }; const response = await apiFetch( - `${config.BACKEND_URL}/api/v1/runsimulationmanuallybydate/`, + `${config.BACKEND_URL}/api/v1/simulations/run-by-date`, { method: "POST", headers: { diff --git a/src/components/olmap/core/Controls/styleEditorUtils.ts b/src/components/olmap/core/Controls/styleEditorUtils.ts index 4e6f24c..0baf15b 100644 --- a/src/components/olmap/core/Controls/styleEditorUtils.ts +++ b/src/components/olmap/core/Controls/styleEditorUtils.ts @@ -1,6 +1,6 @@ import { FlatStyleLike } from "ol/style/flat"; -import { calculateClassification } from "@utils/breaks_classification"; +import { calculateClassification } from "@utils/breaksClassification"; import { parseColor } from "@utils/parseColor"; import { diff --git a/src/components/olmap/core/Controls/useStyleEditor.ts b/src/components/olmap/core/Controls/useStyleEditor.ts index d317cd3..efdd9b4 100644 --- a/src/components/olmap/core/Controls/useStyleEditor.ts +++ b/src/components/olmap/core/Controls/useStyleEditor.ts @@ -31,7 +31,7 @@ import { StyleEditorStateProps, } from "./styleEditorTypes"; import { LegendStyleConfig } from "./StyleLegend"; -import { calculateClassification } from "@utils/breaks_classification"; +import { calculateClassification } from "@utils/breaksClassification"; const UNIT_HEADLOSS_RANGE: [number, number] = [0, 5]; diff --git a/src/contexts/ProjectContext.tsx b/src/contexts/ProjectContext.tsx index ce5660d..4692e8d 100644 --- a/src/contexts/ProjectContext.tsx +++ b/src/contexts/ProjectContext.tsx @@ -53,7 +53,7 @@ export const ProjectProvider: React.FC<{ children: React.ReactNode }> = ({ try { // Open project backend (simulation model) const openResponse = await apiFetch( - `${config.BACKEND_URL}/api/v1/openproject/?network=${net}`, + `${config.BACKEND_URL}/api/v1/projects/open?network=${net}`, { method: "POST", }, @@ -64,7 +64,7 @@ export const ProjectProvider: React.FC<{ children: React.ReactNode }> = ({ // Fetch project metadata const infoResponse = await apiFetch( - `${config.BACKEND_URL}/api/v1/project_info/?network=${net}`, + `${config.BACKEND_URL}/api/v1/project-info?network=${net}`, ); if (!infoResponse.ok) { console.warn( diff --git a/src/utils/breaks_classification.ts b/src/utils/breaksClassification.ts similarity index 92% rename from src/utils/breaks_classification.ts rename to src/utils/breaksClassification.ts index ba98b6e..0e71017 100644 --- a/src/utils/breaks_classification.ts +++ b/src/utils/breaksClassification.ts @@ -50,7 +50,7 @@ function variance(data: number[], start: number, end: number): number { return data.slice(start, end + 1).reduce((sum, val) => sum + (val - mean) ** 2, 0); } -export function jenks_breaks_jenkspy(data: number[], nClasses: number): number[] { +function jenksBreaksJenkspy(data: number[], nClasses: number): number[] { if (data.length === 0) return []; if (nClasses >= data.length) return data.slice().sort((a, b) => a - b); @@ -92,13 +92,13 @@ export function jenks_breaks_jenkspy(data: number[], nClasses: number): number[] return breaks; } -export function jenks_with_stratified_sampling( +function jenksWithStratifiedSampling( data: number[], nClasses: number, sampleSize = 10000 ): number[] { if (data.length <= sampleSize) { - return jenks_breaks_jenkspy(data, nClasses); + return jenksBreaksJenkspy(data, nClasses); } const sortedData = data.slice().sort((a, b) => a - b); @@ -112,7 +112,7 @@ export function jenks_with_stratified_sampling( } } - return jenks_breaks_jenkspy(sampledData, nClasses); + return jenksBreaksJenkspy(sampledData, nClasses); } export function calculateClassification( @@ -129,7 +129,7 @@ export function calculateClassification( } if (classificationMethod === "jenks_optimized") { - return jenks_with_stratified_sampling(data, segments); + return jenksWithStratifiedSampling(data, segments); } return [];