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
10 changes: 7 additions & 3 deletions src/Serval/src/Serval.Translation/Services/PlatformService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public async Task InsertPretranslationsAsync(
int nextModelRevision = engine.ModelRevision + 1;

var batch = new List<Pretranslation>();
double confidenceTotal = 0.0;
double totalConfidence = 0.0;
int numPretranslations = 0;
await foreach (PretranslationContract item in pretranslations.WithCancellation(cancellationToken))
{
Expand Down Expand Up @@ -404,7 +404,7 @@ public async Task InsertPretranslationsAsync(
Confidence = item.Confidence,
}
);
confidenceTotal += item.Confidence ?? 0.0;
totalConfidence += item.Confidence ?? 0.0;
numPretranslations += 1;
if (batch.Count == PretranslationInsertBatchSize)
{
Expand All @@ -417,7 +417,11 @@ public async Task InsertPretranslationsAsync(

await _builds.UpdateAsync(
b => b.Id == buildId,
u => u.Set(b => b.ExecutionData.AveragePretranslationConfidence, confidenceTotal / numPretranslations),
u =>
u.Set(
b => b.ExecutionData.AveragePretranslationConfidence,
numPretranslations > 0 ? totalConfidence / numPretranslations : 0.0
),
cancellationToken: cancellationToken
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,27 @@ await env.Builds.InsertAsync(
Assert.That(env.Pretranslations.Count, Is.EqualTo(1));
await env.PlatformService.BuildCompletedAsync("b0", 0, 0.0);
Assert.That(env.Pretranslations.Count, Is.EqualTo(1));

await env.PlatformService.BuildStartedAsync("b0");
await env.PlatformService.InsertPretranslationsAsync("e0", "b0", GetTestPretranslations());
await env.PlatformService.BuildCompletedAsync("b0", 0, 0.0);
Assert.That(env.Pretranslations.Count, Is.EqualTo(1));
Assert.That(
(await env.Builds.GetAsync(b => b.Id == "b0"))?.ExecutionData.AveragePretranslationConfidence,
Is.Zero
Is.Zero.Within(0.001)
);

await env.PlatformService.BuildStartedAsync("b0");
await env.PlatformService.InsertPretranslationsAsync(
"e0",
"b0",
AsyncEnumerable.Empty<PretranslationContract>()
);
await env.PlatformService.BuildCompletedAsync("b0", 0, 0.0);
Assert.That(env.Pretranslations.Count, Is.EqualTo(0));
Assert.That(
(await env.Builds.GetAsync(b => b.Id == "b0"))?.ExecutionData.AveragePretranslationConfidence,
Is.Zero.Within(0.001)
);
}

Expand Down
Loading