новый график

This commit is contained in:
Володя 2023-05-19 22:50:30 +03:00
parent 7a3284eb75
commit 200d4af5d9
6 changed files with 92 additions and 18 deletions

View File

@ -157,5 +157,28 @@ namespace SchoolAgainStudyBusinessLogic.BusinessLogic
var actList = list.Select(g => new TopersViewModel { Name = _student.ReadElement(new StudentSearchModel { Id = g.Key }).Name, Count = g.Value }).ToList(); var actList = list.Select(g => new TopersViewModel { Name = _student.ReadElement(new StudentSearchModel { Id = g.Key }).Name, Count = g.Value }).ToList();
return actList; return actList;
} }
} public List<TopersViewModel> GetTopInterests(int StudentId)
{
var interests = _interest.ReadList(new InterestSearchModel { StudentId = StudentId });
var products = _product.ReadList(new ProductSearchModel { StudentId = StudentId });
var diyes = _diy.ReadList(new DiySearchModel { StudentId = StudentId });
Dictionary<IInterest, int> list = new Dictionary<IInterest, int>();
foreach(var interest in interests)
{
list.Add(interest, 0);
foreach(var product in products)
{
if (product.ProductInterests.ContainsKey(interest.Id))
list[interest] += 1;
}
foreach (var diy in diyes)
{
if (diy.DiyInterests.ContainsKey(interest.Id))
list[interest] += 1;
}
}
var actList = list.Select(g => new TopersViewModel { Name = g.Key.Title, Count = g.Value }).ToList();
return actList;
}
}
} }

View File

@ -11,7 +11,8 @@ namespace SchoolAgainStudyContracts.BusinessLogicContracts
{ {
public (int Products, int Diyes) GetDifferenceInCount(int StudentId); public (int Products, int Diyes) GetDifferenceInCount(int StudentId);
public List<ActivityChartViewModel> GetActivitys(int StudentId); public List<ActivityChartViewModel> GetActivitys(int StudentId);
public List<TopersViewModel> GetTopMaterials(int TeacherId); public List<TopersViewModel> GetTopInterests(int StudentId);
public List<TopersViewModel> GetTopMaterials(int TeacherId);
public List<TopersViewModel> GetTopStudents(int TeacherId); public List<TopersViewModel> GetTopStudents(int TeacherId);
} }
} }

View File

@ -517,6 +517,20 @@ namespace StudentWebClient.Controllers
NullValueHandling = NullValueHandling.Ignore}); NullValueHandling = NullValueHandling.Ignore});
return View(); return View();
} }
[HttpGet]
public IActionResult TopInterests()
{
if (APIClient.Student == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.DataPoints = JsonConvert.SerializeObject(_chart.GetTopInterests(APIClient.Student.Id),
new JsonSerializerSettings()
{
NullValueHandling = NullValueHandling.Ignore
});
return View();
}
} }

View File

@ -6,28 +6,28 @@
for (var i = 0; i < result.length; i++) { for (var i = 0; i < result.length; i++) {
dataPoints.push({ label: result[i].dateOf, y: result[i].count }); dataPoints.push({ label: result[i].dateOf, y: result[i].count });
} }
window.onload = function () { window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", { var chart = new CanvasJS.Chart("chartContainer", {
theme: "theme2", theme: "theme2",
animationEnabled: true, animationEnabled: true,
title: { title: {
text: "Отслеживание работы за послдений месяц" text: "Отслеживание работы за послдений месяц"
}, },
data: [ data: [
{ {
// change type to bar, line, area, pie, etc. // change type to bar, line, area, pie, etc.
type: "column", type: "column",
dataPoints: dataPoints dataPoints: dataPoints
} }
] ]
}); });
chart.render(); chart.render();
}; };
</script> </script>
<body> <body>
<div id="chartContainer"> <div id="chartContainer">
</div> </div>
</body> </body>

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: "theme2",
animationEnabled: true,
title: {
text: "Общее развитие интересов"
},
data: [
{
// change type to bar, line, area, pie, etc.
type: "pie",
dataPoints: dataPoints
}
]
});
chart.render();
};
</script>
<body>
<div id="chartContainer">
</div>
</body>

View File

@ -51,6 +51,9 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ActivityCharts">Отслеживание</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ActivityCharts">Отслеживание</a>
</li> </li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="TopInterests">ТопИнтересов</a>
</li>
</ul> </ul>
</div> </div>