<commit_before>﻿using System;

using System.Collections.Generic;
using System.Linq;

using Cirrious.MvvmCross.ViewModels;

using bstrkr.core;
using bstrkr.core.map;
using bstrkr.core.services.resources;
using bstrkr.core.spatial;
using bstrkr.mvvm.views;

namespace bstrkr.mvvm.viewmodels
{
	public class VehicleViewModel : MapMarkerViewModelBase<Vehicle>
	{
		private readonly Queue<Tuple<double, GeoPoint>> _queue = new Queue<Tuple<double, GeoPoint>>();

		private long _lastUpdate = 0;

		public VehicleViewModel(IResourceManager resourceManager) : base(resourceManager)
		{
		}

		public override Vehicle Model
		{
			get 
			{
				return base.Model;
			}

			set
			{
				if (base.Model != value)
				{
					base.Model = value;

					this.RaisePropertyChanged(() => this.VehicleId);
					this.RaisePropertyChanged(() => this.VehicleType);
					this.RaisePropertyChanged(() => this.CarPlate);
					this.RaisePropertyChanged(() => this.Location);
				}
			}
		}

		public string VehicleId
		{
			get { return this.Model == null ? string.Empty : this.Model.Id; }
		}

		public VehicleTypes VehicleType
		{
			get { return this.Model == null ? VehicleTypes.Bus : this.Model.Type; }
		}

		public float VehicleHeading
		{
			get 
			{ 
				return this.Model == null ? 0.0f : this.Model.Heading; 
			}

			set
			{
				if (this.Model != null && this.Model.Heading != value)
				{
					this.Model.Heading = value;
					this.RaisePropertyChanged(() => this.VehicleHeading);
				}
			}
		}

		public string CarPlate
		{
			get { return this.Model == null ? string.Empty : this.Model.CarPlate; }
		}

		public override GeoPoint Location
		{
			get 
			{ 
				return this.Model == null ? GeoPoint.Empty : this.Model.Location; 
			}

			set
			{
				if (this.Model != null && !GeoPoint.Equals(this.Model.Location, value))
				{
					this.Model.Location = value;
					this.RaisePropertyChanged(() => this.Location);
				}
			}
		}

		public void AddWaypoints(WaypointCollection waypoints)
		{
			var now = DateTime.UtcNow.Ticks;
			var sortedWaypoints = waypoints.Waypoints.OrderBy(x => x.Fraction);
			lock(_queue)
			{
				_queue.Enqueue(
					new Tuple<double, GeoPoint>(
						TimeSpan.FromTicks(now - _lastUpdate).TotalMilliseconds, 
						sortedWaypoints.First().Location));

				foreach (var waypoint in sortedWaypoints.Skip(1))
				{
					_queue.Enqueue(
						new Tuple<double, GeoPoint>(
							1 * waypoint.Fraction, 
							waypoint.Location));
				}
			}

			_lastUpdate = now;
		}

		protected override object GetIcon()
		{
			return this.Model == null ? null : _resourceManager.GetVehicleMarker(this.Model.Type, this.MarkerSize);
		}
	}
}<commit_msg>animate markers on the map<commit_after>﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

using Cirrious.MvvmCross.ViewModels;

using bstrkr.core;
using bstrkr.core.map;
using bstrkr.core.services.resources;
using bstrkr.core.spatial;
using bstrkr.mvvm.views;

namespace bstrkr.mvvm.viewmodels
{
	public class VehicleViewModel : MapMarkerViewModelBase<Vehicle>
	{
		private readonly ObservableCollection<Waypoint> _waypoints = new ObservableCollection<Waypoint>();

		private long _lastUpdate = 0;

		public VehicleViewModel(IResourceManager resourceManager) : base(resourceManager)
		{
			this.Waypoints = new ReadOnlyObservableCollection<Waypoint>(_waypoints);
		}

		public override Vehicle Model
		{
			get 
			{
				return base.Model;
			}

			set
			{
				if (base.Model != value)
				{
					base.Model = value;

					this.RaisePropertyChanged(() => this.VehicleId);
					this.RaisePropertyChanged(() => this.VehicleType);
					this.RaisePropertyChanged(() => this.CarPlate);
					this.RaisePropertyChanged(() => this.Location);
				}
			}
		}

		public string VehicleId
		{
			get { return this.Model == null ? string.Empty : this.Model.Id; }
		}

		public VehicleTypes VehicleType
		{
			get { return this.Model == null ? VehicleTypes.Bus : this.Model.Type; }
		}

		public float VehicleHeading
		{
			get 
			{ 
				return this.Model == null ? 0.0f : this.Model.Heading; 
			}

			set
			{
				if (this.Model != null && this.Model.Heading != value)
				{
					this.Model.Heading = value;
					this.RaisePropertyChanged(() => this.VehicleHeading);
				}
			}
		}

		public string CarPlate
		{
			get { return this.Model == null ? string.Empty : this.Model.CarPlate; }
		}

		public override GeoPoint Location
		{
			get 
			{ 
				return this.Model == null ? GeoPoint.Empty : this.Model.Location; 
			}

			set
			{
				if (this.Model != null && !GeoPoint.Equals(this.Model.Location, value))
				{
					this.Model.Location = value;
					this.RaisePropertyChanged(() => this.Location);
				}
			}
		}

		public ReadOnlyObservableCollection<Waypoint> Waypoints { get; private set; }

		public void AddWaypoints(WaypointCollection waypoints)
		{
//			var now = DateTime.UtcNow.Ticks;
//			var sortedWaypoints = waypoints.Waypoints.OrderBy(x => x.Fraction);
//			lock(_queue)
//			{
//				_queue.Enqueue(
//					new Tuple<double, GeoPoint>(
//						TimeSpan.FromTicks(now - _lastUpdate).TotalMilliseconds, 
//						sortedWaypoints.First().Location));
//
//				foreach (var waypoint in sortedWaypoints.Skip(1))
//				{
//					_queue.Enqueue(
//						new Tuple<double, GeoPoint>(
//							1 * waypoint.Fraction, 
//							waypoint.Location));
//				}
//			}
//
//			_lastUpdate = now;
		}

		protected override object GetIcon()
		{
			return this.Model == null ? null : _resourceManager.GetVehicleMarker(this.Model.Type, this.MarkerSize);
		}
	}
}
{'fraction_non_alphanumeric': 0.12259572173287794, 'fraction_numerical': 0.0017975912277548086, 'mean_word_length': 2.9657875980042765, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4936462', 'n_tokens_mistral': 2315, 'n_tokens_neox': 1841, 'n_words': 353}