Skip to content

Commit 7451d97

Browse files
authored
Adjustments and limits (#64)
Added statistics questions when creating an application
1 parent 9545460 commit 7451d97

File tree

31 files changed

+3582
-3273
lines changed

31 files changed

+3582
-3273
lines changed

src/Server/Coderr.Server.Api/Core/Applications/Commands/CreateApplication.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,15 @@ public CreateApplication(string name, TypeOfApplication typeOfApplication)
4545
/// </summary>
4646
[IgnoreField]
4747
public int UserId { get; set; }
48+
49+
/// <summary>
50+
/// Estimated number of errors
51+
/// </summary>
52+
public int? NumberOfErrors { get; set; }
53+
54+
/// <summary>
55+
/// Number of developers that work full time with this application.
56+
/// </summary>
57+
public decimal? NumberOfDevelopers { get; set; }
4858
}
4959
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Coderr.Server.Api.Core.Applications.Commands
6+
{
7+
/// <summary>
8+
/// Do not pester the user with the question about adding info for statistics.
9+
/// </summary>
10+
[Command]
11+
public class MuteStatisticsQuestion
12+
{
13+
public int ApplicationId { get; set; }
14+
}
15+
}

src/Server/Coderr.Server.Api/Core/Applications/Queries/GetApplicationInfoResult.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@ public class GetApplicationInfoResult
3939
/// Versions that we have received error reports for.
4040
/// </summary>
4141
public string[] Versions { get; set; }
42+
43+
/// <summary>
44+
/// Got information to be able to compare how the team is performing with other teams.
45+
/// </summary>
46+
public bool ShowStatsQuestion { get; set; }
4247
}
4348
}

src/Server/Coderr.Server.Api/Web/Overview/Queries/GetOverviewResult.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,10 @@ public GetOverviewResult()
3131
/// Labels for the time axis (X-axis) in the chart.
3232
/// </summary>
3333
public string[] TimeAxisLabels { get; set; }
34+
35+
/// <summary>
36+
/// Number of reports that
37+
/// </summary>
38+
public int MissedReports { get; set; }
3439
}
3540
}

src/Server/Coderr.Server.App/Core/Applications/CommandHandlers/CreateApplicationHandler.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ public async Task HandleAsync(IMessageContext context, CreateApplication command
2828
ApplicationType =
2929
(TypeOfApplication) Enum.Parse(typeof(TypeOfApplication), command.TypeOfApplication.ToString())
3030
};
31-
var creator = await _userRepository.GetUserAsync(command.UserId);
3231

32+
if (command.NumberOfDevelopers > 0)
33+
{
34+
app.AddStatsBase(command.NumberOfDevelopers, command.NumberOfErrors);
35+
}
36+
37+
var creator = await _userRepository.GetUserAsync(command.UserId);
3338
await _repository.CreateAsync(app);
3439
await _repository.CreateAsync(new ApplicationTeamMember(app.Id, creator.AccountId, creator.UserName)
3540
{
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Coderr.Server.Api.Core.Applications.Commands;
4+
using Coderr.Server.Domain.Core.Applications;
5+
using DotNetCqs;
6+
7+
namespace Coderr.Server.App.Core.Applications.CommandHandlers
8+
{
9+
class MuteStatisticsQuestionHandler : IMessageHandler<MuteStatisticsQuestion>
10+
{
11+
private readonly IApplicationRepository _applicationRepository;
12+
13+
public MuteStatisticsQuestionHandler(IApplicationRepository applicationRepository)
14+
{
15+
_applicationRepository = applicationRepository ?? throw new ArgumentNullException(nameof(applicationRepository));
16+
}
17+
18+
public async Task HandleAsync(IMessageContext context, MuteStatisticsQuestion message)
19+
{
20+
var app = await _applicationRepository.GetByIdAsync(message.ApplicationId);
21+
app.MuteStatisticsQuestion = true;
22+
await _applicationRepository.UpdateAsync(app);
23+
}
24+
}
25+
}

src/Server/Coderr.Server.App/Core/Applications/QueryHandlers/GetApplicationInfoHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Coderr.Server.Domain.Core.Incidents;
99
using Coderr.Server.Domain.Modules.ApplicationVersions;
1010
using DotNetCqs;
11-
1211
using TypeOfApplication = Coderr.Server.Api.Core.Applications.TypeOfApplication;
1312

1413
namespace Coderr.Server.App.Core.Applications.QueryHandlers
@@ -64,7 +63,8 @@ public async Task<GetApplicationInfoResult> HandleAsync(IMessageContext context,
6463
Name = app.Name,
6564
SharedSecret = app.SharedSecret,
6665
TotalIncidentCount = totalCount,
67-
Versions = versions.ToArray()
66+
Versions = versions.ToArray(),
67+
ShowStatsQuestion = !app.MuteStatisticsQuestion
6868
};
6969
}
7070
}

src/Server/Coderr.Server.App/Modules/MonthlyStats/ApplicationUsageStatisticsDto.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ public class ApplicationUsageStatisticsDto
88
public int ReOpenedCount { get; set; }
99
public int ClosedCount { get; set; }
1010
public int IgnoredCount { get; set; }
11+
public decimal? NumberOfDevelopers { get; set; }
12+
public int? EstimatedNumberOfErrors { get; set; }
1113
}
1214
}

src/Server/Coderr.Server.App/Modules/MonthlyStats/CollectStatsJob.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ from incidents
6767
var item = new AppResult
6868
{
6969
ApplicationId = reader.GetInt32(0),
70-
Count = reader.GetInt32(1)
70+
Count = reader.GetInt32(1),
71+
7172
};
7273
results.Add(item);
7374
}
@@ -211,6 +212,8 @@ private async Task<bool> ReportMonth(DateTime lastMonth)
211212
{
212213
var apps = new Dictionary<int, ApplicationUsageStatisticsDto>();
213214

215+
await GetApps(apps);
216+
214217
var values = await GetIncidentCounts(lastMonth);
215218
MergeStats(values, apps, (stat, value) => stat.IncidentCount = value);
216219

@@ -249,6 +252,27 @@ private async Task<bool> ReportMonth(DateTime lastMonth)
249252
return true;
250253
}
251254

255+
private async Task GetApps(Dictionary<int, ApplicationUsageStatisticsDto> apps)
256+
{
257+
using (var cmd = _unitOfWork.CreateDbCommand())
258+
{
259+
cmd.CommandText = @"select Id, EstimatedNumberOfErrors, NumberOfFtes FROM Applications";
260+
using (var reader = await cmd.ExecuteReaderAsync())
261+
{
262+
while (await reader.ReadAsync())
263+
{
264+
var item = new ApplicationUsageStatisticsDto()
265+
{
266+
ApplicationId = reader.GetInt32(0),
267+
EstimatedNumberOfErrors= reader.GetFieldValue<int?>(1),
268+
NumberOfDevelopers = reader.GetFieldValue<decimal?>(2)
269+
};
270+
apps[item.ApplicationId] = item;
271+
}
272+
}
273+
}
274+
}
275+
252276
private static void MergeStats(IEnumerable<AppResult> appResults, IDictionary<int, ApplicationUsageStatisticsDto> apps, Action<ApplicationUsageStatisticsDto, int> assignMethod)
253277
{
254278
foreach (var count in appResults)

src/Server/Coderr.Server.Domain/Core/Applications/Application.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace Coderr.Server.Domain.Core.Applications
88
/// </summary>
99
public class Application
1010
{
11+
private bool _muteStatisticsQuestion;
12+
1113
/// <summary>
1214
/// Initializes a new instance of the <see cref="Application" /> class.
1315
/// </summary>
@@ -78,6 +80,31 @@ protected Application()
7880
/// </summary>
7981
/// <remarks>The user have to manually configure the secret.</remarks>
8082
public string SharedSecret { get; private set; }
83+
84+
/// <summary>
85+
/// Entered when the user created the application
86+
/// </summary>
87+
public int? EstimatedNumberOfErrors { get; private set; }
88+
89+
/// <summary>
90+
/// Number of full time developers
91+
/// </summary>
92+
public decimal? NumberOfFtes { get; private set; }
93+
94+
public void AddStatsBase(decimal? fte, int? numberOfErrors)
95+
{
96+
EstimatedNumberOfErrors = numberOfErrors;
97+
NumberOfFtes = fte;
98+
}
99+
100+
/// <summary>
101+
/// Don't ask for statistics information
102+
/// </summary>
103+
public bool MuteStatisticsQuestion
104+
{
105+
get => _muteStatisticsQuestion || NumberOfFtes > 0 || EstimatedNumberOfErrors > 0;
106+
set => _muteStatisticsQuestion = value;
107+
}
81108
}
82109

83110

0 commit comments

Comments
 (0)