Сделан график по "Статус обучения - кол-во студентов", думаю над вторым графиком
This commit is contained in:
parent
7bc6efdc0c
commit
6ba2b66dfc
@ -71,6 +71,11 @@ namespace UniversityBusinessLogic.BusinessLogics
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<EducationStatusStudentsCountViewModel> GetEducationStatusStudents()
|
||||||
|
{
|
||||||
|
return _esStorage.GetEducationStatusStudents() ?? new List<EducationStatusStudentsCountViewModel>();
|
||||||
|
}
|
||||||
|
|
||||||
public int GetNumberOfPages(int userId, int pageSize = 10)
|
public int GetNumberOfPages(int userId, int pageSize = 10)
|
||||||
{
|
{
|
||||||
return _esStorage.GetNumberOfPages(userId, pageSize);
|
return _esStorage.GetNumberOfPages(userId, pageSize);
|
||||||
|
@ -16,6 +16,7 @@ namespace UniversityContracts.BusinessLogicContracts
|
|||||||
bool Delete(EducationStatusBindingModel model);
|
bool Delete(EducationStatusBindingModel model);
|
||||||
List<EducationStatusViewModel>? ReadList(EducationStatusSearchModel? model);
|
List<EducationStatusViewModel>? ReadList(EducationStatusSearchModel? model);
|
||||||
EducationStatusViewModel? ReadElement(EducationStatusSearchModel model);
|
EducationStatusViewModel? ReadElement(EducationStatusSearchModel model);
|
||||||
|
List<EducationStatusStudentsCountViewModel> GetEducationStatusStudents();
|
||||||
int GetNumberOfPages(int userId, int pageSize = 10);
|
int GetNumberOfPages(int userId, int pageSize = 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ namespace UniversityContracts.StoragesContracts
|
|||||||
EducationStatusViewModel? Insert(EducationStatusBindingModel model);
|
EducationStatusViewModel? Insert(EducationStatusBindingModel model);
|
||||||
EducationStatusViewModel? Update(EducationStatusBindingModel model);
|
EducationStatusViewModel? Update(EducationStatusBindingModel model);
|
||||||
EducationStatusViewModel? Delete(EducationStatusBindingModel model);
|
EducationStatusViewModel? Delete(EducationStatusBindingModel model);
|
||||||
|
List<EducationStatusStudentsCountViewModel>? GetEducationStatusStudents();
|
||||||
int GetNumberOfPages(int userId, int pageSize = 10);
|
int GetNumberOfPages(int userId, int pageSize = 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace UniversityContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class EducationStatusStudentsCountViewModel
|
||||||
|
{
|
||||||
|
public int Count { get; set; }
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
@ -118,6 +118,24 @@ namespace UniversityDataBaseImplemet.Implements
|
|||||||
return educationStatus.GetViewModel;
|
return educationStatus.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<EducationStatusStudentsCountViewModel>? GetEducationStatusStudents()
|
||||||
|
{
|
||||||
|
using var context = new Database();
|
||||||
|
var result = context.EducationStatuses
|
||||||
|
.GroupJoin(
|
||||||
|
context.Students,
|
||||||
|
status => status.Id,
|
||||||
|
student => student.EducationStatusId,
|
||||||
|
(status, students) => new EducationStatusStudentsCountViewModel
|
||||||
|
{
|
||||||
|
Name = status.Name,
|
||||||
|
Count = students.Count()
|
||||||
|
})
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public int GetNumberOfPages(int userId, int pageSize)
|
public int GetNumberOfPages(int userId, int pageSize)
|
||||||
{
|
{
|
||||||
using var context = new Database();
|
using var context = new Database();
|
||||||
|
@ -90,6 +90,16 @@ namespace UniversityProvider.Controllers
|
|||||||
return educationstatus ?? new();
|
return educationstatus ?? new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<EducationStatusStudentsCountViewModel> GetEducationStatusStudents()
|
||||||
|
{
|
||||||
|
if (APIClient.User == null)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
List<EducationStatusStudentsCountViewModel>? educationstatuscount = APIClient.GetRequest<List<EducationStatusStudentsCountViewModel>>($"api/educationstatus/geteducationstatusstudents");
|
||||||
|
return educationstatuscount ?? new();
|
||||||
|
}
|
||||||
|
|
||||||
public EducationStatusViewModel? Get(int id)
|
public EducationStatusViewModel? Get(int id)
|
||||||
{
|
{
|
||||||
if (APIClient.User == null)
|
if (APIClient.User == null)
|
||||||
|
@ -1,28 +1,8 @@
|
|||||||
<div>
|
<button id="btnFlow">Статистика по потокам</button>
|
||||||
|
<button id="btnStatus">Статистика по статусам обучения</button>
|
||||||
|
<div>
|
||||||
<canvas id="myChart"></canvas>
|
<canvas id="myChart"></canvas>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
||||||
|
<script src="~/js/diagram/diagram.js" asp-append-version="true"></script>
|
||||||
<script>
|
|
||||||
const ctx = document.getElementById('myChart');
|
|
||||||
|
|
||||||
new Chart(ctx, {
|
|
||||||
type: 'bar',
|
|
||||||
data: {
|
|
||||||
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
|
|
||||||
datasets: [{
|
|
||||||
label: '# of Votes',
|
|
||||||
data: [12, 19, 3, 5, 2, 3],
|
|
||||||
borderWidth: 1
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
scales: {
|
|
||||||
y: {
|
|
||||||
beginAtZero: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
85
UniversityProvider/wwwroot/js/diagram/diagram.js
Normal file
85
UniversityProvider/wwwroot/js/diagram/diagram.js
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
var btnFlow = document.getElementById('btnFlow');
|
||||||
|
var btnStatus = document.getElementById('btnStatus');
|
||||||
|
var educationStatusStats = [];
|
||||||
|
|
||||||
|
window.addEventListener('load', async () => {
|
||||||
|
await $.ajax({
|
||||||
|
url: "/educationstatus/geteducationstatusstudents",
|
||||||
|
type: "GET",
|
||||||
|
contentType: "json"
|
||||||
|
}).done((result) => {
|
||||||
|
educationStatusStats = result;
|
||||||
|
console.log(educationStatusStats);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
var ctx = document.getElementById('myChart').getContext('2d');
|
||||||
|
var chart;
|
||||||
|
|
||||||
|
function drawFlowChart() {
|
||||||
|
var flowData = {
|
||||||
|
labels: ['Поток 1', 'Поток 2', 'Поток 3'],
|
||||||
|
datasets: [{
|
||||||
|
label: 'Распределение студентов',
|
||||||
|
data: [80, 120, 100],
|
||||||
|
backgroundColor: ['#FF6384', '#36A2EB', '#FFCE56']
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
// Clear the previous chart if it exists
|
||||||
|
if (chart) {
|
||||||
|
chart.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
chart = new Chart(ctx, {
|
||||||
|
type: 'bar',
|
||||||
|
data: flowData,
|
||||||
|
options: {
|
||||||
|
responsive: true,
|
||||||
|
scales: {
|
||||||
|
y: {
|
||||||
|
beginAtZero: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawStatusChart() {
|
||||||
|
var edStatus = [];
|
||||||
|
var edCount = [];
|
||||||
|
educationStatusStats.forEach((item) => {
|
||||||
|
edStatus.push(item.name);
|
||||||
|
});
|
||||||
|
educationStatusStats.forEach((item) => {
|
||||||
|
edCount.push(item.count);
|
||||||
|
});
|
||||||
|
var statusData = {
|
||||||
|
labels: edStatus,
|
||||||
|
datasets: [{
|
||||||
|
data: edCount
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
// Clear the previous chart if it exists
|
||||||
|
if (chart) {
|
||||||
|
chart.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
chart = new Chart(ctx, {
|
||||||
|
type: 'pie',
|
||||||
|
data: statusData,
|
||||||
|
options: {
|
||||||
|
responsive: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
btnFlow.addEventListener('click', function () {
|
||||||
|
drawFlowChart();
|
||||||
|
});
|
||||||
|
|
||||||
|
btnStatus.addEventListener('click', function () {
|
||||||
|
drawStatusChart();
|
||||||
|
});
|
||||||
|
|
@ -69,6 +69,19 @@ namespace UniversityRestAPI.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<EducationStatusStudentsCountViewModel> GetEducationStatusStudents()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _educationStatusLogic.GetEducationStatusStudents();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void Create(EducationStatusBindingModel model)
|
public void Create(EducationStatusBindingModel model)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user