Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ public PublicAlgorithmService(AlgorithmLibJNIBridgeService runtime, CurveNativeA
parameters.put("height", options.height());
parameters.put("roomSurface", options.roomSurface());
parameters.put("absortionCoef", options.absorptionCoefficient());
if (options.measurementSurfaceArea() != null)
parameters.put("measurementSurfaceArea", options.measurementSurfaceArea());
return Optional.ofNullable(runtime.calculateSimplifiedSoundPowerSurvey(
options.surfaceType(), parameters, levels, backgroundLevels)).map(value ->
new SoundPowerSurveyResult(value.getSoundPowerLevel(), value.getBackgroundCorrection(),
Expand Down Expand Up @@ -234,6 +236,8 @@ private Optional<EngineeringSoundPowerResult> calculateEngineeringSoundPower(
parameters.put("absortionCoef", options.absorptionCoefficient());
parameters.put("temperature", options.temperature()); parameters.put("humidity", options.humidity());
parameters.put("atmosphericPressure", options.atmosphericPressure());
if (options.measurementSurfaceArea() != null)
parameters.put("measurementSurfaceArea", options.measurementSurfaceArea());
parameters.values().removeIf(Objects::isNull);
var response = terminal
? runtime.calculateTerminalEngineeringSoundPower(options.surfaceType(), options.calculationType(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
package com.opentest.algorithm.runtime;

import com.opentest.core.jni.AlgorithmLibJNIBridge;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.Test;
import com.opentest.algorithm.api.*;
import static org.junit.jupiter.api.Assertions.*;
import com.opentest.algorithm.api.AlgorithmException;
import com.opentest.algorithm.api.LaeqOptions;
import com.opentest.algorithm.api.SoundPowerSurveyOptions;
import com.opentest.algorithm.api.SoundPowerSurveyResult;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

class PublicSoundPowerMathTest {
@Test void independentSessionsPreserveOperandsEmptyFailureAndSingleRelease() {
Expand Down Expand Up @@ -58,6 +70,18 @@ class PublicSoundPowerMathTest {
bridge.surveyStatus=13200001;
assertTrue(service.calculateSoundPowerSurvey(options,new double[]{80},new double[]{40}).isEmpty());
}
@Test void explicitSurveyAreaUsesDedicatedSurfaceAndDoesNotChangeLegacyOperands() {
var bridge = new NativeObservation();
var service = new PublicAlgorithmService(new AlgorithmLibJNIBridgeService(bridge));
var options = SoundPowerSurveyOptions.withArea(48.849555921539, 1000D, .5);
assertTrue(service.calculateSoundPowerSurvey(options,new double[]{75},new double[]{65}).isPresent());
assertEquals(-1, bridge.surface);
assertEquals(48.849555921539, bridge.parameters.get("measurementSurfaceArea"));
assertNull(bridge.parameters.get("length"));
assertNull(bridge.parameters.get("sphereRadius"));
assertThrows(IllegalArgumentException.class, () -> SoundPowerSurveyOptions.withArea(Double.NaN,1000D,.5));
assertThrows(IllegalArgumentException.class, () -> new SoundPowerSurveyOptions(3,1D,1D,1D,1D,1D,1000D,.5,50D));
}
private static final class NativeObservation extends AlgorithmLibJNIBridge {
final List<String> ids=new ArrayList<>(),deleted=new ArrayList<>();
final List<List<Double>> options=new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ private List<GraphicResultCodeDto> applyLegacyAxisReadNormalization(GraphicConfi
normalizedUnitY = normalizeReadGraphicUnitY(normalizedUnitY, bindings);
dto.setUnitY(normalizedUnitY);
bindings = rebuildMissingLegacyCarrierUnitsForRead(record, bindings);
LegacyAxisReadResult readResult = legacyAxisReadNormalizer.normalizeForRead(
LegacyAxisReadResult readResult = legacyAxisReadNormalizer.normalizeForDisplay(
record.getGraphicType(),
record.getChartConfig(),
bindings,
Expand Down Expand Up @@ -25597,6 +25597,8 @@ private CurrentGraphicState assembleCurrentState(
state.getGraphicsById().put(graphicId, graphic);
List<GraphicResultCodeDto> resultCodes =
MapUtil.emptyIfNull(graphicResultCodeDtoMap).get(graphicId);
// An unbound card still participates in membership synchronization with an empty catalog.
if (resultCodes == null) resultCodes = new ArrayList<>();
state.getRcByGraphic().put(graphicId, resultCodes);

// 构建placement索引
Expand Down Expand Up @@ -36059,7 +36061,9 @@ private Map<Long, Set<String>> assignChannelsToResults(List<String> channels, Co
channel))
.map(SimpleChannelDto::getVchId)
.collect(Collectors.toCollection(LinkedHashSet::new));
if (CollUtil.isEmpty(effectiveChannelIds)) {
if (effectiveChannelIds.isEmpty()) {
// Provider result members are explicit; an aggregate can omit the new input.
if (result.isProviderDefined()) continue;
effectiveChannelIds.add(sourceChannelId);
}
channelsByResult.computeIfAbsent(result.getId(), k -> new HashSet<>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.opentest.service.axis.CurrentReferenceTestGraphicProjection;
import com.opentest.service.axis.ScalarGraphicMembershipReadProjection;
import com.opentest.service.axis.FrozenEmptyGraphicUnitProjection;
import com.opentest.service.axis.GraphicResultContractClassifier;
import com.opentest.service.mapper.DashboardResultPersistenceMapper;
import com.opentest.service.mapper.GraphicConfigSnapshotDtoMapper;
import com.opentest.service.membership.DomainSpecialGraphicMembershipPlanner;
Expand Down Expand Up @@ -728,7 +729,7 @@ private List<GraphicResultCodeDto> applyLegacyAxisReadNormalization(
List<GraphicResultCodeDto> bindings,
Long expectedRequestId,
boolean hasPersistedBindings) {
LegacyAxisReadResult readResult = legacyAxisReadNormalizer.normalizeForRead(
LegacyAxisReadResult readResult = legacyAxisReadNormalizer.normalizeForDisplay(
record.getGraphicType(),
record.getChartConfig(),
bindings,
Expand Down Expand Up @@ -797,6 +798,10 @@ private List<GraphicResultCodeDto> resolveSnapshotResultCodes(GraphicConfigSnaps
return CollUtil.newArrayList();
}
List<String> channelIds = parseSnapshotChannelIds(record.getChannelIds());
if (channelIds.isEmpty() && GraphicResultContractClassifier.supportsStableAxisContract(record.getGraphicType())) {
// A retained card title is not a result carrier without a persisted result identity.
return CollUtil.newArrayList();
}
GraphicResultCodeDto resultCode = new GraphicResultCodeDto();
resultCode.setGraphicConfigId(record.getId());
resultCode.setResultCode(record.getResultCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
Expand Down Expand Up @@ -171,9 +172,7 @@ private Admission claim(Owner owner, String businessId, String logicalName,
throw conflict("Invalid shared result identity");
// Released RT60 spectra use a flat filename while retaining the same shared
// business identity. Admit only the filename derived exactly from that identity.
String flatName = (owner.projectId() + "_null_" + businessId + ".crybin")
.replaceAll("[\\\\/:*?\"<>|]", "_");
boolean legacyFlat = logicalName.equals(flatName);
boolean legacyFlat = logicalName.equals(flatName(owner.projectId(), businessId));
Path relative = Path.of(logicalName);
if (relative.isAbsolute() || !relative.normalize().toString().replace('\\', '/').equals(logicalName)
|| !legacyFlat && !logicalName.startsWith(owner.projectId() + "/null/")
Expand All @@ -195,39 +194,17 @@ private Admission claim(Owner owner, String businessId, String logicalName,
requireKnownFileSchema();
var definition = requireDefinition(owner);
long tenantId = ((Number) definition.get("tenant_id")).longValue();
var previous = owner.stageWitness() == null ? exactOwners(businessId)
: stageActiveOwners(businessId, owner.projectId(), owner.dashboardId(), tenantId);
var existing = exactOwners(businessId);
var previous = activeOwners(existing, businessId, owner.projectId(), owner.dashboardId(),
tenantId, candidate, owner.stageWitness() != null);
if (owner.stageWitness() != null && !previous.isEmpty())
throw conflict("Stage recapture requires visibility-time invalidation of previous active files");
if (previous.size() > 1) throw conflict("Duplicate shared File owners");
Map<String, Object> row = previous.isEmpty() ? null : previous.getFirst();
String marker = markerName(businessId);
if (row == null) {
boolean retiredStageOwner = owner.stageWitness() != null && !exactOwners(businessId).isEmpty();
if (!retiredStageOwner) {
if (Files.exists(root.resolve(".shared-result-admission").resolve(marker)))
throw conflict("Orphan legacy shared reservation requires quarantine");
ensureAbsent(root, indexRoot, logicalName);
}
} else {
String selected = Objects.toString(row.get("file_url"), "");
String flatBase = flatName.substring(0, flatName.length() - ".crybin".length());
long oldShards = number(row.get("shards_no"));
boolean originalFlat = legacyFlat && (selected.equals(flatName)
|| oldShards > 0 && selected.equals(flatBase + "_" + oldShards + ".crybin"));
boolean generatedFlat = legacyFlat && selected.matches(java.util.regex.Pattern.quote(flatBase)
+ "_g[0-9a-f]{32}(?:_1(?:_\\d{14})?)?\\.crybin");
if (number(row.get("tenant_id")) != tenantId
&& !(row.get("tenant_id") == null && (originalFlat || generatedFlat))
|| number(row.get("business_type")) != FileBusinessTypeEnum.CALCULATE.getType()
|| number(row.get("wait_del")) != 0
|| number(row.get("temporary_result")) != 0
|| row.get("request_id") != null)
throw conflict("Shared File owner is foreign or pending deletion");
if (!(legacyFlat ? originalFlat || generatedFlat
: selected.startsWith(owner.projectId() + "/null/"))
|| !selected.toLowerCase(Locale.ROOT).endsWith(".crybin"))
throw conflict("Shared File selected path is outside its owner");
if (existing.isEmpty()) {
if (Files.exists(root.resolve(".shared-result-admission").resolve(markerName(businessId))))
throw conflict("Orphan legacy shared reservation requires quarantine");
ensureAbsent(root, indexRoot, logicalName);
}
String oldManifest = row == null ? null : selectedManifest(row, root, indexRoot);
long id = row == null ? IdWorker.getId() : number(row.get("id"));
Expand Down Expand Up @@ -453,9 +430,10 @@ private void recoverUnknownPublication(String publication, ConcurrentFileManager
String outcome = null;
for (Map<String, Object> item : items) {
String businessId = Objects.toString(item.get("business_id"), "");
var current = Objects.toString(item.get("definition_witness"), "").startsWith("STAGE:")
? stageActiveOwners(businessId, number(item.get("project_id")), number(item.get("dashboard_id")), number(item.get("tenant_id")))
: exactOwners(businessId);
var current = activeOwners(exactOwners(businessId), businessId, number(item.get("project_id")),
number(item.get("dashboard_id")), number(item.get("tenant_id")),
Objects.toString(item.get("candidate_base"), ""),
Objects.toString(item.get("definition_witness"), "").startsWith("STAGE:"));
boolean previous = matchesPreviousUnknown(item, current, root, indexRoot);
boolean candidate = matchesCandidateUnknown(item, current, root, indexRoot);
if (previous == candidate) {
Expand Down Expand Up @@ -601,12 +579,50 @@ private static String definitionWitness(Owner owner, Map<String,Object> definiti
return (owner.stageWitness() == null ? "" : "STAGE:") + witness(definition);
}
private List<Map<String,Object>> activeOwners(Admission admission) {
return admission.owner().stageWitness() == null ? exactOwners(admission.businessId())
: stageActiveOwners(admission.businessId(), admission.owner().projectId(), admission.owner().dashboardId(), admission.tenantId());
var owner = admission.owner();
return activeOwners(exactOwners(admission.businessId()), admission.businessId(), owner.projectId(),
owner.dashboardId(), admission.tenantId(), admission.candidateBase(), owner.stageWitness() != null);
}

private static List<Map<String, Object>> activeOwners(List<Map<String, Object>> existing,
String business, long project, long dashboard, long tenant, String candidate, boolean stage) {
if (stage) return stageActiveOwners(existing, business, project, dashboard, tenant);
boolean legacyFlat = !candidate.startsWith(project + "/null/");
String flatName = flatName(project, business);
String flatBase = flatName.substring(0, flatName.length() - ".crybin".length());
var active = new ArrayList<Map<String, Object>>();
for (var row : existing) {
String selected = Objects.toString(row.get("file_url"), "");
long oldShards = number(row.get("shards_no"));
boolean originalFlat = legacyFlat && (selected.equals(flatName)
|| oldShards > 0 && selected.equals(flatBase + "_" + oldShards + ".crybin"));
boolean generatedFlat = legacyFlat && selected.matches(Pattern.quote(flatBase)
+ "_g[0-9a-f]{32}(?:_1(?:_\\d{14})?)?\\.crybin");
long waitDelete = number(row.get("wait_del"));
if ((number(row.get("tenant_id")) != tenant
&& !(row.get("tenant_id") == null && (originalFlat || generatedFlat)))
|| number(row.get("business_type")) != FileBusinessTypeEnum.CALCULATE.getType()
|| number(row.get("temporary_result")) != 0 || row.get("request_id") != null
|| (waitDelete != 0 && waitDelete != 1))
throw conflict("Shared File owner is foreign or has an invalid deletion state");
if (!(legacyFlat ? originalFlat || generatedFlat
: selected.startsWith(project + "/null/") && selected.indexOf('\\') < 0
&& Path.of(selected).normalize().toString().replace('\\', '/').equals(selected))
|| !selected.toLowerCase(Locale.ROOT).endsWith(".crybin"))
throw conflict("Shared File selected path is outside its owner");
if (waitDelete == 0) active.add(row);
}
return active;
}
private List<Map<String,Object>> stageActiveOwners(String business, long project, long dashboard, long tenant) {

private static String flatName(long projectId, String businessId) {
return (projectId + "_null_" + businessId + ".crybin").replaceAll("[\\\\/:*?\"<>|]", "_");
}

private static List<Map<String,Object>> stageActiveOwners(List<Map<String, Object>> existing,
String business, long project, long dashboard, long tenant) {
var result = new ArrayList<Map<String,Object>>();
for (var row : exactOwners(business)) {
for (var row : existing) {
String path = Objects.toString(row.get("file_url"), "");
if (number(row.get("tenant_id")) != tenant || row.get("request_id") != null
|| number(row.get("business_type")) != FileBusinessTypeEnum.CALCULATE.getType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ public LegacyAxisReadNormalizer(AxisContractPlanner axisContractPlanner) {
this.axisContractPlanner = axisContractPlanner;
}

/** Project a retained unbound card as explicitly empty, without changing its stored contract. */
public LegacyAxisReadResult normalizeForDisplay(Integer graphicType,
String storedChartConfig,
List<GraphicResultCodeDto> resultBindings,
String graphDisplaySettings,
String legacyUnitY,
LegacyAxisReadContext readContext,
boolean allowEmptySelectedUnit) {
LegacyAxisReadResult read = normalizeForRead(graphicType, storedChartConfig, resultBindings, graphDisplaySettings,
legacyUnitY, readContext, allowEmptySelectedUnit);
if (read.getAxisPlan() != null || CollUtil.isNotEmpty(resultBindings)
|| !GraphicMembershipCapabilityRegistry.supportsStableAxisContract(graphicType)) {
return read;
}
return LegacyAxisReadResult.axisPlan(new AxisContractPlan(
List.of(), List.of(), List.of(), normalizeCarrierGraphDisplaySettings(graphDisplaySettings)));
}

/**
* @return 合法 legacy 曲线的运行时计划;非目标图或完整新合同返回 {@code null}
*/
Expand Down Expand Up @@ -189,7 +207,13 @@ public LegacyAxisReadResult normalizeForRead(Integer graphicType,
.filter(Objects::nonNull)
.anyMatch(this::hasStableMarker);
if (CollUtil.isEmpty(resultBindings)) {
if (hasNewAxes) {
JsonNode container = storedChartTree.path(type.getChartType().getCode());
JsonNode axes = container.path("yAxes");
// Execution snapshots already use an explicit empty array for a card with no bindings.
boolean explicitEmpty = axes.isArray() && axes.isEmpty()
&& !container.has("displayYAxis") && !container.has("overflowAxisSide")
&& !storedChart.containsExplicitLegacyYAxisFields();
if ((hasNewAxes || container.has("displayYAxis")) && !explicitEmpty) {
throw new IllegalArgumentException("Stable axis contract has fields without result bindings");
}
return LegacyAxisReadResult.axisPlan(null);
Expand Down
Loading
Loading