| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- namespace FormulaOneApp.Classic.Core.ViewModels
- {
- using System;
- using System.Threading.Tasks;
- using Cirrious.MvvmCross.ViewModels;
- using ErgastAPI.Model.Driver;
- using ErgastAPI.Services.Driver;
- using OxyPlot;
- using OxyPlot.Series;
- public class DriverDetailViewModel : MvxViewModel
- {
- // Variables
- private Driver _driver;
- private int _champs;
- private int _poles;
- private int _wins;
- private int _races;
- private PlotModel _plotModel;
- // Services
- private IDriverService _driverService;
- public DriverDetailViewModel(IDriverService driverService)
- {
- _driverService = driverService;
- }
- public Driver Driver
- {
- get { return _driver; }
- set
- {
- _driver = value;
- RaisePropertyChanged();
- }
- }
- public int Champs
- {
- get { return _champs; }
- set
- {
- _champs = value;
- RaisePropertyChanged();
- }
- }
- public int Poles
- {
- get { return _poles; }
- set
- {
- _poles = value;
- RaisePropertyChanged();
- }
- }
- public int Wins
- {
- get { return _wins; }
- set
- {
- _wins = value;
- RaisePropertyChanged();
- }
- }
- public int Races
- {
- get { return _races; }
- set
- {
- _races = value;
- RaisePropertyChanged();
- }
- }
- public PlotModel PlotModel
- {
- get { return _plotModel; }
- set
- {
- _plotModel = value;
- RaisePropertyChanged();
- }
- }
- private async Task LoadDriverInfoAsync(string driver)
- {
- var currentYear = DateTime.Today.Year;
- int second = 0;
- int third = 0;
- int four = 0;
- int five = 0;
- for (int i = currentYear; i > 2000; i--)
- {
- var driverResult = await _driverService.GetDriverResultsAsync(driver, i.ToString());
- foreach (var race in driverResult.Races)
- {
- Races = Races + 1;
- foreach (var result in race.Results)
- {
- if (result.Position.Equals("1", StringComparison.CurrentCultureIgnoreCase))
- {
- Wins = Wins + 1;
- }
- if (result.Position.Equals("2", StringComparison.CurrentCultureIgnoreCase))
- {
- second = second + 1;
- }
- if (result.Position.Equals("3", StringComparison.CurrentCultureIgnoreCase))
- {
- third = third + 1;
- }
- if (result.Position.Equals("4", StringComparison.CurrentCultureIgnoreCase))
- {
- four = four + 1;
- }
- if (result.Position.Equals("5", StringComparison.CurrentCultureIgnoreCase))
- {
- five = five + 1;
- }
- }
- }
- }
- PlotModel = new PlotModel
- {
- Title = "Positions"
- };
- var pieSlice = new PieSeries
- {
- StrokeThickness = 2.0,
- InsideLabelPosition = 0.8,
- AngleSpan = 360,
- StartAngle = 0
- };
- pieSlice.Slices.Add(new PieSlice("1º", Wins) { IsExploded = true });
- pieSlice.Slices.Add(new PieSlice("2º", second) { IsExploded = true });
- pieSlice.Slices.Add(new PieSlice("3º", third) { IsExploded = true });
- pieSlice.Slices.Add(new PieSlice("4º", four) { IsExploded = true });
- pieSlice.Slices.Add(new PieSlice("5º", five) { IsExploded = true });
- PlotModel.Series.Add(pieSlice);
- RaisePropertyChanged("PlotModel");
- }
- }
- }
|