From 62a1016e1be1962ef3a42a7a7e2da46126f79294 Mon Sep 17 00:00:00 2001 From: Jaex Date: Mon, 17 Jun 2019 09:02:16 +0300 Subject: [PATCH] Stats related improvements --- .../Forms/HistoryForm.Designer.cs | 12 +++++- ShareX.HistoryLib/Forms/HistoryForm.cs | 25 ++++++------ ShareX.HistoryLib/Forms/HistoryForm.resx | 39 ++++++++++++++++--- 3 files changed, 55 insertions(+), 21 deletions(-) diff --git a/ShareX.HistoryLib/Forms/HistoryForm.Designer.cs b/ShareX.HistoryLib/Forms/HistoryForm.Designer.cs index 45a64296f..08adb1cea 100644 --- a/ShareX.HistoryLib/Forms/HistoryForm.Designer.cs +++ b/ShareX.HistoryLib/Forms/HistoryForm.Designer.cs @@ -56,12 +56,14 @@ private void InitializeComponent() this.cbDateFilter = new System.Windows.Forms.CheckBox(); this.dtpFilterTo = new System.Windows.Forms.DateTimePicker(); this.txtFilenameFilter = new System.Windows.Forms.TextBox(); + this.pStats = new System.Windows.Forms.Panel(); ((System.ComponentModel.ISupportInitialize)(this.scMain)).BeginInit(); this.scMain.Panel1.SuspendLayout(); this.scMain.Panel2.SuspendLayout(); this.scMain.SuspendLayout(); this.panel1.SuspendLayout(); this.gbFilters.SuspendLayout(); + this.pStats.SuspendLayout(); this.SuspendLayout(); // // scMain @@ -72,7 +74,7 @@ private void InitializeComponent() // // scMain.Panel1 // - this.scMain.Panel1.Controls.Add(this.rtbStats); + this.scMain.Panel1.Controls.Add(this.pStats); this.scMain.Panel1.Controls.Add(this.lvHistory); // // scMain.Panel2 @@ -258,6 +260,12 @@ private void InitializeComponent() resources.ApplyResources(this.txtFilenameFilter, "txtFilenameFilter"); this.txtFilenameFilter.Name = "txtFilenameFilter"; // + // pStats + // + this.pStats.Controls.Add(this.rtbStats); + resources.ApplyResources(this.pStats, "pStats"); + this.pStats.Name = "pStats"; + // // HistoryForm // resources.ApplyResources(this, "$this"); @@ -276,6 +284,7 @@ private void InitializeComponent() this.panel1.ResumeLayout(false); this.gbFilters.ResumeLayout(false); this.gbFilters.PerformLayout(); + this.pStats.ResumeLayout(false); this.ResumeLayout(false); } @@ -308,5 +317,6 @@ private void InitializeComponent() private System.Windows.Forms.TextBox txtURLFilter; private System.Windows.Forms.Button btnShowStats; private System.Windows.Forms.RichTextBox rtbStats; + private System.Windows.Forms.Panel pStats; } } \ No newline at end of file diff --git a/ShareX.HistoryLib/Forms/HistoryForm.cs b/ShareX.HistoryLib/Forms/HistoryForm.cs index 20a36c043..ce5175959 100644 --- a/ShareX.HistoryLib/Forms/HistoryForm.cs +++ b/ShareX.HistoryLib/Forms/HistoryForm.cs @@ -54,7 +54,7 @@ public HistoryForm(string historyPath, HistorySettings settings, Action InitializeComponent(); Icon = ShareXResources.Icon; defaultTitle = Text; - //UpdateTitle(); + UpdateTitle(); // Mark the Date column as having a date; used for sorting chDateTime.Tag = new DateTime(); @@ -97,10 +97,9 @@ private void OutputStats(HistoryItem[] historyItems) rtbStats.AppendLine("Total: " + historyItems.Length); IEnumerable types = historyItems. - Select(x => x.Type). - GroupBy(x => x). + GroupBy(x => x.Type). OrderByDescending(x => x.Count()). - Select(x => string.Format("{0}: {1}", x.Key, x.Count())); + Select(x => string.Format("{0}: {1} ({2:N0}%)", x.Key, x.Count(), x.Count() / (float)historyItems.Length * 100)); rtbStats.AppendLine(string.Join(Environment.NewLine, types)); @@ -136,8 +135,7 @@ private void OutputStats(HistoryItem[] historyItems) rtbStats.SetFontRegular(); IEnumerable hosts = historyItems. - Select(x => x.Host). - GroupBy(x => x). + GroupBy(x => x.Host). OrderByDescending(x => x.Count()). Select(x => string.Format("{0} ({1})", x.Key, x.Count())); @@ -235,7 +233,7 @@ private void AddHistoryItems(HistoryItem[] historyItems) { Cursor = Cursors.WaitCursor; - //UpdateTitle(historyItems); + UpdateTitle(historyItems); lvHistory.Items.Clear(); @@ -292,11 +290,10 @@ private void UpdateTitle(HistoryItem[] historyItems = null) status.AppendFormat(" - " + Resources.HistoryForm_UpdateItemCount___Filtered___0_, historyItems.Length.ToString("N0")); } - IEnumerable types = from hi in historyItems - group hi by hi.Type - into t - let count = t.Count() - select string.Format(" - {0}: {1:N0}", t.Key, count); + IEnumerable types = historyItems. + GroupBy(x => x.Type). + OrderByDescending(x => x.Count()). + Select(x => string.Format(" - {0}: {1}", x.Key, x.Count())); foreach (string type in types) { @@ -403,14 +400,14 @@ private void BtnShowStats_Click(object sender, EventArgs e) if (showingStats) { lvHistory.Visible = true; - rtbStats.Visible = false; + pStats.Visible = false; // TODO: Translate btnShowStats.Text = "Show stats"; showingStats = false; } else { - rtbStats.Visible = true; + pStats.Visible = true; lvHistory.Visible = false; // TODO: Translate btnShowStats.Text = "Hide stats"; diff --git a/ShareX.HistoryLib/Forms/HistoryForm.resx b/ShareX.HistoryLib/Forms/HistoryForm.resx index 7d6ef63ba..ee00812d9 100644 --- a/ShareX.HistoryLib/Forms/HistoryForm.resx +++ b/ShareX.HistoryLib/Forms/HistoryForm.resx @@ -132,10 +132,10 @@ Arial, 9.75pt - 0, 0 + 3, 3 - 550, 641 + 544, 635 @@ -144,9 +144,6 @@ - - False - rtbStats @@ -154,11 +151,41 @@ System.Windows.Forms.RichTextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - scMain.Panel1 + pStats 0 + + Fill + + + 0, 0 + + + 3, 3, 3, 3 + + + 550, 641 + + + 2 + + + False + + + pStats + + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + scMain.Panel1 + + + 0 +