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 | |
| parent | b93d7795c84da2e5317fd12d9a41cdd63fcb6659 (diff) | |
| download | Tango-bcfaaf57b60a63acacf0651f5a69b45304abc132.tar.gz Tango-bcfaaf57b60a63acacf0651f5a69b45304abc132.zip | |
FSE Statistics module starter.
Diffstat (limited to 'Software/Visual_Studio/PPC')
12 files changed, 280 insertions, 1 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 + { + + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj index 0adce35a0..d0476647b 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Tango.PPC.Common.csproj @@ -198,6 +198,8 @@ <Compile Include="RemoteNotifications\IRemoteNotificationsService.cs" /> <Compile Include="SQL\DefaultRemoteSqlService.cs" /> <Compile Include="SQL\IRemoteSqlService.cs" /> + <Compile Include="Statistics\DefaultStatisticsService.cs" /> + <Compile Include="Statistics\IStatisticsService.cs" /> <Compile Include="Synchronization\DefaultMachineDataSynchronizer.cs" /> <Compile Include="Synchronization\IMachineDataSynchronizer.cs" /> <Compile Include="Synchronization\SynchronizationEndedEventArgs.cs" /> @@ -587,7 +589,7 @@ </Target> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/Filters.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/Filters.cs new file mode 100644 index 000000000..0438c699a --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/Filters.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Shared.Statistics +{ + public class Filters + { + public DateTime StartDateUTC { get; set; } + public DateTime EndDateUTC { get; set; } + public List<String> Threads { get; set; } + public String JobName { get; set; } + public int MinLength { get; set; } + public int MaxLength { get; set; } + public List<int> EndStatuses { get; set; } + public bool IncludeHeadCleaning { get; set; } + + public Filters() + { + Threads = new List<string>(); + EndStatuses = new List<int>(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/GetStatisticsRequest.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/GetStatisticsRequest.cs new file mode 100644 index 000000000..cacd8db2f --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/GetStatisticsRequest.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Shared.Statistics +{ + public class GetStatisticsRequest + { + public Filters Filters { get; set; } + + public GetStatisticsRequest() + { + Filters = new Filters(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/GetStatisticsRequiredFiltersRequest.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/GetStatisticsRequiredFiltersRequest.cs new file mode 100644 index 000000000..fb10cfbfc --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/GetStatisticsRequiredFiltersRequest.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Shared.Statistics +{ + public class GetStatisticsRequiredFiltersRequest + { + + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/GetStatisticsRequiredFiltersResponse.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/GetStatisticsRequiredFiltersResponse.cs new file mode 100644 index 000000000..44611f68e --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/GetStatisticsRequiredFiltersResponse.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Shared.Statistics +{ + public class GetStatisticsRequiredFiltersResponse + { + public RequiredFiltersData FiltersData { get; set; } + + public GetStatisticsRequiredFiltersResponse() + { + FiltersData = new RequiredFiltersData(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/GetStatisticsResponse.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/GetStatisticsResponse.cs new file mode 100644 index 000000000..a46f15b63 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/GetStatisticsResponse.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Shared.Statistics +{ + public class GetStatisticsResponse + { + public StatisticsResult Result { get; set; } + + public GetStatisticsResponse() + { + Result = new StatisticsResult(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/JobRunComposition.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/JobRunComposition.cs new file mode 100644 index 000000000..643f5a63c --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/JobRunComposition.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.DTO; + +namespace Tango.PPC.Shared.Statistics +{ + public class JobRunComposition + { + public JobRunDTO JobRun { get; set; } + public List<MachinesEventDTO> Events { get; set; } + + public JobRunComposition() + { + Events = new List<MachinesEventDTO>(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/RequiredFiltersData.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/RequiredFiltersData.cs new file mode 100644 index 000000000..6b934fa49 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/RequiredFiltersData.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.PPC.Shared.Statistics +{ + public class RequiredFiltersData + { + public List<String> Rmls { get; set; } + + public List<String> Jobs { get; set; } + + public RequiredFiltersData() + { + Rmls = new List<string>(); + Jobs = new List<string>(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/StatisticsResult.cs b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/StatisticsResult.cs new file mode 100644 index 000000000..8cee4c545 --- /dev/null +++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Statistics/StatisticsResult.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL.DTO; + +namespace Tango.PPC.Shared.Statistics +{ + public class StatisticsResult + { + public List<JobRunComposition> JobRuns { get; set; } + + public StatisticsResult() + { + JobRuns = new List<JobRunComposition>(); + } + } +} diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj index 73f142f67..4f06312c6 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj +++ b/Software/Visual_Studio/PPC/Tango.PPC.Shared/Tango.PPC.Shared.csproj @@ -121,6 +121,14 @@ <Compile Include="SQL\RemoteSqlColumnCollection.cs" /> <Compile Include="SQL\RemoteSqlDataSet.cs" /> <Compile Include="SQL\RemoteSqlRow.cs" /> + <Compile Include="Statistics\Filters.cs" /> + <Compile Include="Statistics\GetStatisticsRequest.cs" /> + <Compile Include="Statistics\GetStatisticsRequiredFiltersRequest.cs" /> + <Compile Include="Statistics\GetStatisticsRequiredFiltersResponse.cs" /> + <Compile Include="Statistics\GetStatisticsResponse.cs" /> + <Compile Include="Statistics\JobRunComposition.cs" /> + <Compile Include="Statistics\RequiredFiltersData.cs" /> + <Compile Include="Statistics\StatisticsResult.cs" /> <Compile Include="Updates\GetUpdatesAndPackagesRequest.cs" /> <Compile Include="Updates\GetUpdatesAndPackagesResponse.cs" /> <Compile Include="Updates\PackageInstallation.cs" /> |
