Skip to content

Commit

Permalink
Add export functionality for rounds.
Browse files Browse the repository at this point in the history
Also fixed single-gender team generation issue.
  • Loading branch information
Ashley Donaldson committed Jan 28, 2016
1 parent f257ec3 commit 30c0282
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 6 deletions.
16 changes: 16 additions & 0 deletions KingsAndQueensHat/Model/HatRound.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ public void SaveToFile()
}
}

public void ExportToCsv(string filename)
{
using (var stream = new StreamWriter(filename))
{
foreach (var team in Teams)
{
stream.WriteLine(team.Name);
foreach (var player in team.Players)
{
stream.WriteLine(player.Name);
}
stream.WriteLine();
}
}
}

public void AddRoundToPairingCount(PlayerPairings pairings)
{
foreach (var team in Teams)
Expand Down
5 changes: 5 additions & 0 deletions KingsAndQueensHat/Model/Tournament.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ internal void DeleteRound(int roundNum)

}

internal void ExportRoundToCsv(int roundNum, string filename)
{
Rounds[roundNum].ExportToCsv(filename);
}

internal void AddPlayerToLastRound(Player player)
{
var round = Rounds.Last();
Expand Down
4 changes: 2 additions & 2 deletions KingsAndQueensHat/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: AssemblyVersion("1.0.2")]
[assembly: AssemblyFileVersion("1.0.2")]
3 changes: 2 additions & 1 deletion KingsAndQueensHat/TeamGeneration/RangeOfSkillsPenalty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public class RangeOfSkillsPenalty : IPenalty
public double ScorePenalty(List<Team> teams)
{
double result = 0;
foreach (var gender in new[] { Gender.Male, Gender.Female })
var genders = teams.SelectMany(t => t.GenderSkills.Keys).Distinct();
foreach (var gender in genders)
{
var standardDeviations = teams.Select(t => HatMath.StdDeviation(t.Players.Where(p => p.Gender == gender).Select(p => (double)p.SkillValue).ToList())).ToList();
// Yo dawg
Expand Down
3 changes: 2 additions & 1 deletion KingsAndQueensHat/TeamGeneration/UnevenGenderSkillPenalty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public double ScorePenalty(List<Team> teams)
{
var scores = teams.Select(team => team.GenderSkills).ToList();
int result = 0;
foreach (var gender in new[] { Gender.Male, Gender.Female })
var genders = teams.SelectMany(t => t.GenderSkills.Keys).Distinct();
foreach (var gender in genders)
{
var total = scores.Sum(s => s[gender]);
var teamCount = teams.Count;
Expand Down
5 changes: 3 additions & 2 deletions KingsAndQueensHat/View/RoundManagerView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
<Label Content="{Binding CurrentRoundNumber}" FontSize="20" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Button Name="NextRoundButton" Content="&gt;" HorizontalAlignment="Left" VerticalAlignment="Top" Width="13" Margin="0,10,0,0" Click="NextRoundButton_Click" IsEnabled="{Binding CanNavigateForwards}"/>
</StackPanel>
<Button Content="Delete" HorizontalAlignment="Left" Margin="176,10,0,0" VerticalAlignment="Top" Width="47" Name="DeleteButton" IsEnabled="{Binding CanDeleteRound}" Click="DeleteButton_Click"/>
<Button Content="Delete All" Name="DeleteAllButton" HorizontalAlignment="Left" Margin="228,10,0,0" VerticalAlignment="Top" Width="75" IsEnabled="{Binding CanDeleteRound}" Click="DeleteAllButton_Click"/>
<Button Content="Export" HorizontalAlignment="Left" Margin="158,10,0,0" VerticalAlignment="Top" Width="47" Name="ExportButton" IsEnabled="{Binding CanDeleteRound}" Click="ExportButton_Click"/>
<Button Content="Delete" HorizontalAlignment="Left" Margin="209,10,0,0" VerticalAlignment="Top" Width="47" Name="DeleteButton" IsEnabled="{Binding CanDeleteRound}" Click="DeleteButton_Click"/>
<Button Content="Delete All" Name="DeleteAllButton" HorizontalAlignment="Left" Margin="261,10,0,0" VerticalAlignment="Top" Width="75" IsEnabled="{Binding CanDeleteRound}" Click="DeleteAllButton_Click"/>
<ScrollViewer Margin="0,47,0,0">
<k:RoundView DataContext="{Binding CurrentRoundViewModel}"/>
</ScrollViewer>
Expand Down
15 changes: 15 additions & 0 deletions KingsAndQueensHat/View/RoundManagerView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using KingsAndQueensHat.ViewModel;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -79,6 +80,20 @@ private void DeleteButton_Click(object sender, RoutedEventArgs e)
}
}

private void ExportButton_Click(object sender, RoutedEventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog
{
DefaultExt = "*.csv",
Filter = "CSV File (*.csv)|*.csv"
};
var ok = dialog.ShowDialog();
if (ok.HasValue && ok.Value)
{
ViewModel.ExportThisRound(dialog.FileName);
}
}

private void DeleteAllButton_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("Are you sure you want to permanently delete all data?", "Confirm", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK)
Expand Down
5 changes: 5 additions & 0 deletions KingsAndQueensHat/ViewModel/RoundManagerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ internal void DeleteThisRound()
OnPropertyChanged("CanDeleteRound");
}

internal void ExportThisRound(string filename)
{
Tournament.ExportRoundToCsv(CurrentRoundNumber - 1, filename);
}

internal void DeleteAllData()
{
Tournament.DeleteAllData();
Expand Down

0 comments on commit 30c0282

Please sign in to comment.