Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MetricsAdvisor] Made MetricFeedback class abstract #18511

Merged
merged 2 commits into from
Feb 8, 2021
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 @@ -1005,7 +1005,7 @@ internal MetricEnrichedSeriesData() { }
public System.Collections.Generic.IReadOnlyList<double?> UpperBoundaries { get { throw null; } }
public System.Collections.Generic.IReadOnlyList<double> Values { get { throw null; } }
}
public partial class MetricFeedback
public abstract partial class MetricFeedback
{
internal MetricFeedback() { }
public System.DateTimeOffset? CreatedTime { get { throw null; } }
Expand Down

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 @@ -2,14 +2,15 @@
// Licensed under the MIT License.

using System;
using System.Text.Json;
using Azure.Core;

namespace Azure.AI.MetricsAdvisor.Models
{
/// <summary> <see cref="MetricFeedback"/>s are used to describe feedback on unsatisfactory anomaly detection results.
/// When feedback is created for a given metric, it is applied to future anomaly detection processing of the same series.
/// The processed points will not be re-calculated. </summary>
public partial class MetricFeedback
public abstract partial class MetricFeedback : IUtf8JsonSerializable
{
/// <summary> Initializes a new instance of the <see cref="MetricFeedback"/> class. </summary>
/// <param name="metricId"> The metric unique Id. </param>
Expand Down Expand Up @@ -43,5 +44,31 @@ internal MetricFeedback(string metricId, FeedbackDimensionFilter dimensionFilter

/// <summary> The dimension filter. </summary>
public FeedbackDimensionFilter DimensionFilter { get; internal set; }

internal static MetricFeedback DeserializeMetricFeedback(JsonElement element)
{
if (element.TryGetProperty("feedbackType", out JsonElement discriminator))
{
var discriminatorString = discriminator.GetString();

switch (discriminatorString)
{
case "Anomaly":
return MetricAnomalyFeedback.DeserializeMetricAnomalyFeedback(element);
case "ChangePoint":
return MetricChangePointFeedback.DeserializeMetricChangePointFeedback(element);
case "Comment":
return MetricCommentFeedback.DeserializeMetricCommentFeedback(element);
case "Period":
return MetricPeriodFeedback.DeserializeMetricPeriodFeedback(element);
default:
throw new ArgumentException($"Unknown feedback type returned by the service: {discriminatorString}");
}
}
else
{
throw new ArgumentException("The feedback type was not returned by the service");
}
kinelski marked this conversation as resolved.
Show resolved Hide resolved
}
}
}