private List <Reading> ParseReadings(QueryResultPage queryResultPage)
        {
            var readings = new List <Reading>();

            if (queryResultPage.Properties != null && queryResultPage.Timestamps != null)
            {
                Console.Write("timestamp,");
                Console.WriteLine(string.Join(",", queryResultPage.Properties.Select(v => v.Name)));
                int i          = 0;
                var heartRates = queryResultPage.Properties.Where(p => p.Name == "heart_rate").First();
                var o2s        = queryResultPage.Properties.Where(p => p.Name == "o2").First();

                foreach (DateTime?bodyTimestamp in queryResultPage.Timestamps)
                {
                    Reading reading = new Reading();
                    reading.TimeStamp = bodyTimestamp;
                    reading.HeartRate = int.Parse(heartRates.Values[i].ToString());
                    reading.SpO2      = (double)o2s.Values[i];
                    readings.Add(reading);
                    i++;
                }
                Console.WriteLine();
            }
            return(readings);
        }
Exemplo n.º 2
0
        private static void PrintResponse(QueryResultPage queryResultPage)
        {
            Console.WriteLine();
            Console.WriteLine("Query result page:");
            Console.WriteLine();

            if (queryResultPage.Properties != null && queryResultPage.Timestamps != null)
            {
                Console.Write("timestamp,");
                Console.WriteLine(string.Join(",", queryResultPage.Properties.Select(v => v.Name)));
                int i = 0;
                foreach (DateTime?bodyTimestamp in queryResultPage.Timestamps)
                {
                    List <string> row = new List <string>();

                    row.Add(bodyTimestamp?.ToString("o"));
                    foreach (PropertyValues propertyValues in queryResultPage.Properties)
                    {
                        row.Add(propertyValues.Values[i] == null ? "null" : propertyValues.Values[i].ToString());
                    }

                    Console.WriteLine(string.Join(",", row));
                    i++;
                }
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("Result page is empty.");
            }
        }
Exemplo n.º 3
0
        private static async Task RunGetSeriesAsync()
        {
            string continuationToken;

            do
            {
                QueryResultPage queryResponse = await _client.ExecuteQueryPagedAsync(
                    new QueryRequest(
                        getSeries : new GetSeries(
                            timeSeriesId : TimeSeriesId,
                            searchSpan : SearchSpan,
                            filter : null,
                            projectedVariables : new[] { "Value" },
                            inlineVariables : new Dictionary <string, Variable>()
                {
                    ["Value"] = new NumericVariable(
                        value : new Tsx("$event.data"),
                        aggregation : new Tsx("avg($value)"))
                })));

                PrintResponse(queryResponse);

                continuationToken = queryResponse.ContinuationToken;
            }while (continuationToken != null);
        }
Exemplo n.º 4
0
        public async Task <QueryResultPage> GetSeries(string EnvironmentFqdn, string TimeSeriesId)
        {
            TimeSeriesInsightsClient tsi = GetTimeSeriesInsightsClientAsync(EnvironmentFqdn).Result;
            string continuationToken;

            do
            {
                DateTimeRange SearchSpan = new DateTimeRange(new DateTime(2019, 12, 26).ToUniversalTime(), new DateTime(2019, 12, 27).ToUniversalTime());
                //object[] TimeSeriesIdValue = new object[] { "AND-ARU-XI82121_F" };
                QueryResultPage queryResponse = await tsi.ExecuteQueryPagedAsync(
                    new QueryRequest(
                        getSeries : new GetSeries(
                            timeSeriesId : new object[] { TimeSeriesId },
                            searchSpan : SearchSpan,
                            filter : null,
                            projectedVariables : new[] { "Float" },
                            inlineVariables : new Dictionary <string, NumericVariable>()
                {
                    ["Float"] = new NumericVariable(
                        value : new Tsx("$event.series_value"),
                        aggregation : new Tsx("avg($value)"))
                })));

                return(queryResponse);
                //continuationToken = queryResponse.ContinuationToken;
            }while (continuationToken != null);
        }
Exemplo n.º 5
0
        private static async Task RunGetEventsAsync()
        {
            string continuationToken;

            do
            {
                QueryResultPage queryResponse = await _client.ExecuteQueryPagedAsync(
                    new QueryRequest(
                        getEvents : new GetEvents(
                            timeSeriesId : TimeSeriesId,
                            searchSpan : SearchSpan,
                            filter : null)));

                PrintResponse(queryResponse);

                continuationToken = queryResponse.ContinuationToken;
            }while (continuationToken != null);
        }
Exemplo n.º 6
0
        private static async Task RunAggregateSeriesAsync()
        {
            string continuationToken = null;

            do
            {
                QueryResultPage queryResponse = await _client.Query.ExecuteAsync(
                    new QueryRequest(
                        aggregateSeries : new AggregateSeries(
                            timeSeriesId : TimeSeriesId,
                            searchSpan : SearchSpan,
                            filter : null,
                            interval : TimeSpan.FromMinutes(5),
                            projectedVariables : new[] { "Min_Numeric", "Max_Numeric", "Sum_Numeric", "Avg_Numeric", "First_Numeric", "Last_Numeric", "Count_Aggregate" },
                            inlineVariables : new Dictionary <string, Variable>()
                {
                    ["Min_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.data"),
                        aggregation : new Tsx("min($value)")),
                    ["Max_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.data"),
                        aggregation : new Tsx("max($value)")),
                    ["Sum_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.data"),
                        aggregation : new Tsx("sum($value)")),
                    ["Avg_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.data"),
                        aggregation : new Tsx("avg($value)")),
                    ["First_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.data"),
                        aggregation : new Tsx("first($value)")),
                    ["Last_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.data"),
                        aggregation : new Tsx("last($value)")),
                    ["Count_Aggregate"] = new AggregateVariable(
                        aggregation : new Tsx("count()"))
                })),
                    continuationToken : continuationToken);

                PrintResponse(queryResponse);

                continuationToken = queryResponse.ContinuationToken;
            }while (continuationToken != null);
        }
Exemplo n.º 7
0
        public async Task <QueryResultPage> GetAggregateSeries(string EnvironmentFqdn, string TimeSeriesId)
        {
            TimeSeriesInsightsClient tsi = GetTimeSeriesInsightsClientAsync(EnvironmentFqdn).Result;
            string continuationToken;

            do
            {
                DateTimeRange SearchSpan = new DateTimeRange(new DateTime(2019, 12, 26).ToUniversalTime(), new DateTime(2019, 12, 27).ToUniversalTime());
                //object[] TimeSeriesIdValue = new object[] { "AND-ARU-XI82121_F" };
                QueryResultPage queryResponse = await tsi.ExecuteQueryPagedAsync(
                    new QueryRequest(
                        aggregateSeries : new AggregateSeries(
                            timeSeriesId : new object[] { TimeSeriesId },
                            searchSpan : SearchSpan,
                            filter : null,
                            interval : TimeSpan.FromHours(5),
                            projectedVariables : new[] { "Min_Numeric", "Max_Numeric", "Sum_Numeric", "Avg_Numeric", "First_Numeric", "Last_Numeric" },
                            inlineVariables : new Dictionary <string, Variable>()
                {
                    ["Min_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.series_value"),
                        aggregation : new Tsx("min($value)")),
                    ["Max_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.series_value"),
                        aggregation : new Tsx("max($value)")),
                    ["Sum_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.series_value"),
                        aggregation : new Tsx("sum($value)")),
                    ["Avg_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.series_value"),
                        aggregation : new Tsx("avg($value)")),
                    ["First_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.series_value"),
                        aggregation : new Tsx("first($value)")),
                    ["Last_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.series_value"),
                        aggregation : new Tsx("last($value)"))
                })));

                return(queryResponse);
                //continuationToken = queryResponse.ContinuationToken;
            }while (continuationToken != null);
        }
        private List <Reading> GetReadingsBetween(DateTime from, DateTime to)
        {
            var           readings    = new List <Reading>();
            DateTimeRange SearchToday = new DateTimeRange(from.ToUniversalTime(), to.ToUniversalTime());

            string continuationToken;

            do
            {
                QueryResultPage queryResponse = client.ExecuteQueryPagedAsync(
                    new QueryRequest(
                        getEvents: new GetEvents(timeSeriesId: timeSeriesId, searchSpan: SearchToday, filter: null))).Result;

                readings.AddRange(ParseReadings(queryResponse));

                continuationToken = queryResponse.ContinuationToken;
            }while (continuationToken != null);

            return(readings);
        }
Exemplo n.º 9
0
        public async Task <QueryResultPage> GetEvents(string EnvironmentFqdn, string TimeSeriesId)
        {
            TimeSeriesInsightsClient tsi = GetTimeSeriesInsightsClientAsync(EnvironmentFqdn).Result;
            string continuationToken;

            do
            {
                DateTimeRange SearchSpan = new DateTimeRange(new DateTime(2019, 12, 26).ToUniversalTime(), new DateTime(2019, 12, 27).ToUniversalTime());
                //object[] TimeSeriesIdValue = new object[] { "AND-ARU-XI82121_F" };
                QueryResultPage queryResponse = await tsi.ExecuteQueryPagedAsync(
                    new QueryRequest(
                        getSeries : new GetSeries(
                            timeSeriesId : new object[] { TimeSeriesId },
                            searchSpan : SearchSpan,
                            filter : null
                            )));

                return(queryResponse);
                //continuationToken = queryResponse.ContinuationToken;
            }while (continuationToken != null);
        }
Exemplo n.º 10
0
        private static async Task RunGetEventsWithProjectedPropertiesAsync()
        {
            string continuationToken;

            do
            {
                QueryResultPage queryResponse = await _client.Query.ExecuteAsync(
                    new QueryRequest(
                        getEvents : new GetEvents(
                            timeSeriesId : TimeSeriesId,
                            searchSpan : SearchSpan,
                            filter : null,
                            projectedProperties : new List <EventProperty>()
                {
                    new EventProperty("data", PropertyTypes.Double)
                })));

                PrintResponse(queryResponse);

                continuationToken = queryResponse.ContinuationToken;
            }while (continuationToken != null);
        }
Exemplo n.º 11
0
        private static async Task RunAggregateSeriesAsync()
        {
            string continuationToken;

            do
            {
                QueryResultPage queryResponse = await _client.Query.ExecuteAsync(
                    new QueryRequest(
                        aggregateSeries : new AggregateSeries(
                            timeSeriesId : TimeSeriesId,
                            searchSpan : SearchSpan,
                            filter : null,
                            interval : TimeSpan.FromMinutes(5),
                            projectedVariables : new[] { "Min_Numeric", "Max_Numeric", "Sum_Numeric", "Avg_Numeric", "First_Numeric", "Last_Numeric", "SampleInterpolated_Numeric_Step_NoBoundary", "SampleInterpolated_Numeric_Step", "SampleInterpolated_Numeric_Linear_NoBoundary", "SampleInterpolated_Numeric_Linear", "Categorical_NonInterpolated", "Categorical_Interpolated", "Count_Aggregate" },
                            inlineVariables : new Dictionary <string, Variable>()
                {
                    ["Min_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.data"),
                        aggregation : new Tsx("min($value)")),
                    ["Max_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.data"),
                        aggregation : new Tsx("max($value)")),
                    ["Sum_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.data"),
                        aggregation : new Tsx("sum($value)")),
                    ["Avg_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.data"),
                        aggregation : new Tsx("avg($value)")),
                    ["First_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.data"),
                        aggregation : new Tsx("first($value)")),
                    ["Last_Numeric"] = new NumericVariable(
                        value : new Tsx("$event.data"),
                        aggregation : new Tsx("last($value)")),
                    ["SampleInterpolated_Numeric_Step_NoBoundary"] = new NumericVariable(
                        value : new Tsx("$event.data"),
                        aggregation : new Tsx("left($value)"),
                        interpolation : new Interpolation(kind : "Step")),
                    ["SampleInterpolated_Numeric_Step"] = new NumericVariable(
                        value : new Tsx("$event.data"),
                        aggregation : new Tsx("left($value)"),
                        interpolation : new Interpolation(kind : "Step", boundary : new InterpolationBoundary(TimeSpan.FromMinutes(1)))),
                    ["SampleInterpolated_Numeric_Linear_NoBoundary"] = new NumericVariable(
                        value : new Tsx("$event.data"),
                        aggregation : new Tsx("left($value)"),
                        interpolation : new Interpolation(kind : "Linear")),
                    ["SampleInterpolated_Numeric_Linear"] = new NumericVariable(
                        value : new Tsx("$event.data"),
                        aggregation : new Tsx("left($value)"),
                        interpolation : new Interpolation(kind : "Linear", boundary : new InterpolationBoundary(TimeSpan.FromMinutes(1)))),
                    ["Categorical_NonInterpolated"] = new CategoricalVariable(
                        value : new Tsx("tolong($event.data)"),
                        categories : new List <TimeSeriesAggregateCategory>()
                    {
                        new TimeSeriesAggregateCategory(label : "Good", values : new List <object>()
                        {
                            39
                        }),
                        new TimeSeriesAggregateCategory(label : "Bad", values : new List <object>()
                        {
                            40
                        }),
                        new TimeSeriesAggregateCategory(label : "OK", values : new List <object>()
                        {
                            41
                        }),
                        new TimeSeriesAggregateCategory(label : "Reject", values : new List <object>()
                        {
                            42
                        })
                    },
                        defaultCategory : new TimeSeriesDefaultCategory("Others")),
                    ["Categorical_Interpolated"] = new CategoricalVariable(
                        value : new Tsx("tolong($event.data)"),
                        categories : new List <TimeSeriesAggregateCategory>()
                    {
                        new TimeSeriesAggregateCategory(label : "Good", values : new List <object>()
                        {
                            39
                        }),
                        new TimeSeriesAggregateCategory(label : "Bad", values : new List <object>()
                        {
                            40
                        }),
                        new TimeSeriesAggregateCategory(label : "OK", values : new List <object>()
                        {
                            41
                        }),
                        new TimeSeriesAggregateCategory(label : "Reject", values : new List <object>()
                        {
                            42
                        })
                    },
                        defaultCategory : new TimeSeriesDefaultCategory("Others"),
                        interpolation : new Interpolation(kind : "Step", boundary : new InterpolationBoundary(TimeSpan.FromMinutes(1)))),
                    ["Count_Aggregate"] = new AggregateVariable(
                        aggregation : new Tsx("count()"))
                })));

                PrintResponse(queryResponse);

                continuationToken = queryResponse.ContinuationToken;
            }while (continuationToken != null);
        }