package com.medithings.vesiscan.managers import com.medithings.vesiscan.walldetect.MethodDRunner import org.junit.Test import java.io.File /** * 기존(팬텀) 경로가 이번 이식으로 **한 글자도 안 바뀌었는지** 실증하는 덤프 하네스. * * 검출 → BV 전 구간을 `align_cm{0,1}.csv` 의 모든 cycle 에 대해 돌려 결과를 파일로 * 떨군다. HEAD 코드와 작업트리 코드에서 각각 돌린 덤프가 **바이트 단위로 같으면** * 기존 경로 무변경이 증명된다. * * 이 파일은 [AlgoMode] 를 참조하지 않는다 — HEAD 에는 그 타입이 없기 때문이다. * 기본값이 기존 경로이므로 기본 호출만으로 그 경로가 그대로 실행된다. */ class LegacyEquivalenceDumpTest { private fun res(name: String) = javaClass.classLoader!!.getResourceAsStream(name)!!.bufferedReader().use { it.readText() } /** cycle → 6채널 신호 (`cycle,channel,s0..s99`). */ private fun loadCycles(name: String): Map> { val out = HashMap>>() for (line in res(name).lineSequence()) { val t = line.trim() if (t.isEmpty()) continue val f = t.split(",") if (f.size < 3) continue val cyc = f[0].toIntOrNull() ?: continue val ch = f[1].toIntOrNull() ?: continue val sig = DoubleArray(f.size - 2) { f[it + 2].trim().toDouble() } out.getOrPut(cyc) { ArrayList() }.add(ch to sig) } return out.mapValues { (_, v) -> val byCh = v.toMap() (0..5).map { byCh[it] ?: DoubleArray(0) } } } @Test fun dump() { val sb = StringBuilder() for (cm in 0..1) { val cycles = loadCycles("align_cm$cm.csv") for (cyc in cycles.keys.sorted()) { val sig = cycles[cyc]!! for (cross in listOf(false, true)) { val dets = MethodDRunner.detectMultichannel(sig, applyCross = cross) val walls = dets.map { r -> r?.let { WallWithSpan(it.antRefined, it.postRefined, it.lowStart, it.lowEnd) } } val bv = estimateBv(walls) sb.append("cm$cm cyc$cyc cross=$cross") dets.forEachIndexed { i, r -> sb.append(if (r == null) " CH$i=-" else " CH$i=%d/%d/%.4f/%.4f/%d/%d".format( r.ant, r.post, r.antRefined, r.postRefined, r.lowStart, r.lowEnd)) } sb.append(if (bv == null) " BV=-" else " BV=%.6f lr=%.6f nch=%d topH=%.4f botH=%.4f vT=%.4f vB=%.4f".format( bv.volumeMl, bv.lrRatio, bv.validChannels.size, bv.topHMm, bv.bottomHMm, bv.vTopMm3, bv.vBottomMm3)) sb.append('\n') } } } val out = File(System.getProperty("legacyDump") ?: "build/legacy_dump.txt") out.parentFile?.mkdirs() out.writeText(sb.toString()) println("[dump] ${out.absolutePath} lines=${sb.lines().size}") } }