diff options
| author | Roy <Roy.mail.net@gmail.com> | 2022-11-03 09:16:24 +0200 |
|---|---|---|
| committer | Roy <Roy.mail.net@gmail.com> | 2022-11-03 09:16:24 +0200 |
| commit | bcfaaf57b60a63acacf0651f5a69b45304abc132 (patch) | |
| tree | a8f7166e9b522af1af019c636825659ae1a84c44 /Software/Visual_Studio/PPC/Tango.PPC.Common/Statistics | |
| parent | b93d7795c84da2e5317fd12d9a41cdd63fcb6659 (diff) | |
| download | Tango-bcfaaf57b60a63acacf0651f5a69b45304abc132.tar.gz Tango-bcfaaf57b60a63acacf0651f5a69b45304abc132.zip | |
FSE Statistics module starter.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Statistics')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/Statistics/DefaultStatisticsService.cs | 103 | ||||
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/Statistics/IStatisticsService.cs | 13 |
2 files changed, 116 insertions, 0 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Statistics/DefaultStatisticsService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Statistics/DefaultStatisticsService.cs new file mode 100644 index 000000000..a603410d0 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Statistics/DefaultStatisticsService.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Data.Entity; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL; +using Tango.Core; +using Tango.Core.DI; +using Tango.Integration.ExternalBridge; +using Tango.PPC.Common.ExternalBridge; +using Tango.PPC.Shared.Statistics; + +namespace Tango.PPC.Common.Statistics +{ + [TangoCreateWhenRegistered] + public class DefaultStatisticsService : ExtendedObject, IStatisticsService, IExternalBridgeRequestHandler + { + public bool Enabled { get; set; } = true; + + public DefaultStatisticsService(IPPCExternalBridgeService externalBridge) + { + try + { + externalBridge.RegisterRequestHandler(this); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error initializing the statistics service."); + Enabled = false; + } + } + + [ExternalBridgeRequestHandlerMethod(typeof(GetStatisticsRequiredFiltersRequest), RequestHandlerLoggingMode.LogRequestName)] + public async Task OnGetStatisticsRequiredFiltersRequest(GetStatisticsRequiredFiltersRequest request, String token, ExternalBridgeReceiver receiver) + { + this.ThrowIfDisabled(); + + var response = new GetStatisticsRequiredFiltersResponse(); + + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + var jobNames = await db.JobRuns.Select(x => x.JobName).ToListAsync(); + var threadNames = await db.Rmls.Select(x => x.DisplayName).ToListAsync(); + response.FiltersData.Jobs = jobNames; + response.FiltersData.Rmls = threadNames; + } + + await receiver.SendGenericResponse(response, token); + } + + [ExternalBridgeRequestHandlerMethod(typeof(GetStatisticsRequest), RequestHandlerLoggingMode.LogRequestName)] + public async Task OnGetStatisticsRequest(GetStatisticsRequest request, String token, ExternalBridgeReceiver receiver) + { + this.ThrowIfDisabled(); + + var response = new GetStatisticsResponse(); + + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + var filters = request.Filters; + + var db_JobRuns = db.JobRuns.Where(x => (x.StartDate <= filters.EndDateUTC && x.StartDate >= filters.StartDateUTC)); + + int[] jobRunStatusArr = filters.EndStatuses.Distinct().ToArray(); + if (jobRunStatusArr.Length > 0) + { + db_JobRuns = db_JobRuns.Where(x => jobRunStatusArr.Contains(x.Status)); + } + + if (!filters.IncludeHeadCleaning) + { + db_JobRuns = db_JobRuns.Where(x => !x.IsHeadCleaning); + } + + List<String> rmlGuids = filters.Threads; + + if (filters.Threads.Count > 0) + { + db_JobRuns = db_JobRuns.Where(x => rmlGuids.Contains(x.RmlGuid)); + } + + if (filters.JobName.IsNotNullOrEmpty()) + { + db_JobRuns = db_JobRuns.Where(x => x.JobName.ToLower().StartsWith(filters.JobName.ToLower())); + } + + db_JobRuns = db_JobRuns.Where(x => x.JobLength < filters.MinLength && x.JobLength >= filters.MaxLength); + + var runs_db = await db_JobRuns.ToListAsync(); + + runs_db.ForEach(x => x.LiquidQuantityString = null); + } + + await receiver.SendGenericResponse(response, token); + } + + public void OnReceiverDisconnected(ExternalBridgeReceiver receiver) + { + + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Statistics/IStatisticsService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Statistics/IStatisticsService.cs new file mode 100644 index 000000000..553264d42 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Statistics/IStatisticsService.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Common.Statistics +{ + public interface IStatisticsService : IPPCService + { + + } +} |
