Skip to content

Commit b7e3b32

Browse files
authored
Merge pull request #243 from knelson-farmbeltnorth/develop
Handling binary variations in certain early datasets; filling Role on PersonRole.
2 parents a22c648 + c134077 commit b7e3b32

File tree

6 files changed

+158
-69
lines changed

6 files changed

+158
-69
lines changed

ISOv4Plugin/Mappers/AllocationStampMapper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public static IEnumerable<TimeScope> ImportAllocationStamps(IEnumerable<ISOAllo
8989
public static TimeScope ImportAllocationStamp(ISOAllocationStamp isoAllocationStamp)
9090
{
9191
TimeScope adaptTimeScope = new TimeScope();
92+
adaptTimeScope.DateContext = DateContextEnum.ActualStart;
9293
adaptTimeScope.TimeStamp1 = isoAllocationStamp.Start;
9394

9495
//[Check] AllocationStamp XML element: a recording with only the Start attribute defined is allowed

ISOv4Plugin/Mappers/TaskDataMapper.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class TaskDataMapper : ITaskDataMapper
3535
public const string ExportVersion = "ExportVersion"; //Version "3" or "4"
3636
public const string SuppressTimeLogDataInterpolation = "SuppressTimeLogDataInterpolation";
3737

38-
public TaskDataMapper(string dataPath, Properties properties)
38+
public TaskDataMapper(string dataPath, Properties properties, int? taskDataVersionMajor = null)
3939
{
4040
BaseFolder = dataPath;
4141
RepresentationMapper = new RepresentationMapper();
@@ -45,16 +45,22 @@ public TaskDataMapper(string dataPath, Properties properties)
4545
InstanceIDMap = new InstanceIDMap();
4646
Errors = new List<IError>();
4747

48-
//Export version
49-
string exportVersion = Properties.GetProperty(ExportVersion);
50-
if (Int32.TryParse(exportVersion, out int version))
48+
if (taskDataVersionMajor.HasValue)
5149
{
52-
Version = version; //3 or 4
50+
Version = taskDataVersionMajor.Value;
5351
}
54-
if (version != 3 && version != 4)
52+
else
5553
{
56-
Version = 4; //Default ISO Version for the export
57-
}
54+
string exportVersion = Properties.GetProperty(ExportVersion);
55+
if (Int32.TryParse(exportVersion, out int version))
56+
{
57+
Version = version; //3 or 4
58+
}
59+
if (version != 3 && version != 4)
60+
{
61+
Version = 4; //Default ISO Version for the export
62+
}
63+
}
5864
}
5965

6066
public string BaseFolder { get; private set; }

ISOv4Plugin/Mappers/TaskMapper.cs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using AgGateway.ADAPT.ISOv4Plugin.ISOModels;
1818
using AgGateway.ADAPT.ISOv4Plugin.Mappers.Factories;
1919
using AgGateway.ADAPT.ISOv4Plugin.Representation;
20+
using AgGateway.ADAPT.Representation.RepresentationSystem.ExtensionMethods;
2021

2122
namespace AgGateway.ADAPT.ISOv4Plugin.Mappers
2223
{
@@ -571,7 +572,11 @@ private LoggedData ImportLoggedData(ISOTask isoLoggedTask)
571572
if (personID.HasValue)
572573
{
573574
//Create a Role
574-
PersonRole role = new PersonRole() { PersonId = personID.Value };
575+
PersonRole role = new PersonRole()
576+
{
577+
PersonId = personID.Value,
578+
Role = new EnumeratedValue { Value = AgGateway.ADAPT.Representation.RepresentationSystem.DefinedTypeEnumerationInstanceList.dtiPersonRoleOperator.ToModelEnumMember() }
579+
};
575580

576581
//Add to Catalog
577582
DataModel.Catalog.PersonRoles.Add(role);
@@ -713,19 +718,28 @@ private Summary ImportSummary(ISOTask isoLoggedTask, LoggedData loggedData)
713718
foreach (ISOTime time in isoLoggedTask.Times.Where(t => t.HasStart && t.HasType)) //Nothing added without a Start and Type attribute
714719
{
715720
TimeScope timeScope = new TimeScope();
721+
timeScope.DateContext = DateContextEnum.ActualStart;
716722
timeScope.TimeStamp1 = time.Start;
717723
if (time.Stop != null)
718724
{
719725
timeScope.TimeStamp2 = time.Stop;
720726
}
721727

722-
if (time.Stop == null && time.Duration != null)
728+
if (time.Duration != null)
723729
{
724-
//Calculate the Stop time if missing and duration present
725-
timeScope.TimeStamp2 = timeScope.TimeStamp1.Value.AddSeconds(time.Duration.Value);
730+
timeScope.Duration = System.TimeSpan.FromSeconds(time.Duration.Value);
731+
if (time.Stop == null)
732+
{
733+
//Calculate the Stop time if missing and duration present
734+
timeScope.TimeStamp2 = timeScope.TimeStamp1.Value.AddSeconds(time.Duration.Value);
735+
}
736+
}
737+
else if (timeScope.TimeStamp1.HasValue && timeScope.TimeStamp2.HasValue)
738+
{
739+
//Calculate the Duration if missing and start/stop present
740+
timeScope.Duration = timeScope.TimeStamp2.Value - timeScope.TimeStamp1.Value;
726741
}
727742
timeScope.DateContext = time.Type == ISOEnumerations.ISOTimeType.Planned ? DateContextEnum.ProposedStart : DateContextEnum.ActualStart;
728-
timeScope.Duration = timeScope.TimeStamp2.GetValueOrDefault() - timeScope.TimeStamp1.GetValueOrDefault();
729743
summary.TimeScopes.Add(timeScope);
730744
}
731745

@@ -827,6 +841,7 @@ private StampedMeteredValues GetStampedMeteredValuesForTimes(IEnumerable<ISOTime
827841

828842
//TimeScope
829843
stampedValues.Stamp = new TimeScope();
844+
stampedValues.Stamp.DateContext = DateContextEnum.ActualStart;
830845
stampedValues.Stamp.TimeStamp1 = orderedTimes.First().Start;
831846
if (orderedTimes.Last().Stop != null)
832847
{
@@ -841,7 +856,10 @@ private StampedMeteredValues GetStampedMeteredValuesForTimes(IEnumerable<ISOTime
841856
//All types should be the same
842857
stampedValues.Stamp.DateContext = orderedTimes.First().Type == ISOEnumerations.ISOTimeType.Planned ? DateContextEnum.ProposedStart : DateContextEnum.ActualStart;
843858
//Duration will define the time from the first to the last time. Gaps will be identifiable by examining Summary.Timescopes as defined above.
844-
stampedValues.Stamp.Duration = stampedValues.Stamp.TimeStamp2.GetValueOrDefault() - stampedValues.Stamp.TimeStamp1.GetValueOrDefault();
859+
if (stampedValues.Stamp.TimeStamp1.HasValue && stampedValues.Stamp.TimeStamp2.HasValue)
860+
{
861+
stampedValues.Stamp.Duration = stampedValues.Stamp.TimeStamp2.Value - stampedValues.Stamp.TimeStamp1.Value;
862+
}
845863

846864
//Values
847865
foreach (ISODataLogValue dlv in orderedTimes.Last().DataLogValues) //The last Time contains the comprehensive Task totals

0 commit comments

Comments
 (0)