From 5211a9412100f3ea892346ba4f3a589aa94df697 Mon Sep 17 00:00:00 2001 From: Danil Kislov Date: Tue, 25 Jun 2019 21:47:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D1=80=D0=B0=D0=BD=D0=B4=D0=BE=D0=BC=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D0=BC=D0=B8=D0=BD=D1=83=D1=82=20+=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BE?= =?UTF-8?q?=D0=BF=D0=B5=D1=87=D0=B0=D1=82=D0=BA=D0=B0=20=D0=B2=20=D0=BE?= =?UTF-8?q?=D0=BA=D1=80=D1=83=D0=B3=D0=BB=D0=B5=D0=BD=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .semver.txt | 2 +- src/JiraTimeBot/Configuration/Settings.cs | 5 +- src/JiraTimeBot/Properties/AssemblyInfo.cs | 62 +++++++++---------- .../TaskTime/TaskTimeByCommitsCalculator.cs | 20 ++++-- src/JiraTimeBot/UI/frmSettings.Designer.cs | 32 ++++++++-- src/JiraTimeBot/UI/frmSettings.cs | 12 +++- 6 files changed, 86 insertions(+), 47 deletions(-) diff --git a/.semver.txt b/.semver.txt index f133985..3e9c4a6 100644 --- a/.semver.txt +++ b/.semver.txt @@ -1 +1 @@ -1.0.49 +1.0.50 diff --git a/src/JiraTimeBot/Configuration/Settings.cs b/src/JiraTimeBot/Configuration/Settings.cs index 7577240..84a3f37 100644 --- a/src/JiraTimeBot/Configuration/Settings.cs +++ b/src/JiraTimeBot/Configuration/Settings.cs @@ -10,7 +10,7 @@ namespace JiraTimeBot.Configuration public class Settings { public int MinuterPerWorkDay { get; set; } - public int RountToMinutes { get; set; } + public int RoundToMinutes { get; set; } public string JiraUrl = "https://myteam.aeroclub.ru"; @@ -23,6 +23,7 @@ namespace JiraTimeBot.Configuration public WorkType WorkType { get; set; } public string JiraQuery { get; set; } public string TimeControlTask { get; set; } + public int RandomWorkMinutes { get; set; } public static Settings LoadAndCheck(Action settingsSource, Action errorMessageReporter) { @@ -60,7 +61,7 @@ namespace JiraTimeBot.Configuration var errors = new List(); message = null; - if (settings.RountToMinutes == default(int)) + if (settings.RoundToMinutes == default(int)) { errors.Add("Укажите округление времени, например, 10 (минут)"); } diff --git a/src/JiraTimeBot/Properties/AssemblyInfo.cs b/src/JiraTimeBot/Properties/AssemblyInfo.cs index 338e76e..e328dc5 100644 --- a/src/JiraTimeBot/Properties/AssemblyInfo.cs +++ b/src/JiraTimeBot/Properties/AssemblyInfo.cs @@ -1,31 +1,31 @@ -using System.Reflection; -using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("JiraTimeBot")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("JiraTimeBot")] -[assembly: AssemblyCopyright("Copyright © 2019")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("f3b89316-c38c-4ce6-9d88-0b1373cfba1a")] -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// 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.49")] -[assembly: AssemblyFileVersion("1.0.49")] -[assembly: AssemblyInformationalVersion("1.0.49")] +using System.Reflection; +using System.Runtime.InteropServices; +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("JiraTimeBot")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("JiraTimeBot")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f3b89316-c38c-4ce6-9d88-0b1373cfba1a")] +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// 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.50")] +[assembly: AssemblyFileVersion("1.0.50")] +[assembly: AssemblyInformationalVersion("1.0.50")] diff --git a/src/JiraTimeBot/TaskTime/TaskTimeByCommitsCalculator.cs b/src/JiraTimeBot/TaskTime/TaskTimeByCommitsCalculator.cs index 7c50954..ed697a7 100644 --- a/src/JiraTimeBot/TaskTime/TaskTimeByCommitsCalculator.cs +++ b/src/JiraTimeBot/TaskTime/TaskTimeByCommitsCalculator.cs @@ -20,7 +20,7 @@ namespace JiraTimeBot.TaskTime public List CalculateTaskTime(List commits, Settings settings, CancellationToken cancellationToken = default(CancellationToken)) { - int minutesPerWorkDay = settings.MinuterPerWorkDay; + int minutesPerWorkDay = settings.MinuterPerWorkDay + GetRandomMinutes(settings); int workHours = (settings.MinuterPerWorkDay / 60); int totalCommitsCount = commits.Count; @@ -30,11 +30,11 @@ namespace JiraTimeBot.TaskTime } //если кол-во коммитов более чем кол-во интервалов - то уменьшим интервал вдвое. - while (totalCommitsCount > (workHours * (60.0 / settings.RountToMinutes))) + while (totalCommitsCount > (workHours * (60.0 / settings.RoundToMinutes))) { - settings.RountToMinutes = (int)RoundTo((decimal)(settings.RountToMinutes / 2.0), 5); - _log.Info($"Слишком много задач - уменьшаю интервал до {settings.RountToMinutes}."); - if (settings.RountToMinutes == 5) + settings.RoundToMinutes = (int)RoundTo((decimal)(settings.RoundToMinutes / 2.0), 5); + _log.Info($"Слишком много задач - уменьшаю интервал до {settings.RoundToMinutes}."); + if (settings.RoundToMinutes == 5) { break; } @@ -65,7 +65,7 @@ namespace JiraTimeBot.TaskTime } int currentTaskCommits = taskGroup.Count(); - int currentTaskTime = (int)RoundTo(minutesPerWorkDay / totalCommitsCount * currentTaskCommits, settings.RountToMinutes); + int currentTaskTime = (int)RoundTo(minutesPerWorkDay / totalCommitsCount * currentTaskCommits, settings.RoundToMinutes); remainMinutes = remainMinutes - currentTaskTime; var orderedTasks = taskGroup.OrderBy(f => f.Time).ToArray(); @@ -110,6 +110,14 @@ namespace JiraTimeBot.TaskTime return workTimeItems; } + private int GetRandomMinutes(Settings settings) + { + var rand = new Random(); + int randomIntervals = settings.RandomWorkMinutes / settings.RoundToMinutes; + int randomMinutes = rand.Next(0, randomIntervals + 1) * settings.RoundToMinutes; + return randomMinutes; + } + private void PrintTotal(List workTimeItems) { var totalTime = TimeSpan.Zero; diff --git a/src/JiraTimeBot/UI/frmSettings.Designer.cs b/src/JiraTimeBot/UI/frmSettings.Designer.cs index 48f1ba6..1b00f56 100644 --- a/src/JiraTimeBot/UI/frmSettings.Designer.cs +++ b/src/JiraTimeBot/UI/frmSettings.Designer.cs @@ -51,6 +51,8 @@ this.chkAutostart = new System.Windows.Forms.CheckBox(); this.lblWorkDay = new System.Windows.Forms.Label(); this.txtWorkDayDuration = new System.Windows.Forms.TextBox(); + this.label9 = new System.Windows.Forms.Label(); + this.txtRandomMinutes = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // label5 @@ -78,6 +80,7 @@ this.label4.Size = new System.Drawing.Size(76, 13); this.label4.TabIndex = 26; this.label4.Text = "Путь до репо:"; + this.label4.TextAlign = System.Drawing.ContentAlignment.TopRight; // // txtRepoPath // @@ -94,6 +97,7 @@ this.label2.Size = new System.Drawing.Size(82, 13); this.label2.TabIndex = 24; this.label2.Text = "Mercurial name:"; + this.label2.TextAlign = System.Drawing.ContentAlignment.TopRight; // // txtMercurialEmail // @@ -155,7 +159,7 @@ // chkAddComments // this.chkAddComments.AutoSize = true; - this.chkAddComments.Location = new System.Drawing.Point(65, 308); + this.chkAddComments.Location = new System.Drawing.Point(65, 336); this.chkAddComments.Name = "chkAddComments"; this.chkAddComments.Size = new System.Drawing.Size(133, 17); this.chkAddComments.TabIndex = 31; @@ -164,7 +168,7 @@ // // btnSave // - this.btnSave.Location = new System.Drawing.Point(86, 331); + this.btnSave.Location = new System.Drawing.Point(86, 359); this.btnSave.Name = "btnSave"; this.btnSave.Size = new System.Drawing.Size(75, 23); this.btnSave.TabIndex = 32; @@ -229,7 +233,7 @@ // chkAutostart // this.chkAutostart.AutoSize = true; - this.chkAutostart.Location = new System.Drawing.Point(65, 285); + this.chkAutostart.Location = new System.Drawing.Point(65, 313); this.chkAutostart.Name = "chkAutostart"; this.chkAutostart.Size = new System.Drawing.Size(96, 17); this.chkAutostart.TabIndex = 40; @@ -252,11 +256,29 @@ this.txtWorkDayDuration.Size = new System.Drawing.Size(99, 20); this.txtWorkDayDuration.TabIndex = 41; // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(30, 284); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(101, 13); + this.label9.TabIndex = 44; + this.label9.Text = "Рандомных минут:"; + // + // txtRandomMinutes + // + this.txtRandomMinutes.Location = new System.Drawing.Point(133, 280); + this.txtRandomMinutes.Name = "txtRandomMinutes"; + this.txtRandomMinutes.Size = new System.Drawing.Size(99, 20); + this.txtRandomMinutes.TabIndex = 43; + // // frmSettings // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(243, 362); + this.ClientSize = new System.Drawing.Size(243, 391); + this.Controls.Add(this.label9); + this.Controls.Add(this.txtRandomMinutes); this.Controls.Add(this.lblWorkDay); this.Controls.Add(this.txtWorkDayDuration); this.Controls.Add(this.chkAutostart); @@ -316,5 +338,7 @@ private System.Windows.Forms.CheckBox chkAutostart; private System.Windows.Forms.Label lblWorkDay; private System.Windows.Forms.TextBox txtWorkDayDuration; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.TextBox txtRandomMinutes; } } \ No newline at end of file diff --git a/src/JiraTimeBot/UI/frmSettings.cs b/src/JiraTimeBot/UI/frmSettings.cs index 112aa16..6a37b51 100644 --- a/src/JiraTimeBot/UI/frmSettings.cs +++ b/src/JiraTimeBot/UI/frmSettings.cs @@ -34,11 +34,12 @@ namespace JiraTimeBot.UI txtRepoPath.Text = settings.RepositoryPath; actTime.Text = settings.ActivationTime.ToString("hh\\:mm\\:ss"); chkAddComments.Checked = settings.AddCommentsToWorklog; - txtRoundTo.Text = settings.RountToMinutes.ToString(); + txtRoundTo.Text = settings.RoundToMinutes.ToString(); cboWorkType.SelectedIndex = (int) settings.WorkType; txtTimeControlTask.Text = settings.TimeControlTask; txtJQL.Text = settings.JiraQuery; txtWorkDayDuration.Text = settings.MinuterPerWorkDay.ToString(); + txtRandomMinutes.Text = settings.RandomWorkMinutes.ToString(); cboWorkType_SelectedIndexChanged(null, null); } @@ -53,6 +54,10 @@ namespace JiraTimeBot.UI { minuterPerWorkDay = 8 * 60; } + if (!int.TryParse(txtRandomMinutes.Text, out var randomWorkMinutes)) + { + randomWorkMinutes = 0; + } var settings = new Settings { @@ -62,11 +67,12 @@ namespace JiraTimeBot.UI ActivationTime = TimeSpan.Parse(actTime.Text), RepositoryPath = txtRepoPath.Text, AddCommentsToWorklog = chkAddComments.Checked, - RountToMinutes = roundTo, + RoundToMinutes = roundTo, WorkType = (WorkType) cboWorkType.SelectedIndex, JiraQuery = txtJQL.Text, TimeControlTask = txtTimeControlTask.Text, - MinuterPerWorkDay = minuterPerWorkDay + MinuterPerWorkDay = minuterPerWorkDay, + RandomWorkMinutes = randomWorkMinutes }; //LockUnlock(false);