feat(api): заготовка для получения статистики по маониторингу роботов
This commit is contained in:
@@ -220,7 +220,7 @@
|
|||||||
|
|
||||||
public static class StatRobotState
|
public static class StatRobotState
|
||||||
{
|
{
|
||||||
public const string Get = BaseStat + "/robot-states/";
|
public const string Get = BaseStat + "/robot-states/{robot}";
|
||||||
public const string Send = BaseStat + "/robot-states/";
|
public const string Send = BaseStat + "/robot-states/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace PARR.API.Contracts.V1.Requests.Queries
|
||||||
|
{
|
||||||
|
public class RobotStateGetQuery
|
||||||
|
{
|
||||||
|
public DateTimeOffset? DateStart { get; set; }
|
||||||
|
public DateTimeOffset? DateEnd { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using PARR.API.Contracts.V1;
|
using PARR.API.Contracts.V1;
|
||||||
using PARR.API.Contracts.V1.Requests;
|
using PARR.API.Contracts.V1.Requests;
|
||||||
|
using PARR.API.Contracts.V1.Requests.Queries;
|
||||||
using PARR.API.Contracts.V1.Responses.Base;
|
using PARR.API.Contracts.V1.Responses.Base;
|
||||||
using PARR.API.Controllers.V1.Base;
|
using PARR.API.Controllers.V1.Base;
|
||||||
using PARR.Constants;
|
using PARR.Constants;
|
||||||
@@ -35,6 +36,54 @@ namespace PARR.API.Controllers.V1.Statistics
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Доступность робота
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet(ApiRoutes.StatRobotState.Get)]
|
||||||
|
public async Task<IActionResult> Get([FromRoute] RobotsAllEnum robot, [FromQuery] RobotStateGetQuery query)
|
||||||
|
{
|
||||||
|
|
||||||
|
var result = await influxDbService.QueryAsync(async handler =>
|
||||||
|
{
|
||||||
|
//var flux = "from(bucket:\"robots\") " +
|
||||||
|
// "|> range(start: 0) " +
|
||||||
|
// "|> filter(fn: (r) => " +
|
||||||
|
// "r._measurement == \"altitude\" and " +
|
||||||
|
// "r._value > 3500)";
|
||||||
|
|
||||||
|
var query = $"from(bucket:\"{influxDbSettings.Robots!.Bucket}\") " +
|
||||||
|
$"|> range(start: -3h) " +
|
||||||
|
$"|> filter(fn: (r) => " +
|
||||||
|
$"r._measurement == \"robots\" " +
|
||||||
|
$"and r.robot == \"{robot.ToString()}\"" +
|
||||||
|
$")";
|
||||||
|
|
||||||
|
|
||||||
|
var tables = await handler.QueryAsync(query, influxDbSettings.Organization);
|
||||||
|
|
||||||
|
|
||||||
|
//return tables.SelectMany(table =>
|
||||||
|
// table.Records.Select(record =>
|
||||||
|
// new AltitudeModel
|
||||||
|
// {
|
||||||
|
// Time = record.GetTime().ToString(),
|
||||||
|
// Altitude = int.Parse(record.GetValue()?.ToString() ?? "0")
|
||||||
|
// }));
|
||||||
|
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}, influxDbSettings.Robots!.Token);
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Ошибка при получении статистики" } }));
|
||||||
|
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Статистика доступности роботов. Передать инф-у о доступности
|
/// Статистика доступности роботов. Передать инф-у о доступности
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -59,7 +108,7 @@ namespace PARR.API.Controllers.V1.Statistics
|
|||||||
}, influxDbSettings.Robots!.Token);
|
}, influxDbSettings.Robots!.Token);
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
return BadRequest($"Ошибка при отправке данных");
|
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = $"Ошибка при отправке данных" } }));
|
||||||
|
|
||||||
return Ok(new Response<string>("", true));
|
return Ok(new Response<string>("", true));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,6 @@ namespace PARR.DAL.InfluxDbServices
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//using var client = new InfluxDBClient(settings.Url, token);
|
|
||||||
//using var write = client.GetWriteApi();
|
|
||||||
|
|
||||||
using var client = new InfluxDBClient(settings.Url, token);
|
using var client = new InfluxDBClient(settings.Url, token);
|
||||||
using (var write = client.GetWriteApi())
|
using (var write = client.GetWriteApi())
|
||||||
{
|
{
|
||||||
@@ -39,21 +36,21 @@ namespace PARR.DAL.InfluxDbServices
|
|||||||
|
|
||||||
public async Task<T> QueryAsync<T>(Func<QueryApi, Task<T>> action, string token)
|
public async Task<T> QueryAsync<T>(Func<QueryApi, Task<T>> action, string token)
|
||||||
{
|
{
|
||||||
//TODO:
|
try
|
||||||
throw new NotImplementedException();
|
{
|
||||||
//try
|
using var client = new InfluxDBClient(settings.Url, token);
|
||||||
//{
|
var query = client.GetQueryApi();
|
||||||
using var client = InfluxDBClientFactory.Create(settings.Url, token);
|
|
||||||
var query = client.GetQueryApi();
|
|
||||||
|
|
||||||
return await action(query);
|
return await action(query);
|
||||||
//}
|
}
|
||||||
//catch (Exception ex)
|
catch (Exception ex)
|
||||||
//{
|
{
|
||||||
// logger.LogError(ex, "Ошибка при запросе данных из БД, InfuxDb");
|
logger.LogError(ex, "Ошибка при запросе данных из БД, InfuxDb");
|
||||||
// // return Task.FromResult();
|
// return Task.FromResult();
|
||||||
// return Task.CompletedTask;
|
// return Task.CompletedTask;
|
||||||
//}
|
//return default(T);
|
||||||
|
return default(T);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user