Графики готовы

This commit is contained in:
ityurner02@mail.ru 2023-05-19 18:30:49 +04:00
parent b241c59c1c
commit b3a2699d7d
4 changed files with 88 additions and 3 deletions

View File

@ -21,8 +21,9 @@ namespace SchoolAgainStudyBusinessLogic.BusinessLogic
private readonly ILessonLogic _lesson; private readonly ILessonLogic _lesson;
private readonly IMaterialLogic _material; private readonly IMaterialLogic _material;
private readonly ITaskLogic _task; private readonly ITaskLogic _task;
private readonly IStudentLogic _student;
public ChartLogic(IInterestLogic interest, IProductLogic product, IDiyLogic diy, ILessonLogic lesson, ITaskLogic task, IMaterialLogic mateial) public ChartLogic(IInterestLogic interest, IProductLogic product, IDiyLogic diy, ILessonLogic lesson, ITaskLogic task, IMaterialLogic mateial, IStudentLogic student)
{ {
_interest = interest; _interest = interest;
@ -31,6 +32,7 @@ namespace SchoolAgainStudyBusinessLogic.BusinessLogic
_lesson = lesson; _lesson = lesson;
_task = task; _task = task;
_material = mateial; _material = mateial;
_student = student;
} }
public (int Products, int Diyes) GetDifferenceInCount(int StudentId) public (int Products, int Diyes) GetDifferenceInCount(int StudentId)
{ {
@ -120,7 +122,40 @@ namespace SchoolAgainStudyBusinessLogic.BusinessLogic
public List<TopersViewModel> GetTopStudents(int TeacherId) public List<TopersViewModel> GetTopStudents(int TeacherId)
{ {
throw new NotImplementedException(); var lessons = _lesson.ReadList(new LessonSearchModel
{
TeacherId = TeacherId
});
var tasks = _task.ReadList(new TaskSearchModel
{
TeacherId = TeacherId,
});
var diys = _diy.ReadList(null);
Dictionary<int, int> list = new Dictionary<int, int>();
foreach(var lesson in lessons)
{
var product = _product.ReadElement(new ProductSearchModel
{
Id = lesson.ProductId
});
if (list.ContainsKey(product.StudentId))
list[product.StudentId] += 1;
else list.Add(product.StudentId, 1);
}
foreach (var task in tasks)
{
foreach(var diy in diys)
{
if(diy.TaskId == task.Id)
{
if (list.ContainsKey(diy.StudentId))
list[diy.StudentId] += 1;
else list.Add(diy.StudentId, 1);
}
}
}
var actList = list.Select(g => new TopersViewModel { Name = _student.ReadElement(new StudentSearchModel { Id = g.Key }).Name, Count = g.Value }).ToList();
return actList;
} }
} }
} }

View File

@ -503,7 +503,21 @@ namespace TeacherWebClient.Controllers
{ {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
ViewBag.DataPoints = JsonConvert.SerializeObject(_chart.GetActivitys(APIClient.Teacher.Id), ViewBag.DataPoints = JsonConvert.SerializeObject(_chart.GetTopMaterials(APIClient.Teacher.Id),
new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore
});
return View();
}
[HttpGet]
public IActionResult TopStudents()
{
if (APIClient.Teacher == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.DataPoints = JsonConvert.SerializeObject(_chart.GetTopStudents(APIClient.Teacher.Id),
new JsonSerializerSettings() new JsonSerializerSettings()
{ {
NullValueHandling = NullValueHandling.Ignore NullValueHandling = NullValueHandling.Ignore

View File

@ -0,0 +1,33 @@
@using SchoolAgainStudyContracts.ViewModel;
@model List<TopersViewModel>
<script type="text/javascript">
var result = @Html.Raw(ViewBag.DataPoints);
var dataPoints = [];
for (var i = 0; i < result.length; i++) {
dataPoints.push({ label: result[i].Name, y: result[i].Count });
}
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
theme: "theme1",
animationEnabled: true,
title: {
text: "Топ студентов"
},
data: [
{
// change type to bar, line, area, pie, etc.
type: "column",
dataPoints: dataPoints
}
]
});
chart.render();
};
</script>
<body>
<div id="chartContainer">
</div>
</body>

View File

@ -46,6 +46,9 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="TopMaterials">Топ материалов</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="TopMaterials">Топ материалов</a>
</li> </li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="TopStudents">Топ учеников</a>
</li>
</ul> </ul>
</div> </div>
</div> </div>