public static Model.ConnectionInfo FromDataModel(Core.Data.ConnectionInfo s, bool isVerboseMode)
        {
            if (s == null) return null;

            var connectionInfo = new Model.ConnectionInfo()
            {
                ID = s.ID,
                Reference = s.Reference,
                Amps = s.Amps,
                Voltage = s.Voltage,
                PowerKW = s.PowerKW,
                Quantity = s.Quantity,
                Comments = s.Comments
            };

            //connection type (full object or id only)
            if (isVerboseMode)
            {
                connectionInfo.ConnectionType = ConnectionType.FromDataModel(s.ConnectionType);
                connectionInfo.ConnectionTypeID = (s.ConnectionType != null ? s.ConnectionType.ID : s.ConnectionTypeID);
            }
            else
            {
                connectionInfo.ConnectionTypeID = s.ConnectionTypeID;
            }

            //status type (full object or id only)
            if (isVerboseMode && (s.StatusTypeID != null || s.StatusType != null))
            {
                connectionInfo.StatusType = StatusType.FromDataModel(s.StatusType);
                connectionInfo.StatusTypeID = s.StatusTypeID;
            }
            else
            {
                if (s.StatusTypeID != null) connectionInfo.StatusTypeID = s.StatusTypeID;
            }

            //charging level type (full object or id only)
            if (isVerboseMode && (s.LevelTypeID != null || s.ChargerType != null))
            {
                connectionInfo.Level = ChargerType.FromDataModel(s.ChargerType);
                connectionInfo.LevelID = s.ChargerType.ID;
            }
            else
            {
                if (s.LevelTypeID != null) connectionInfo.LevelID = s.LevelTypeID;
            }

            if (isVerboseMode && (s.CurrentTypeID != null || s.CurrentType != null))
            {
                connectionInfo.CurrentType = CurrentType.FromDataModel(s.CurrentType);
                connectionInfo.CurrentTypeID = s.CurrentType.ID;
            }
            else
            {
                if (s.CurrentTypeID != null) connectionInfo.CurrentTypeID = s.CurrentTypeID;
            }

            return connectionInfo;
        }
        public static int?ComputeChargingLevel(Model.ConnectionInfo c)
        {
            if (c.PowerKW > 0)
            {
                if (c.PowerKW < 2.4 || c.Voltage <= 120)
                {
                    // low power/voltage
                    // SAE Level 1, unit is probably AC output
                    return(1);
                }
                else if (c.CurrentTypeID == (int)StandardCurrentTypes.SinglePhaseAC || c.CurrentTypeID == null)
                {
                    // medium power/voltage AC
                    // SAE Level 2, unit is probably AC output
                    return(2);
                }
                else if (c.CurrentTypeID == (int)StandardCurrentTypes.ThreePhaseAC)
                {
                    if (c.PowerKW < 40 || c.Amps < 60)
                    {
                        return(2);
                    }
                    else
                    {
                        // Typically these are 43kW Type 2 charge connectors, used for rapid AC charging
                        return(3);
                    }
                }
                else if (c.CurrentTypeID == (int)StandardCurrentTypes.DC && (c.PowerKW > 19.2 || c.Amps > 80 || c.Voltage > 400))
                {
                    // DC charging/high power
                    // SAE Level 3, unit is probably DC output
                    return(3);
                }
            }

            return(null);
        }
        public static Model.ConnectionInfo FromDataModel(Core.Data.ConnectionInfo s, bool isVerboseMode, Model.CoreReferenceData refData)
        {
            if (s == null)
            {
                return(null);
            }

            var connectionInfo = new Model.ConnectionInfo()
            {
                ID        = s.Id,
                Reference = s.Reference,
                Amps      = s.Amps,
                Voltage   = s.Voltage,
                PowerKW   = s.PowerKw,
                Quantity  = s.Quantity,
                Comments  = s.Comments
            };

            //connection type (full object or id only)
            connectionInfo.ConnectionTypeID = s.ConnectionTypeId;

            if (isVerboseMode)
            {
                connectionInfo.ConnectionType = refData.ConnectionTypes.FirstOrDefault(c => c.ID == s.ConnectionTypeId);
            }


            //status type (full object or id only)
            connectionInfo.StatusTypeID = s.StatusTypeId;
            if (isVerboseMode)
            {
                connectionInfo.StatusType = refData.StatusTypes.FirstOrDefault(i => i.ID == s.StatusTypeId);
            }


            connectionInfo.CurrentTypeID = s.CurrentTypeId;
            if (isVerboseMode)
            {
                connectionInfo.CurrentType = refData.CurrentTypes.FirstOrDefault(i => i.ID == connectionInfo.CurrentTypeID);
            }

            // if PowerKW not manually supplied, attempt to compute it

            if (connectionInfo.PowerKW == null || connectionInfo.PowerKW == 0)
            {
                connectionInfo.PowerKW = ConnectionInfo.ComputePowerkW(connectionInfo);
            }

            // determine legacy charging 'level' (SAE definition) based on kw/voltage if available
            // if can't be computed use existing user supplied value (if any)

            connectionInfo.LevelID = ComputeChargingLevel(connectionInfo);

            if (connectionInfo.LevelID == null)
            {
                connectionInfo.LevelID = s.LevelTypeId;
            }

            if (isVerboseMode)
            {
                connectionInfo.Level = refData.ChargerTypes.FirstOrDefault(i => i.ID == connectionInfo.LevelID);
            }

            return(connectionInfo);
        }
Exemple #4
0
        public static Model.ConnectionInfo FromDataModel(Core.Data.ConnectionInfo s, bool isVerboseMode)
        {
            if (s == null)
            {
                return(null);
            }

            var connectionInfo = new Model.ConnectionInfo()
            {
                ID        = s.ID,
                Reference = s.Reference,
                Amps      = s.Amps,
                Voltage   = s.Voltage,
                PowerKW   = s.PowerKW,
                Quantity  = s.Quantity,
                Comments  = s.Comments
            };

            //connection type (full object or id only)
            if (isVerboseMode)
            {
                connectionInfo.ConnectionType   = ConnectionType.FromDataModel(s.ConnectionType);
                connectionInfo.ConnectionTypeID = (s.ConnectionType != null ? s.ConnectionType.ID : s.ConnectionTypeID);
            }
            else
            {
                connectionInfo.ConnectionTypeID = s.ConnectionTypeID;
            }

            //status type (full object or id only)
            if (isVerboseMode && (s.StatusTypeID != null || s.StatusType != null))
            {
                connectionInfo.StatusType   = StatusType.FromDataModel(s.StatusType);
                connectionInfo.StatusTypeID = s.StatusTypeID;
            }
            else
            {
                if (s.StatusTypeID != null)
                {
                    connectionInfo.StatusTypeID = s.StatusTypeID;
                }
            }

            //charging level type (full object or id only)
            if (isVerboseMode && (s.LevelTypeID != null || s.ChargerType != null))
            {
                connectionInfo.Level   = ChargerType.FromDataModel(s.ChargerType);
                connectionInfo.LevelID = s.ChargerType.ID;
            }
            else
            {
                if (s.LevelTypeID != null)
                {
                    connectionInfo.LevelID = s.LevelTypeID;
                }
            }

            if (isVerboseMode && (s.CurrentTypeID != null || s.CurrentType != null))
            {
                connectionInfo.CurrentType   = CurrentType.FromDataModel(s.CurrentType);
                connectionInfo.CurrentTypeID = s.CurrentType.ID;
            }
            else
            {
                if (s.CurrentTypeID != null)
                {
                    connectionInfo.CurrentTypeID = s.CurrentTypeID;
                }
            }

            return(connectionInfo);
        }