style(web): translate the comments in the src/views directory into English
This commit is contained in:
@@ -1,9 +1,24 @@
|
||||
/*
|
||||
* @Author: ZhaoYing
|
||||
* @Date: 2026-02-03 17:00:20
|
||||
* @Last Modified by: ZhaoYing
|
||||
* @Last Modified time: 2026-02-03 17:00:20
|
||||
*/
|
||||
/**
|
||||
* Line Chart Component
|
||||
* Visualizes forgetting curves based on different configurations
|
||||
* Compares current config with quick/slow forgetting presets
|
||||
*/
|
||||
|
||||
import { type FC, useRef, useEffect, useState, useMemo, useCallback } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import ReactEcharts from 'echarts-for-react';
|
||||
|
||||
import type { ConfigForm } from '../types'
|
||||
|
||||
// 定义当前数据类型
|
||||
/**
|
||||
* Current data item type
|
||||
*/
|
||||
type CurrentDataItem = {
|
||||
name: string;
|
||||
data: number[];
|
||||
@@ -16,7 +31,9 @@ type CurrentDataItem = {
|
||||
emphasis: { focus: string };
|
||||
};
|
||||
|
||||
// 定义图表系列数据类型
|
||||
/**
|
||||
* Chart series data item type
|
||||
*/
|
||||
type SeriesDataItem = {
|
||||
name: string;
|
||||
data: number[];
|
||||
@@ -29,17 +46,26 @@ type SeriesDataItem = {
|
||||
emphasis: { focus: string };
|
||||
};
|
||||
|
||||
// 定义简化的配置类型,只包含图表计算需要的属性
|
||||
/**
|
||||
* Simplified config type for chart calculations
|
||||
*/
|
||||
interface ChartConfig {
|
||||
lambda_mem: number;
|
||||
lambda_time: number;
|
||||
offset: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Component props
|
||||
*/
|
||||
interface LineCardProps {
|
||||
/** Forgetting engine configuration */
|
||||
config: ConfigForm
|
||||
}
|
||||
|
||||
/**
|
||||
* ECharts series configuration
|
||||
*/
|
||||
const SeriesConfig = {
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
@@ -55,10 +81,18 @@ const SeriesConfig = {
|
||||
focus: 'series'
|
||||
},
|
||||
}
|
||||
/**
|
||||
* Chart color palette
|
||||
*/
|
||||
const Colors = ['#155EEF', '#4DA8FF', '#FFB048']
|
||||
|
||||
|
||||
// 快速遗忘:lambda_mem=0.3,lambda_time=1,offset=0.05; 慢速遗忘:lambda_mem=1,lambda_time=0.3,offset=0.2
|
||||
/**
|
||||
* Line chart component for forgetting curves
|
||||
* Formula: R = offset + (1 - offset) × e^(-λ_time × t / λ_mem)
|
||||
* Quick forgetting: λ_mem=0.3, λ_time=1, offset=0.05
|
||||
* Slow forgetting: λ_mem=1, λ_time=0.3, offset=0.2
|
||||
*/
|
||||
const LineChart: FC<LineCardProps> = ({ config }) => {
|
||||
const { t } = useTranslation()
|
||||
const chartRef = useRef<ReactEcharts>(null);
|
||||
@@ -131,8 +165,7 @@ const LineChart: FC<LineCardProps> = ({ config }) => {
|
||||
}
|
||||
}, [config])
|
||||
|
||||
// 快速遗忘:lambda_mem=0.3,lambda_time=1,offset=0.05;
|
||||
// 慢速遗忘:lambda_mem=1,lambda_time=0.3,offset=0.2
|
||||
/** Initialize preset forgetting curves */
|
||||
const getInitData = useCallback(() => {
|
||||
const list = seriesData.map(item => ({
|
||||
...item,
|
||||
@@ -141,6 +174,7 @@ const LineChart: FC<LineCardProps> = ({ config }) => {
|
||||
setInitialData(list)
|
||||
}, [seriesData])
|
||||
|
||||
/** Calculate retention rate for given days and config */
|
||||
const calculateSeriesData = useCallback((days: number, data: ChartConfig | ConfigForm) => {
|
||||
const offset = Number(data.offset)
|
||||
const lambda_time = Number(data.lambda_time)
|
||||
@@ -148,10 +182,12 @@ const LineChart: FC<LineCardProps> = ({ config }) => {
|
||||
// R = offset + (1 - offset) × e^(-λtime × t / (λmem × S))
|
||||
return +(offset + (1 - offset) * Math.exp(-lambda_time * days / lambda_mem)).toFixed(4)
|
||||
}, [])
|
||||
/** Format data for all x-axis points */
|
||||
const formatData = useCallback((data: ChartConfig | ConfigForm) => {
|
||||
return xAxisData.map(days => Number(calculateSeriesData(days, data)))
|
||||
}, [calculateSeriesData])
|
||||
|
||||
/** Calculate current configuration curve data */
|
||||
const getCaculateData = useCallback((data: ConfigForm) => {
|
||||
if (!data) {
|
||||
return
|
||||
|
||||
@@ -1,7 +1,20 @@
|
||||
/*
|
||||
* @Author: ZhaoYing
|
||||
* @Date: 2026-02-03 17:00:12
|
||||
* @Last Modified by: ZhaoYing
|
||||
* @Last Modified time: 2026-02-03 17:00:12
|
||||
*/
|
||||
/**
|
||||
* Forgetting Engine Configuration Page
|
||||
* Configures memory forgetting curve parameters
|
||||
* Uses Ebbinghaus forgetting curve formula: R = offset + (1 - offset) × e^(-λ_time × t / λ_mem)
|
||||
*/
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Row, Col, Form, Slider, Button, Space, message } from 'antd';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import RbCard from '@/components/RbCard/Card';
|
||||
import strategyImpactSimulator from '@/assets/images/memory/strategyImpactSimulator.svg'
|
||||
import LineChart from './components/LineChart'
|
||||
@@ -9,6 +22,9 @@ import { getMemoryForgetConfig, updateMemoryForgetConfig } from '@/api/memory'
|
||||
import type { ConfigForm } from './types'
|
||||
import SwitchFormItem from '@/components/FormItem/SwitchFormItem'
|
||||
|
||||
/**
|
||||
* Configuration field definitions
|
||||
*/
|
||||
const configList = [
|
||||
{
|
||||
key: 'minimumRetention',
|
||||
@@ -82,6 +98,9 @@ const configList = [
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* Forgetting engine configuration component
|
||||
*/
|
||||
const ForgettingEngine: React.FC = () => {
|
||||
const { t } = useTranslation();
|
||||
const { id } = useParams();
|
||||
@@ -96,6 +115,7 @@ const ForgettingEngine: React.FC = () => {
|
||||
getConfigData()
|
||||
}, [])
|
||||
|
||||
/** Fetch forgetting engine configuration */
|
||||
const getConfigData = () => {
|
||||
getMemoryForgetConfig(id as string)
|
||||
.then((res) => {
|
||||
@@ -113,9 +133,11 @@ const ForgettingEngine: React.FC = () => {
|
||||
console.error('Failed to load data');
|
||||
})
|
||||
}
|
||||
/** Reset form to saved configuration */
|
||||
const handleReset = () => {
|
||||
form.setFieldsValue(configData || {});
|
||||
}
|
||||
/** Save forgetting engine configuration */
|
||||
const handleSave = () => {
|
||||
setLoading(true)
|
||||
updateMemoryForgetConfig({
|
||||
|
||||
@@ -1,56 +1,111 @@
|
||||
// 标签表单数据类型
|
||||
/*
|
||||
* @Author: ZhaoYing
|
||||
* @Date: 2026-02-03 17:00:08
|
||||
* @Last Modified by: ZhaoYing
|
||||
* @Last Modified time: 2026-02-03 17:00:08
|
||||
*/
|
||||
/**
|
||||
* Type definitions for Forgetting Engine
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tag form data (legacy, not used in current implementation)
|
||||
*/
|
||||
export interface TagFormData {
|
||||
/** Tag name */
|
||||
tagName: string;
|
||||
/** Tag type */
|
||||
type: string;
|
||||
/** Tag color */
|
||||
color: string;
|
||||
/** Tag description */
|
||||
description?: string;
|
||||
/** Applicable scope */
|
||||
applicableScope?: string[];
|
||||
/** Semantic expansion */
|
||||
semanticExpansion?: string;
|
||||
/** Whether tag is active */
|
||||
isActive?: boolean;
|
||||
// 扩展字段用于区分编辑和新增操作
|
||||
/** Whether in editing mode */
|
||||
isEditing?: boolean;
|
||||
/** Tag ID */
|
||||
tagId?: string;
|
||||
}
|
||||
|
||||
// 记忆总览数据类型
|
||||
/**
|
||||
* Memory overview record (legacy, not used in current implementation)
|
||||
*/
|
||||
export interface MemoryOverviewRecord {
|
||||
/** Record ID */
|
||||
id: number;
|
||||
/** Memory ID */
|
||||
memoryID: string,
|
||||
/** Content summary */
|
||||
contentSummary: string;
|
||||
/** Memory type */
|
||||
type: string;
|
||||
/** Creation time */
|
||||
createTime: string;
|
||||
/** Last call time */
|
||||
lastCallTime: string;
|
||||
/** Retention degree */
|
||||
retentionDegree: string;
|
||||
/** Status */
|
||||
status: string;
|
||||
}
|
||||
// 定义组件暴露的方法接口
|
||||
|
||||
/**
|
||||
* Memory overview form ref interface (legacy)
|
||||
*/
|
||||
export interface MemoryOverviewFormRef {
|
||||
/** Open form with optional record */
|
||||
handleOpen: (memoryOverview?: MemoryOverviewRecord | null) => void;
|
||||
}
|
||||
|
||||
// 遗忘曲线数据类型
|
||||
/**
|
||||
* Forgetting curve record (legacy, not used in current implementation)
|
||||
*/
|
||||
export interface CurveRecord {
|
||||
/** Memory ID */
|
||||
memoryID: string;
|
||||
/** Memory type */
|
||||
type: string;
|
||||
/** Current retention rate */
|
||||
currentRetentionRate: string;
|
||||
/** Finally activated time */
|
||||
finallyActivated: string;
|
||||
/** Expected forgetting time */
|
||||
expectedForgettingTime: string;
|
||||
/** Reinforcement count */
|
||||
reinforcementCount: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forgetting engine configuration form
|
||||
*/
|
||||
export interface ConfigForm {
|
||||
/** Configuration ID */
|
||||
config_id?: string;
|
||||
/** Time decay factor (λ_time) */
|
||||
lambda_time: string | number;
|
||||
/** Memory strength factor (λ_mem) */
|
||||
lambda_mem: string | number;
|
||||
/** Minimum retention offset */
|
||||
offset: string | number;
|
||||
|
||||
/** Decay constant */
|
||||
decay_constant: string | number;
|
||||
/** Maximum history length */
|
||||
max_history_length: string | number;
|
||||
/** Forgetting threshold */
|
||||
forgetting_threshold: string | number;
|
||||
/** Minimum days since last access */
|
||||
min_days_since_access: string | number;
|
||||
/** Whether to enable LLM summary */
|
||||
enable_llm_summary: boolean;
|
||||
/** Maximum merge batch size */
|
||||
max_merge_batch_size: string | number;
|
||||
/** Forgetting interval in hours */
|
||||
forgetting_interval_hours: string | number;
|
||||
|
||||
/** Additional dynamic fields */
|
||||
[key: string]: any;
|
||||
}
|
||||
Reference in New Issue
Block a user