<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using AgGateway.ADAPT.ISOv4Plugin.ObjectModel;

namespace AgGateway.ADAPT.ISOv4Plugin.ImportMappers.LogMappers.XmlReaders
{
    public interface IDlvReader
    {
        IEnumerable<DLVHeader> Read(List<XElement> dlvElement);
    }

    public class DlvReader : IDlvReader
    {
        public IEnumerable<DLVHeader> Read(List<XElement> dlvElements)
        {
            if(dlvElements == null)
                return null;
                
            return dlvElements.Select(Read);
        }

        private DLVHeader Read(XElement dlvElement)
        {
            return new DLVHeader
            {
                ProcessDataDDI = GetProcessDataDdi(dlvElement),
                ProcessDataValue = new HeaderProperty(dlvElement.Attribute("B")),
                DeviceElementIdRef = new HeaderProperty(dlvElement.Attribute("C")),
                DataLogPGN = new HeaderProperty(dlvElement.Attribute("D")),
                DataLogPGNStartBit = new HeaderProperty(dlvElement.Attribute("E")),
                DataLogPGNStopBit = new HeaderProperty(dlvElement.Attribute("F"))
            };
        }

        private static HeaderProperty GetProcessDataDdi(XElement dlvElement)
        {
            if(dlvElement.Attribute("A") == null)
                return new HeaderProperty{ State = HeaderPropertyState.IsNull };

            var stringDdi = dlvElement.Attribute("A").Value;
            var byteDdi = Convert.ToByte(stringDdi, 16);
            var intDdi = Convert.ToInt32(byteDdi);

            return new HeaderProperty { State = HeaderPropertyState.HasValue, Value = intDdi };
        }
    }
}<commit_msg>Fix to read in dlv attribute A correctly from xml --Signed-off-by <NAME><commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using AgGateway.ADAPT.ISOv4Plugin.ObjectModel;

namespace AgGateway.ADAPT.ISOv4Plugin.ImportMappers.LogMappers.XmlReaders
{
    public interface IDlvReader
    {
        IEnumerable<DLVHeader> Read(List<XElement> dlvElement);
    }

    public class DlvReader : IDlvReader
    {
        public IEnumerable<DLVHeader> Read(List<XElement> dlvElements)
        {
            if(dlvElements == null)
                return null;
                
            return dlvElements.Select(Read);
        }

        private DLVHeader Read(XElement dlvElement)
        {
            return new DLVHeader
            {
                ProcessDataDDI = GetProcessDataDdi(dlvElement),
                ProcessDataValue = new HeaderProperty(dlvElement.Attribute("B")),
                DeviceElementIdRef = new HeaderProperty(dlvElement.Attribute("C")),
                DataLogPGN = new HeaderProperty(dlvElement.Attribute("D")),
                DataLogPGNStartBit = new HeaderProperty(dlvElement.Attribute("E")),
                DataLogPGNStopBit = new HeaderProperty(dlvElement.Attribute("F"))
            };
        }

        private static HeaderProperty GetProcessDataDdi(XElement dlvElement)
        {
            if(dlvElement.Attribute("A") == null)
                return new HeaderProperty{ State = HeaderPropertyState.IsNull };

            var hexDdi = dlvElement.Attribute("A").Value;
            var intDdi = int.Parse(hexDdi, System.Globalization.NumberStyles.HexNumber);

            return new HeaderProperty { State = HeaderPropertyState.HasValue, Value = intDdi };
        }
    }
}
{'fraction_non_alphanumeric': 0.08832807570977919, 'fraction_numerical': 0.002294235732721537, 'mean_word_length': 2.3667953667953667, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5561555', 'n_tokens_mistral': 972, 'n_tokens_neox': 956, 'n_words': 178}