Add a CSV Export of Selected Tournament (can stack multiple rankings but the UI get messy)
This commit is contained in:
@@ -1,16 +1,19 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Caliburn.Micro;
|
using System.Text;
|
||||||
|
using System.Windows.Forms;
|
||||||
using LaDOSE.DesktopApp.Utils;
|
using LaDOSE.DesktopApp.Utils;
|
||||||
using LaDOSE.DTO;
|
using LaDOSE.DTO;
|
||||||
using LaDOSE.REST;
|
using LaDOSE.REST;
|
||||||
|
using SaveFileDialog = Microsoft.Win32.SaveFileDialog;
|
||||||
|
using Screen = Caliburn.Micro.Screen;
|
||||||
|
|
||||||
namespace LaDOSE.DesktopApp.ViewModels
|
namespace LaDOSE.DesktopApp.ViewModels
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
public class TournamentResultViewModel : Screen
|
public class TournamentResultViewModel : Screen
|
||||||
{
|
{
|
||||||
public override string DisplayName => "Tournament Result";
|
public override string DisplayName => "Tournament Result";
|
||||||
@@ -22,7 +25,6 @@ namespace LaDOSE.DesktopApp.ViewModels
|
|||||||
this.RestService = restService;
|
this.RestService = restService;
|
||||||
_selectedTournaments = new ObservableCollection<TournamentDTO>();
|
_selectedTournaments = new ObservableCollection<TournamentDTO>();
|
||||||
Tournaments = new List<TournamentDTO>();
|
Tournaments = new List<TournamentDTO>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private TournamentsResultDTO _results;
|
private TournamentsResultDTO _results;
|
||||||
@@ -37,7 +39,9 @@ namespace LaDOSE.DesktopApp.ViewModels
|
|||||||
NotifyOfPropertyChange(() => Results);
|
NotifyOfPropertyChange(() => Results);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObservableCollection<TournamentDTO> _selectedTournaments;
|
private ObservableCollection<TournamentDTO> _selectedTournaments;
|
||||||
|
|
||||||
public ObservableCollection<TournamentDTO> SelectedTournaments
|
public ObservableCollection<TournamentDTO> SelectedTournaments
|
||||||
{
|
{
|
||||||
get { return _selectedTournaments; }
|
get { return _selectedTournaments; }
|
||||||
@@ -64,7 +68,9 @@ namespace LaDOSE.DesktopApp.ViewModels
|
|||||||
NotifyOfPropertyChange(() => SelectedGame);
|
NotifyOfPropertyChange(() => SelectedGame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObservableCollection<ResultDTO> _selectedGameResult;
|
private ObservableCollection<ResultDTO> _selectedGameResult;
|
||||||
|
|
||||||
public ObservableCollection<ResultDTO> SelectedGameResult
|
public ObservableCollection<ResultDTO> SelectedGameResult
|
||||||
{
|
{
|
||||||
get { return _selectedGameResult; }
|
get { return _selectedGameResult; }
|
||||||
@@ -76,6 +82,7 @@ namespace LaDOSE.DesktopApp.ViewModels
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String _first;
|
private String _first;
|
||||||
|
|
||||||
public String First
|
public String First
|
||||||
{
|
{
|
||||||
get { return _first; }
|
get { return _first; }
|
||||||
@@ -85,6 +92,7 @@ namespace LaDOSE.DesktopApp.ViewModels
|
|||||||
NotifyOfPropertyChange(() => First);
|
NotifyOfPropertyChange(() => First);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnInitialize()
|
protected override void OnInitialize()
|
||||||
{
|
{
|
||||||
LoadTournaments();
|
LoadTournaments();
|
||||||
@@ -103,10 +111,106 @@ namespace LaDOSE.DesktopApp.ViewModels
|
|||||||
var tournamentsIds = SelectedTournaments.Select(e => e.Id).ToList();
|
var tournamentsIds = SelectedTournaments.Select(e => e.Id).ToList();
|
||||||
var resultsDto = this.RestService.GetResults(tournamentsIds);
|
var resultsDto = this.RestService.GetResults(tournamentsIds);
|
||||||
this.Results = resultsDto;
|
this.Results = resultsDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Export()
|
||||||
|
{
|
||||||
|
if (this.Results == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
ComputeTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ComputeTable()
|
||||||
|
{
|
||||||
|
SaveFileDialog sfDialog = new SaveFileDialog()
|
||||||
|
{
|
||||||
|
AddExtension = true
|
||||||
|
};
|
||||||
|
if (sfDialog.ShowDialog() == true)
|
||||||
|
{
|
||||||
|
var computed = new Dictionary<string, Dictionary<int, int>>();
|
||||||
|
;
|
||||||
|
var resultsParticipents = this.Results.Participents.OrderBy(e => e.Name).ToList();
|
||||||
|
foreach (var participent in resultsParticipents)
|
||||||
|
{
|
||||||
|
computed.Add(participent.Name, new Dictionary<int, int>());
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var game in Results.Games)
|
||||||
|
{
|
||||||
|
var results = this.Results.Results.Where(e => e.GameId == game.Id).ToList();
|
||||||
|
foreach (var result in results)
|
||||||
|
{
|
||||||
|
var dictionary = computed[result.Player];
|
||||||
|
if (dictionary.ContainsKey(result.GameId))
|
||||||
|
dictionary[game.Id] += result.Point;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dictionary.Add(game.Id, result.Point);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
|
||||||
|
sb.AppendLine(Results.Games.Aggregate("Player;", (current, t) => current + (t.Name + ";")));
|
||||||
|
|
||||||
|
for (int i = 0; i < resultsParticipents.Count; i++)
|
||||||
|
{
|
||||||
|
var entry = "";
|
||||||
|
|
||||||
|
var resultsParticipent = resultsParticipents[i];
|
||||||
|
|
||||||
|
entry= resultsParticipent.Name+";";
|
||||||
|
var gameDtos = Results.Games.Distinct().ToList();
|
||||||
|
for (int j = 0; j < gameDtos.Count; j++)
|
||||||
|
{
|
||||||
|
var resultsGame = Results.Games[j];
|
||||||
|
var dictionary = computed[resultsParticipent.Name];
|
||||||
|
entry += dictionary.ContainsKey(resultsGame.Id)
|
||||||
|
? dictionary[resultsGame.Id].ToString() + ";"
|
||||||
|
: ";";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sb.AppendLine(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//string[][] resultCsv = new string[resultsParticipents.Count + 1][];
|
||||||
|
//resultCsv[0] = new string[Results.Games.Count + 1];
|
||||||
|
//resultCsv[0][0] = "Player";
|
||||||
|
//for (int j = 0; j < Results.Games.Count; j++)
|
||||||
|
//{
|
||||||
|
// resultCsv[0][j + 1] = Results.Games[j].Name;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//for (int i = 0; i < resultsParticipents.Count; i++)
|
||||||
|
//{
|
||||||
|
// resultCsv[i + 1] = new string[Results.Games.Count + 1];
|
||||||
|
|
||||||
|
// var resultsParticipent = resultsParticipents[i];
|
||||||
|
|
||||||
|
// resultCsv[i + 1][0] = resultsParticipent.Name;
|
||||||
|
// for (int j = 0; j < Results.Games.Count; j++)
|
||||||
|
// {
|
||||||
|
// var resultsGame = Results.Games[j];
|
||||||
|
// var dictionary = computed[resultsParticipent.Name];
|
||||||
|
// if (dictionary.ContainsKey(resultsGame.Id))
|
||||||
|
// {
|
||||||
|
// var i1 = dictionary[resultsGame.Id];
|
||||||
|
// resultCsv[i + 1][j + 1] = i1.ToString();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
//Save
|
||||||
|
File.WriteAllText(sfDialog.FileName,sb.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -42,6 +42,8 @@
|
|||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
@@ -49,6 +51,8 @@
|
|||||||
<ColumnDefinition Width="2*" />
|
<ColumnDefinition Width="2*" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Button Grid.Row="0" Grid.ColumnSpan="3" x:Name="Select">Select</Button>
|
<Button Grid.Row="0" Grid.ColumnSpan="3" x:Name="Select">Select</Button>
|
||||||
|
|
||||||
|
|
||||||
<StackPanel Grid.Row="1" Grid.ColumnSpan="3" Orientation="Horizontal">
|
<StackPanel Grid.Row="1" Grid.ColumnSpan="3" Orientation="Horizontal">
|
||||||
<TextBlock> Jeux :</TextBlock>
|
<TextBlock> Jeux :</TextBlock>
|
||||||
<TextBlock Margin="5,0,0,0" Text="{Binding Results.Games.Count}" />
|
<TextBlock Margin="5,0,0,0" Text="{Binding Results.Games.Count}" />
|
||||||
@@ -90,7 +94,7 @@
|
|||||||
<TextBlock Text="{Binding SelectedGameResult.Count,UpdateSourceTrigger=PropertyChanged}"></TextBlock>
|
<TextBlock Text="{Binding SelectedGameResult.Count,UpdateSourceTrigger=PropertyChanged}"></TextBlock>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<ListView ItemsSource="{Binding SelectedGameResult}" Margin="5,5,5,5"
|
<ListView ItemsSource="{Binding SelectedGameResult}" Margin="5,5,5,5"
|
||||||
IsTextSearchEnabled="True" TextSearch.TextPath="Name">
|
IsTextSearchEnabled="True" TextSearch.TextPath="Name" DockPanel.Dock="Top">
|
||||||
<ListView.ItemTemplate>
|
<ListView.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
@@ -101,8 +105,10 @@
|
|||||||
</ListView.ItemTemplate>
|
</ListView.ItemTemplate>
|
||||||
|
|
||||||
</ListView>
|
</ListView>
|
||||||
|
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
|
<Button Grid.Row="3" Grid.ColumnSpan="3" x:Name="Export">Export</Button>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
|
||||||
</UserControl>
|
</UserControl>
|
||||||
@@ -134,7 +134,7 @@ namespace LaDOSE.Business.Service
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Games = tournaments.Select(e => e.Game).ToList();
|
result.Games = tournaments.Select(e => e.Game).Distinct((game, game1) => game.Name==game1.Name).ToList();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user