Skip to content

Commit

Permalink
Format support (#3400)
Browse files Browse the repository at this point in the history
* use typespec diagonistics when there is some error in typespec file

* apply format for string

* remove unused code

* add unit test

* update test

* resolve skipGenerateion option does not work issue

* format

* add test

* set format in getInputType

* prettier code

* update test

* update the sample code for Uri type

* update sample data for uri type

* remove unused code

* update test

* combine type and format to formattedType

* wrap a function to get FormattedType

* call getFormattedType
  • Loading branch information
chunyu3 authored May 19, 2023
1 parent 4b70017 commit 5d8e3c5
Show file tree
Hide file tree
Showing 51 changed files with 1,330 additions and 504 deletions.
2 changes: 1 addition & 1 deletion samples/AnomalyDetector/multivariate/models.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ either pointed to an Azure blob storage folder, or pointed to a CSV file in
Azure blob storage based on you data schema selection. The data schema should
be exactly the same with those used in the training phase.
""")
dataSource: string;
dataSource: url;

@doc("""
An optional field, which is used to specify the number of top contributed
Expand Down
38 changes: 11 additions & 27 deletions samples/AnomalyDetector/src/Generated/AnomalyDetectorClient.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -521,39 +521,39 @@ Console.WriteLine(result.GetProperty("confidenceScores")[0].ToString());
]]></code>
</example>
</member>
<member name="GetMultivariateBatchDetectionResultAsync(string,CancellationToken)">
<member name="GetMultivariateBatchDetectionResultAsync(Guid,CancellationToken)">
<example>
This sample shows how to call GetMultivariateBatchDetectionResultAsync with required parameters.
<code><![CDATA[
var credential = new AzureKeyCredential("<key>");
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new AnomalyDetectorClient(endpoint, credential);
var result = await client.GetMultivariateBatchDetectionResultAsync("<resultId>");
var result = await client.GetMultivariateBatchDetectionResultAsync(Guid.NewGuid());
]]></code>
</example>
</member>
<member name="GetMultivariateBatchDetectionResult(string,CancellationToken)">
<member name="GetMultivariateBatchDetectionResult(Guid,CancellationToken)">
<example>
This sample shows how to call GetMultivariateBatchDetectionResult with required parameters.
<code><![CDATA[
var credential = new AzureKeyCredential("<key>");
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new AnomalyDetectorClient(endpoint, credential);
var result = client.GetMultivariateBatchDetectionResult("<resultId>");
var result = client.GetMultivariateBatchDetectionResult(Guid.NewGuid());
]]></code>
</example>
</member>
<member name="GetMultivariateBatchDetectionResultAsync(string,RequestContext)">
<member name="GetMultivariateBatchDetectionResultAsync(Guid,RequestContext)">
<example>
This sample shows how to call GetMultivariateBatchDetectionResultAsync with required parameters and parse the result.
<code><![CDATA[
var credential = new AzureKeyCredential("<key>");
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new AnomalyDetectorClient(endpoint, credential);
Response response = await client.GetMultivariateBatchDetectionResultAsync("<resultId>", new RequestContext());
Response response = await client.GetMultivariateBatchDetectionResultAsync(Guid.NewGuid(), new RequestContext());
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("resultId").ToString());
Expand Down Expand Up @@ -581,15 +581,15 @@ Console.WriteLine(result.GetProperty("results")[0].GetProperty("errors")[0].GetP
]]></code>
</example>
</member>
<member name="GetMultivariateBatchDetectionResult(string,RequestContext)">
<member name="GetMultivariateBatchDetectionResult(Guid,RequestContext)">
<example>
This sample shows how to call GetMultivariateBatchDetectionResult with required parameters and parse the result.
<code><![CDATA[
var credential = new AzureKeyCredential("<key>");
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new AnomalyDetectorClient(endpoint, credential);
Response response = client.GetMultivariateBatchDetectionResult("<resultId>", new RequestContext());
Response response = client.GetMultivariateBatchDetectionResult(Guid.NewGuid(), new RequestContext());
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("resultId").ToString());
Expand Down Expand Up @@ -1061,7 +1061,7 @@ var credential = new AzureKeyCredential("<key>");
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new AnomalyDetectorClient(endpoint, credential);
var options = new MultivariateBatchDetectionOptions("<dataSource>", 1234, DateTimeOffset.UtcNow, DateTimeOffset.UtcNow);
var options = new MultivariateBatchDetectionOptions(new Uri("http://localhost:3000"), 1234, DateTimeOffset.UtcNow, DateTimeOffset.UtcNow);
var result = await client.DetectMultivariateBatchAnomalyAsync("<modelId>", options);
]]></code>
</example>
Expand All @@ -1074,7 +1074,7 @@ var credential = new AzureKeyCredential("<key>");
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new AnomalyDetectorClient(endpoint, credential);
var options = new MultivariateBatchDetectionOptions("<dataSource>", 1234, DateTimeOffset.UtcNow, DateTimeOffset.UtcNow);
var options = new MultivariateBatchDetectionOptions(new Uri("http://localhost:3000"), 1234, DateTimeOffset.UtcNow, DateTimeOffset.UtcNow);
var result = client.DetectMultivariateBatchAnomaly("<modelId>", options);
]]></code>
</example>
Expand All @@ -1088,7 +1088,7 @@ var endpoint = new Uri("<https://my-service.azure.com>");
var client = new AnomalyDetectorClient(endpoint, credential);
var data = new {
dataSource = "<dataSource>",
dataSource = "http://localhost:3000",
topContributorCount = 1234,
startTime = "2022-05-10T14:57:31.2311892-04:00",
endTime = "2022-05-10T14:57:31.2311892-04:00",
Expand Down Expand Up @@ -1131,7 +1131,7 @@ var endpoint = new Uri("<https://my-service.azure.com>");
var client = new AnomalyDetectorClient(endpoint, credential);
var data = new {
dataSource = "<dataSource>",
dataSource = "http://localhost:3000",
topContributorCount = 1234,
startTime = "2022-05-10T14:57:31.2311892-04:00",
endTime = "2022-05-10T14:57:31.2311892-04:00",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ internal static AnomalyDetectionModel DeserializeAnomalyDetectionModel(JsonEleme
{
return null;
}
string modelId = default;
Guid modelId = default;
DateTimeOffset createdTime = default;
DateTimeOffset lastUpdatedTime = default;
Optional<ModelInfo> modelInfo = default;
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("modelId"u8))
{
modelId = property.Value.GetString();
modelId = property.Value.GetGuid();
continue;
}
if (property.NameEquals("createdTime"u8))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal AnomalyDetectionModel(DateTimeOffset createdTime, DateTimeOffset lastUp
/// Training result of a model including its status, errors and diagnostics
/// information.
/// </param>
internal AnomalyDetectionModel(string modelId, DateTimeOffset createdTime, DateTimeOffset lastUpdatedTime, ModelInfo modelInfo)
internal AnomalyDetectionModel(Guid modelId, DateTimeOffset createdTime, DateTimeOffset lastUpdatedTime, ModelInfo modelInfo)
{
ModelId = modelId;
CreatedTime = createdTime;
Expand All @@ -38,7 +38,7 @@ internal AnomalyDetectionModel(string modelId, DateTimeOffset createdTime, DateT
}

/// <summary> Model identifier. </summary>
public string ModelId { get; }
public Guid ModelId { get; }
/// <summary> Date and time (UTC) when the model was created. </summary>
public DateTimeOffset CreatedTime { get; }
/// <summary> Date and time (UTC) when the model was last updated. </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("dataSource"u8);
writer.WriteStringValue(DataSource);
writer.WriteStringValue(DataSource.AbsoluteUri);
writer.WritePropertyName("topContributorCount"u8);
writer.WriteNumberValue(TopContributorCount);
writer.WritePropertyName("startTime"u8);
Expand All @@ -34,15 +34,15 @@ internal static MultivariateBatchDetectionOptions DeserializeMultivariateBatchDe
{
return null;
}
string dataSource = default;
Uri dataSource = default;
int topContributorCount = default;
DateTimeOffset startTime = default;
DateTimeOffset endTime = default;
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("dataSource"u8))
{
dataSource = property.Value.GetString();
dataSource = new Uri(property.Value.GetString());
continue;
}
if (property.NameEquals("topContributorCount"u8))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public partial class MultivariateBatchDetectionOptions
/// be date-time of ISO 8601 format.
/// </param>
/// <exception cref="ArgumentNullException"> <paramref name="dataSource"/> is null. </exception>
public MultivariateBatchDetectionOptions(string dataSource, int topContributorCount, DateTimeOffset startTime, DateTimeOffset endTime)
public MultivariateBatchDetectionOptions(Uri dataSource, int topContributorCount, DateTimeOffset startTime, DateTimeOffset endTime)
{
Argument.AssertNotNull(dataSource, nameof(dataSource));

Expand All @@ -53,7 +53,7 @@ public MultivariateBatchDetectionOptions(string dataSource, int topContributorCo
/// Azure blob storage based on you data schema selection. The data schema should
/// be exactly the same with those used in the training phase.
/// </summary>
public string DataSource { get; set; }
public Uri DataSource { get; set; }
/// <summary>
/// An optional field, which is used to specify the number of top contributed
/// variables for one anomalous timestamp in the response. The default number is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#nullable disable

using System;
using System.Collections.Generic;
using System.Text.Json;
using Azure;
Expand All @@ -20,14 +21,14 @@ internal static MultivariateDetectionResult DeserializeMultivariateDetectionResu
{
return null;
}
string resultId = default;
Guid resultId = default;
MultivariateBatchDetectionResultSummary summary = default;
IReadOnlyList<AnomalyState> results = default;
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("resultId"u8))
{
resultId = property.Value.GetString();
resultId = property.Value.GetGuid();
continue;
}
if (property.NameEquals("summary"u8))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ internal MultivariateDetectionResult(MultivariateBatchDetectionResultSummary sum
/// <param name="resultId"> Result identifier, which is used to fetch the results of an inference call. </param>
/// <param name="summary"> Multivariate anomaly detection status. </param>
/// <param name="results"> Detection result for each timestamp. </param>
internal MultivariateDetectionResult(string resultId, MultivariateBatchDetectionResultSummary summary, IReadOnlyList<AnomalyState> results)
internal MultivariateDetectionResult(Guid resultId, MultivariateBatchDetectionResultSummary summary, IReadOnlyList<AnomalyState> results)
{
ResultId = resultId;
Summary = summary;
Results = results;
}

/// <summary> Result identifier, which is used to fetch the results of an inference call. </summary>
public string ResultId { get; }
public Guid ResultId { get; }
/// <summary> Multivariate anomaly detection status. </summary>
public MultivariateBatchDetectionResultSummary Summary { get; }
/// <summary> Detection result for each timestamp. </summary>
Expand Down
Loading

0 comments on commit 5d8e3c5

Please sign in to comment.