School Commit Init
@@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class CacheModule<T>
|
||||
{
|
||||
private readonly Dictionary<string, CacheItem<T>> cache = new Dictionary<string, CacheItem<T>>();
|
||||
private readonly object @lock = new object();
|
||||
public T Get(string key)
|
||||
{
|
||||
lock (@lock)
|
||||
{
|
||||
if (cache.TryGetValue(key, out CacheItem<T> cacheItem))
|
||||
{
|
||||
if (!cacheItem.IsExpired())
|
||||
{
|
||||
return cacheItem.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
cache.Remove(key);
|
||||
}
|
||||
}
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
public void Set(string key, T value, TimeSpan expirationTime)
|
||||
{
|
||||
lock (@lock)
|
||||
{
|
||||
var expirationTimeUtc = DateTime.UtcNow.Add(expirationTime);
|
||||
cache[key] = new CacheItem<T>(value, expirationTimeUtc);
|
||||
}
|
||||
}
|
||||
public void Remove(string key)
|
||||
{
|
||||
lock (@lock)
|
||||
{
|
||||
cache.Remove(key);
|
||||
}
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
lock (@lock)
|
||||
{
|
||||
cache.Clear();
|
||||
}
|
||||
}
|
||||
private class CacheItem<TValue>
|
||||
{
|
||||
public TValue Value { get; }
|
||||
public DateTime ExpirationTimeUtc { get; }
|
||||
|
||||
public CacheItem(TValue value, DateTime expirationTimeUtc)
|
||||
{
|
||||
Value = value;
|
||||
ExpirationTimeUtc = expirationTimeUtc;
|
||||
}
|
||||
|
||||
public bool IsExpired()
|
||||
{
|
||||
return DateTime.UtcNow >= ExpirationTimeUtc;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var cache = new CacheModule<string>();
|
||||
|
||||
cache.Set("key1", "value1", TimeSpan.FromSeconds(5));
|
||||
|
||||
string cachedData = cache.Get("key1");
|
||||
Console.WriteLine("Cached Data: " + cachedData);
|
||||
|
||||
|
||||
Console.WriteLine("Waiting for 3 seconds...");
|
||||
System.Threading.Thread.Sleep(3000);
|
||||
|
||||
cachedData = cache.Get("key1");
|
||||
Console.WriteLine("Cached Data after 3 seconds: " + cachedData);
|
||||
|
||||
Console.WriteLine("Waiting for 3 more seconds...");
|
||||
System.Threading.Thread.Sleep(3000);
|
||||
|
||||
cachedData = cache.Get("key1");
|
||||
if (cachedData != null)
|
||||
{
|
||||
Console.WriteLine("Cached Data after 6 seconds: " + cachedData);
|
||||
|
||||
}
|
||||
else
|
||||
{ Console.WriteLine("Expiration time exceeded!"); }
|
||||
|
||||
|
||||
|
||||
cache.Set("key1", "value1", TimeSpan.FromSeconds(5));
|
||||
cache.Set("key2", "value2", TimeSpan.FromSeconds(5));
|
||||
string cachedData1 = cache.Get("key1");
|
||||
string cachedData2 = cache.Get("key2");
|
||||
|
||||
Console.WriteLine("Cached Data 1: " + cachedData1);
|
||||
Console.WriteLine("Cached Data 2: " + cachedData2);
|
||||
|
||||
cache.Remove("key1");
|
||||
|
||||
cachedData1 = cache.Get("key1");
|
||||
|
||||
Console.WriteLine("Cached Data 1 after remove: " + cachedData1);
|
||||
Console.WriteLine("Cached Data 2 after remove: " + cachedData2);
|
||||
cache.Clear();
|
||||
string cachedDataFinal = cache.Get("key2");
|
||||
Console.WriteLine("Cached Data 2 after clear: " + cachedDataFinal);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,41 @@
|
||||
<UserControl x:Class="Statistics.LikedPosts"
|
||||
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:Statistics"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Canvas Background="White">
|
||||
<TextBlock Text="Liked Posts" FontSize="24" FontWeight="Bold" RenderTransformOrigin="0.323,0.698" Canvas.Left="45" Canvas.Top="34" HorizontalAlignment="Center" VerticalAlignment="Top"/>
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Height="376" Width="558" Canvas.Left="192" Canvas.Top="47" HorizontalAlignment="Center" VerticalAlignment="Top">
|
||||
<UniformGrid Columns="4">
|
||||
<UniformGrid.Resources>
|
||||
<Style TargetType="Image">
|
||||
<Setter Property="Width" Value="200"/>
|
||||
<Setter Property="Height" Value="200"/>
|
||||
</Style>
|
||||
</UniformGrid.Resources>
|
||||
|
||||
<Image Source="C:\Users\herta\Desktop\Sem4\ISS\App\District 3 App\Statistics\pics\hd-wallpaper-g598bd113c_1920.jpg" Margin="5" Stretch="Uniform"/>
|
||||
<Image x:Name="img2" Source="C:\Users\herta\Desktop\Sem4\ISS\App\District 3 App\Statistics\pics\tpjhc5wp18b71.jpg" Margin="5"/>
|
||||
<Image Source="C:\Users\herta\Desktop\Sem4\ISS\App\District 3 App\Statistics\pics\240_F_233118616_WElVq2Sajc1swjWTAj1IsBRFMGNm0vzN.jpg" Margin="5"/>
|
||||
<Image Source="C:\Users\herta\Desktop\Sem4\ISS\App\District 3 App\Statistics\pics\240_F_266724172_Iy8gdKgMa7XmrhYYxLCxyhx6J7070Pr8.jpg" Margin="5"/>
|
||||
<Image Source="C:\Users\herta\Desktop\Sem4\ISS\App\District 3 App\Statistics\pics\240_F_303624505_u0bFT1Rnoj8CMUSs8wMCwoKlnWlh5Jiq.jpg" Margin="5"/>
|
||||
<Image Source="C:\Users\herta\Desktop\Sem4\ISS\App\District 3 App\Statistics\pics\240_F_605374009_hEUHatmKPzuHTIacg7rLneAgnLHUgegM.jpg" Margin="5"/>
|
||||
<Image Source="C:\Users\herta\Desktop\Sem4\ISS\App\District 3 App\Statistics\pics\240_F_74159556_67n5823V7Ei87a4g6JJnYHC0yMSo1AEy.jpg" Margin="5"/>
|
||||
<Image Source="C:\Users\herta\Desktop\Sem4\ISS\App\District 3 App\Statistics\pics\240_F_97589769_t45CqXyzjz0KXwoBZT9PRaWGHRk5hQqQ.jpg" Margin="5"/>
|
||||
<Image Source="C:\Users\herta\OneDrive\Pictures\tpjhc5wp18b71.jpg" Margin="5"/>
|
||||
<Image Source="C:\Users\herta\Desktop\Sem4\ISS\App\District 3 App\Statistics\pics\240_F_266724172_Iy8gdKgMa7XmrhYYxLCxyhx6J7070Pr8.jpg" Margin="5"/>
|
||||
<Image Source="C:\Users\herta\Desktop\Sem4\ISS\App\District 3 App\Statistics\pics\240_F_303624505_u0bFT1Rnoj8CMUSs8wMCwoKlnWlh5Jiq.jpg" Margin="5"/>
|
||||
<Image Source="C:\Users\herta\Desktop\Sem4\ISS\App\District 3 App\Statistics\pics\240_F_605374009_hEUHatmKPzuHTIacg7rLneAgnLHUgegM.jpg" Margin="5"/>
|
||||
<Image Source="C:\Users\herta\Desktop\Sem4\ISS\App\District 3 App\Statistics\pics\240_F_74159556_67n5823V7Ei87a4g6JJnYHC0yMSo1AEy.jpg" Margin="5"/>
|
||||
<Image Source="C:\Users\herta\OneDrive\Pictures\tpjhc5wp18b71.jpg" Margin="5"/>
|
||||
<Image Source="C:\Users\herta\OneDrive\Pictures\tpjhc5wp18b71.jpg" Margin="5"/>
|
||||
<Image Source="C:\Users\herta\OneDrive\Pictures\tpjhc5wp18b71.jpg" Margin="5"/>
|
||||
<Image Source="C:\Users\herta\OneDrive\Pictures\tpjhc5wp18b71.jpg" Margin="5"/>
|
||||
<Image Source="C:\Users\herta\OneDrive\Pictures\tpjhc5wp18b71.jpg" Margin="5"/>
|
||||
</UniformGrid>
|
||||
</ScrollViewer>
|
||||
</Canvas>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,29 @@
|
||||
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;
|
||||
using District_3_App.Statistics;
|
||||
|
||||
namespace Statistics
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for LikedPosts.xaml
|
||||
/// </summary>
|
||||
public partial class LikedPosts : UserControl
|
||||
{
|
||||
public LikedPosts()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Compile Update="LikedPosts.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="LikedPosts.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.9.34728.123
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Statistics", "Statistics.csproj", "{3609975B-8C03-463C-A5D1-613EDA6C83D5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{3609975B-8C03-463C-A5D1-613EDA6C83D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3609975B-8C03-463C-A5D1-613EDA6C83D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3609975B-8C03-463C-A5D1-613EDA6C83D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3609975B-8C03-463C-A5D1-613EDA6C83D5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {24484E9E-0865-4567-B8F9-A11BDF9EC6BE}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,90 @@
|
||||
<UserControl x:Class="District_3_App.Statistics.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:District_3_App.Statistics"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid Background="White">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="229.573"/>
|
||||
<ColumnDefinition Width="18.427"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Left side -->
|
||||
<StackPanel Grid.Column="0" VerticalAlignment="Top" Margin="20,42,0,0" Grid.ColumnSpan="2" HorizontalAlignment="Left">
|
||||
<TextBlock Text="Statistics" FontSize="24" FontWeight="Bold"/>
|
||||
<TextBlock Text="Time Spent on the app" FontSize="20" FontFamily="Segoe UI Semibold" Margin="0,10,0,20"/>
|
||||
<TextBlock FontSize="16" Margin="0,20,0,0">
|
||||
<Run FontWeight="Bold" Text="Streaks"/><Run Text=" - Top 5 interactions"/>
|
||||
</TextBlock>
|
||||
<!-- Stack panel containing usernames -->
|
||||
<StackPanel Margin="0,20,0,0">
|
||||
<StackPanel Height="34" Width="228" Orientation="Horizontal">
|
||||
<TextBlock Text="1. " VerticalAlignment="Center" FontSize="16" FontWeight="Bold" />
|
||||
<TextBlock x:Name="Bestie1" Text="" VerticalAlignment="Center" FontSize="16"/>
|
||||
<Image Source="\images\user.png" Width="24" Height="18" Margin="5" VerticalAlignment="Center"/>
|
||||
<TextBlock x:Name="Streak1" Text="" VerticalAlignment="Center" FontSize="16"/>
|
||||
</StackPanel>
|
||||
<StackPanel Height="34" Width="228" Orientation="Horizontal">
|
||||
<TextBlock Text="2. " VerticalAlignment="Center" FontSize="16" FontWeight="Bold" />
|
||||
<TextBlock x:Name="Bestie2" Text="" VerticalAlignment="Center" FontSize="16"/>
|
||||
<Image Source="\images\user.png" Width="24" Height="18" Margin="5" VerticalAlignment="Center"/>
|
||||
<TextBlock x:Name="Streak2" Text="" VerticalAlignment="Center" FontSize="16"/>
|
||||
</StackPanel>
|
||||
<StackPanel Height="34" Width="228" Orientation="Horizontal">
|
||||
<TextBlock Text="3. " VerticalAlignment="Center" FontSize="16" FontWeight="Bold"/>
|
||||
<TextBlock x:Name="Bestie3" Text="" VerticalAlignment="Center" FontSize="16"/>
|
||||
<Image Source="\images\user.png" Width="24" Height="18" Margin="5" VerticalAlignment="Center"/>
|
||||
<TextBlock x:Name="Streak3" Text="" VerticalAlignment="Center" FontSize="16"/>
|
||||
</StackPanel>
|
||||
<StackPanel Height="34" Width="228" Orientation="Horizontal">
|
||||
<TextBlock Text="4. " VerticalAlignment="Center" FontSize="16" FontWeight="Bold"/>
|
||||
<TextBlock x:Name="Bestie4" Text="" VerticalAlignment="Center" FontSize="16"/>
|
||||
<Image Source="\images\user.png" Width="24" Height="18" Margin="5" VerticalAlignment="Center"/>
|
||||
<TextBlock x:Name="Streak4" Text="" VerticalAlignment="Center" FontSize="16"/>
|
||||
</StackPanel>
|
||||
<StackPanel Height="34" Width="228" Orientation="Horizontal">
|
||||
<TextBlock Text="5. " VerticalAlignment="Center" FontSize="16" FontWeight="Bold"/>
|
||||
<TextBlock x:Name="Bestie5" Text="" VerticalAlignment="Center" FontSize="16"/>
|
||||
<Image Source="\images\user.png" Width="24" Height="18" Margin="5" VerticalAlignment="Center"/>
|
||||
<TextBlock x:Name="Streak5" Text="" VerticalAlignment="Center" FontSize="16"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
<!-- Right side -->
|
||||
<!-- Add your right side elements here -->
|
||||
<StackPanel Grid.Column="2" VerticalAlignment="Top" Margin="50,0,10,0">
|
||||
<!-- First circle with bold text and normal text -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,20,0,0" Width="200">
|
||||
<StackPanel Width="88">
|
||||
<TextBlock Text="Today" FontWeight="Bold" FontSize="23"/>
|
||||
<TextBlock x:Name="TodaysTime" Text="" FontSize="17"/>
|
||||
</StackPanel>
|
||||
<Ellipse Width="97" Height="100" Fill="Red"/>
|
||||
</StackPanel>
|
||||
<!-- Second circle with bold text and normal text -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
|
||||
<Ellipse Width="100" Height="100" Fill="Green" Margin="0,0,10,0"/>
|
||||
<StackPanel>
|
||||
<TextBlock Text="This Week" FontWeight="Bold" FontSize="23"/>
|
||||
<TextBlock x:Name="WeeksTime" Text="" FontSize="17"/>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
<!-- Third circle with bold text and normal text -->
|
||||
<StackPanel Orientation="Horizontal" Margin="0,20,0,0" Width="300">
|
||||
<StackPanel>
|
||||
<TextBlock Text="This Month" FontWeight="Bold" FontSize="23"/>
|
||||
<TextBlock x:Name="MonthsTime" Text="" FontSize="17"/>
|
||||
</StackPanel>
|
||||
<Ellipse Width="100" Height="100" Fill="Blue" Margin="0,0,20,0"/>
|
||||
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,48 @@
|
||||
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;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace District_3_App.Statistics
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for Statistics.xaml
|
||||
/// </summary>
|
||||
public partial class Statistics : UserControl
|
||||
{
|
||||
private StatisticsService srv = new StatisticsService("Stats.xml");
|
||||
|
||||
public Statistics()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
this.Bestie1.Text = srv.GetFriendNames()[0];
|
||||
this.Bestie2.Text = srv.GetFriendNames()[1];
|
||||
this.Bestie3.Text = srv.GetFriendNames()[2];
|
||||
this.Bestie4.Text = srv.GetFriendNames()[3];
|
||||
this.Bestie5.Text = srv.GetFriendNames()[4];
|
||||
|
||||
this.Streak1.Text = srv.GetUserStreaks()[0].ToString();
|
||||
this.Streak2.Text = srv.GetUserStreaks()[1].ToString();
|
||||
this.Streak3.Text = srv.GetUserStreaks()[2].ToString();
|
||||
this.Streak4.Text = srv.GetUserStreaks()[3].ToString();
|
||||
this.Streak5.Text = srv.GetUserStreaks()[4].ToString();
|
||||
|
||||
/*MessageBox.Show(srv.ConvertSecondsToHMS());*/
|
||||
this.TodaysTime.Text = srv.ConvertSecondsToHMS(srv.GetToday());
|
||||
this.WeeksTime.Text = srv.ConvertSecondsToHMS(srv.GetWeek());
|
||||
this.MonthsTime.Text = srv.ConvertSecondsToHMS(srv.GetMonth());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using District_3_App.ProfileSocialNetworkInfoStuff.Entities;
|
||||
using District_3_App.Repository;
|
||||
|
||||
namespace District_3_App.Statistics
|
||||
{
|
||||
public class StatisticsService
|
||||
{
|
||||
private int timeSpentOnAppToday = 0;
|
||||
private int timeSpentOnAppMonthly = 0;
|
||||
private int timeSpentOnAppWeekly = 0;
|
||||
|
||||
private Dictionary<User, int> friends = new Dictionary<User, int>();
|
||||
private Window mainWindow;
|
||||
private string filePath;
|
||||
|
||||
public StatisticsService(string filePath)
|
||||
{
|
||||
this.mainWindow = Application.Current.MainWindow;
|
||||
|
||||
this.filePath = GenerateDefaultFilePath();
|
||||
Console.WriteLine(filePath);
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
CreateXml(filePath);
|
||||
}
|
||||
Load(filePath);
|
||||
|
||||
var sortedSequence = friends.OrderByDescending(pair => pair.Value);
|
||||
Dictionary<User, int> sortedDictionary = sortedSequence.ToDictionary(pair => pair.Key, pair => pair.Value);
|
||||
|
||||
friends = sortedDictionary;
|
||||
|
||||
SaveStreaksToXML();
|
||||
ReadXML();
|
||||
}
|
||||
|
||||
private string GenerateDefaultFilePath()
|
||||
{
|
||||
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Stats.xml");
|
||||
}
|
||||
|
||||
public void CreateXml(string filePath)
|
||||
{
|
||||
XDocument xDocument = new XDocument(new XElement("Friends"));
|
||||
xDocument.Save(filePath);
|
||||
}
|
||||
private void Load(string filePath)
|
||||
{
|
||||
Console.WriteLine("Reading from file: " + filePath);
|
||||
|
||||
XDocument xDocument = XDocument.Load(filePath);
|
||||
XElement root = xDocument.Element("Friends");
|
||||
if (!root.HasElements)
|
||||
{
|
||||
throw new Exception("No friend elements found in the XML file.");
|
||||
}
|
||||
|
||||
foreach (var friendElem in root.Elements("Friend"))
|
||||
{
|
||||
string username = friendElem.Element("Username")?.Value;
|
||||
int streak = int.Parse(friendElem.Element("Streak")?.Value ?? "0");
|
||||
|
||||
if (!string.IsNullOrEmpty(username))
|
||||
{
|
||||
User user = new User(Guid.NewGuid(), username, string.Empty, string.Empty, DateTime.Now.ToString()); // Fill in appropriate values for other properties
|
||||
friends.Add(user, streak);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveStreaksToXML()
|
||||
{
|
||||
XDocument xDocument = XDocument.Load(filePath);
|
||||
XElement root = xDocument.Element("Friends");
|
||||
|
||||
root.Elements("Friend").Remove();
|
||||
|
||||
foreach (var kvp in friends)
|
||||
{
|
||||
XElement friendElem = new XElement("Friend",
|
||||
new XElement("Username", kvp.Key.Username),
|
||||
new XElement("Streak", kvp.Value));
|
||||
root.Add(friendElem);
|
||||
}
|
||||
|
||||
xDocument.Save(filePath);
|
||||
}
|
||||
|
||||
private static int GetIso8601WeekOfYear(DateTime time)
|
||||
{
|
||||
// Seriously cheat. If its Monday, Tuesday or Wednesday, then it'll
|
||||
// be the same week# as whatever Thursday, Friday or Saturday are,
|
||||
// and we always get those right
|
||||
DayOfWeek day = CultureInfo.InvariantCulture.Calendar.GetDayOfWeek(time);
|
||||
if (day >= DayOfWeek.Monday && day <= DayOfWeek.Wednesday)
|
||||
{
|
||||
time = time.AddDays(3);
|
||||
}
|
||||
|
||||
// Return the week of our adjusted day
|
||||
return CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(time, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
|
||||
}
|
||||
|
||||
private void ReadXML()
|
||||
{
|
||||
// Read from the XML file
|
||||
try
|
||||
{
|
||||
DateTime dateValue;
|
||||
|
||||
// Load the XML document from the file
|
||||
string filePath = "TimeData.xml";
|
||||
XmlDocument xmlDoc = new XmlDocument();
|
||||
xmlDoc.Load(filePath);
|
||||
|
||||
// Get the root element
|
||||
XmlElement root = xmlDoc.DocumentElement;
|
||||
|
||||
// Get all entry elements
|
||||
XmlNodeList entryNodes = root.SelectNodes("Entry");
|
||||
|
||||
// Iterate over each entry element
|
||||
foreach (XmlNode entryNode in entryNodes)
|
||||
{
|
||||
// Get the time and date elements for this entry
|
||||
XmlNode timeNode = entryNode.SelectSingleNode("Time");
|
||||
XmlNode dateNode = entryNode.SelectSingleNode("Date");
|
||||
|
||||
if (timeNode != null && dateNode != null)
|
||||
{
|
||||
// Parse the time value and add it to the timeSpentOnAppToday variable
|
||||
int timeValue;
|
||||
if (int.TryParse(timeNode.InnerText, out timeValue) && DateTime.TryParse(dateNode.InnerText, out dateValue))
|
||||
{
|
||||
int day = dateValue.Day;
|
||||
int week = GetIso8601WeekOfYear(dateValue);
|
||||
int month = dateValue.Month;
|
||||
|
||||
if (day == DateTime.Now.Day)
|
||||
{
|
||||
timeSpentOnAppToday += timeValue;
|
||||
timeSpentOnAppWeekly += timeValue;
|
||||
timeSpentOnAppMonthly += timeValue;
|
||||
}
|
||||
else if (week == GetIso8601WeekOfYear(DateTime.Now))
|
||||
{
|
||||
timeSpentOnAppWeekly += timeValue;
|
||||
timeSpentOnAppMonthly += timeValue;
|
||||
}
|
||||
else if (month == DateTime.Now.Month)
|
||||
{
|
||||
timeSpentOnAppMonthly += timeValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the date value
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Handle any exceptions
|
||||
MessageBox.Show($"Error reading time data from XML file: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public List<string> GetFriendNames()
|
||||
{
|
||||
List<string> friendNames = new List<string>();
|
||||
int contor = 5;
|
||||
foreach (User user in friends.Keys)
|
||||
{
|
||||
contor--;
|
||||
friendNames.Add(user.Username);
|
||||
if (contor == 0)
|
||||
{
|
||||
return friendNames;
|
||||
}
|
||||
}
|
||||
|
||||
return friendNames;
|
||||
}
|
||||
public List<int> GetUserStreaks()
|
||||
{
|
||||
List<int> friendStreaks = new List<int>();
|
||||
int contor = 5;
|
||||
foreach (User user in friends.Keys)
|
||||
{
|
||||
contor--;
|
||||
friendStreaks.Add(friends[user]);
|
||||
if (contor == 0)
|
||||
{
|
||||
return friendStreaks;
|
||||
}
|
||||
}
|
||||
|
||||
return friendStreaks;
|
||||
}
|
||||
|
||||
public int GetToday()
|
||||
{
|
||||
return timeSpentOnAppToday;
|
||||
}
|
||||
|
||||
public int GetWeek()
|
||||
{
|
||||
return timeSpentOnAppWeekly;
|
||||
}
|
||||
public int GetMonth()
|
||||
{
|
||||
return timeSpentOnAppMonthly;
|
||||
}
|
||||
|
||||
public string ConvertSecondsToHMS(int timeSpentOnApp)
|
||||
{
|
||||
// Calculate hours
|
||||
int hours = timeSpentOnApp / 3600;
|
||||
|
||||
// Calculate remaining seconds after removing hours
|
||||
int remainingSeconds = timeSpentOnApp % 3600;
|
||||
|
||||
// Calculate minutes
|
||||
int minutes = remainingSeconds / 60;
|
||||
|
||||
// Calculate remaining seconds after removing minutes
|
||||
int seconds = remainingSeconds % 60;
|
||||
|
||||
// Format the result as hours:minutes:seconds
|
||||
return $"{hours:D2}h{minutes:D2}min";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Images>
|
||||
<ImageInfo Source="C:\Users\herta\Desktop\Sem4\ISS\App\District 3 App\Statistics\pics\hd-wallpaper-g598bd113c_1920.jp" Margin="5" Stretch="Uniform"/>
|
||||
<ImageInfo Source="C:\Users\herta\Desktop\Sem4\ISS\App\District 3 App\Statistics\pics\tpjhc5wp18b71.jpg" Margin="10" Stretch="Fill"/>
|
||||
</Images>
|
||||
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 336 KiB |
|
After Width: | Height: | Size: 92 KiB |