1717using AgGateway . ADAPT . ISOv4Plugin . ISOModels ;
1818using AgGateway . ADAPT . ISOv4Plugin . Mappers . Factories ;
1919using AgGateway . ADAPT . ISOv4Plugin . Representation ;
20+ using AgGateway . ADAPT . Representation . RepresentationSystem . ExtensionMethods ;
2021
2122namespace 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