mirror of
https://github.com/ShareX/ShareX.git
synced 2025-12-27 23:44:52 +00:00
Added "Show stats" button to Image history form
This commit is contained in:
parent
c71a3380e5
commit
4b5ab1918b
@ -42,7 +42,7 @@ namespace ShareX.HistoryLib
|
||||
public bool Favorites { get; private set; }
|
||||
|
||||
private HistoryItemManager him;
|
||||
private HistoryItem[] allHistoryItems;
|
||||
private List<HistoryItem> allHistoryItems;
|
||||
private HistoryItem[] filteredHistoryItems;
|
||||
private string defaultTitle;
|
||||
private Dictionary<string, string> typeNamesLocaleLookup;
|
||||
@ -138,7 +138,7 @@ namespace ShareX.HistoryLib
|
||||
cbHostFilterSelection.Items.Clear();
|
||||
tstbSearch.AutoCompleteCustomSource.Clear();
|
||||
|
||||
if (allHistoryItems.Length > 0)
|
||||
if (allHistoryItems.Count > 0)
|
||||
{
|
||||
allTypeNames = allHistoryItems.Select(x => x.Type).Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().ToArray();
|
||||
cbTypeFilterSelection.Items.AddRange(allTypeNames.Select(x => typeNamesLocaleLookup.TryGetValue(x, out string value) ? value : x).ToArray());
|
||||
@ -193,7 +193,7 @@ namespace ShareX.HistoryLib
|
||||
await RefreshHistoryItems();
|
||||
}
|
||||
|
||||
private async Task<HistoryItem[]> GetHistoryItems(bool mockData = false)
|
||||
private async Task<List<HistoryItem>> GetHistoryItems(bool mockData = false)
|
||||
{
|
||||
HistoryManager history;
|
||||
|
||||
@ -210,12 +210,12 @@ namespace ShareX.HistoryLib
|
||||
|
||||
List<HistoryItem> historyItems = await history.GetHistoryItemsAsync();
|
||||
historyItems.Reverse();
|
||||
return historyItems.ToArray();
|
||||
return historyItems;
|
||||
}
|
||||
|
||||
private void ApplyFilter(HistoryFilter filter)
|
||||
{
|
||||
if (allHistoryItems != null && allHistoryItems.Length > 0)
|
||||
if (allHistoryItems != null && allHistoryItems.Count > 0)
|
||||
{
|
||||
IEnumerable<HistoryItem> historyItems = filter.ApplyFilter(allHistoryItems);
|
||||
filteredHistoryItems = historyItems.ToArray();
|
||||
@ -345,9 +345,9 @@ namespace ShareX.HistoryLib
|
||||
StringBuilder status = new StringBuilder();
|
||||
|
||||
status.Append(" (");
|
||||
status.AppendFormat(Resources.HistoryForm_UpdateItemCount_Total___0_, allHistoryItems.Length.ToString("N0"));
|
||||
status.AppendFormat(Resources.HistoryForm_UpdateItemCount_Total___0_, allHistoryItems.Count.ToString("N0"));
|
||||
|
||||
if (allHistoryItems.Length > historyItems.Length)
|
||||
if (allHistoryItems.Count > historyItems.Length)
|
||||
{
|
||||
status.AppendFormat(" - " + Resources.HistoryForm_UpdateItemCount___Filtered___0_, historyItems.Length.ToString("N0"));
|
||||
}
|
||||
@ -401,67 +401,6 @@ namespace ShareX.HistoryLib
|
||||
}
|
||||
}
|
||||
|
||||
private string OutputStats(HistoryItem[] historyItems)
|
||||
{
|
||||
string empty = "(empty)";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine(Resources.HistoryItemCounts);
|
||||
sb.AppendLine(Resources.HistoryStats_Total + " " + historyItems.Length);
|
||||
|
||||
IEnumerable<string> types = historyItems.
|
||||
GroupBy(x => x.Type).
|
||||
OrderByDescending(x => x.Count()).
|
||||
Select(x => string.Format("{0}: {1} ({2:N0}%)", x.Key, x.Count(), x.Count() / (float)historyItems.Length * 100));
|
||||
|
||||
sb.AppendLine(string.Join(Environment.NewLine, types));
|
||||
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(Resources.HistoryStats_YearlyUsages);
|
||||
|
||||
IEnumerable<string> yearlyUsages = historyItems.
|
||||
GroupBy(x => x.DateTime.Year).
|
||||
OrderByDescending(x => x.Key).
|
||||
Select(x => string.Format("{0}: {1} ({2:N0}%)", x.Key, x.Count(), x.Count() / (float)historyItems.Length * 100));
|
||||
|
||||
sb.AppendLine(string.Join(Environment.NewLine, yearlyUsages));
|
||||
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(Resources.HistoryStats_FileExtensions);
|
||||
|
||||
IEnumerable<string> fileExtensions = historyItems.
|
||||
Where(x => !string.IsNullOrEmpty(x.FileName) && !x.FileName.EndsWith(")")).
|
||||
Select(x => FileHelpers.GetFileNameExtension(x.FileName)).
|
||||
GroupBy(x => string.IsNullOrWhiteSpace(x) ? empty : x).
|
||||
OrderByDescending(x => x.Count()).
|
||||
Select(x => string.Format("[{0}] {1}", x.Count(), x.Key));
|
||||
|
||||
sb.AppendLine(string.Join(Environment.NewLine, fileExtensions));
|
||||
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(Resources.HistoryStats_Hosts);
|
||||
|
||||
IEnumerable<string> hosts = historyItems.
|
||||
GroupBy(x => string.IsNullOrWhiteSpace(x.Host) ? empty : x.Host).
|
||||
OrderByDescending(x => x.Count()).
|
||||
Select(x => string.Format("[{0}] {1}", x.Count(), x.Key));
|
||||
|
||||
sb.AppendLine(string.Join(Environment.NewLine, hosts));
|
||||
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(Resources.ProcessNames);
|
||||
|
||||
IEnumerable<string> processNames = historyItems.
|
||||
GroupBy(x => string.IsNullOrWhiteSpace(x.TagsProcessName) ? empty : x.TagsProcessName).
|
||||
OrderByDescending(x => x.Count()).
|
||||
Select(x => string.Format("[{0}] {1}", x.Count(), x.Key));
|
||||
|
||||
sb.Append(string.Join(Environment.NewLine, processNames));
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
#region Form events
|
||||
|
||||
private async void HistoryForm_Shown(object sender, EventArgs e)
|
||||
@ -526,7 +465,7 @@ namespace ShareX.HistoryLib
|
||||
|
||||
private void tsbShowStats_Click(object sender, EventArgs e)
|
||||
{
|
||||
string stats = OutputStats(allHistoryItems);
|
||||
string stats = HistoryHelpers.OutputStats(allHistoryItems);
|
||||
OutputBox.Show(stats, Resources.HistoryStats);
|
||||
}
|
||||
|
||||
|
||||
85
ShareX.HistoryLib/Forms/ImageHistoryForm.Designer.cs
generated
85
ShareX.HistoryLib/Forms/ImageHistoryForm.Designer.cs
generated
@ -28,10 +28,10 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader imageListViewColumnHeader5 = new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader(Manina.Windows.Forms.ColumnType.Name, "Name", 100, 0, true);
|
||||
Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader imageListViewColumnHeader6 = new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader(Manina.Windows.Forms.ColumnType.FileSize, "Size", 100, 1, true);
|
||||
Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader imageListViewColumnHeader7 = new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader(Manina.Windows.Forms.ColumnType.Dimensions, "Dimensions", 100, 2, true);
|
||||
Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader imageListViewColumnHeader8 = new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader(Manina.Windows.Forms.ColumnType.FilePath, "Path", 100, 3, true);
|
||||
Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader imageListViewColumnHeader13 = new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader(Manina.Windows.Forms.ColumnType.Name, "Name", 100, 0, true);
|
||||
Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader imageListViewColumnHeader14 = new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader(Manina.Windows.Forms.ColumnType.FileSize, "Size", 100, 1, true);
|
||||
Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader imageListViewColumnHeader15 = new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader(Manina.Windows.Forms.ColumnType.Dimensions, "Dimensions", 100, 2, true);
|
||||
Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader imageListViewColumnHeader16 = new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader(Manina.Windows.Forms.ColumnType.FilePath, "Path", 100, 3, true);
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ImageHistoryForm));
|
||||
tscMain = new System.Windows.Forms.ToolStripContainer();
|
||||
ilvImages = new Manina.Windows.Forms.ImageListView();
|
||||
@ -39,9 +39,11 @@
|
||||
tslSearch = new System.Windows.Forms.ToolStripLabel();
|
||||
tstbSearch = new System.Windows.Forms.ToolStripTextBox();
|
||||
tsbSearch = new System.Windows.Forms.ToolStripButton();
|
||||
tsbFavorites = new System.Windows.Forms.ToolStripButton();
|
||||
tss1 = new System.Windows.Forms.ToolStripSeparator();
|
||||
tsbSettings = new System.Windows.Forms.ToolStripButton();
|
||||
tsbFavorites = new System.Windows.Forms.ToolStripButton();
|
||||
tss2 = new System.Windows.Forms.ToolStripSeparator();
|
||||
tsbShowStats = new System.Windows.Forms.ToolStripButton();
|
||||
tscMain.ContentPanel.SuspendLayout();
|
||||
tscMain.TopToolStripPanel.SuspendLayout();
|
||||
tscMain.SuspendLayout();
|
||||
@ -69,27 +71,27 @@
|
||||
ilvImages.AllowItemReorder = false;
|
||||
ilvImages.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
ilvImages.CacheLimit = "100MB";
|
||||
imageListViewColumnHeader5.Comparer = null;
|
||||
imageListViewColumnHeader5.DisplayIndex = 0;
|
||||
imageListViewColumnHeader5.Grouper = null;
|
||||
imageListViewColumnHeader5.Key = "";
|
||||
imageListViewColumnHeader5.Type = Manina.Windows.Forms.ColumnType.Name;
|
||||
imageListViewColumnHeader6.Comparer = null;
|
||||
imageListViewColumnHeader6.DisplayIndex = 1;
|
||||
imageListViewColumnHeader6.Grouper = null;
|
||||
imageListViewColumnHeader6.Key = "";
|
||||
imageListViewColumnHeader6.Type = Manina.Windows.Forms.ColumnType.FileSize;
|
||||
imageListViewColumnHeader7.Comparer = null;
|
||||
imageListViewColumnHeader7.DisplayIndex = 2;
|
||||
imageListViewColumnHeader7.Grouper = null;
|
||||
imageListViewColumnHeader7.Key = "";
|
||||
imageListViewColumnHeader7.Type = Manina.Windows.Forms.ColumnType.Dimensions;
|
||||
imageListViewColumnHeader8.Comparer = null;
|
||||
imageListViewColumnHeader8.DisplayIndex = 3;
|
||||
imageListViewColumnHeader8.Grouper = null;
|
||||
imageListViewColumnHeader8.Key = "";
|
||||
imageListViewColumnHeader8.Type = Manina.Windows.Forms.ColumnType.FilePath;
|
||||
ilvImages.Columns.AddRange(new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader[] { imageListViewColumnHeader5, imageListViewColumnHeader6, imageListViewColumnHeader7, imageListViewColumnHeader8 });
|
||||
imageListViewColumnHeader13.Comparer = null;
|
||||
imageListViewColumnHeader13.DisplayIndex = 0;
|
||||
imageListViewColumnHeader13.Grouper = null;
|
||||
imageListViewColumnHeader13.Key = "";
|
||||
imageListViewColumnHeader13.Type = Manina.Windows.Forms.ColumnType.Name;
|
||||
imageListViewColumnHeader14.Comparer = null;
|
||||
imageListViewColumnHeader14.DisplayIndex = 1;
|
||||
imageListViewColumnHeader14.Grouper = null;
|
||||
imageListViewColumnHeader14.Key = "";
|
||||
imageListViewColumnHeader14.Type = Manina.Windows.Forms.ColumnType.FileSize;
|
||||
imageListViewColumnHeader15.Comparer = null;
|
||||
imageListViewColumnHeader15.DisplayIndex = 2;
|
||||
imageListViewColumnHeader15.Grouper = null;
|
||||
imageListViewColumnHeader15.Key = "";
|
||||
imageListViewColumnHeader15.Type = Manina.Windows.Forms.ColumnType.Dimensions;
|
||||
imageListViewColumnHeader16.Comparer = null;
|
||||
imageListViewColumnHeader16.DisplayIndex = 3;
|
||||
imageListViewColumnHeader16.Grouper = null;
|
||||
imageListViewColumnHeader16.Key = "";
|
||||
imageListViewColumnHeader16.Type = Manina.Windows.Forms.ColumnType.FilePath;
|
||||
ilvImages.Columns.AddRange(new Manina.Windows.Forms.ImageListView.ImageListViewColumnHeader[] { imageListViewColumnHeader13, imageListViewColumnHeader14, imageListViewColumnHeader15, imageListViewColumnHeader16 });
|
||||
resources.ApplyResources(ilvImages, "ilvImages");
|
||||
ilvImages.Name = "ilvImages";
|
||||
ilvImages.ThumbnailSize = new System.Drawing.Size(100, 100);
|
||||
@ -102,7 +104,7 @@
|
||||
//
|
||||
resources.ApplyResources(tsMain, "tsMain");
|
||||
tsMain.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden;
|
||||
tsMain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { tslSearch, tstbSearch, tsbSearch, tsbFavorites, tss1, tsbSettings });
|
||||
tsMain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { tslSearch, tstbSearch, tsbSearch, tss1, tsbFavorites, tsbShowStats, tss2, tsbSettings });
|
||||
tsMain.Name = "tsMain";
|
||||
//
|
||||
// tslSearch
|
||||
@ -127,6 +129,15 @@
|
||||
tsbSearch.Name = "tsbSearch";
|
||||
tsbSearch.Click += tsbSearch_Click;
|
||||
//
|
||||
// tsbFavorites
|
||||
//
|
||||
tsbFavorites.CheckOnClick = true;
|
||||
tsbFavorites.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
tsbFavorites.Image = Properties.Resources.star;
|
||||
resources.ApplyResources(tsbFavorites, "tsbFavorites");
|
||||
tsbFavorites.Name = "tsbFavorites";
|
||||
tsbFavorites.Click += tsbFavorites_Click;
|
||||
//
|
||||
// tss1
|
||||
//
|
||||
tss1.Name = "tss1";
|
||||
@ -140,14 +151,18 @@
|
||||
tsbSettings.Name = "tsbSettings";
|
||||
tsbSettings.Click += tsbSettings_Click;
|
||||
//
|
||||
// tsbFavorites
|
||||
// tss2
|
||||
//
|
||||
tsbFavorites.CheckOnClick = true;
|
||||
tsbFavorites.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
tsbFavorites.Image = Properties.Resources.star;
|
||||
resources.ApplyResources(tsbFavorites, "tsbFavorites");
|
||||
tsbFavorites.Name = "tsbFavorites";
|
||||
tsbFavorites.Click += tsbFavorites_Click;
|
||||
tss2.Name = "tss2";
|
||||
resources.ApplyResources(tss2, "tss2");
|
||||
//
|
||||
// tsbShowStats
|
||||
//
|
||||
tsbShowStats.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
|
||||
tsbShowStats.Image = Properties.Resources.chart;
|
||||
resources.ApplyResources(tsbShowStats, "tsbShowStats");
|
||||
tsbShowStats.Name = "tsbShowStats";
|
||||
tsbShowStats.Click += tsbShowStats_Click;
|
||||
//
|
||||
// ImageHistoryForm
|
||||
//
|
||||
@ -181,5 +196,7 @@
|
||||
private System.Windows.Forms.ToolStripSeparator tss1;
|
||||
private System.Windows.Forms.ToolStripButton tsbSettings;
|
||||
private System.Windows.Forms.ToolStripButton tsbFavorites;
|
||||
private System.Windows.Forms.ToolStripSeparator tss2;
|
||||
private System.Windows.Forms.ToolStripButton tsbShowStats;
|
||||
}
|
||||
}
|
||||
@ -314,6 +314,12 @@ namespace ShareX.HistoryLib
|
||||
await RefreshHistoryItems(false);
|
||||
}
|
||||
|
||||
private void tsbShowStats_Click(object sender, EventArgs e)
|
||||
{
|
||||
string stats = HistoryHelpers.OutputStats(allHistoryItems);
|
||||
OutputBox.Show(stats, Resources.HistoryStats);
|
||||
}
|
||||
|
||||
private void tsbSettings_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (ImageHistorySettingsForm form = new ImageHistorySettingsForm(Settings))
|
||||
|
||||
@ -234,6 +234,9 @@
|
||||
<data name="tsbSearch.ToolTipText" xml:space="preserve">
|
||||
<value>Search</value>
|
||||
</data>
|
||||
<data name="tss1.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>6, 25</value>
|
||||
</data>
|
||||
<data name="tsbFavorites.ImageTransparentColor" type="System.Drawing.Color, System.Drawing">
|
||||
<value>Magenta</value>
|
||||
</data>
|
||||
@ -243,7 +246,16 @@
|
||||
<data name="tsbFavorites.Text" xml:space="preserve">
|
||||
<value>Favorites</value>
|
||||
</data>
|
||||
<data name="tss1.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<data name="tsbShowStats.ImageTransparentColor" type="System.Drawing.Color, System.Drawing">
|
||||
<value>Magenta</value>
|
||||
</data>
|
||||
<data name="tsbShowStats.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>23, 22</value>
|
||||
</data>
|
||||
<data name="tsbShowStats.Text" xml:space="preserve">
|
||||
<value>Show stats...</value>
|
||||
</data>
|
||||
<data name="tss2.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>6, 25</value>
|
||||
</data>
|
||||
<data name="tsbSettings.ImageTransparentColor" type="System.Drawing.Color, System.Drawing">
|
||||
@ -259,7 +271,7 @@
|
||||
<value>3, 0</value>
|
||||
</data>
|
||||
<data name="tsMain.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>456, 25</value>
|
||||
<value>485, 25</value>
|
||||
</data>
|
||||
<data name="tsMain.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>0</value>
|
||||
@ -333,6 +345,12 @@
|
||||
<data name=">>tsbSearch.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.ToolStripButton, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>tsbFavorites.Name" xml:space="preserve">
|
||||
<value>tsbFavorites</value>
|
||||
</data>
|
||||
<data name=">>tsbFavorites.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.ToolStripButton, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>tss1.Name" xml:space="preserve">
|
||||
<value>tss1</value>
|
||||
</data>
|
||||
@ -345,10 +363,16 @@
|
||||
<data name=">>tsbSettings.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.ToolStripButton, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>tsbFavorites.Name" xml:space="preserve">
|
||||
<value>tsbFavorites</value>
|
||||
<data name=">>tss2.Name" xml:space="preserve">
|
||||
<value>tss2</value>
|
||||
</data>
|
||||
<data name=">>tsbFavorites.Type" xml:space="preserve">
|
||||
<data name=">>tss2.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.ToolStripSeparator, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>tsbShowStats.Name" xml:space="preserve">
|
||||
<value>tsbShowStats</value>
|
||||
</data>
|
||||
<data name=">>tsbShowStats.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.ToolStripButton, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>$this.Name" xml:space="preserve">
|
||||
|
||||
98
ShareX.HistoryLib/HistoryHelpers.cs
Normal file
98
ShareX.HistoryLib/HistoryHelpers.cs
Normal file
@ -0,0 +1,98 @@
|
||||
#region License Information (GPL v3)
|
||||
|
||||
/*
|
||||
ShareX - A program that allows you to take screenshots and share any file type
|
||||
Copyright (c) 2007-2025 ShareX Team
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#endregion License Information (GPL v3)
|
||||
|
||||
using ShareX.HelpersLib;
|
||||
using ShareX.HistoryLib.Properties;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace ShareX.HistoryLib
|
||||
{
|
||||
public static class HistoryHelpers
|
||||
{
|
||||
public static string OutputStats(List<HistoryItem> historyItems)
|
||||
{
|
||||
string empty = "(empty)";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine(Resources.HistoryItemCounts);
|
||||
sb.AppendLine(Resources.HistoryStats_Total + " " + historyItems.Count);
|
||||
|
||||
IEnumerable<string> types = historyItems.
|
||||
GroupBy(x => x.Type).
|
||||
OrderByDescending(x => x.Count()).
|
||||
Select(x => string.Format("{0}: {1} ({2:N0}%)", x.Key, x.Count(), x.Count() / (float)historyItems.Count * 100));
|
||||
|
||||
sb.AppendLine(string.Join(Environment.NewLine, types));
|
||||
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(Resources.HistoryStats_YearlyUsages);
|
||||
|
||||
IEnumerable<string> yearlyUsages = historyItems.
|
||||
GroupBy(x => x.DateTime.Year).
|
||||
OrderByDescending(x => x.Key).
|
||||
Select(x => string.Format("{0}: {1} ({2:N0}%)", x.Key, x.Count(), x.Count() / (float)historyItems.Count * 100));
|
||||
|
||||
sb.AppendLine(string.Join(Environment.NewLine, yearlyUsages));
|
||||
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(Resources.HistoryStats_FileExtensions);
|
||||
|
||||
IEnumerable<string> fileExtensions = historyItems.
|
||||
Where(x => !string.IsNullOrEmpty(x.FileName) && !x.FileName.EndsWith(")")).
|
||||
Select(x => FileHelpers.GetFileNameExtension(x.FileName)).
|
||||
GroupBy(x => string.IsNullOrWhiteSpace(x) ? empty : x).
|
||||
OrderByDescending(x => x.Count()).
|
||||
Select(x => string.Format("[{0}] {1}", x.Count(), x.Key));
|
||||
|
||||
sb.AppendLine(string.Join(Environment.NewLine, fileExtensions));
|
||||
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(Resources.HistoryStats_Hosts);
|
||||
|
||||
IEnumerable<string> hosts = historyItems.
|
||||
GroupBy(x => string.IsNullOrWhiteSpace(x.Host) ? empty : x.Host).
|
||||
OrderByDescending(x => x.Count()).
|
||||
Select(x => string.Format("[{0}] {1}", x.Count(), x.Key));
|
||||
|
||||
sb.AppendLine(string.Join(Environment.NewLine, hosts));
|
||||
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(Resources.ProcessNames);
|
||||
|
||||
IEnumerable<string> processNames = historyItems.
|
||||
GroupBy(x => string.IsNullOrWhiteSpace(x.TagsProcessName) ? empty : x.TagsProcessName).
|
||||
OrderByDescending(x => x.Count()).
|
||||
Select(x => string.Format("[{0}] {1}", x.Count(), x.Key));
|
||||
|
||||
sb.Append(string.Join(Environment.NewLine, processNames));
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user