[feat] negodata: 협상 학습 메뉴 신설 — 카드별 학습 성적 · 앵커링 현황/조정 이력

agent(협상카드 강화학습)와 anchoring(구간별 자동 조정)이 쌓아온 결과를 볼 수 있는 화면이
없어 DB 를 직접 열어야 확인이 됐다. 두 축은 성격이 달라 한 화면에 섞지 않고 탭으로 나눈다.

백엔드(읽기 전용 — 값의 주인은 agent·anchoring):
- crud/learning_crud.py: learning·anchoring 스키마 경량 조회(negodata ORM 미매핑 테이블)
- services/learning_service.py + router/v1/learning: /v1/learning/cards · /anchoring

프론트:
- 사이드바 '협상 학습'(/learning) 추가, 탭 = 협상카드 | 앵커링
- 협상카드: 학습 협상·기록·타결 비율 요약 + 카드별 사용/타결/평균 점수(0 기준 좌우 막대)
- 앵커링: 구간별 현재 인하폭 + 조정 이력(표본·성공률·값 변화)

검증: 로컬 실협상 3건으로 데이터 생성 후 두 탭 실화면 확인, tsc·eslint 통과.
This commit is contained in:
minaChoi committed 2026-08-10 13:24:32 +09:00
1 parent 37fa65707f
commit e816bfbba4
28 files changed
+1077 -1

No files matched your search

@@ -0,0 +1,217 @@
/**
* Generated by orval v7.21.0 🍺
* Do not edit manually.
* Negodata Api Server
* OpenAPI spec version: 0.1.0
*/
import {
useQuery
} from '@tanstack/react-query';
import type {
DataTag,
DefinedInitialDataOptions,
DefinedUseQueryResult,
QueryClient,
QueryFunction,
QueryKey,
UndefinedInitialDataOptions,
UseQueryOptions,
UseQueryResult
} from '@tanstack/react-query';
import type {
ResAnchoringStatus,
ResLearningStatus
} from '.././model';
import { customFetch } from '../../mutator/custom-fetch';
type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
/**
* @summary 협상카드 학습 현황
*/
export const getLearningStatus = (
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
) => {
return customFetch<ResLearningStatus>(
{url: `/v1/learning/cards`, method: 'GET', signal
},
options);
}
export const getGetLearningStatusQueryKey = () => {
return [
`/v1/learning/cards`
] as const;
}
export const getGetLearningStatusQueryOptions = <TData = Awaited<ReturnType<typeof getLearningStatus>>, TError = void>( options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getLearningStatus>>, TError, TData>>, request?: SecondParameter<typeof customFetch>}
) => {
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetLearningStatusQueryKey();
const queryFn: QueryFunction<Awaited<ReturnType<typeof getLearningStatus>>> = ({ signal }) => getLearningStatus(requestOptions, signal);
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getLearningStatus>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetLearningStatusQueryResult = NonNullable<Awaited<ReturnType<typeof getLearningStatus>>>
export type GetLearningStatusQueryError = void
export function useGetLearningStatus<TData = Awaited<ReturnType<typeof getLearningStatus>>, TError = void>(
options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getLearningStatus>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getLearningStatus>>,
TError,
Awaited<ReturnType<typeof getLearningStatus>>
> , 'initialData'
>, request?: SecondParameter<typeof customFetch>}
, queryClient?: QueryClient
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetLearningStatus<TData = Awaited<ReturnType<typeof getLearningStatus>>, TError = void>(
options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getLearningStatus>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getLearningStatus>>,
TError,
Awaited<ReturnType<typeof getLearningStatus>>
> , 'initialData'
>, request?: SecondParameter<typeof customFetch>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetLearningStatus<TData = Awaited<ReturnType<typeof getLearningStatus>>, TError = void>(
options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getLearningStatus>>, TError, TData>>, request?: SecondParameter<typeof customFetch>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary 협상카드 학습 현황
*/
export function useGetLearningStatus<TData = Awaited<ReturnType<typeof getLearningStatus>>, TError = void>(
options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getLearningStatus>>, TError, TData>>, request?: SecondParameter<typeof customFetch>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetLearningStatusQueryOptions(options)
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* @summary 앵커링 현황·조정 이력
*/
export const getAnchoringStatus = (
options?: SecondParameter<typeof customFetch>,signal?: AbortSignal
) => {
return customFetch<ResAnchoringStatus>(
{url: `/v1/learning/anchoring`, method: 'GET', signal
},
options);
}
export const getGetAnchoringStatusQueryKey = () => {
return [
`/v1/learning/anchoring`
] as const;
}
export const getGetAnchoringStatusQueryOptions = <TData = Awaited<ReturnType<typeof getAnchoringStatus>>, TError = void>( options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getAnchoringStatus>>, TError, TData>>, request?: SecondParameter<typeof customFetch>}
) => {
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetAnchoringStatusQueryKey();
const queryFn: QueryFunction<Awaited<ReturnType<typeof getAnchoringStatus>>> = ({ signal }) => getAnchoringStatus(requestOptions, signal);
return { queryKey, queryFn, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getAnchoringStatus>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetAnchoringStatusQueryResult = NonNullable<Awaited<ReturnType<typeof getAnchoringStatus>>>
export type GetAnchoringStatusQueryError = void
export function useGetAnchoringStatus<TData = Awaited<ReturnType<typeof getAnchoringStatus>>, TError = void>(
options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getAnchoringStatus>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getAnchoringStatus>>,
TError,
Awaited<ReturnType<typeof getAnchoringStatus>>
> , 'initialData'
>, request?: SecondParameter<typeof customFetch>}
, queryClient?: QueryClient
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetAnchoringStatus<TData = Awaited<ReturnType<typeof getAnchoringStatus>>, TError = void>(
options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getAnchoringStatus>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getAnchoringStatus>>,
TError,
Awaited<ReturnType<typeof getAnchoringStatus>>
> , 'initialData'
>, request?: SecondParameter<typeof customFetch>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetAnchoringStatus<TData = Awaited<ReturnType<typeof getAnchoringStatus>>, TError = void>(
options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getAnchoringStatus>>, TError, TData>>, request?: SecondParameter<typeof customFetch>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary 앵커링 현황·조정 이력
*/
export function useGetAnchoringStatus<TData = Awaited<ReturnType<typeof getAnchoringStatus>>, TError = void>(
options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getAnchoringStatus>>, TError, TData>>, request?: SecondParameter<typeof customFetch>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetAnchoringStatusQueryOptions(options)
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
query.queryKey = queryOptions.queryKey ;
return query;
}
@@ -0,0 +1,15 @@
/**
* Generated by orval v7.21.0 🍺
* Do not edit manually.
* Negodata Api Server
* OpenAPI spec version: 0.1.0
*/
import type { AnchoringCellLastAdjustedAt } from './anchoringCellLastAdjustedAt';
export interface AnchoringCell {
supplier_type?: number;
supplier_type_label?: string;
price_range_index?: number;
anchoring_value?: number;
last_adjusted_at?: AnchoringCellLastAdjustedAt;
}
@@ -0,0 +1,8 @@
/**
* Generated by orval v7.21.0 🍺
* Do not edit manually.
* Negodata Api Server
* OpenAPI spec version: 0.1.0
*/
export type AnchoringCellLastAdjustedAt = string | null;
@@ -0,0 +1,18 @@
/**
* Generated by orval v7.21.0 🍺
* Do not edit manually.
* Negodata Api Server
* OpenAPI spec version: 0.1.0
*/
import type { AnchoringHistoryRowCreatedAt } from './anchoringHistoryRowCreatedAt';
export interface AnchoringHistoryRow {
supplier_type_label?: string;
price_range_index?: number;
value_before?: number;
value_after?: number;
sample_count?: number;
success_count?: number;
success_rate?: number;
created_at?: AnchoringHistoryRowCreatedAt;
}
@@ -0,0 +1,8 @@
/**
* Generated by orval v7.21.0 🍺
* Do not edit manually.
* Negodata Api Server
* OpenAPI spec version: 0.1.0
*/
export type AnchoringHistoryRowCreatedAt = string | null;
@@ -0,0 +1,18 @@
/**
* Generated by orval v7.21.0 🍺
* Do not edit manually.
* Negodata Api Server
* OpenAPI spec version: 0.1.0
*/
import type { CardPerformanceRowName } from './cardPerformanceRowName';
export interface CardPerformanceRow {
number: string;
name?: CardPerformanceRowName;
type?: string;
used_sessions?: number;
uses?: number;
avg_reward?: number;
settled_sessions?: number;
settle_rate?: number;
}
@@ -0,0 +1,8 @@
/**
* Generated by orval v7.21.0 🍺
* Do not edit manually.
* Negodata Api Server
* OpenAPI spec version: 0.1.0
*/
export type CardPerformanceRowName = string | null;
@@ -5,6 +5,10 @@
* OpenAPI spec version: 0.1.0
*/
export * from './anchoringCell';
export * from './anchoringCellLastAdjustedAt';
export * from './anchoringHistoryRow';
export * from './anchoringHistoryRowCreatedAt';
export * from './bodyUploadItemImageV1ItemImagePost';
export * from './cardData';
export * from './cardDataCondition';
@@ -18,6 +22,8 @@ export * from './cardDataScript';
export * from './cardDataTactic';
export * from './cardDataUpdatedAt';
export * from './cardDataUserId';
export * from './cardPerformanceRow';
export * from './cardPerformanceRowName';
export * from './cardStatus';
export * from './cardType';
export * from './cardUsageType';
@@ -77,6 +83,8 @@ export * from './itemDataVatYn';
export * from './itemSupplyType';
export * from './itemSupplyTypeSupplierItemId';
export * from './itemSupplyTypeSupplierName';
export * from './learningKpi';
export * from './learningKpiLastLearnedAt';
export * from './listCardsParams';
export * from './listItemsParams';
export * from './listNotificationsParams';
@@ -274,6 +282,8 @@ export * from './reqUpdateSupplierManagerName';
export * from './reqUpdateSupplierName';
export * from './reqUpdateSupplierTotalRevenue';
export * from './reqUpdateSupplyType';
export * from './resAnchoringStatus';
export * from './resAnchoringStatusMsg';
export * from './resBulkMapByNames';
export * from './resBulkMapByNamesMsg';
export * from './resCard';
@@ -327,6 +337,8 @@ export * from './resItemListMsg';
export * from './resItemMsg';
export * from './resItemSupplyTypeList';
export * from './resItemSupplyTypeListMsg';
export * from './resLearningStatus';
export * from './resLearningStatusMsg';
export * from './resLogin';
export * from './resLoginMsg';
export * from './resLowestPriceResult';
@@ -0,0 +1,15 @@
/**
* Generated by orval v7.21.0 🍺
* Do not edit manually.
* Negodata Api Server
* OpenAPI spec version: 0.1.0
*/
import type { LearningKpiLastLearnedAt } from './learningKpiLastLearnedAt';
export interface LearningKpi {
learned_sessions?: number;
records?: number;
settled_sessions?: number;
settle_rate?: number;
last_learned_at?: LearningKpiLastLearnedAt;
}
@@ -0,0 +1,8 @@
/**
* Generated by orval v7.21.0 🍺
* Do not edit manually.
* Negodata Api Server
* OpenAPI spec version: 0.1.0
*/
export type LearningKpiLastLearnedAt = string | null;
@@ -0,0 +1,18 @@
/**
* Generated by orval v7.21.0 🍺
* Do not edit manually.
* Negodata Api Server
* OpenAPI spec version: 0.1.0
*/
import type { ErrorInfo } from './errorInfo';
import type { ResAnchoringStatusMsg } from './resAnchoringStatusMsg';
import type { AnchoringCell } from './anchoringCell';
import type { AnchoringHistoryRow } from './anchoringHistoryRow';
export interface ResAnchoringStatus {
result?: ErrorInfo;
msg?: ResAnchoringStatusMsg;
cells?: AnchoringCell[];
history?: AnchoringHistoryRow[];
adjusted_count?: number;
}
@@ -0,0 +1,8 @@
/**
* Generated by orval v7.21.0 🍺
* Do not edit manually.
* Negodata Api Server
* OpenAPI spec version: 0.1.0
*/
export type ResAnchoringStatusMsg = string | null;
@@ -0,0 +1,17 @@
/**
* Generated by orval v7.21.0 🍺
* Do not edit manually.
* Negodata Api Server
* OpenAPI spec version: 0.1.0
*/
import type { ErrorInfo } from './errorInfo';
import type { ResLearningStatusMsg } from './resLearningStatusMsg';
import type { LearningKpi } from './learningKpi';
import type { CardPerformanceRow } from './cardPerformanceRow';
export interface ResLearningStatus {
result?: ErrorInfo;
msg?: ResLearningStatusMsg;
kpi?: LearningKpi;
cards?: CardPerformanceRow[];
}
@@ -0,0 +1,8 @@
/**
* Generated by orval v7.21.0 🍺
* Do not edit manually.
* Negodata Api Server
* OpenAPI spec version: 0.1.0
*/
export type ResLearningStatusMsg = string | null;
+2
View File
@@ -5,6 +5,7 @@ import {hasSeenOnboarding} from '../features/onboarding/storage';
import AuthenticatedLayout from '@/components/layout/AuthenticatedLayout';
import LoginPage from '../pages/login';
import DashboardPage from '../pages/dashboard';
import LearningPage from '../pages/learning';
import StatisticsPage from '../pages/statistics';
import ForbiddenPage from '../pages/forbidden';
import DevDesignPage from '../pages/dev-design';
@@ -69,6 +70,7 @@ export const router = createBrowserRouter([
children: [
{path: 'dashboard', Component: DashboardPage},
{path: 'statistics', Component: StatisticsPage},
{path: 'learning', Component: LearningPage},
{path: 'products', Component: ProductsPage},
{path: 'partners', Component: PartnersPage},
{path: 'quotation', Component: QuotationPage},
@@ -7,6 +7,7 @@ import {showToast} from '@/lib/notify';
const PAGE_TO_PATH: Record<PageType, string> = {
DASHBOARD: '/dashboard',
STATISTICS: '/statistics',
LEARNING: '/learning',
PRODUCTS: '/products',
PARTNERS: '/partners',
QUOTATION: '/quotation',
@@ -18,6 +18,7 @@ import {
import {
LayoutDashboard,
BarChart3,
Brain,
Briefcase,
Users,
UserCog,
@@ -56,6 +57,7 @@ const menuGroups: { label?: string; items: MenuItem[] }[] = [
items: [
{ type: 'DASHBOARD', label: '대시보드', icon: LayoutDashboard, id: 'sidebar-dashboard' },
{ type: 'STATISTICS', label: '통계', icon: BarChart3, id: 'sidebar-statistics' },
{ type: 'LEARNING', label: '협상 학습', icon: Brain, id: 'sidebar-learning' },
],
},
{
@@ -96,6 +98,7 @@ const canSee = (item: MenuItem, role?: string): boolean => {
const pageLabelMap: Record<PageType, string> = {
DASHBOARD: '대시보드',
STATISTICS: '통계',
LEARNING: '협상 학습',
PRODUCTS: '상품관리',
PARTNERS: '협력사관리',
QUOTATION: '견적관리',
@@ -0,0 +1,203 @@
import { Bot, CheckCircle2, Layers, Ruler } from 'lucide-react';
import { Panel } from '@/features/statistics/components/Panel';
import { StatTile } from '@/features/statistics/components/StatTile';
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
import { Typography } from '@/components/ui/typography';
import { fmtDateTime } from '@/features/quotations/types';
import type { AnchoringData, LearningData } from './types';
// 협상 학습 현황. 협상카드(강화학습)와 앵커링(자동 조정)은 서로 다른 축이라 탭으로 나눠 각각 한 화면에 담는다.
// 두 값 모두 agent·anchoring 서비스가 쌓은 결과를 읽기만 한다.
export function CardLearningView({ data }: { data: LearningData }) {
const best = data.cards.filter((c) => c.uses > 0);
return (
<div className="space-y-4">
<div className="grid grid-cols-2 gap-3 lg:grid-cols-4">
<StatTile label="학습한 협상" value={`${data.learnedSessions}건`} icon={Bot} tone="purple" />
<StatTile label="학습 기록" value={`${data.records}건`} icon={Layers} tone="blue" />
<StatTile label="타결 협상" value={`${data.settledSessions}건`} icon={CheckCircle2} tone="emerald" />
<StatTile label="타결 비율" value={pct(data.settleRate)} icon={Ruler} tone="amber" />
</div>
<Panel
title="카드별 학습 성적"
subtitle="AI가 협상 결과로 매긴 점수입니다. 점수가 높을수록 그 카드를 쓴 협상이 잘 풀렸다는 뜻입니다."
right={
data.lastLearnedAt ? (
<Typography as="span" variant="small" className="text-[11px] text-muted-foreground">
최근 학습 {fmtDateTime(data.lastLearnedAt)}
</Typography>
) : undefined
}
>
{best.length === 0 ? (
<EmptyRow text="아직 학습된 협상이 없습니다. 협상이 진행되면 카드별 성적이 쌓입니다." />
) : (
<Table className="text-xs">
<TableHeader>
<TableRow>
<TableHead className="w-24">카드번호</TableHead>
<TableHead>카드이름</TableHead>
<TableHead className="w-20 text-center">종류</TableHead>
<TableHead className="w-24 text-right">사용 협상</TableHead>
<TableHead className="w-24 text-right">사용 횟수</TableHead>
<TableHead className="w-24 text-right">타결 비율</TableHead>
<TableHead className="w-28 text-right">평균 점수</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{best.map((c) => (
<TableRow key={c.number}>
<TableCell className="font-mono">{c.number}</TableCell>
<TableCell className="font-medium">{c.name}</TableCell>
<TableCell className="text-center">
<TypeBadge isWild={c.isWild} />
</TableCell>
<TableCell className="text-right">{c.usedSessions}</TableCell>
<TableCell className="text-right">{c.uses}</TableCell>
<TableCell className="text-right">{pct(c.settleRate)}</TableCell>
<TableCell className="text-right">
<RewardBar value={c.avgReward} />
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)}
</Panel>
</div>
);
}
export function AnchoringStatusView({ data }: { data: AnchoringData }) {
const adjusted = data.cells.filter((c) => c.adjustedAt).length;
const avg = data.cells.length
? data.cells.reduce((sum, c) => sum + c.value, 0) / data.cells.length
: 0;
return (
<div className="space-y-4">
<div className="grid grid-cols-2 gap-3 lg:grid-cols-4">
<StatTile label="관리 중인 구간" value={`${data.cells.length}개`} icon={Layers} tone="purple" />
<StatTile label="조정된 구간" value={`${adjusted}개`} icon={CheckCircle2} tone="emerald" />
<StatTile label="평균 인하폭" value={permille(avg)} icon={Ruler} tone="blue" />
<StatTile label="조정 이력" value={`${data.history.length}건`} icon={Bot} tone="amber" />
</div>
<div className="grid gap-4 xl:grid-cols-2">
<Panel title="현재 앵커링 값" subtitle="협력사 유형과 가격대 구간마다 따로 관리합니다.">
{data.cells.length === 0 ? (
<EmptyRow text="아직 설정된 구간이 없습니다. 협상이 쌓이면 구간별로 값이 만들어집니다." />
) : (
<Table className="text-xs">
<TableHeader>
<TableRow>
<TableHead className="w-24">협력사 유형</TableHead>
<TableHead className="w-24 text-right">가격대</TableHead>
<TableHead className="w-24 text-right">인하폭</TableHead>
<TableHead className="text-right">마지막 조정</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{data.cells.map((c) => (
<TableRow key={`${c.supplierType}-${c.priceRange}`}>
<TableCell>{c.supplierType}</TableCell>
<TableCell className="text-right font-mono">{c.priceRange}</TableCell>
<TableCell className="text-right font-mono">{permille(c.value)}</TableCell>
<TableCell className="text-right text-muted-foreground">
{c.adjustedAt ? fmtDateTime(c.adjustedAt) : '조정 전'}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)}
</Panel>
<Panel title="조정 이력" subtitle="표본이 충분히 쌓인 구간만 성공률을 보고 값을 조정합니다.">
{data.history.length === 0 ? (
<EmptyRow text="아직 조정된 이력이 없습니다." />
) : (
<Table className="text-xs">
<TableHeader>
<TableRow>
<TableHead className="w-24">협력사 유형</TableHead>
<TableHead className="w-16 text-right">가격대</TableHead>
<TableHead className="w-28 text-right">변화</TableHead>
<TableHead className="w-20 text-right">표본</TableHead>
<TableHead className="w-20 text-right">성공률</TableHead>
<TableHead className="text-right">시각</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{data.history.map((h, i) => (
<TableRow key={`${h.supplierType}-${h.priceRange}-${h.at ?? i}`}>
<TableCell>{h.supplierType}</TableCell>
<TableCell className="text-right font-mono">{h.priceRange}</TableCell>
<TableCell className="text-right font-mono">
{permille(h.before)} → <span className="font-semibold">{permille(h.after)}</span>
</TableCell>
<TableCell className="text-right">{h.samples}</TableCell>
<TableCell className="text-right">{pct(h.successRate)}</TableCell>
<TableCell className="text-right text-muted-foreground">
{h.at ? fmtDateTime(h.at) : '-'}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)}
</Panel>
</div>
</div>
);
}
// 평균 점수는 −1~1 범위라 숫자만으론 감이 안 온다 — 0 기준 좌우 막대로 방향과 크기를 같이 보여준다.
function RewardBar({ value }: { value: number }) {
const width = Math.min(Math.abs(value), 1) * 50;
const positive = value >= 0;
return (
<div className="flex items-center justify-end gap-2">
<div className="relative h-2 w-24 rounded bg-muted">
<div
className={`absolute top-0 h-2 ${positive ? 'bg-emerald-500' : 'bg-rose-500'}`}
style={{ left: positive ? '50%' : `${50 - width}%`, width: `${width}%` }}
/>
<div className="absolute left-1/2 top-0 h-2 w-px bg-border" />
</div>
<span className="w-12 text-right font-mono">{value.toFixed(2)}</span>
</div>
);
}
function TypeBadge({ isWild }: { isWild: boolean }) {
return (
<span
className={`inline-flex items-center rounded-full border px-2 py-0.5 text-[10px] font-semibold ${
isWild
? 'border-amber-300/45 bg-amber-50 text-amber-700 dark:bg-amber-950/20 dark:text-amber-400'
: 'border-primary/25 bg-primary/5 text-primary'
}`}
>
{isWild ? '와일드' : '협상'}
</span>
);
}
function EmptyRow({ text }: { text: string }) {
return (
<Typography as="div" variant="small" className="py-10 text-center text-xs text-muted-foreground">
{text}
</Typography>
);
}
function pct(v: number): string {
return `${(v * 100).toFixed(0)}%`;
}
// 앵커링 값은 천분율(‰) — 목표가에서 이만큼 낮춘 가격이 앵커가가 된다.
function permille(v: number): string {
return `${v.toFixed(1)}‰`;
}
@@ -0,0 +1,51 @@
import { useGetAnchoringStatus, useGetLearningStatus } from '@/api/generated/learning/learning';
import type { AnchoringData, LearningData } from './types';
// 생성 API(snake_case·전부 optional) → 화면 타입 매퍼. api/generated 는 수정 금지라 여기서 흡수한다.
export function useLearningData(): { data: LearningData; isLoading: boolean } {
const { data, isLoading } = useGetLearningStatus();
const k = data?.kpi ?? {};
return {
isLoading,
data: {
learnedSessions: k.learned_sessions ?? 0,
records: k.records ?? 0,
settledSessions: k.settled_sessions ?? 0,
settleRate: k.settle_rate ?? 0,
lastLearnedAt: k.last_learned_at ?? null,
cards: (data?.cards ?? []).map((c) => ({
number: c.number,
name: c.name ?? c.number,
isWild: c.type === 'wild',
usedSessions: c.used_sessions ?? 0,
uses: c.uses ?? 0,
avgReward: c.avg_reward ?? 0,
settleRate: c.settle_rate ?? 0,
})),
},
};
}
export function useAnchoringData(): { data: AnchoringData; isLoading: boolean } {
const { data, isLoading } = useGetAnchoringStatus();
return {
isLoading,
data: {
cells: (data?.cells ?? []).map((c) => ({
supplierType: c.supplier_type_label ?? '미지정',
priceRange: c.price_range_index ?? 0,
value: c.anchoring_value ?? 0,
adjustedAt: c.last_adjusted_at ?? null,
})),
history: (data?.history ?? []).map((h) => ({
supplierType: h.supplier_type_label ?? '미지정',
priceRange: h.price_range_index ?? 0,
before: h.value_before ?? 0,
after: h.value_after ?? 0,
samples: h.sample_count ?? 0,
successRate: h.success_rate ?? 0,
at: h.created_at ?? null,
})),
},
};
}
@@ -0,0 +1,42 @@
// 협상 학습 화면 도메인 타입. api/generated(snake_case·전부 optional)를 api.ts 에서 이 형태로 흡수한다.
export type CardRow = {
number: string;
name: string;
isWild: boolean;
usedSessions: number; // 이 카드를 쓴 협상 수
uses: number; // 총 사용 횟수
avgReward: number; // 평균 보상 — 협상 결과로 매겨진 성적
settleRate: number; // 이 카드를 쓴 협상의 타결 비율
};
export type LearningData = {
learnedSessions: number;
records: number;
settledSessions: number;
settleRate: number;
lastLearnedAt: string | null;
cards: CardRow[];
};
export type AnchorCell = {
supplierType: string; // 유통/제조/총판/미지정
priceRange: number; // 가격대 구간
value: number; // 앵커링 인하폭(‰)
adjustedAt: string | null;
};
export type AnchorHistoryRow = {
supplierType: string;
priceRange: number;
before: number;
after: number;
samples: number; // 조정 판단에 쓴 협상 표본 수
successRate: number;
at: string | null;
};
export type AnchoringData = {
cells: AnchorCell[];
history: AnchorHistoryRow[];
};
+63
View File
@@ -0,0 +1,63 @@
import { useState } from 'react';
import { PageContainer } from '@/components/layout/PageContainer';
import { Typography } from '@/components/ui/typography';
import { AnchoringStatusView, CardLearningView } from '@/features/learning/LearningView';
import { useAnchoringData, useLearningData } from '@/features/learning/api';
// 협상 학습. AI가 협상을 거치며 쌓은 결과를 보는 화면이다.
// 협상카드 = 어떤 카드가 잘 먹혔는지(강화학습), 앵커링 = 구간별 인하폭이 어떻게 조정됐는지.
// 두 축은 성격이 달라 탭으로 나눈다 — 각각 한 화면에서 끝나야 훑기 좋다.
type Tab = 'cards' | 'anchoring';
export default function LearningPage() {
const [tab, setTab] = useState<Tab>('cards');
const learning = useLearningData();
const anchoring = useAnchoringData();
const isLoading = tab === 'cards' ? learning.isLoading : anchoring.isLoading;
return (
<PageContainer>
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<Typography variant="h2">협상 학습</Typography>
<div className="flex gap-1 rounded-lg border border-border bg-card p-1">
<TabButton active={tab === 'cards'} onClick={() => setTab('cards')}>
협상카드
</TabButton>
<TabButton active={tab === 'anchoring'} onClick={() => setTab('anchoring')}>
앵커링
</TabButton>
</div>
</div>
{isLoading ? (
<Typography variant="muted">학습 현황을 불러오는 중…</Typography>
) : tab === 'cards' ? (
<CardLearningView data={learning.data} />
) : (
<AnchoringStatusView data={anchoring.data} />
)}
</PageContainer>
);
}
function TabButton({
active,
onClick,
children,
}: {
active: boolean;
onClick: () => void;
children: React.ReactNode;
}) {
return (
<button
type="button"
onClick={onClick}
className={`rounded-md px-3 py-1.5 text-xs font-semibold transition-colors ${
active ? 'bg-primary text-primary-foreground' : 'text-muted-foreground hover:bg-muted'
}`}
>
{children}
</button>
);
}
+1 -1
View File
@@ -45,4 +45,4 @@ export interface CardTactic {
offer_variable?: string; // 제시 가격 변수 명시 지정. 없으면 멘트 파싱(마지막 가격 변수) — 멘트에 있는 변수만 허용
}
export type PageType = 'DASHBOARD' | 'STATISTICS' | 'PRODUCTS' | 'PARTNERS' | 'QUOTATION' | 'CARDS' | 'RENEGOTIATION' | 'MEMBERS' | 'SETTINGS' | 'DEV_SETTINGS' | 'DESIGN' | 'NOTIFICATIONS';
export type PageType = 'DASHBOARD' | 'STATISTICS' | 'LEARNING' | 'PRODUCTS' | 'PARTNERS' | 'QUOTATION' | 'CARDS' | 'RENEGOTIATION' | 'MEMBERS' | 'SETTINGS' | 'DEV_SETTINGS' | 'DESIGN' | 'NOTIFICATIONS';