Skip to content

Commit

Permalink
Responding to reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
johnml1135 committed Jan 15, 2024
1 parent 4e77b48 commit 1f52812
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"csharpier": {
"version": "0.26.7",
"version": "0.27.0",
"commands": [
"dotnet-csharpier"
]
Expand Down
61 changes: 26 additions & 35 deletions samples/EchoTranslationEngine/TranslationEngineServiceV1.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
namespace EchoTranslationEngine;

public class TranslationEngineServiceV1 : TranslationEngineApi.TranslationEngineApiBase
public class TranslationEngineServiceV1(BackgroundTaskQueue taskQueue, HealthCheckService healthCheckService)
: TranslationEngineApi.TranslationEngineApiBase
{
private static readonly Empty Empty = new();
private readonly BackgroundTaskQueue _taskQueue;
private readonly HealthCheckService _healthCheckService;
private readonly BackgroundTaskQueue _taskQueue = taskQueue;

public TranslationEngineServiceV1(BackgroundTaskQueue taskQueue, HealthCheckService healthCheckService)
{
_taskQueue = taskQueue;
_healthCheckService = healthCheckService;
}
private readonly HealthCheckService _healthCheckService = healthCheckService;

public override Task<Empty> Create(CreateRequest request, ServerCallContext context)
{
Expand Down Expand Up @@ -88,18 +84,16 @@ await client.BuildStartedAsync(
if (!corpus.PretranslateAll && corpus.PretranslateTextIds.Count == 0)
continue;

var sourceFiles = corpus.SourceFiles
.Where(
f =>
(corpus.PretranslateAll || corpus.PretranslateTextIds.Contains(f.TextId))
&& f.Format == FileFormat.Text
var sourceFiles = corpus
.SourceFiles.Where(f =>
(corpus.PretranslateAll || corpus.PretranslateTextIds.Contains(f.TextId))
&& f.Format == FileFormat.Text
)
.ToDictionary(f => f.TextId, f => f.Location);
var targetFiles = corpus.TargetFiles
.Where(
f =>
(corpus.PretranslateAll || corpus.PretranslateTextIds.Contains(f.TextId))
&& f.Format == FileFormat.Text
var targetFiles = corpus
.TargetFiles.Where(f =>
(corpus.PretranslateAll || corpus.PretranslateTextIds.Contains(f.TextId))
&& f.Format == FileFormat.Text
)
.ToDictionary(f => f.TextId, f => f.Location);

Expand Down Expand Up @@ -272,23 +266,20 @@ public override Task<GetWordGraphResponse> GetWordGraph(GetWordGraphRequest requ
{
Enumerable
.Range(0, tokens.Length - 1)
.Select(
index =>
new WordGraphArc
{
PrevState = index,
NextState = index + 1,
Score = 1.0,
TargetTokens = { tokens[index] },
Confidences = { 1.0 },
SourceSegmentStart = index,
SourceSegmentEnd = index + 1,
Alignment =
{
new AlignedWordPair { SourceIndex = 0, TargetIndex = 0 }
}
}
)
.Select(index => new WordGraphArc
{
PrevState = index,
NextState = index + 1,
Score = 1.0,
TargetTokens = { tokens[index] },
Confidences = { 1.0 },
SourceSegmentStart = index,
SourceSegmentEnd = index + 1,
Alignment =
{
new AlignedWordPair { SourceIndex = 0, TargetIndex = 0 }
}
})
},
FinalStates = { tokens.Length }
}
Expand Down
26 changes: 9 additions & 17 deletions src/Serval.ApiServer/Controllers/StatusController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,17 @@ namespace Serval.ApiServer.Controllers;
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/status")]
[OpenApiTag("Status")]
public class StatusController : ServalControllerBase
public class StatusController(
HealthCheckService healthCheckService,
IAuthorizationService authService,
IWebHostEnvironment env,
IConfiguration configuration
) : ServalControllerBase(authService)
{
private readonly HealthCheckService _healthCheckService;
private readonly IWebHostEnvironment _env;
private readonly HealthCheckService _healthCheckService = healthCheckService;
private readonly IWebHostEnvironment _env = env;

private readonly IConfiguration _configuration;

public StatusController(
HealthCheckService healthCheckService,
IAuthorizationService authService,
IWebHostEnvironment env,
IConfiguration configuration
)
: base(authService)
{
_healthCheckService = healthCheckService;
_env = env;
_configuration = configuration;
}
private readonly IConfiguration _configuration = configuration;

/// <summary>
/// Get Health
Expand Down
4 changes: 3 additions & 1 deletion src/Serval.ApiServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public void ConfigureServices(IServiceCollection services)
var dataFileOptions = new DataFileOptions();
Configuration.GetSection(DataFileOptions.Key).Bind(dataFileOptions);
// find drive letter for DataFilesDir
string driveLetter = Path.GetPathRoot(dataFileOptions.FilesDirectory)![..1];
string? driveLetter = Path.GetPathRoot(dataFileOptions.FilesDirectory)?[..1];
if (driveLetter == null)
throw new InvalidOperationException("Cannot find drive letter for DataFilesDir");

// add health check for disk storage capacity
services
Expand Down
6 changes: 3 additions & 3 deletions src/Serval.Shared/Configuration/IServalBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public static IServalBuilder AddMongoDataAccess(
Action<IMongoDataAccessConfigurator> configure
)
{
var mongoConnectionString =
builder.Configuration?.GetConnectionString("Mongo")
?? throw new Exception("Mongo connection string not configured");
var mongoConnectionString = builder.Configuration?.GetConnectionString("Mongo");
if (mongoConnectionString is null)
throw new InvalidOperationException("Mongo connection string not configured");
builder.Services.AddMongoDataAccess(mongoConnectionString, "Serval", configure);
builder.Services.AddHealthChecks().AddMongoDb(mongoConnectionString, name: "Mongo");
return builder;
Expand Down

0 comments on commit 1f52812

Please sign in to comment.