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

[TSI] Readme for samples #20765

Merged
merged 8 commits into from
May 5, 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
652 changes: 643 additions & 9 deletions sdk/timeseriesinsights/Azure.IoT.TimeSeriesInsights/samples/Readme.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public async Task RunSamplesAsync(TimeSeriesInsightsClient client)
PrintHeader("TIME SERIES INSIGHTS HIERARCHIES SAMPLE");

#region Snippet:TimeSeriesInsightsSampleCreateHierarchies
var tsiHierarchyName = "sampleHierarchy";
var tsiInstanceField1 = "hierarchyLevel1";
var hierarchySource = new TimeSeriesHierarchySource();
hierarchySource.InstanceFieldNames.Add(tsiInstanceField1);
hierarchySource.InstanceFieldNames.Add("hierarchyLevel1");

var tsiHierarchy = new TimeSeriesHierarchy(tsiHierarchyName, hierarchySource);
tsiHierarchy.Id = "sampleHierarchyId";
var tsiHierarchy = new TimeSeriesHierarchy("sampleHierarchy", hierarchySource)
{
Id = "sampleHierarchyId"
};

var timeSeriesHierarchies = new List<TimeSeriesHierarchy>
{
Expand Down Expand Up @@ -66,10 +66,9 @@ public async Task RunSamplesAsync(TimeSeriesInsightsClient client)

#region Snippet:TimeSeriesInsightsSampleReplaceHierarchies
// Update hierarchies with adding a new instance field
var tsiInstanceField2 = "hierarchyLevel2";
foreach (TimeSeriesHierarchy hierarchy in timeSeriesHierarchies)
{
hierarchy.Source.InstanceFieldNames.Add(tsiInstanceField2);
hierarchy.Source.InstanceFieldNames.Add("hierarchyLevel2");
}

Response<TimeSeriesHierarchyOperationResult[]> updateHierarchiesResult = await client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private static TimeSeriesInsightsClient GetTimeSeriesInsightsClient(string tenan

#region Snippet:TimeSeriesInsightsSampleCreateServiceClientWithClientSecret

// DefaultAzureCredential supports different authentication mechanisms and determines the appropriate credential type based of the environment it is executing in.
// DefaultAzureCredential supports different authentication mechanisms and determines the appropriate credential type based on the environment it is executing in.
// It attempts to use multiple credential types in an order until it finds a working credential.
var tokenCredential = new DefaultAzureCredential();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private async Task RunQuerySeriesSample(TimeSeriesInsightsClient client, TimeSer
{
// Query for two series, one with the temperature values in Celsius and another in Fahrenheit
#region Snippet:TimeSeriesInsightsSampleQuerySeries
Console.WriteLine("\n\nQuery for temperature series in celsius and fahrenheit over the past 10 minutes.\n");
Console.WriteLine("\n\nQuery for temperature series in Celsius and Fahrenheit over the past 10 minutes.\n");

DateTimeOffset endTime = DateTime.UtcNow;
DateTimeOffset startTime = endTime.AddMinutes(-10);
Expand Down Expand Up @@ -141,7 +141,7 @@ private async Task RunQueryAggregateSeriesSample(TimeSeriesInsightsClient client
#endregion Snippet:TimeSeriesInsightsSampleQueryAggregateSeriesWithNumericVariable

#region Snippet:TimeSeriesInsightsSampleQueryAggregateSeriesWithAggregateVariable
Console.WriteLine("\n\nCount the number of temperature vents over the past 3 minutes, in 1-minute time slots.\n");
Console.WriteLine("\n\nCount the number of temperature events over the past 3 minutes, in 1-minute time slots.\n");

// Get the count of events in 60-second time slots over the past 3 minutes
DateTimeOffset endTime = DateTime.UtcNow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,16 @@ public async Task RunSamplesAsync(TimeSeriesInsightsClient client)
PrintHeader("TIME SERIES INSIGHTS TYPES SAMPLE");

#region Snippet:TimeSeriesInsightsSampleCreateType
// Create an aggregate type
// Create a type with an aggregate variable
var timeSeriesTypes = new List<TimeSeriesType>();

var countExpression = new TimeSeriesExpression("count()");
var aggregateVariable = new AggregateVariable(countExpression);
var variables = new Dictionary<string, TimeSeriesVariable>();
var variableName = "aggregateVariable";
variables.Add(variableName, aggregateVariable);
variables.Add("aggregateVariable", aggregateVariable);

var timeSeriesTypesProperties = new Dictionary<string, string>
{
{ "Type1", "Type1Id"},
{ "Type2", "Type2Id"}
};

foreach (KeyValuePair<string, string> property in timeSeriesTypesProperties)
{
var type = new TimeSeriesType(property.Key, variables)
{
Id = property.Value
};
timeSeriesTypes.Add(type);
}
timeSeriesTypes.Add(new TimeSeriesType("Type1", variables) { Id = "Type1Id" });
timeSeriesTypes.Add(new TimeSeriesType("Type2", variables) { Id = "Type2Id" });

Response<TimeSeriesTypeOperationResult[]> createTypesResult = await client
.Types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class TimeSeriesInsightsClient
/// </seealso>
/// <example>
/// <code snippet="Snippet:TimeSeriesInsightsSampleCreateServiceClientWithClientSecret">
/// // DefaultAzureCredential supports different authentication mechanisms and determines the appropriate credential type based of the environment it is executing in.
/// // DefaultAzureCredential supports different authentication mechanisms and determines the appropriate credential type based on the environment it is executing in.
/// // It attempts to use multiple credential types in an order until it finds a working credential.
/// var tokenCredential = new DefaultAzureCredential();
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,13 +416,13 @@ public virtual Response<TimeSeriesHierarchyOperationResult[]> GetById(
/// </exception>
/// <example>
/// <code snippet="Snippet:TimeSeriesInsightsSampleCreateHierarchies">
/// var tsiHierarchyName = &quot;sampleHierarchy&quot;;
/// var tsiInstanceField1 = &quot;hierarchyLevel1&quot;;
/// var hierarchySource = new TimeSeriesHierarchySource();
/// hierarchySource.InstanceFieldNames.Add(tsiInstanceField1);
/// hierarchySource.InstanceFieldNames.Add(&quot;hierarchyLevel1&quot;);
///
/// var tsiHierarchy = new TimeSeriesHierarchy(tsiHierarchyName, hierarchySource);
/// tsiHierarchy.Id = &quot;sampleHierarchyId&quot;;
/// var tsiHierarchy = new TimeSeriesHierarchy(&quot;sampleHierarchy&quot;, hierarchySource)
/// {
/// Id = &quot;sampleHierarchyId&quot;
/// };
///
/// var timeSeriesHierarchies = new List&lt;TimeSeriesHierarchy&gt;
/// {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public virtual QueryAnalyzer CreateEventsQueryAnalyzer(
/// <returns>The <see cref="QueryAnalyzer"/> object that can be used to retrieve the pageable list <see cref="AsyncPageable{TimeSeriesPoint}"/>.</returns>
/// <example>
/// <code snippet="Snippet:TimeSeriesInsightsSampleQuerySeries">
/// Console.WriteLine(&quot;\n\nQuery for temperature series in celsius and fahrenheit over the past 10 minutes.\n&quot;);
/// Console.WriteLine(&quot;\n\nQuery for temperature series in Celsius and Fahrenheit over the past 10 minutes.\n&quot;);
///
/// DateTimeOffset endTime = DateTime.UtcNow;
/// DateTimeOffset startTime = endTime.AddMinutes(-10);
Expand Down Expand Up @@ -261,7 +261,7 @@ public virtual QueryAnalyzer CreateSeriesQueryAnalyzer(
/// <returns>The <see cref="QueryAnalyzer"/> object that can be used to retrieve the pageable list <see cref="AsyncPageable{TimeSeriesPoint}"/>.</returns>
/// <example>
/// <code snippet="Snippet:TimeSeriesInsightsSampleQueryAggregateSeriesWithAggregateVariable">
/// Console.WriteLine(&quot;\n\nCount the number of temperature vents over the past 3 minutes, in 1-minute time slots.\n&quot;);
/// Console.WriteLine(&quot;\n\nCount the number of temperature events over the past 3 minutes, in 1-minute time slots.\n&quot;);
///
/// // Get the count of events in 60-second time slots over the past 3 minutes
/// DateTimeOffset endTime = DateTime.UtcNow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,29 +416,16 @@ public virtual Response<TimeSeriesTypeOperationResult[]> GetById(
/// </exception>
/// <example>
/// <code snippet="Snippet:TimeSeriesInsightsSampleCreateType">
/// // Create an aggregate type
/// // Create a type with an aggregate variable
/// var timeSeriesTypes = new List&lt;TimeSeriesType&gt;();
///
/// var countExpression = new TimeSeriesExpression(&quot;count()&quot;);
/// var aggregateVariable = new AggregateVariable(countExpression);
/// var variables = new Dictionary&lt;string, TimeSeriesVariable&gt;();
/// var variableName = &quot;aggregateVariable&quot;;
/// variables.Add(variableName, aggregateVariable);
/// variables.Add(&quot;aggregateVariable&quot;, aggregateVariable);
///
/// var timeSeriesTypesProperties = new Dictionary&lt;string, string&gt;
/// {
/// { &quot;Type1&quot;, &quot;Type1Id&quot;},
/// { &quot;Type2&quot;, &quot;Type2Id&quot;}
/// };
///
/// foreach (KeyValuePair&lt;string, string&gt; property in timeSeriesTypesProperties)
/// {
/// var type = new TimeSeriesType(property.Key, variables)
/// {
/// Id = property.Value
/// };
/// timeSeriesTypes.Add(type);
/// }
/// timeSeriesTypes.Add(new TimeSeriesType(&quot;Type1&quot;, variables) { Id = &quot;Type1Id&quot; });
/// timeSeriesTypes.Add(new TimeSeriesType(&quot;Type2&quot;, variables) { Id = &quot;Type2Id&quot; });
///
/// Response&lt;TimeSeriesTypeOperationResult[]&gt; createTypesResult = await client
/// .Types
Expand Down