public static IDictionary <TestInfo, JObject> GetTestData(int inspectionId) { _log.InfoFormat("Getting test data for inspection {0}", inspectionId); var containers = new Dictionary <TestInfo, JObject>(2); int i = 0; foreach (string fileName in _testDataFileNames) { i++; if (fileName.Contains(inspectionId.ToString())) { var fullPath = GetTestDataPath(fileName); var content = File.ReadAllText(fullPath); // parse json & check signature var json = JObject.Parse(content); TestDataJsonFormat_0_1.CheckSignature(json); var methodId = TestDataJsonFormat_0_1.GetMethodId(json); // extract the method-specific json var testDataJson = TestDataJsonFormat_0_1.GetTestData(json); var basicTestData = TestDataJsonFormat_0_1.GetTestData <TestRawData>(json); // return the data (base data + the json data that the specific data can be extracted from) containers.Add(basicTestData.TestInfo, testDataJson); } } return(containers); }
public static SvmrResults ProcessFileWithSettings(string filename, ProcessingSettings settings) { // Open file and load JObject from the file var content = File.ReadAllText(filename); var json = JObject.Parse(content); TestDataJsonFormat_0_1.CheckSignature(json); var methodId = TestDataJsonFormat_0_1.GetMethodId(json); if (methodId != SvmrMethodId.MethodId) { throw new NotSupportedException($"Method with id '{methodId}' is not supported!"); } // extract the method-specific json var testDataJson = TestDataJsonFormat_0_1.GetTestData(json); var hrvRawData = TestDataJsonFormat_0_1.GetTestData <SvmrRawData>(json); var dp = new SvmrDataProcessor(); if (settings != null) { dp.Set(settings); } return((SvmrResults)dp.ProcessData(hrvRawData)); }
private RusHydroInspectionData GetInspectionData( EmployeeDto employee, DateTimeOffset desiredFinishTime, string hrvDataJson, string svmrDataJson ) { Tuple <T, JObject> ReadPskJsonFormat <T>(string content) { // parse json & check signature var json = JObject.Parse(content); TestDataJsonFormat_0_1.CheckSignature(json); var testDataJson = TestDataJsonFormat_0_1.GetTestData(json); // extract the method-specific json return(Tuple.Create(TestDataJsonFormat_0_1.GetTestData <T>(json), testDataJson)); } TestPostDto MakeTestDto(TestInfo testInfo, JObject rawData) { // replace patient info with a real employee data testInfo.Patient.Id = employee.Id; testInfo.Patient.Name = string.Join(employee.LastName, employee.FirstName, employee.Patronymic); testInfo.Patient.BirthDate = employee.BirthDate; testInfo.Patient.Gender = (Gender)employee.Gender; testInfo.Patient.BranchOfficeId = employee.BranchOfficeId; testInfo.Patient.BranchOfficeName = ""; testInfo.Patient.DepartmentId = employee.DepartmentId; testInfo.Patient.DepartmentName = ""; testInfo.Patient.PositionId = employee.PositionId; testInfo.Patient.PositionName = ""; return(new TestPostDto { MethodId = testInfo.MethodId, Comment = testInfo.Comment, FinishTime = testInfo.FinishTime, StartTime = testInfo.StartTime, MethodVersion = testInfo.MethodModuleVersion, MethodRawDataJson = rawData }); } var hrvData = ReadPskJsonFormat <HrvRawData>(hrvDataJson); var svmrData = ReadPskJsonFormat <SvmrRawData>(svmrDataJson); // adjust test start time hrvData = UpdateTestTime(hrvData, desiredFinishTime, TimeSpan.FromMinutes(3)); svmrData = UpdateTestTime(svmrData, desiredFinishTime - TimeSpan.FromMinutes(3), TimeSpan.FromMinutes(2)); var svmrTestInfo = svmrData.Item1.TestInfo; var hrvTestInfo = hrvData.Item1.TestInfo; return(new RusHydroInspectionData { SvmrTest = MakeTestDto(svmrTestInfo, svmrData.Item2), HrvTest = MakeTestDto(hrvTestInfo, hrvData.Item2), Inspection = new InspectionPostDto { EmployeeId = employee.Id, StartTime = svmrTestInfo.StartTime < hrvTestInfo.StartTime ? svmrTestInfo.StartTime : hrvTestInfo.StartTime, InspectionPlace = PskOnline.Client.Api.Inspection.InspectionPlace.OnWorkplace, InspectionType = PskOnline.Client.Api.Inspection.InspectionType.PreShift, MachineName = "made-up machine name", MethodSetId = RushydroPsaMethodSetId.Value, } }); }