Example #1
0
        static void AppendDeviceValues(StringBuilder sb, Device device)
        {
            AppendValues(sb, device.Name.Replace(",", " "));
            AppendValues(sb, device.SerialNumber);
            GoDevice goDevice = device as GoDevice;

            AppendValues(sb, (goDevice == null ? "" : goDevice.VehicleIdentificationNumber ?? "").Replace(",", " "));
        }
Example #2
0
        public GoDevice GetGoDevice(int hardwareId, List <Group> groups)
        {
            GoDevice device = (GoDevice)Device.FromProductId(Device.Go7ProductId);

            device.PopulateDefaults();
            device.Name       = GetRandomString(16);
            device.HardwareId = hardwareId;
            device.Groups     = groups;

            return(device);
        }
 // Use this for initialization
 void Start()
 {
     infoUI               = GameObject.Find("OVRCameraRig/TrackingSpace/CenterEyeAnchor/InfoUI").GetComponent <InfoUI>();
     goDevice             = GameObject.Find("OVRCameraRig/TrackingSpace").GetComponent <GoDevice>();
     pointManager         = GetComponent <PointManager>();
     timeManager          = GetComponent <TimeManager>();
     nowPhase             = Phase.StartPhase;
     holdTime             = holdTimeMax;
     instantInfoBoad      = Instantiate(infoBoad, boadSpowner.transform.position, boadSpowner.transform.rotation);
     instantInfoBoad.name = "InfoBoad";
     instantInfoBoad.GetComponent <InfoBoad>().WriteInfo(InfoBoad.ruleText);
     enemySpowner = GameObject.Find("EnemySpowner").GetComponent <EnemySpowner>();
 }
Example #4
0
        /// <summary>
        /// Calculates fuel usage for a collection of fuel tax details, classified by jurisdiction and fuel type.
        /// </summary>
        /// <param name="api">The Geotab API.</param>
        /// <param name="device">The device.</param>
        /// <param name="details">The fuel tax details.</param>
        /// <returns>A list of fuel tax data objects.</returns>
        static Dictionary <string, Dictionary <FuelType, FuelUsage> > GetFuelUsageByJurisdiction(API api, GoDevice device, IList <FuelTaxDetail> details)
        {
            var fuelUsageByJurisdiction = new Dictionary <string, Dictionary <FuelType, FuelUsage> >();

            // Get the details' time interval.
            DateTime fromDate = details[0].EnterTime;
            DateTime toDate   = details[details.Count - 1].ExitTime;

            // Get the fuel transactions within the details' time interval.
            Search fuelTransactionSearch = new FuelTransactionSearch
            {
                VehicleIdentificationNumber = device.VehicleIdentificationNumber,
                FromDate = fromDate,
                ToDate   = toDate
            };
            List <FuelTransaction> fuelTransactions = api.Call <IList <FuelTransaction> >("Get", typeof(FuelTransaction), new { search = fuelTransactionSearch }).ToList();

            fuelTransactions.Sort((transaction1, transaction2) => DateTime.Compare(transaction1.DateTime.Value, transaction2.DateTime.Value));

            // Calculate total purchased fuel by fuel type and jurisdiction.
            Dictionary <FuelType, double> fuelPurchasedByType = new Dictionary <FuelType, double>();
            double totalDistance = 0;

            foreach (var fuelTransaction in fuelTransactions)
            {
                // Locate the fuel transaction within a detail.
                FuelTaxDetail detail = details.Last(x => x.EnterTime <= fuelTransaction.DateTime);

                // Update jurisdiction fuel usage.
                string jurisdiction = detail.Jurisdiction;
                if (jurisdiction != null)
                {
                    if (!fuelUsageByJurisdiction.TryGetValue(jurisdiction, out Dictionary <FuelType, FuelUsage> fuelUsageByType))
                    {
                        fuelUsageByType = new Dictionary <FuelType, FuelUsage>();
                        fuelUsageByJurisdiction.Add(jurisdiction, fuelUsageByType);
                    }
                    FuelTransactionProductType?productType = fuelTransaction.ProductType;
                    FuelType fuelType = productType == null ? FuelType.None : GetFuelType(productType.Value);
                    if (!fuelUsageByType.TryGetValue(fuelType, out FuelUsage fuelUsage))
                    {
                        fuelUsage = new FuelUsage();
                        fuelUsageByType.Add(fuelType, fuelUsage);
                    }
                    double volume = fuelTransaction.Volume.Value;
                    fuelUsage.FuelPurchased += volume;
                    if (!fuelPurchasedByType.ContainsKey(fuelType))
                    {
                        fuelPurchasedByType.Add(fuelType, 0);
                    }
                    fuelPurchasedByType[fuelType] += volume;
                }
            }

            // Resolve fuel type None into the fuel type with the largest purchased volume.
            if (fuelPurchasedByType.TryGetValue(FuelType.None, out double _))
            {
                FuelType topFuelType = FuelType.None;
                double   topVolume   = 0;
                foreach (var fuelTypePurchased in fuelPurchasedByType)
                {
                    FuelType fuelType = fuelTypePurchased.Key;
                    if (fuelType != FuelType.None)
                    {
                        double volume = fuelTypePurchased.Value;
                        if (volume > topVolume)
                        {
                            topVolume   = volume;
                            topFuelType = fuelType;
                        }
                    }
                }
                if (topFuelType != FuelType.None)
                {
                    fuelPurchasedByType[topFuelType] += fuelPurchasedByType[FuelType.None];
                    fuelPurchasedByType.Remove(FuelType.None);
                }
                foreach (var fuelUsageByType in fuelUsageByJurisdiction.Values)
                {
                    if (fuelUsageByType.TryGetValue(FuelType.None, out FuelUsage typeNoneFuelUsage))
                    {
                        fuelUsageByType[topFuelType].FuelPurchased += typeNoneFuelUsage.FuelPurchased;
                        fuelUsageByType.Remove(FuelType.None);
                    }
                }
            }

            // Create fuel usage stumps for jurisdictions where no fuel transactions occurred.
            foreach (var detail in details)
            {
                string jurisdiction = detail.Jurisdiction;
                if (jurisdiction != null)
                {
                    if (!fuelUsageByJurisdiction.TryGetValue(jurisdiction, out Dictionary <FuelType, FuelUsage> fuelUsageByType))
                    {
                        fuelUsageByType = new Dictionary <FuelType, FuelUsage>();
                        fuelUsageByJurisdiction.Add(jurisdiction, fuelUsageByType);
                    }
                    double detailDistance = detail.ExitOdometer - detail.EnterOdometer;
                    foreach (var fuelType in fuelPurchasedByType.Keys)
                    {
                        if (!fuelUsageByType.TryGetValue(fuelType, out FuelUsage fuelUsage))
                        {
                            fuelUsage = new FuelUsage();
                            fuelUsageByType.Add(fuelType, fuelUsage);
                        }
                        fuelUsage.Distance += detailDistance;
                    }
                    totalDistance += detailDistance;
                }
            }

            // Calculate fuel economy for each fuel type. Fill in fuel usage per jurisdiction and fuel type.
            foreach (var typeVolume in fuelPurchasedByType)
            {
                FuelType fuelType    = typeVolume.Key;
                double   totalVolume = typeVolume.Value;
                double   volumePerKm = totalVolume / totalDistance;
                foreach (var fuelUsageByType in fuelUsageByJurisdiction.Values)
                {
                    FuelUsage fuelUsage = fuelUsageByType[fuelType];
                    fuelUsage.FuelUsed    = volumePerKm * fuelUsage.Distance;
                    fuelUsage.FuelEconomy = volumePerKm * 100;
                }
            }
            return(fuelUsageByJurisdiction);
        }
Example #5
0
 // Use this for initialization
 void Start()
 {
     shotInterval = shotIntervalMax;
     phaseManager = GameObject.Find("GameMaster").GetComponent <PhaseManager>();
     goDevice     = GetComponent <GoDevice>();
 }
        /// <summary>
        /// Updates the supplied <see cref="Device"/> using the values of the supplied parameters.
        /// </summary>
        /// <param name="myGeotabApi">An authenticated MyGeotab <see cref="API"/> object.</param>
        /// <param name="device">The <see cref="Device"/> to be updated.</param>
        /// <param name="name">The name of this entity that uniquely identifies it and is used when displaying this entity. Maximum length [50].</param>
        /// <param name="enableDeviceBeeping">Master toggle to enable the device buzzer. When set to <c>false</c>, the device will not provide driver feedback of any kind. Default <c>false</c>.</param>
        /// <param name="enableDriverIdentificationReminder">A value mainly used for enable or disable driver identification reminder. If it is used in conjunction with vehicle relay circuits, it can force the driver to swipe the driver key before starting the vehicle. Default <c>false</c>.</param>
        /// <param name="driverIdentificationReminderImmobilizeSeconds">With enableDriverIdentificationReminder being true, it is used to define the delay before the driver identification reminder is sent out if the driver key has not been not swiped. The maximum value of this property is 255. When it is less or equal to 180, it indicates the number of seconds of the delay. When it is greater than 180, the delay increases 30 seconds for every increment of one of this property. For example, 180 indicates 180 seconds, 181 indicates 210 seconds, and 182 indicates 240 seconds. Maximum [255] Default <c>30</c>.</param>
        /// <param name="enableBeepOnEngineRpm">Toggle to enable beeping when the vehicle's RPM exceeds the 'engineRpmBeepValue'. Default <c>false</c>.</param>
        /// <param name="engineRpmBeepValue">The RPM value that when exceeded triggers device beeping. Default <c>3500</c>.</param>
        /// <param name="enableBeepOnIdle">Toggle to enable beeping when the vehicle idles for more than idleMinutesBeepValue. Default <c>false</c>.</param>
        /// <param name="idleMinutesBeepValue">The number of minutes of allowed idling before device beeping starts. enableBeepOnIdle must be enabled. Default <c>3</c>.</param>
        /// <param name="enableBeepOnSpeeding">A toggle to beep constantly when the vehicle reaches the speed set in 'speedingStartBeepingSpeed', and do not stop until the vehicle slows below the 'speedingStopBeepingSpeed' speed. To only beep briefly (instead of continuously), enable 'enableBeepBrieflyWhenApprocahingWarningSpeed'. Default <c>false</c>.</param>
        /// <param name="speedingStartBeepingSpeed">The speeding on value in km/h. When 'enableBeepOnSpeeding' is enabled, the device will start beeping when the vehicle exceeds this speed. Default <c>100</c>.</param>
        /// <param name="speedingStopBeepingSpeed">The speeding off value in km/h. When 'enableBeepOnSpeeding' is enabled, once beeping starts, the vehicle must slow down to this speed for the beeping to stop. Default <c>90</c>.</param>
        /// <param name="enableBeepBrieflyWhenApprocahingWarningSpeed">Toggle to enable speed warning value for the vehicle. When enabled [true], only beep briefly (instead of continuously), when 'speedingStopBeepingSpeed' value is exceeded. 'speedingStartBeepingSpeed' must also be enabled. Default <c>false</c>.</param>
        /// <param name="enableBeepOnDangerousDriving">Toggle to enable beeping when any of the acceleration thresholds are exceeded by device accelerometer readings. Default <c>false</c>.</param>
        /// <param name="accelerationWarningThreshold">The acceleration warning accelerometer threshold (y axis) value for the vehicle. A positive value that when exceeded will trigger device beeping. Threshold value to mS2 conversion (threshold * 18 = milli-g / 1000 = g / 1.0197162 = mS2). Default <c>22</c>.</param>
        /// <param name="brakingWarningThreshold">The braking warning accelerometer threshold (y axis) value for the vehicle. A negative value that when exceeded will trigger device beeping. Threshold value to mS2 conversion (threshold * 18 = milli-g / 1000 = g / 1.0197162 = mS2). Default <c>-34</c>.</param>
        /// <param name="corneringWarningThreshold">The cornering warning threshold (x axis) value for the vehicle. A positive value that when exceeded will trigger device beeping (the additive inverse is automatically applied: 26/-26). Threshold value to mS2 conversion (threshold * 18 = milli-g / 1000 = g / 1.0197162 = mS2). Default <c>26</c>.</param>
        /// <param name="enableBeepWhenSeatbeltNotUsed">Value which toggles beeping if an unbuckled seat belt is detected. This will only work if the device is able to obtain seat belt information from the vehicle. Default <c>false</c>.</param>
        /// <param name="seatbeltNotUsedWarningSpeed">The value in km/h that below will not trigger 'enableBeepWhenSeatbeltNotUsed'. Default <c>10</c>.</param>
        /// <param name="enableBeepWhenPassengerSeatbeltNotUsed">Value which toggles monitoring both passenger and driver unbuckled seat belt, otherwise only the driver is monitored. Default <c>false</c>.</param>
        /// <param name="beepWhenReversing">Value which toggles device beeping when the vehicle is reversing. Default <c>false</c>.</param>
        /// <returns></returns>
        public static async Task UpdateDeviceAsync(API myGeotabApi, Device device, string name, bool enableDeviceBeeping = false, bool enableDriverIdentificationReminder = false, int driverIdentificationReminderImmobilizeSeconds = 30, bool enableBeepOnEngineRpm = false, int engineRpmBeepValue = 3500, bool enableBeepOnIdle = false, int idleMinutesBeepValue = 3, bool enableBeepOnSpeeding = false, int speedingStartBeepingSpeed = 100, int speedingStopBeepingSpeed = 90, bool enableBeepBrieflyWhenApprocahingWarningSpeed = false, bool enableBeepOnDangerousDriving = false, int accelerationWarningThreshold = 22, int brakingWarningThreshold = -34, int corneringWarningThreshold = 26, bool enableBeepWhenSeatbeltNotUsed = false, int seatbeltNotUsedWarningSpeed = 10, bool enableBeepWhenPassengerSeatbeltNotUsed = false, bool beepWhenReversing = false)
        {
            // Update device name.
            device.Name = name;
            // Update properties available to all GO devices.
            if (device is GoDevice)
            {
                GoDevice goDevice = device as GoDevice;
                goDevice.DisableBuzzer      = !enableDeviceBeeping;
                goDevice.EnableBeepOnIdle   = enableBeepOnIdle;
                goDevice.IdleMinutes        = idleMinutesBeepValue;
                goDevice.IsSpeedIndicator   = enableBeepOnSpeeding;
                goDevice.SpeedingOn         = speedingStartBeepingSpeed;
                goDevice.SpeedingOff        = speedingStopBeepingSpeed;
                goDevice.EnableSpeedWarning = enableBeepBrieflyWhenApprocahingWarningSpeed;
                // Update properties by specific GO device type.
                if (goDevice is Go4v3)
                {
                    Go4v3 go4v3 = goDevice as Go4v3;
                    go4v3.ImmobilizeUnit                      = enableDriverIdentificationReminder;
                    go4v3.ImmobilizeArming                    = driverIdentificationReminderImmobilizeSeconds;
                    go4v3.EnableBeepOnRpm                     = enableBeepOnEngineRpm;
                    go4v3.RpmValue                            = engineRpmBeepValue;
                    go4v3.EnableBeepOnDangerousDriving        = enableBeepOnDangerousDriving;
                    go4v3.AccelerationWarningThreshold        = accelerationWarningThreshold;
                    go4v3.AccelerometerThresholdWarningFactor = 0;
                    go4v3.BrakingWarningThreshold             = brakingWarningThreshold;
                    go4v3.CorneringWarningThreshold           = corneringWarningThreshold;
                    go4v3.IsDriverSeatbeltWarningOn           = enableBeepWhenSeatbeltNotUsed;
                    go4v3.SeatbeltWarningSpeed                = seatbeltNotUsedWarningSpeed;
                    go4v3.IsPassengerSeatbeltWarningOn        = enableBeepWhenPassengerSeatbeltNotUsed;
                    go4v3.IsReverseDetectOn                   = beepWhenReversing;

                    await myGeotabApi.CallAsync <object>("Set", typeof(Device), new { entity = go4v3 });
                }
                else if (goDevice is Go5)
                {
                    Go5 go5 = goDevice as Go5;
                    go5.EnableBeepOnRpm = enableBeepOnEngineRpm;
                    go5.RpmValue        = engineRpmBeepValue;
                    go5.EnableBeepOnDangerousDriving        = enableBeepOnDangerousDriving;
                    go5.AccelerationWarningThreshold        = accelerationWarningThreshold;
                    go5.AccelerometerThresholdWarningFactor = 0;
                    go5.BrakingWarningThreshold             = brakingWarningThreshold;
                    go5.CorneringWarningThreshold           = corneringWarningThreshold;
                    go5.IsDriverSeatbeltWarningOn           = enableBeepWhenSeatbeltNotUsed;
                    go5.SeatbeltWarningSpeed         = seatbeltNotUsedWarningSpeed;
                    go5.IsPassengerSeatbeltWarningOn = enableBeepWhenPassengerSeatbeltNotUsed;
                    go5.IsReverseDetectOn            = beepWhenReversing;

                    await myGeotabApi.CallAsync <object>("Set", typeof(Device), new { entity = go5 });
                }
                else if (goDevice is Go6)
                {
                    Go6 go6 = goDevice as Go6;
                    go6.ImmobilizeUnit                      = enableDriverIdentificationReminder;
                    go6.ImmobilizeArming                    = driverIdentificationReminderImmobilizeSeconds;
                    go6.EnableBeepOnRpm                     = enableBeepOnEngineRpm;
                    go6.RpmValue                            = engineRpmBeepValue;
                    go6.EnableBeepOnDangerousDriving        = enableBeepOnDangerousDriving;
                    go6.AccelerationWarningThreshold        = accelerationWarningThreshold;
                    go6.AccelerometerThresholdWarningFactor = 0;
                    go6.BrakingWarningThreshold             = brakingWarningThreshold;
                    go6.CorneringWarningThreshold           = corneringWarningThreshold;
                    go6.IsDriverSeatbeltWarningOn           = enableBeepWhenSeatbeltNotUsed;
                    go6.SeatbeltWarningSpeed                = seatbeltNotUsedWarningSpeed;
                    go6.IsPassengerSeatbeltWarningOn        = enableBeepWhenPassengerSeatbeltNotUsed;
                    go6.IsReverseDetectOn                   = beepWhenReversing;

                    await myGeotabApi.CallAsync <object>("Set", typeof(Device), new { entity = go6 });
                }
                else if (goDevice is Go7)
                {
                    Go7 go7 = goDevice as Go7;
                    go7.ImmobilizeUnit                      = enableDriverIdentificationReminder;
                    go7.ImmobilizeArming                    = driverIdentificationReminderImmobilizeSeconds;
                    go7.EnableBeepOnRpm                     = enableBeepOnEngineRpm;
                    go7.RpmValue                            = engineRpmBeepValue;
                    go7.EnableBeepOnDangerousDriving        = enableBeepOnDangerousDriving;
                    go7.AccelerationWarningThreshold        = accelerationWarningThreshold;
                    go7.AccelerometerThresholdWarningFactor = 0;
                    go7.BrakingWarningThreshold             = brakingWarningThreshold;
                    go7.CorneringWarningThreshold           = corneringWarningThreshold;
                    go7.IsDriverSeatbeltWarningOn           = enableBeepWhenSeatbeltNotUsed;
                    go7.SeatbeltWarningSpeed                = seatbeltNotUsedWarningSpeed;
                    go7.IsPassengerSeatbeltWarningOn        = enableBeepWhenPassengerSeatbeltNotUsed;
                    go7.IsReverseDetectOn                   = beepWhenReversing;

                    await myGeotabApi.CallAsync <object>("Set", typeof(Device), new { entity = go7 });
                }
                else if (goDevice is Go8)
                {
                    Go8 go8 = goDevice as Go8;
                    go8.ImmobilizeUnit                      = enableDriverIdentificationReminder;
                    go8.ImmobilizeArming                    = driverIdentificationReminderImmobilizeSeconds;
                    go8.EnableBeepOnRpm                     = enableBeepOnEngineRpm;
                    go8.RpmValue                            = engineRpmBeepValue;
                    go8.EnableBeepOnDangerousDriving        = enableBeepOnDangerousDriving;
                    go8.AccelerationWarningThreshold        = accelerationWarningThreshold;
                    go8.AccelerometerThresholdWarningFactor = 0;
                    go8.BrakingWarningThreshold             = brakingWarningThreshold;
                    go8.CorneringWarningThreshold           = corneringWarningThreshold;
                    go8.IsDriverSeatbeltWarningOn           = enableBeepWhenSeatbeltNotUsed;
                    go8.SeatbeltWarningSpeed                = seatbeltNotUsedWarningSpeed;
                    go8.IsPassengerSeatbeltWarningOn        = enableBeepWhenPassengerSeatbeltNotUsed;
                    go8.IsReverseDetectOn                   = beepWhenReversing;

                    await myGeotabApi.CallAsync <object>("Set", typeof(Device), new { entity = go8 });
                }
                else if (goDevice is Go9)
                {
                    Go9 go9 = goDevice as Go9;
                    go9.ImmobilizeUnit                      = enableDriverIdentificationReminder;
                    go9.ImmobilizeArming                    = driverIdentificationReminderImmobilizeSeconds;
                    go9.EnableBeepOnRpm                     = enableBeepOnEngineRpm;
                    go9.RpmValue                            = engineRpmBeepValue;
                    go9.EnableBeepOnDangerousDriving        = enableBeepOnDangerousDriving;
                    go9.AccelerationWarningThreshold        = accelerationWarningThreshold;
                    go9.AccelerometerThresholdWarningFactor = 0;
                    go9.BrakingWarningThreshold             = brakingWarningThreshold;
                    go9.CorneringWarningThreshold           = corneringWarningThreshold;
                    go9.IsDriverSeatbeltWarningOn           = enableBeepWhenSeatbeltNotUsed;
                    go9.SeatbeltWarningSpeed                = seatbeltNotUsedWarningSpeed;
                    go9.IsPassengerSeatbeltWarningOn        = enableBeepWhenPassengerSeatbeltNotUsed;
                    go9.IsReverseDetectOn                   = beepWhenReversing;

                    await myGeotabApi.CallAsync <object>("Set", typeof(Device), new { entity = go9 });
                }
                else
                {
                    await myGeotabApi.CallAsync <object>("Set", typeof(Device), new { entity = goDevice });
                }
            }
        }