Skip to content

Commit

Permalink
Added "Statistics" page (WIP - #84)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed May 8, 2021
1 parent 7cce2d2 commit 9965f1c
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Gavilya/Classes/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,28 @@ internal static void SortGames()
}
}

/// <summary>
/// Returns in seconds the toal time played of all games
/// </summary>
/// <returns></returns>
internal static int GetTotalTimePlayed()
{
if (Definitions.Games.Count > 0)
{
int result = 0;
for (int i = 0; i < Definitions.Games.Count; i++)
{
result += Definitions.Games[i].TotalTimePlayed; // Add time played
}

return result; // Return the total
}
else
{
return 0;
}
}

public static string UserName => Environment.UserName;
}
}
45 changes: 45 additions & 0 deletions Gavilya/Pages/Statistics.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<Page x:Class="Gavilya.Pages.Statistics"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Gavilya.Pages"
xmlns:lang="clr-namespace:Gavilya.Properties"
mc:Ignorable="d"
FontFamily="../Fonts/#Montserrat"
d:DesignHeight="450" d:DesignWidth="800"
Title="Statistics" Foreground="White">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>

<TextBlock Grid.Row="0" Text="{x:Static lang:Resources.Statistics}" FontWeight="Bold" FontSize="20" Foreground="White" VerticalAlignment="Center"/>

<Border CornerRadius="25" Background="#FF141428" Grid.Row="1" Margin="10" Padding="25">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<TextBlock Text="{x:Static lang:Resources.StatsTimePlayed}" FontSize="16" FontWeight="Bold" Foreground="#FF64648C"/>
<TextBlock x:Name="TotalTimePlayedTxt" Text="" FontSize="48" FontWeight="Bold" d:Text="150,7h"/>
</StackPanel>
<Grid Margin="0,5,0,0" Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<ScrollViewer Template="{StaticResource ScrollViewerTemplate1}">
<StackPanel x:Name="GamesInfoDisplayer">
<!-- Content loaded on start -->
</StackPanel>
</ScrollViewer>
</Grid>
</Grid>
</Border>
</Grid>
</Page>
85 changes: 85 additions & 0 deletions Gavilya/Pages/Statistics.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
MIT License
Copyright (c) Léo Corporation
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using Gavilya.Classes;
using Gavilya.UserControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Gavilya.Pages
{
/// <summary>
/// Interaction logic for Statistics.xaml
/// </summary>
public partial class Statistics : Page
{
public Statistics()
{
InitializeComponent();
InitUI();
}

private void InitUI()
{
// Values
Dictionary<GameInfo, int> gameTimes = new(); // Create dictionnary

for (int i = 0; i < Definitions.Games.Count; i++)
{
gameTimes.Add(Definitions.Games[i], Definitions.Games[i].TotalTimePlayed); // Add item
}

var items = from pair in gameTimes orderby pair.Value descending select pair; // Sort

// Top 10 most played games
int c = 0; // Counter
foreach (KeyValuePair<GameInfo, int> keyValuePair in items)
{
if (c <= 10)
{
GamesInfoDisplayer.Children.Add(new StatInfoCard(keyValuePair.Key)); // Add item
c++; // Increment counter
}
else
{
break;
}
}

// Text
TotalTimePlayedTxt.Text = $"{Global.GetTotalTimePlayed() / 3600}{Properties.Resources.HourShort}"; // Set text
}
}
}
27 changes: 27 additions & 0 deletions Gavilya/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Gavilya/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,13 @@
<data name="Reset" xml:space="preserve">
<value>Reset</value>
</data>
<data name="Statistics" xml:space="preserve">
<value>Statistics</value>
</data>
<data name="StatsTimePlayed" xml:space="preserve">
<value>TOTAL TIME PLAYED</value>
</data>
<data name="HourShort" xml:space="preserve">
<value>h</value>
</data>
</root>
9 changes: 9 additions & 0 deletions Gavilya/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -507,4 +507,13 @@
<data name="Reset" xml:space="preserve">
<value>Réinitialiser</value>
</data>
<data name="Statistics" xml:space="preserve">
<value>Statistiques</value>
</data>
<data name="StatsTimePlayed" xml:space="preserve">
<value>TEMPS TOTAL JOUE</value>
</data>
<data name="HourShort" xml:space="preserve">
<value>h</value>
</data>
</root>
9 changes: 9 additions & 0 deletions Gavilya/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -514,4 +514,13 @@
<data name="Reset" xml:space="preserve">
<value>Reset</value>
</data>
<data name="Statistics" xml:space="preserve">
<value>Statistics</value>
</data>
<data name="StatsTimePlayed" xml:space="preserve">
<value>TOTAL TIME PLAYED</value>
</data>
<data name="HourShort" xml:space="preserve">
<value>h</value>
</data>
</root>

0 comments on commit 9965f1c

Please sign in to comment.