Esempio n. 1
0
        public static void CalculateStatistics(this StatisticsItem item, List<LocationTrack> dayTrackList, LocationTrack lastTrack)
        {
            dayTrackList.Sort((t1, t2) => t1.TimeStamp.CompareTo(t2.TimeStamp));
            LocationTrack lastSaved = dayTrackList.LastOrDefault();
            if (lastSaved == null)
            {
                return;
            }

            if (lastSaved.TimeStamp.AddMinutes(10) < lastTrack.TimeStamp)
            {
                //Difference too much
                return;
            }

            double? distance = lastTrack.Location.Distance(lastSaved.Location);
            if (!distance.HasValue)
            {
                return;
            }

            decimal co2Index = GetCo2Index(lastTrack.Speed);
            decimal distanceValue = Convert.ToDecimal(distance.Value);
            decimal co2InKilograms = 0.15m * co2Index * distanceValue / (1000.0m);
            const decimal co2RecycleInOneDay = 44.0m / 365.0m;

            decimal result = co2InKilograms/co2RecycleInOneDay;
            item.Day = lastTrack.TimeStamp.Date;
            item.UserProfile = lastTrack.UserProfile;
            item.Value += result;
            item.Consumer = "Car";
        }
Esempio n. 2
0
 private LocationTrack CreateLocationTrack(Position position, string token)
 {
     UserProfile user = _db.UserProfiles.First(u => u.UserName == token);
     var locationTrack = new LocationTrack();
     locationTrack.UserProfile = user;
     locationTrack.TimeStamp = DateTime.MinValue.Add(TimeSpan.FromTicks(position.UtcTicks));
     locationTrack.Location = DbGeography.FromText(string.Format("POINT ({0} {1})",position.Latitude, position.Longitude));
     locationTrack.Speed = position.Speed;
     locationTrack.Id = Guid.NewGuid();
     return locationTrack;
 }