Track basic statistics

This commit is contained in:
2016-01-19 23:15:31 +01:00
parent 337f0c308f
commit 0502f854b1
8 changed files with 67 additions and 21 deletions
+2
View File
@@ -10,6 +10,7 @@ using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using Windows.ApplicationModel.Core;
using YJMPD_UWP.Helpers;
namespace YJMPD_UWP
{
@@ -259,6 +260,7 @@ namespace YJMPD_UWP
var deferral = e.SuspendingOperation.GetDeferral();
App.Network.Disconnect();
Settings.SaveStatistics();
deferral.Complete();
}
@@ -4,13 +4,11 @@ namespace YJMPD_UWP.Helpers.EventArgs
{
public class PositionUpdatedEventArgs : System.EventArgs
{
public Geoposition Old { get; private set; }
public Geoposition New { get; private set; }
public Geoposition Position { get; private set; }
public PositionUpdatedEventArgs(Geoposition old, Geoposition notold)
public PositionUpdatedEventArgs(Geoposition pos)
{
Old = old;
New = notold;
Position = pos;
}
}
}
+5
View File
@@ -34,6 +34,11 @@ namespace YJMPD_UWP.Helpers
}
}
public static void SaveStatistics()
{
Values["statistics"] = Util.Serialize(st);
}
public static string Username
{
+1 -1
View File
@@ -49,7 +49,7 @@ namespace YJMPD_UWP.Model
if (o["selected"].ToObject<bool>() == true)
{
Debug.WriteLine("Selected player taking picture");
App.Game.Selected = true;
App.Game.SetSelected(true);
App.Navigate(typeof(PhotoView));
}
else
+39 -1
View File
@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Windows.Devices.Geolocation.Geofencing;
using Windows.Foundation;
using Windows.Services.Maps;
using Windows.UI.Xaml.Media.Imaging;
using YJMPD_UWP.Helpers;
using YJMPD_UWP.Helpers.EventArgs;
@@ -24,12 +27,17 @@ namespace YJMPD_UWP.Model
public List<Player> Players { get; private set; }
public bool Selected { get; set; }
public bool Selected { get; private set; }
private void UpdateGameStatus(GameStatus status)
{
Status = status;
if (Status == GameStatus.STARTED)
App.Geo.KeepHistory();
else
App.Geo.ClearHistory();
if (OnStatusUpdate == null) return;
OnStatusUpdate(this, new GameStatusUpdatedEventArgs(status));
@@ -54,6 +62,17 @@ namespace YJMPD_UWP.Model
UpdateGamePlayers(p);
}
public void SetSelected(bool b)
{
if (b)
{
Selected = true;
Settings.Statistics.Selected += 1;
}
else
Selected = false;
}
public void MoveToWaiting()
{
UpdateGameStatus(GameStatus.WAITING);
@@ -77,6 +96,7 @@ namespace YJMPD_UWP.Model
App.Photo.Reset();
Selected = false;
Players.Clear();
GeofenceMonitor.Current.Geofences.Clear();
UpdateGamePlayers(null);
App.Navigate(typeof(MatchView));
@@ -95,6 +115,24 @@ namespace YJMPD_UWP.Model
}
}
//Ending
public async Task<bool> End()
{
CalculateDistanceWalked();
Settings.Statistics.Matches += 1;
UpdateGameStatus(GameStatus.ENDED);
return true;
}
public async void CalculateDistanceWalked()
{
MapRoute r = await Util.FindWalkingRoute(App.Geo.History.Select(p => p.Coordinate.Point).ToList());
Settings.Statistics.Distance += r.LengthInMeters;
}
//Starting and Stopping
public async Task<bool> Start()
+14 -11
View File
@@ -21,6 +21,7 @@ namespace YJMPD_UWP.Model
public bool? Connected { get; private set; }
private bool trackhistory = false;
private List<Geoposition> _history;
public List<Geoposition> History
{
@@ -61,9 +62,15 @@ namespace YJMPD_UWP.Model
public void ClearHistory()
{
trackhistory = false;
_history.Clear();
}
public void KeepHistory()
{
trackhistory = true;
}
public async Task<String> StartTracking()
{
// Request permission to access location
@@ -124,15 +131,11 @@ namespace YJMPD_UWP.Model
private void Geo_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
if (_history.Count > 0)
UpdatePosition(_history.Last(), args.Position);
else
{
_position = args.Position;
UpdatePosition(args.Position, args.Position);
}
_history.Add(args.Position);
UpdatePosition(args.Position);
if(trackhistory)
_history.Add(args.Position);
}
private void UpdateStatus(PositionStatus s)
@@ -144,13 +147,13 @@ namespace YJMPD_UWP.Model
OnStatusUpdate(this, new PositionStatusUpdatedEventArgs(s));
}
private void UpdatePosition(Geoposition old, Geoposition newp)
private void UpdatePosition(Geoposition pos)
{
_position = newp;
_position = pos;
if (OnPositionUpdate == null) return;
OnPositionUpdate(this, new PositionUpdatedEventArgs(old, newp));
OnPositionUpdate(this, new PositionUpdatedEventArgs(pos));
}
}
}
+2 -2
View File
@@ -10,13 +10,13 @@ namespace YJMPD_UWP.Model.Object
Points = new List<double>();
Distance = 0;
Matches = 0;
Leader = 0;
Selected = 0;
}
public List<double> Points { get; set; }
public double Distance { get; set; }
public int Matches { get; set; }
public int Leader { get; set; }
public int Selected { get; set; }
public void AddPoints(double points)
{
+1 -1
View File
@@ -33,7 +33,7 @@ namespace YJMPD_UWP.ViewModels
{
get
{
return st.Leader + "";
return st.Selected + "";
}
}