<commit_before>﻿using System;
using System.Linq;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Windows.Input;
using Acr.UserDialogs;
using FleetComplete.Geocoder;
using Plugin.Geolocator.Abstractions;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Xamarin.Forms;


namespace OgreTest.ViewModels
{
    public class MainViewModel : ReactiveObject
    {
        readonly IUserDialogs dialogs;
        readonly IGeolocator geolocator;
        readonly Subject<object> zoomRequest;
        bool isStarted = false;


        public MainViewModel(IUserDialogs dialogs, IGeolocator geolocator, IGeocoder geocoder)
        {
            this.dialogs = dialogs;
            this.geolocator = geolocator;
            this.zoomRequest = new Subject<object>();

            this.Zoom = ReactiveCommand.CreateAsyncTask(
                this.WhenAny(
                    x => x.CurrentCoordinates,
                    x => x.ResolvedCityCoordinates,
                    (current, resolved) => current.Value != null && resolved != null
                ),
                async _ => this.zoomRequest.OnNext(null)
            );

            this.WhenAnyValue(x => x.CurrentCoordinates)
                .Skip(1)
                .Subscribe(async x =>
                {
                    var results = await geocoder.FindClosestCitiesAsync(x.Latitude, x.Longitude, 1);
                    var result = results.First();

                    this.Distance = Convert.ToInt32(Math.Round(result.ApproxDistance.TotalKilometers, 0));
                    this.LocationName = $"{result.City}, {result.StateProvince}, {result.Country}";
                    this.LocationNameAbbreviated = $"{result.City}, {result.StateProvinceCode}, {result.CountryCode}";
                    this.DirectionInDegrees = Math.Round(result.DirectionInDegreesFrom, 0);
                    this.Direction = result.DirectionFrom;
                    this.ResolvedCityCoordinates = new Coordinates(result.Coordinates.Latitude, result.Coordinates.Longitude);

                    this.CurrentCoordinatesText = this.CurrentCoordinates.ToString();
                    this.ResolvedCoordinatesText = this.ResolvedCityCoordinates.ToString();
                    if (!this.isStarted)
                    {
                        this.isStarted = true;
                        this.zoomRequest.OnNext(null);
                    }
                });
        }



        public IObservable<object> WhenZoomRequested() => this.zoomRequest;


        public async void Start()
        {
            if (this.isStarted)
                return;

            try
            {
                using (this.dialogs.Loading("Resolving Current Location..."))
                {
                    var position = await this.geolocator.GetPositionAsync();
                    this.CurrentCoordinates = new Coordinates(position.Latitude, position.Longitude);
                }
            }
            catch
            {
                this.dialogs.Alert("Could not retrieve current location");
            }
        }

<commit_msg>small change to sample<commit_after>﻿using System;
using System.Linq;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Threading.Tasks;
using System.Windows.Input;
using Acr.UserDialogs;
using FleetComplete.Geocoder;
using Plugin.Geolocator.Abstractions;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
using Xamarin.Forms;


namespace OgreTest.ViewModels
{
    public class MainViewModel : ReactiveObject
    {
        readonly IUserDialogs dialogs;
        readonly IGeolocator geolocator;
        readonly Subject<object> zoomRequest;
        bool isStarted = false;


        public MainViewModel(IUserDialogs dialogs, IGeolocator geolocator, IGeocoder geocoder)
        {
            this.dialogs = dialogs;
            this.geolocator = geolocator;
            this.zoomRequest = new Subject<object>();

            this.Zoom = ReactiveCommand.CreateAsyncTask(
                this.WhenAny(
                    x => x.CurrentCoordinates,
                    x => x.ResolvedCityCoordinates,
                    (current, resolved) => current.Value != null && resolved != null
                ),
                async _ => this.zoomRequest.OnNext(null)
            );

            this.WhenAnyValue(x => x.CurrentCoordinates)
                .Skip(1)
                .Subscribe(async x =>
                {
                    RemoveValues();

                    IGeocoderResult result = null;
                    await Task.Run(async () =>
                    {
                        var results = await geocoder.FindClosestCitiesAsync(x.Latitude, x.Longitude, 1);
                        result = results.First();
                    });

                    this.Distance = Convert.ToInt32(Math.Round(result.ApproxDistance.TotalKilometers, 0));
                    this.LocationName = $"{result.City}, {result.StateProvince}, {result.Country}";
                    this.LocationNameAbbreviated = $"{result.City}, {result.StateProvinceCode}, {result.CountryCode}";
                    this.DirectionInDegrees = Math.Round(result.DirectionInDegreesFrom, 0);
                    this.Direction = result.DirectionFrom;
                    this.ResolvedCityCoordinates = new Coordinates(result.Coordinates.Latitude, result.Coordinates.Longitude);

                    this.CurrentCoordinatesText = this.CurrentCoordinates.ToString();
                    this.ResolvedCoordinatesText = this.ResolvedCityCoordinates.ToString();
                    if (!this.isStarted)
                    {
                        this.isStarted = true;
                        this.zoomRequest.OnNext(null);
                    }
                });
        }

        private void RemoveValues()
        {
            this.Distance = 0;
            this.LocationName = "";
            this.LocationNameAbbreviated = "";
            this.DirectionInDegrees = 0;
            this.Direction = CardinalDirection.North;
            this.ResolvedCityCoordinates = null;
            this.CurrentCoordinatesText = "";
            this.ResolvedCoordinatesText = "";
        }

        public IObservable<object> WhenZoomRequested() => this.zoomRequest;


        public async void Start()
        {
            if (this.isStarted)
                return;

            try
            {
                using (this.dialogs.Loading("Resolving Current Location..."))
                {
                    var position = await this.geolocator.GetPositionAsync();
                    this.CurrentCoordinates = new Coordinates(position.Latitude, position.Longitude);
                }
            }
            catch
            {
                this.dialogs.Alert("Could not retrieve current location");
            }
        }


{'fraction_non_alphanumeric': 0.08887262079062958, 'fraction_numerical': 0.0020497803806734994, 'mean_word_length': 1.6673174541194846, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 24, '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': '1876034', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1680, 'n_words': 309}