tkxk2026701
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "tkxk2026701" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-8161b371c1a1893c449923b1cde0efcc5abf6ffa6ffd3a989f7c5c96f75c37ae. Verify the upstream source and version against https://skillhub.cn/skills/user_f1b049da/tkxk2026701 before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Calculate month-over-month and year-over-year growth rates for KPI/performance dashboards, supporting formatting and up/down style classes. Use when you need MoM/YoY calculations, performance growth rates, or dashboard up/down styling. Pure front-end arithmetic with no backend assumptions.
Introduction source: third_party · user_f1b049da · 1.0.0 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: tkxk2026701
slug: tkxk2026701
displayName: 同比环比计算
version: 1.0.0
summary: 计算 KPI/业绩的环比与同比增长率,并格式化展示与涨跌 class。
license: MIT
description: 计算 KPI/业绩看板的环比与同比增长率,支持格式化与涨跌样式类。当用户要同比环比计算、业绩增长率、看板涨跌色时使用。纯前端算术,无后端假设。同比环比计算
灵感:能力工具箱 rate-calculator(calculateRate)。
小四原创:
(当期 - 基期) / 基期 * 100→ 保留精度;基期为 0 时特殊处理。
不实现完整 BI 看板,只提供增长率工具函数。
何时使用
- KPI 卡片显示环比 ↑/↓
- 业绩表同比列
- Demo 输入当期/上期/去年同月试算
硬约束
- 基期
null/undefined→ 返回null(展示-)。 - 基期为
0:当期也为 0 →null;当期非 0 →100(视为从零增长的约定值)。 - 默认精度 2 位;
formatRate输出绝对值 +%,零/空为-。 getRateClass:正up、负down、空/零normal;可加前缀。- 实现要点注释标 小四原创。
- 金额请先转 number;勿直接拿带千分位字符串做除法。
推荐实现
// 小四原创:环比
export function monthOnMonth(
current: number,
previous: number | null | undefined,
precision = 2,
): number | null {
if (previous == null) return null
if (previous === 0) return current === 0 ? null : 100
return Number((((current - previous) / previous) * 100).toFixed(precision))
}
// 小四原创:同比(基期换去年同月即可)
export function yearOnYear(
current: number,
lastYear: number | null | undefined,
precision = 2,
): number | null {
return monthOnMonth(current, lastYear, precision)
}
export function formatRate(value: number | null | undefined, precision = 2): string {
if (value == null || value === 0) return '-'
return `${Math.abs(value).toFixed(precision)}%`
}
export function rateClass(value: number | null | undefined, prefix = ''): string {
const base =
value == null || value === 0 ? 'normal' : value > 0 ? 'up' : 'down'
return prefix ? `${prefix}-${base}` : base
}
Agent 步骤
- 准备当期、上期、去年同月三个 number。
- 算 MoM/YoY;
formatRate填单元格,rateClass上色。 - UI 可另加箭头符号(↑/↓),与 class 一致。
- 自测:基期 0、基期空、负增长、精度。
不要做
- 把「环比」误算成同比基期(必须用对时间点)。
- 在本 Skill 内拉私有 KPI 接口。
附加
Current listing version
1.0.0
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供 KPI/业绩看板的环比与同比增长率计算,满足数据分析与报表展示的高频需求
- 纯前端算术实现,无后端依赖,适用性强
Highlights
- 触发场景描述清晰(同比环比计算、业绩增长率、看板涨跌色),边界明确
Highlights
- 文档结构完整,包含使用场景、约束、实现代码、执行步骤与自测建议
- frontmatter 规范,代码示例清晰
Highlights
- 覆盖基期为 null/undefined/0 等异常场景,逻辑健壮
- 提供格式化与样式类输出,可直接用于 UI 展示
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.