# `Fun_GetHumpDiff` (function)

> 获取驼峰之间的差值


- **Type:** FUNCTION
- **Returns:** `varchar(255)`
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `p_sData` | `longtext` |

## Body

_Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE FUNCTION `Fun_GetHumpDiff`'`._

## Narrative

**Business context:** "Hump" (峰) difference — `获取驼峰之间的差值`. Takes a comma-separated integer time-series and sums the rise heights of every monotonically increasing run (peak − trough), then totals them. Used by the production-dashboard reports to derive output-counter deltas from monotonically-resetting machine counters.

**What it does:** two-pass. Pass 1 normalizes the series — for each comma-token, if the value drops vs. previous, inserts a `0` between them; this re-anchors each rising run to start from 0. Pass 2 walks the normalized series tracking current `p_min` and `p_max`; on each descent or at end-of-series, adds `max-min` to `p_diff`. Returns `p_diff`.

**Invocation:** widely used by the production-board (`bd_` = 报表板/business dashboard) family — `Sp_Bd_bi16…bi24`, `Sp_Bd_cq_workshop_*` (车间 workshop boards: hh/mt/pj/pm/sy/ys), `Sp_Bd_hy_workshop_oy`, `Sp_bd_MachinePlanTemplate*` (机台计划 templates), `Sp_bd_McPlanConter`, `Sp_bd_McPlanRate`, `Sp_bd_TmComplianceRate*`, `Sp_bd_TmSpeed*`, `Sp_bd_TmYield*`. Customer override exists at `script/客户/.../Sp_Bd_Cqzy_Report*` (前一天/今天 白班/晚班).
