зеркало из https://github.com/microsoft/mwt-ds.git
enabled VW string format stream download via API
This commit is contained in:
Родитель
87d9110b88
Коммит
f86212a8a4
|
@ -130,6 +130,7 @@
|
|||
<Compile Include="Metrics.cs" />
|
||||
<Compile Include="OfflineTrainer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="VowpalWabbitStreamWriter.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
using System.IO;
|
||||
using System.Text;
|
||||
using VW;
|
||||
using VW.Serializer;
|
||||
|
||||
namespace Experimentation
|
||||
{
|
||||
public class VowpalWabbitStreamWriter : StreamWriter
|
||||
{
|
||||
private VowpalWabbit vw;
|
||||
|
||||
public VowpalWabbitStreamWriter(Stream stream, Encoding encoding, string arguments) : base(stream, encoding)
|
||||
{
|
||||
vw = new VowpalWabbit(new VowpalWabbitSettings { Arguments = arguments, EnableStringExampleGeneration = true, EnableStringFloatCompact = true });
|
||||
}
|
||||
|
||||
public override void WriteLine(string value)
|
||||
{
|
||||
using (var jsonSerializer = new VowpalWabbitJsonSerializer(vw))
|
||||
using (var example = jsonSerializer.ParseAndCreate(value))
|
||||
{
|
||||
if (example == null)
|
||||
throw new InvalidDataException($"Invalid example: {value}");
|
||||
|
||||
var str = example.VowpalWabbitString;
|
||||
if (example is VowpalWabbitMultiLineExampleCollection)
|
||||
str += "\n";
|
||||
|
||||
base.WriteLine(str);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
vw.Dispose();
|
||||
base.Close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -82,14 +82,37 @@ namespace DecisionServicePrivateWeb.Controllers
|
|||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult> Offline(string startTimeInclusive, string endTimeExclusive)
|
||||
public async Task<ActionResult> Offline(string startTimeInclusive, string endTimeExclusive, string dataFormat = "json")
|
||||
{
|
||||
var token = Request.Headers["auth"];
|
||||
if (token != ConfigurationManager.AppSettings[ApplicationMetadataStore.AKPassword])
|
||||
throw new UnauthorizedAccessException();
|
||||
|
||||
var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.AppSettings[ApplicationMetadataStore.AKConnectionString]);
|
||||
using (var responseWriter = new StreamWriter(Response.OutputStream, Encoding.UTF8))
|
||||
|
||||
var blobClient = storageAccount.CreateCloudBlobClient();
|
||||
|
||||
StreamWriter responseWriter = null;
|
||||
switch (dataFormat)
|
||||
{
|
||||
case "json":
|
||||
responseWriter = new StreamWriter(Response.OutputStream, Encoding.UTF8);
|
||||
break;
|
||||
case "vw":
|
||||
var settingsBlobContainer = blobClient.GetContainerReference(ApplicationBlobConstants.SettingsContainerName);
|
||||
var blob = settingsBlobContainer.GetBlockBlobReference(ApplicationBlobConstants.LatestClientSettingsBlobName);
|
||||
if (!await blob.ExistsAsync())
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Application settings blob not found.");
|
||||
}
|
||||
ApplicationClientMetadata clientMeta = JsonConvert.DeserializeObject<ApplicationClientMetadata>(await blob.DownloadTextAsync());
|
||||
responseWriter = new VowpalWabbitStreamWriter(Response.OutputStream, Encoding.UTF8, clientMeta.TrainArguments);
|
||||
break;
|
||||
default:
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Unrecognized data format.");
|
||||
}
|
||||
|
||||
using (responseWriter)
|
||||
{
|
||||
await AzureBlobDownloader.Download(
|
||||
storageAccount,
|
||||
|
|
Загрузка…
Ссылка в новой задаче