-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathStatisticsController.cs
More file actions
139 lines (116 loc) · 6.43 KB
/
Copy pathStatisticsController.cs
File metadata and controls
139 lines (116 loc) · 6.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System.Collections.Generic;
using System.Threading.Tasks;
using BackendFramework.Interfaces;
using BackendFramework.Models;
using BackendFramework.Otel;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace BackendFramework.Controllers
{
[Authorize]
[Produces("application/json")]
[Route("v1/projects/{projectId}/statistics")]
public class StatisticsController : Controller
{
private readonly IStatisticsService _statService;
private readonly IPermissionService _permissionService;
private readonly IProjectRepository _projRepo;
private const string otelTagName = "otel.StatisticsController";
public StatisticsController(
IStatisticsService statService, IPermissionService permissionService, IProjectRepository projRepo)
{
_statService = statService;
_permissionService = permissionService;
_projRepo = projRepo;
}
/// <summary> Get a list of <see cref="SemanticDomainCount"/>s of a specific project in order </summary>
/// <returns> A list of <see cref="SemanticDomainCount"/>s </returns>
[HttpGet("GetSemanticDomainCounts", Name = "GetSemanticDomainCounts")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List<SemanticDomainCount>))]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> GetSemanticDomainCounts(string projectId, string lang)
{
using var activity = OtelService.StartActivityWithTag(otelTagName, "getting semantic domain counts");
if (!await _permissionService.HasProjectPermission(HttpContext, Permission.Statistics, projectId))
{
return Forbid();
}
return Ok(await _statService.GetSemanticDomainCounts(projectId, lang));
}
/// <summary> Get a list of <see cref="WordsPerDayPerUserCount"/>s of a specific project in order </summary>
/// <returns> A list of <see cref="WordsPerDayPerUserCount"/>s </returns>
[HttpGet("GetWordsPerDayPerUserCounts", Name = "GetWordsPerDayPerUserCounts")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List<WordsPerDayPerUserCount>))]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> GetWordsPerDayPerUserCounts(string projectId)
{
using var activity = OtelService.StartActivityWithTag(otelTagName, "getting words per day per user counts");
if (!await _permissionService.HasProjectPermission(HttpContext, Permission.Statistics, projectId))
{
return Forbid();
}
return Ok(await _statService.GetWordsPerDayPerUserCounts(projectId));
}
/// <summary> Get a <see cref="ChartRootData"/> to generate an estimate Line Chart </summary>
[HttpGet("GetProgressEstimationLineChartRoot", Name = "GetProgressEstimationLineChartRoot")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ChartRootData))]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetProgressEstimationLineChartRoot(string projectId)
{
using var activity = OtelService.StartActivityWithTag(otelTagName, "getting progress estimation line chart root");
if (!await _permissionService.HasProjectPermission(HttpContext, Permission.Statistics, projectId))
{
return Forbid();
}
var proj = await _projRepo.GetProject(projectId);
if (proj is null)
{
return NotFound();
}
return Ok(await _statService.GetProgressEstimationLineChartRoot(projectId, proj.WorkshopSchedule));
}
/// <summary> Get a <see cref="ChartRootData"/> to generate a Line Chart </summary>
[HttpGet("GetLineChartRootData", Name = "GetLineChartRootData")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(ChartRootData))]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> GetLineChartRootData(string projectId)
{
using var activity = OtelService.StartActivityWithTag(otelTagName, "getting line chart root data");
if (!await _permissionService.HasProjectPermission(HttpContext, Permission.Statistics, projectId))
{
return Forbid();
}
return Ok(await _statService.GetLineChartRootData(projectId));
}
/// <summary> Get a list of <see cref="SemanticDomainUserCount"/>s of a specific project in order </summary>
/// <returns> A list of <see cref="SemanticDomainUserCount"/>s </returns>
[HttpGet("GetSemanticDomainUserCounts", Name = "GetSemanticDomainUserCounts")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List<SemanticDomainUserCount>))]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> GetSemanticDomainUserCounts(string projectId)
{
using var activity = OtelService.StartActivityWithTag(otelTagName, "getting semantic domain user counts");
if (!await _permissionService.HasProjectPermission(HttpContext, Permission.Statistics, projectId))
{
return Forbid();
}
return Ok(await _statService.GetSemanticDomainUserCounts(projectId));
}
/// <summary> Get the proportion of descendant domains that have at least one entry </summary>
/// <returns> A double value between 0 and 1 </returns>
[HttpGet("GetDomainProgressProportion", Name = "GetDomainProgressProportion")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(double))]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
public async Task<IActionResult> GetDomainProgressProportion(string projectId, string domainId)
{
using var activity = OtelService.StartActivityWithTag(otelTagName, "getting domain progress proportion");
if (!await _permissionService.HasProjectPermission(HttpContext, Permission.WordEntry, projectId))
{
return Forbid();
}
return Ok(await _statService.GetDomainProgressProportion(projectId, domainId));
}
}
}