-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into feature/1952-gap-anal…
…yzer-functionality # Conflicts: # Src/WitsmlExplorer.Api/Models/JobType.cs
- Loading branch information
Showing
18 changed files
with
1,751 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
using Microsoft.IdentityModel.Tokens; | ||
|
||
using WitsmlExplorer.Api.Jobs.Common; | ||
using WitsmlExplorer.Api.Models; | ||
|
||
namespace WitsmlExplorer.Api.Jobs | ||
{ | ||
public record MissingDataJob : Job | ||
{ | ||
public IEnumerable<WellReference> WellReferences { get; init; } | ||
public IEnumerable<WellboreReference> WellboreReferences { get; init; } | ||
public IEnumerable<MissingDataCheck> MissingDataChecks { get; init; } | ||
|
||
public override string Description() | ||
{ | ||
return $"Missing Data Agent" | ||
+ $" - WellUids: {GetWellUid()};" | ||
+ $" WellboreUids: {string.Join(", ", WellboreReferences.Select(w => w.WellboreUid))}"; | ||
} | ||
|
||
public override string GetObjectName() | ||
{ | ||
return null; | ||
} | ||
|
||
public override string GetWellboreName() | ||
{ | ||
return WellboreReferences.IsNullOrEmpty() ? null : string.Join(", ", WellboreReferences.Select(w => w.WellboreName)); | ||
} | ||
|
||
public override string GetWellName() | ||
{ | ||
var wellNames = new List<string>(); | ||
|
||
if (!WellboreReferences.IsNullOrEmpty()) | ||
{ | ||
wellNames.AddRange(WellboreReferences.Select(w => w.WellName).Distinct()); | ||
} | ||
|
||
if (!WellReferences.IsNullOrEmpty()) | ||
{ | ||
wellNames.AddRange(WellReferences.Select(w => w.WellName).Distinct()); | ||
} | ||
|
||
return string.Join(", ", wellNames.Distinct()); | ||
} | ||
|
||
private string GetWellUid() | ||
{ | ||
var wellUids = new List<string>(); | ||
|
||
if (!WellboreReferences.IsNullOrEmpty()) | ||
{ | ||
wellUids.AddRange(WellboreReferences.Select(w => w.WellUid).Distinct()); | ||
} | ||
|
||
if (!WellReferences.IsNullOrEmpty()) | ||
{ | ||
wellUids.AddRange(WellReferences.Select(w => w.WellUid).Distinct()); | ||
} | ||
|
||
return string.Join(", ", wellUids.Distinct()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ public enum JobType | |
ReplaceComponents, | ||
ReplaceObjects, | ||
CheckLogHeader, | ||
MissingData, | ||
AnalyzeGaps | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace WitsmlExplorer.Api.Models | ||
{ | ||
public class MissingDataCheck | ||
{ | ||
public EntityType ObjectType { get; set; } | ||
public IEnumerable<string> Properties { get; set; } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Src/WitsmlExplorer.Api/Models/Reports/MissingDataReport.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
namespace WitsmlExplorer.Api.Models.Reports | ||
{ | ||
public class MissingDataReport : BaseReport { } | ||
|
||
public class MissingDataReportItem | ||
{ | ||
public string ObjectType { get; set; } | ||
public string Property { get; init; } | ||
public string WellUid { get; init; } | ||
public string WellName { get; init; } | ||
public string WellboreUid { get; init; } | ||
public string WellboreName { get; init; } | ||
public string ObjectUid { get; init; } | ||
public string ObjectName { get; init; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
using WitsmlExplorer.Api.Extensions; | ||
|
||
namespace WitsmlExplorer.Api.Query | ||
{ | ||
public static class QueryHelper | ||
{ | ||
/// <summary> | ||
/// Adds properties to an object based on a list of property names. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the object.</typeparam> | ||
/// <param name="obj">The object to which properties will be added.</param> | ||
/// <param name="properties">A collection of property names to add, optionally supporting nested properties (e.g., "commonData.sourceName").</param> | ||
/// <returns>The modified object with added properties.</returns> | ||
public static T AddPropertiesToObject<T>(T obj, IEnumerable<string> properties) | ||
{ | ||
foreach (string property in properties) | ||
{ | ||
obj = AddPropertyToObject(obj, property); | ||
} | ||
return obj; | ||
} | ||
|
||
/// <summary> | ||
/// Adds a single property to an object based on its name. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the object.</typeparam> | ||
/// <param name="obj">The object to which the property will be added.</param> | ||
/// <param name="property">The name of the property to add, optionally supporting nested properties (e.g., "commonData.sourceName").</param> | ||
/// <returns>The modified object with the added property.</returns> | ||
public static T AddPropertyToObject<T>(T obj, string property) | ||
{ | ||
string childProperty = null; | ||
if (property.Contains('.')) | ||
{ | ||
var propertyParts = property.Split(".", 2); | ||
property = propertyParts[0]; | ||
childProperty = propertyParts[1]; | ||
} | ||
|
||
PropertyInfo propertyInfo = obj.GetType().GetProperty(property.CapitalizeFirstLetter()); | ||
|
||
if (propertyInfo == null || !propertyInfo.CanWrite) | ||
{ | ||
throw new ArgumentException($"{property} must be a supported property of a {obj.GetType()}."); | ||
} | ||
|
||
object instance = GetOrCreateInstanceOfProperty(obj, propertyInfo); | ||
|
||
if (!string.IsNullOrEmpty(childProperty)) | ||
{ | ||
instance = AddPropertyToObject(instance, childProperty); | ||
} | ||
|
||
propertyInfo.SetValue(obj, instance); | ||
|
||
return obj; | ||
} | ||
|
||
private static object GetOrCreateInstanceOfProperty(object obj, PropertyInfo propertyInfo) | ||
{ | ||
Type propertyType = propertyInfo.PropertyType; | ||
|
||
object instance = (propertyType == typeof(string) | ||
? "" | ||
: propertyInfo.GetValue(obj, null)) | ||
?? (propertyType == typeof(string[]) | ||
? new string[] { "" } | ||
: Activator.CreateInstance(propertyType)); | ||
|
||
if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(List<>)) | ||
{ | ||
Type listObjectType = propertyType.GetGenericArguments()[0]; | ||
object listObjectInstance = listObjectType == typeof(string) | ||
? "" | ||
: Activator.CreateInstance(listObjectType); | ||
((IList)instance).Add(listObjectInstance); | ||
} | ||
|
||
return instance; | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves a property from an object based on its name, supporting nested properties. | ||
/// </summary> | ||
/// <param name="obj">The object from which to retrieve the property.</param> | ||
/// <param name="property">The name of the property to retrieve, possibly nested (e.g., "commonData.sourceName").</param> | ||
/// <returns>The value of the specified property.</returns> | ||
public static object GetPropertyFromObject(object obj, string property) | ||
{ | ||
var propertyParts = property.Split("."); | ||
foreach (var propertyPart in propertyParts) | ||
{ | ||
obj = obj?.GetType().GetProperty(propertyPart.CapitalizeFirstLetter())?.GetValue(obj, null); | ||
} | ||
return obj; | ||
} | ||
} | ||
} |
Oops, something went wrong.