forked from ddrilling/AsbCloudServer
Modify telemetry tracker to keep remote and server dates.
Update related services. Small refactor TelemetryController: exclude dictionaries updates from tracker update. All tracker updates moved to services.
This commit is contained in:
parent
5966920019
commit
da9e94b4b9
@ -8,7 +8,6 @@ namespace AsbCloudApp.Services
|
|||||||
{
|
{
|
||||||
public interface ITelemetryService
|
public interface ITelemetryService
|
||||||
{
|
{
|
||||||
void SaveRequestDate(string uid);
|
|
||||||
int? GetidWellByTelemetryUid(string uid);
|
int? GetidWellByTelemetryUid(string uid);
|
||||||
int GetOrCreateTemetryIdByUid(string uid);
|
int GetOrCreateTemetryIdByUid(string uid);
|
||||||
double GetTimezoneOffsetByTelemetryId(int idTelemetry);
|
double GetTimezoneOffsetByTelemetryId(int idTelemetry);
|
||||||
@ -19,5 +18,6 @@ namespace AsbCloudApp.Services
|
|||||||
IEnumerable<TelemetryDto> GetTransmittingTelemetriesAsync(int idCompany);
|
IEnumerable<TelemetryDto> GetTransmittingTelemetriesAsync(int idCompany);
|
||||||
DateTime GetLastTelemetryDate(string telemetryUid);
|
DateTime GetLastTelemetryDate(string telemetryUid);
|
||||||
DateTime GetLastTelemetryDate(int telemetryId);
|
DateTime GetLastTelemetryDate(int telemetryId);
|
||||||
|
void SaveRequestDate(string uid, DateTime remoteDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@ namespace AsbCloudApp.Services
|
|||||||
{
|
{
|
||||||
public interface ITelemetryTracker
|
public interface ITelemetryTracker
|
||||||
{
|
{
|
||||||
void SaveRequestDate(string uid);
|
|
||||||
DateTime GetLastTelemetryDateByUid(string uid);
|
DateTime GetLastTelemetryDateByUid(string uid);
|
||||||
IEnumerable<string> GetTransmittingTelemetryUids();
|
IEnumerable<string> GetTransmittingTelemetriesUids();
|
||||||
|
void SaveRequestDate(string uid, DateTime remoteDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,6 +145,9 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
var telemetryId = telemetryService.GetOrCreateTemetryIdByUid(uid);
|
var telemetryId = telemetryService.GetOrCreateTemetryIdByUid(uid);
|
||||||
|
|
||||||
|
var maxDateDto = dtos.Max(m => m.Date);
|
||||||
|
telemetryService.SaveRequestDate(uid, maxDateDto);
|
||||||
|
|
||||||
foreach (var dto in dtos)
|
foreach (var dto in dtos)
|
||||||
{
|
{
|
||||||
var entity = dto.Adapt<TelemetryMessage>();
|
var entity = dto.Adapt<TelemetryMessage>();
|
||||||
|
@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -45,6 +44,9 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
var idTelemetry = telemetryService.GetOrCreateTemetryIdByUid(uid);
|
var idTelemetry = telemetryService.GetOrCreateTemetryIdByUid(uid);
|
||||||
var dtoMinDate = dtos.Min(d => d.Date);
|
var dtoMinDate = dtos.Min(d => d.Date);
|
||||||
var dtoMaxDate = dtos.Max(d => d.Date);
|
var dtoMaxDate = dtos.Max(d => d.Date);
|
||||||
|
|
||||||
|
telemetryService.SaveRequestDate(uid, dtoMaxDate);
|
||||||
|
|
||||||
var dataSet = db.Set<TModel>();
|
var dataSet = db.Set<TModel>();
|
||||||
|
|
||||||
var oldData = await (from d in dataSet
|
var oldData = await (from d in dataSet
|
||||||
|
@ -29,7 +29,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
public IEnumerable<TelemetryDto> GetTransmittingTelemetriesAsync(int idCompany)
|
public IEnumerable<TelemetryDto> GetTransmittingTelemetriesAsync(int idCompany)
|
||||||
{
|
{
|
||||||
var telemetryDtos = new List<TelemetryDto>();
|
var telemetryDtos = new List<TelemetryDto>();
|
||||||
IEnumerable<string> activeTelemetriesUids = telemetryTracker.GetTransmittingTelemetryUids();
|
IEnumerable<string> activeTelemetriesUids = telemetryTracker.GetTransmittingTelemetriesUids();
|
||||||
if (activeTelemetriesUids.Any())
|
if (activeTelemetriesUids.Any())
|
||||||
{
|
{
|
||||||
var telemetries = cacheTelemetry
|
var telemetries = cacheTelemetry
|
||||||
@ -40,8 +40,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return telemetryDtos;
|
return telemetryDtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveRequestDate(string uid) =>
|
public void SaveRequestDate(string uid, DateTime remoteDate) =>
|
||||||
telemetryTracker.SaveRequestDate(uid);
|
telemetryTracker.SaveRequestDate(uid, remoteDate);
|
||||||
|
|
||||||
public DateTime GetLastTelemetryDate(string telemetryUid) =>
|
public DateTime GetLastTelemetryDate(string telemetryUid) =>
|
||||||
telemetryTracker.GetLastTelemetryDateByUid(telemetryUid);
|
telemetryTracker.GetLastTelemetryDateByUid(telemetryUid);
|
||||||
@ -113,17 +113,6 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
// найти телеметрию с наиболее полными справочниками и принять её за основную
|
// найти телеметрию с наиболее полными справочниками и принять её за основную
|
||||||
// отделить основную от остальных
|
// отделить основную от остальных
|
||||||
// связонные сущности:
|
|
||||||
// Telemetry
|
|
||||||
// TelemetryInfo
|
|
||||||
// TelemetryEvent
|
|
||||||
// TelemetryUser
|
|
||||||
|
|
||||||
// TelemetryMessage
|
|
||||||
// TelemetryDataSpin
|
|
||||||
// TelemetryDataSaub
|
|
||||||
// TelemetryAnalysis
|
|
||||||
// Well
|
|
||||||
|
|
||||||
// Оценка трудоебкости
|
// Оценка трудоебкости
|
||||||
var telemetriesGrade = db.Telemetries
|
var telemetriesGrade = db.Telemetries
|
||||||
|
@ -10,7 +10,24 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
public class TelemetryTracker : ITelemetryTracker
|
public class TelemetryTracker : ITelemetryTracker
|
||||||
{
|
{
|
||||||
private readonly Dictionary<string, DateTime> requests;
|
class TrackerStat
|
||||||
|
{
|
||||||
|
//public int Id { get; set; }
|
||||||
|
|
||||||
|
public string RemoteUid { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Время последнего запроса (по времени сервера)
|
||||||
|
/// </summary>
|
||||||
|
public DateTime LastTimeServer { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Время указанное в данных последнего запроса (из удаленного источника)
|
||||||
|
/// </summary>
|
||||||
|
public DateTime LastTimeRemote { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly Dictionary<string, TrackerStat> requests;
|
||||||
|
|
||||||
public TelemetryTracker(CacheDb cacheDb)
|
public TelemetryTracker(CacheDb cacheDb)
|
||||||
{
|
{
|
||||||
@ -33,18 +50,34 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
requests = lastTelemetriesDates.Select(t => new
|
requests = lastTelemetriesDates.Select(t => new
|
||||||
{
|
{
|
||||||
Uid = cacheTelemetry.FirstOrDefault(c => c.Id == t.IdTelemetry).RemoteUid,
|
//Id = t.IdTelemetry,
|
||||||
t.Date
|
RemoteUid = cacheTelemetry.FirstOrDefault(c => c.Id == t.IdTelemetry).RemoteUid,
|
||||||
}).ToDictionary(t => t.Uid, u => u.Date);
|
LastTimeRemote = t.Date,
|
||||||
|
|
||||||
|
}).ToDictionary(t => t.RemoteUid, t => new TrackerStat {
|
||||||
|
//Id = t.Id,
|
||||||
|
RemoteUid = t.RemoteUid,
|
||||||
|
LastTimeRemote = t.LastTimeRemote,
|
||||||
|
LastTimeServer = t.LastTimeRemote,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveRequestDate(string uid) =>
|
public void SaveRequestDate(string uid, DateTime remoteDate)
|
||||||
requests[uid] = DateTime.Now;
|
{
|
||||||
|
var stat = requests.GetValueOrDefault(uid);
|
||||||
|
if(stat is null)
|
||||||
|
{
|
||||||
|
stat = new TrackerStat{ RemoteUid = uid };
|
||||||
|
requests[uid] = stat;
|
||||||
|
}
|
||||||
|
stat.LastTimeServer = DateTime.Now;
|
||||||
|
stat.LastTimeRemote = remoteDate;
|
||||||
|
}
|
||||||
|
|
||||||
public DateTime GetLastTelemetryDateByUid(string uid) =>
|
public DateTime GetLastTelemetryDateByUid(string uid) =>
|
||||||
requests.GetValueOrDefault(uid, DateTime.MinValue);
|
requests.GetValueOrDefault(uid)?.LastTimeRemote ?? default;
|
||||||
|
|
||||||
public IEnumerable<string> GetTransmittingTelemetryUids() =>
|
public IEnumerable<string> GetTransmittingTelemetriesUids() =>
|
||||||
requests.Keys;
|
requests.Keys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,6 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
public IActionResult PostInfo(string uid, [FromBody] TelemetryInfoDto info)
|
public IActionResult PostInfo(string uid, [FromBody] TelemetryInfoDto info)
|
||||||
{
|
{
|
||||||
telemetryService.UpdateInfo(uid, info);
|
telemetryService.UpdateInfo(uid, info);
|
||||||
telemetryService.SaveRequestDate(uid);
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +71,6 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
await Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}")
|
await Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}")
|
||||||
.SendAsync("ReceiveMessages", dtos), token).ConfigureAwait(false);
|
.SendAsync("ReceiveMessages", dtos), token).ConfigureAwait(false);
|
||||||
|
|
||||||
telemetryService.SaveRequestDate(uid);
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +88,6 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
{
|
{
|
||||||
await eventService.UpsertAsync(uid, events, token)
|
await eventService.UpsertAsync(uid, events, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
telemetryService.SaveRequestDate(uid);
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +102,6 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
public IActionResult PostUsers(string uid, [FromBody] List<TelemetryUserDto> users)
|
public IActionResult PostUsers(string uid, [FromBody] List<TelemetryUserDto> users)
|
||||||
{
|
{
|
||||||
telemetryUserService.Upsert(uid, users);
|
telemetryUserService.Upsert(uid, users);
|
||||||
telemetryService.SaveRequestDate(uid);
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,6 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
await Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}")
|
await Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}")
|
||||||
.SendAsync(SirnalRMethodGetDataName, dtos), token).ConfigureAwait(false);
|
.SendAsync(SirnalRMethodGetDataName, dtos), token).ConfigureAwait(false);
|
||||||
|
|
||||||
telemetryService.SaveRequestDate(uid);
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user