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
|
||||
{
|
||||
void SaveRequestDate(string uid);
|
||||
int? GetidWellByTelemetryUid(string uid);
|
||||
int GetOrCreateTemetryIdByUid(string uid);
|
||||
double GetTimezoneOffsetByTelemetryId(int idTelemetry);
|
||||
@ -19,5 +18,6 @@ namespace AsbCloudApp.Services
|
||||
IEnumerable<TelemetryDto> GetTransmittingTelemetriesAsync(int idCompany);
|
||||
DateTime GetLastTelemetryDate(string telemetryUid);
|
||||
DateTime GetLastTelemetryDate(int telemetryId);
|
||||
void SaveRequestDate(string uid, DateTime remoteDate);
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ namespace AsbCloudApp.Services
|
||||
{
|
||||
public interface ITelemetryTracker
|
||||
{
|
||||
void SaveRequestDate(string uid);
|
||||
DateTime GetLastTelemetryDateByUid(string uid);
|
||||
IEnumerable<string> GetTransmittingTelemetryUids();
|
||||
IEnumerable<string> GetTransmittingTelemetriesUids();
|
||||
void SaveRequestDate(string uid, DateTime remoteDate);
|
||||
}
|
||||
}
|
||||
|
@ -144,6 +144,9 @@ namespace AsbCloudInfrastructure.Services
|
||||
return null;
|
||||
|
||||
var telemetryId = telemetryService.GetOrCreateTemetryIdByUid(uid);
|
||||
|
||||
var maxDateDto = dtos.Max(m => m.Date);
|
||||
telemetryService.SaveRequestDate(uid, maxDateDto);
|
||||
|
||||
foreach (var dto in dtos)
|
||||
{
|
||||
|
@ -6,7 +6,6 @@ using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -45,6 +44,9 @@ namespace AsbCloudInfrastructure.Services
|
||||
var idTelemetry = telemetryService.GetOrCreateTemetryIdByUid(uid);
|
||||
var dtoMinDate = dtos.Min(d => d.Date);
|
||||
var dtoMaxDate = dtos.Max(d => d.Date);
|
||||
|
||||
telemetryService.SaveRequestDate(uid, dtoMaxDate);
|
||||
|
||||
var dataSet = db.Set<TModel>();
|
||||
|
||||
var oldData = await (from d in dataSet
|
||||
|
@ -29,7 +29,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
public IEnumerable<TelemetryDto> GetTransmittingTelemetriesAsync(int idCompany)
|
||||
{
|
||||
var telemetryDtos = new List<TelemetryDto>();
|
||||
IEnumerable<string> activeTelemetriesUids = telemetryTracker.GetTransmittingTelemetryUids();
|
||||
IEnumerable<string> activeTelemetriesUids = telemetryTracker.GetTransmittingTelemetriesUids();
|
||||
if (activeTelemetriesUids.Any())
|
||||
{
|
||||
var telemetries = cacheTelemetry
|
||||
@ -40,8 +40,8 @@ namespace AsbCloudInfrastructure.Services
|
||||
return telemetryDtos;
|
||||
}
|
||||
|
||||
public void SaveRequestDate(string uid) =>
|
||||
telemetryTracker.SaveRequestDate(uid);
|
||||
public void SaveRequestDate(string uid, DateTime remoteDate) =>
|
||||
telemetryTracker.SaveRequestDate(uid, remoteDate);
|
||||
|
||||
public DateTime GetLastTelemetryDate(string telemetryUid) =>
|
||||
telemetryTracker.GetLastTelemetryDateByUid(telemetryUid);
|
||||
@ -113,17 +113,6 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
// найти телеметрию с наиболее полными справочниками и принять её за основную
|
||||
// отделить основную от остальных
|
||||
// связонные сущности:
|
||||
// Telemetry
|
||||
// TelemetryInfo
|
||||
// TelemetryEvent
|
||||
// TelemetryUser
|
||||
|
||||
// TelemetryMessage
|
||||
// TelemetryDataSpin
|
||||
// TelemetryDataSaub
|
||||
// TelemetryAnalysis
|
||||
// Well
|
||||
|
||||
// Оценка трудоебкости
|
||||
var telemetriesGrade = db.Telemetries
|
||||
|
@ -10,7 +10,24 @@ namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
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)
|
||||
{
|
||||
@ -33,18 +50,34 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
requests = lastTelemetriesDates.Select(t => new
|
||||
{
|
||||
Uid = cacheTelemetry.FirstOrDefault(c => c.Id == t.IdTelemetry).RemoteUid,
|
||||
t.Date
|
||||
}).ToDictionary(t => t.Uid, u => u.Date);
|
||||
//Id = t.IdTelemetry,
|
||||
RemoteUid = cacheTelemetry.FirstOrDefault(c => c.Id == t.IdTelemetry).RemoteUid,
|
||||
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) =>
|
||||
requests[uid] = DateTime.Now;
|
||||
public void SaveRequestDate(string uid, DateTime remoteDate)
|
||||
{
|
||||
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) =>
|
||||
requests.GetValueOrDefault(uid, DateTime.MinValue);
|
||||
requests.GetValueOrDefault(uid)?.LastTimeRemote ?? default;
|
||||
|
||||
public IEnumerable<string> GetTransmittingTelemetryUids() =>
|
||||
public IEnumerable<string> GetTransmittingTelemetriesUids() =>
|
||||
requests.Keys;
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,6 @@ namespace AsbCloudWebApi.Controllers
|
||||
public IActionResult PostInfo(string uid, [FromBody] TelemetryInfoDto info)
|
||||
{
|
||||
telemetryService.UpdateInfo(uid, info);
|
||||
telemetryService.SaveRequestDate(uid);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
@ -72,7 +71,6 @@ namespace AsbCloudWebApi.Controllers
|
||||
await Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}")
|
||||
.SendAsync("ReceiveMessages", dtos), token).ConfigureAwait(false);
|
||||
|
||||
telemetryService.SaveRequestDate(uid);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
@ -90,7 +88,6 @@ namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
await eventService.UpsertAsync(uid, events, token)
|
||||
.ConfigureAwait(false);
|
||||
telemetryService.SaveRequestDate(uid);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
@ -105,7 +102,6 @@ namespace AsbCloudWebApi.Controllers
|
||||
public IActionResult PostUsers(string uid, [FromBody] List<TelemetryUserDto> users)
|
||||
{
|
||||
telemetryUserService.Upsert(uid, users);
|
||||
telemetryService.SaveRequestDate(uid);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
@ -56,8 +56,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
if (idWell != null && dtos.Any())
|
||||
await Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}")
|
||||
.SendAsync(SirnalRMethodGetDataName, dtos), token).ConfigureAwait(false);
|
||||
|
||||
telemetryService.SaveRequestDate(uid);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user