Skip to content

Commit

Permalink
[UPDATE] [FIX] Visual adjustments to the today main page and mark sav…
Browse files Browse the repository at this point in the history
…ing pages (#244)
  • Loading branch information
ilyalehchylin committed Apr 9, 2024
2 parents f1b2927 + 4bbc4f0 commit 0372c0f
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 48 deletions.
12 changes: 12 additions & 0 deletions source/EduCATS.iOS/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@
"contentHash": "WG3r7EyjUe9CMPFSs6bty5doUqT+q9pbI80hlNzo2SkPkZ4VTuZkGWjpp77JB8+uaL4DFPRdBsAY+DX3dBK92A=="
}
},
"Xamarin.iOS,Version=v1.0/win-arm64": {
"SkiaSharp": {
"type": "Transitive",
"resolved": "2.80.2",
"contentHash": "D25rzdCwh+3L+XyXqpNa+H/yiLJbE3/R3K/XexwHyQjGdzZvSufFW3oqf3En7hhqSIsxsJ8f5NEZ0J5W5wlGBg=="
},
"System.Security.Cryptography.Cng": {
"type": "Transitive",
"resolved": "4.5.0",
"contentHash": "WG3r7EyjUe9CMPFSs6bty5doUqT+q9pbI80hlNzo2SkPkZ4VTuZkGWjpp77JB8+uaL4DFPRdBsAY+DX3dBK92A=="
}
},
"Xamarin.iOS,Version=v1.0/win-x64": {
"SkiaSharp": {
"type": "Transitive",
Expand Down
5 changes: 4 additions & 1 deletion source/EduCATS/Controls/RoundedListView/RoundedListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.CompilerServices;
using EduCATS.Controls.RoundedListView.Selectors;
using EduCATS.Helpers.Forms.Styles;
using EduCATS.Pages.Today.Base.Views.ViewCells;
using EduCATS.Themes;
using Nyxbull.Plugins.CrossLocalization;
using Xamarin.Forms;
Expand Down Expand Up @@ -55,7 +56,8 @@ public class RoundedListView : ListView
double footerBottomPadding = 0,
Func<object> func = null)
{
HasUnevenRows = true;
if (type == typeof(SubjectPageViewCell) || type == typeof(CalendarSubjectsViewCell)) HasUnevenRows = false;
else HasUnevenRows = true;
ItemTemplate = func == null ?
new RoundedListTemplateSelector(type, checkbox) :
new RoundedListTemplateSelector(func, checkbox);
Expand Down Expand Up @@ -142,6 +144,7 @@ Grid createFooterCap(double bottomPadding)
};

var frame = new Frame {
Padding = new Thickness(0, 0, 0, bottomPadding),
HasShadow = false,
CornerRadius = (float)_capHeight,
BackgroundColor = Color.FromHex(Theme.Current.RoundedListViewBackgroundColor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class SaveSingleStudentMarkPageView : ContentPage
const double _heightRequest = 40;

static Thickness _padding = new Thickness(10, 1);
static Thickness _margin = new Thickness(0, 10);
public List<int> Marks = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
public List<string> NameOfLabOrPractice = new List<string>();
public string _title { get; set; }
Expand Down Expand Up @@ -56,10 +57,11 @@ public SaveSingleStudentMarkPageView(string title, string name, LabsVisitingList
var inicials = new Label
{
VerticalOptions = LayoutOptions.CenterAndExpand,
Margin = _margin,
HorizontalOptions = LayoutOptions.CenterAndExpand,
TextColor = Color.FromHex(Theme.Current.StatisticsDetailsTitleColor),
Style = AppStyles.GetLabelStyle(),
Font = Font.SystemFontOfSize(NamedSize.Large).WithSize(20).WithAttributes(FontAttributes.Bold),
Font = Font.SystemFontOfSize(NamedSize.Large).WithSize(20).WithAttributes(FontAttributes.None),
Text = name,
};

Expand Down Expand Up @@ -142,6 +144,20 @@ public SaveSingleStudentMarkPageView(string title, string name, LabsVisitingList

commentEntry.SetBinding(Entry.TextProperty, "Comment");

nameOfPrOrLb.PropertyChanged += delegate {
if (nameOfPrOrLb.SelectedItem is not null)
if (marks.Students.First(student => student.FullName == name).LabsMarks.First(labmarks => labmarks.LabId == prOrLabStat.Labs.First(lab => lab.ShortName == nameOfPrOrLb.SelectedItem as string).LabId).Mark != string.Empty)
{
markPicker.SelectedIndex = Convert.ToInt32(marks.Students.First(student => student.FullName == name).LabsMarks.First(labmarks => labmarks.LabId == prOrLabStat.Labs.First(lab => lab.ShortName == nameOfPrOrLb.SelectedItem as string).LabId).Mark) - 1;
commentEntry.Text = marks.Students.First(student => student.FullName == name).LabsMarks.First(labmarks => labmarks.LabId == prOrLabStat.Labs.First(lab => lab.ShortName == nameOfPrOrLb.SelectedItem as string).LabId).Comment;
}
else
{
markPicker.SelectedItem = null;
commentEntry.Text = string.Empty;
}
};

var gridLayout = new Grid
{
BackgroundColor = Color.FromHex(Theme.Current.BaseBlockColor),
Expand Down
2 changes: 1 addition & 1 deletion source/EduCATS/Pages/SaveMarks/SavePractSingle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace EduCATS.Pages.SaveMarks
{
public class SavePractSingle
{
[JsonProperty("comment")]
[JsonProperty("Comment")]
public string Comment { get; set; }
public string date { get; set; }
public int id { get; set; }
Expand Down
193 changes: 156 additions & 37 deletions source/EduCATS/Pages/Statistics/Base/ViewModels/StatsPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using EduCATS.Networking.Models.SaveMarks.LabSchedule;
using EduCATS.Networking.Models.SaveMarks.Practicals;
using EduCATS.Pages.Pickers;
using EduCATS.Pages.SaveMarks;
using EduCATS.Pages.Statistics.Base.Models;
using EduCATS.Pages.Statistics.Enums;
using Nyxbull.Plugins.CrossLocalization;
Expand Down Expand Up @@ -358,7 +359,8 @@ protected virtual async Task getAndSetStatistics()
{
try
{
if (CurrentSubject != null)
if (CurrentSubject != null)
{
if (_isStudent)
{
var studentsStatistics = await getStatistics();
Expand All @@ -373,19 +375,67 @@ protected virtual async Task getAndSetStatistics()
s => s.StudentId == PlatformServices.Preferences.UserId);
currentPractStudentStatistics = studentsPractStatistics.Students.SingleOrDefault(
s => s.StudentId == PlatformServices.Preferences.UserId);
setChartData(currentStudentStatistics, currentTestStudentStatistics, currentPractStudentStatistics);
setChartData(currentStudentStatistics, studentTestStatistics, studentsPractStatistics);
_studentsTest = studentTestStatistics;
}
else
{
var labsTest = new LaboratoryWorksModel();
var currentStudentStatistics = new StatsStudentModel();
studentsStatistics = await getStatistics();
currentStudentStatistics = studentsStatistics.SingleOrDefault(
s => s.StudentId == PlatformServices.Preferences.UserId);
setChartData(currentStudentStatistics, labsTest, currentPractStudentStatistics);
setChartData(currentStudentStatistics, new LabsVisitingList(), studentsPractStatistics);
_students = studentsStatistics;
}
}
else
{
var studentsStatistics = await getStatistics();

var groupsModel = new GroupsViewModel(new PlatformServices(), CurrentSubject.Id);

await groupsModel.SetupGroups();

var currentStudentStatistics = new StatsStudentModel();

List<double> averages = new();
averages.Add(0);
averages.Add(0);
averages.Add(0);

List<double> avForGroup;

int countOfGroups = 0;

foreach (var group in (groupsModel.CurrentGroups))
{
countOfGroups++;
var studentsPractStatistics = await DataAccess.GetTestPracticialStatistics(CurrentSubject.Id, group.GroupId);

if (Servers.Current == Servers.EduCatsAddress)
{
var studentTestStatistics = await DataAccess.GetTestStatistics(CurrentSubject.Id, group.GroupId);
avForGroup = calculateChartData(currentStudentStatistics, studentTestStatistics, studentsPractStatistics, new(), new());
averages[0] += avForGroup[0];
averages[1] += avForGroup[1];
averages[2] += avForGroup[2];
}
else
{
studentsStatistics = await getStatistics();
avForGroup = calculateChartData(currentStudentStatistics, new LabsVisitingList(), studentsPractStatistics, new(), new());
averages[0] += avForGroup[0];
averages[1] += avForGroup[1];
averages[2] += avForGroup[2];
}
}

averages[0] /= countOfGroups;
averages[1] /= countOfGroups;
averages[2] /= countOfGroups;

setChartData(currentStudentStatistics, new LabsVisitingList(), null, averages);
}
}
}
catch (Exception ex)
Expand All @@ -408,72 +458,141 @@ void executeExpandCommand()
}
}

void setChartData(StatsStudentModel stats, LaboratoryWorksModel currentPractStudentStatistics, LaboratoryWorksModel worksModel)
void setChartData(StatsStudentModel stats, LabsVisitingList studentsPractStatistics, LabsVisitingList studentTestStatistics, List<double> averages = null)
{
try {
double avgLabs = 0;
double avgTests = 0;
double avgPract = 0;
try {
double rating = 0;

if (stats == null) {
stats = new StatsStudentModel();
}
}

if (Servers.Current == Servers.EduCatsAddress)
{
avgPract = calculateAvgPractMarks(worksModel.PracticalsMarks);
AveragePract = avgPract.ToString(_doubleStringFormat, CultureInfo.InvariantCulture);

avgLabs = calculateAvgLabsMarkTest(currentPractStudentStatistics.LabsMarks);
AverageLabs = avgLabs.ToString(_doubleStringFormat, CultureInfo.InvariantCulture);
LaboratoryWorksModel currentPractStudentStatistics = null, worksModel = null;

if (_isStudent)
{
averages = calculateChartData(stats, studentsPractStatistics, studentTestStatistics, currentPractStudentStatistics, worksModel);
}

if (currentPractStudentStatistics.TestMark != null)
avgTests = double.Parse(currentPractStudentStatistics.TestMark, CultureInfo.InvariantCulture);
AveragePract = averages[2].ToString(_doubleStringFormat, CultureInfo.InvariantCulture);
AverageLabs = averages[0].ToString(_doubleStringFormat, CultureInfo.InvariantCulture);
AverageTests = averages[1].ToString(_doubleStringFormat, CultureInfo.InvariantCulture);

AverageTests = avgTests.ToString(_doubleStringFormat, CultureInfo.InvariantCulture);
if (Servers.Current == Servers.EduCatsAddress)
{

if (worksModel.PracticalsMarks.Count == 0)
if (worksModel is not null && worksModel.PracticalsMarks.Count == 0 || worksModel is null && averages[2] == 0)
{
rating = (avgLabs + avgTests) / 2;
rating = (averages[0] + averages[1]) / 2;
Rating = rating.ToString(_doubleStringFormat, CultureInfo.InvariantCulture);
ChartEntries = new List<double> {
avgLabs, avgTests, rating, avgPract
averages[0], averages[1], rating, averages[2]
};
setNotEnoughDetails(avgLabs == 0 && avgTests == 0 && rating == 0);
setNotEnoughDetails(averages[0] == 0 && averages[1] == 0 && rating == 0);
}
else
{
rating = (avgLabs + avgTests + avgPract) / 3;
rating = (averages[0] + averages[1] + averages[2]) / 3;
Rating = rating.ToString(_doubleStringFormat, CultureInfo.InvariantCulture);
ChartEntries = new List<double> {
avgLabs, avgTests, rating, avgPract
averages[0], averages[1], rating, averages[2]
};
setNotEnoughDetails(avgLabs == 0 && avgTests == 0 && avgPract == 0 && rating == 0);
setNotEnoughDetails(averages[0] == 0 && averages[1] == 0 && averages[2] == 0 && rating == 0);
}
}
else
{
avgLabs = calculateAvgLabsMark(stats.MarkList);
AverageLabs = avgLabs.ToString(_doubleStringFormat, CultureInfo.InvariantCulture);

if (stats.AverageTestMark != null)
avgTests = double.Parse(stats.AverageTestMark, CultureInfo.InvariantCulture);

AverageTests = avgTests.ToString(_doubleStringFormat, CultureInfo.InvariantCulture);

rating = (avgLabs + avgTests) / 2;
rating = (averages[0] + averages[1]) / 2;
Rating = rating.ToString(_doubleStringFormat, CultureInfo.InvariantCulture);
ChartEntries = new List<double> {
avgLabs, avgTests, rating
averages[0], averages[1], rating
};
setNotEnoughDetails(avgLabs == 0 && avgTests == 0 && rating == 0);
setNotEnoughDetails(averages[0] == 0 && averages[1] == 0 && rating == 0);
}

} catch (Exception ex) {
AppLogs.Log(ex);
}
}

List<double> calculateChartData(StatsStudentModel stats, LabsVisitingList studentsPractStatistics, LabsVisitingList studentTestStatistics, LaboratoryWorksModel currentPractStudentStatistics, LaboratoryWorksModel worksModel)
{
double avgLabs = 0;
double avgTests = 0;
double avgPract = 0;

List<double> averages = new();

if (_isStudent)
{
currentPractStudentStatistics = studentsPractStatistics.Students.SingleOrDefault(
s => s.StudentId == PlatformServices.Preferences.UserId);
worksModel = studentTestStatistics.Students.SingleOrDefault(
s => s.StudentId == PlatformServices.Preferences.UserId);

if (Servers.Current == Servers.EduCatsAddress)
{
avgPract = calculateAvgPractMarks(worksModel.PracticalsMarks);

avgLabs = calculateAvgLabsMarkTest(currentPractStudentStatistics.LabsMarks);

if (currentPractStudentStatistics.TestMark != null)
avgTests = double.Parse(currentPractStudentStatistics.TestMark, CultureInfo.InvariantCulture);
}
else
{
avgLabs = calculateAvgLabsMark(stats.MarkList);

if (stats.AverageTestMark != null)
avgTests = double.Parse(stats.AverageTestMark, CultureInfo.InvariantCulture);
}
}
else
{
if (Servers.Current == Servers.EduCatsAddress)
{
int countOfPractStudents = 0;
foreach (var student in studentTestStatistics.Students)
{
avgPract += calculateAvgPractMarks(student.PracticalsMarks);
countOfPractStudents++;
}

avgPract /= countOfPractStudents;



int countOfStudents = 0;
foreach (var student in studentsPractStatistics.Students)
{
avgLabs += calculateAvgLabsMarkTest(student.LabsMarks);
countOfStudents++;

if (student.TestMark != null)
avgTests += double.Parse(student.TestMark, CultureInfo.InvariantCulture);
}

avgLabs /= countOfStudents;

avgTests /= countOfStudents;
}
else
{
avgLabs = calculateAvgLabsMark(stats.MarkList);

if (stats.AverageTestMark != null)
avgTests = double.Parse(stats.AverageTestMark, CultureInfo.InvariantCulture);
}
}

averages.Add(avgLabs);
averages.Add(avgTests);
averages.Add(avgPract);

return averages;
}

double calculateAvgPractMarks(List<PracticialMarks> practicalsMarks)
{
if (practicalsMarks == null)
Expand Down
4 changes: 2 additions & 2 deletions source/EduCATS/Pages/Statistics/Base/Views/StatsPageView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ RoundedListView createRoundedList(View header)
IsPullToRefreshEnabled = true
};

roundedListView.ItemTapped += (sender, e) => ((ListView)sender).SelectedItem = null;
//roundedListView.ItemTapped += (sender, e) => ((ListView)sender).SelectedItem = null;
roundedListView.SetBinding(ListView.IsRefreshingProperty, "IsLoading");
roundedListView.SetBinding(ListView.RefreshCommandProperty, "RefreshCommand");
roundedListView.SetBinding(ListView.SelectedItemProperty, "SelectedItem");
Expand All @@ -63,7 +63,7 @@ StackLayout createHeaderView()
{
var subjectsView = new SubjectsPickerView();
var radarChartView = createFrameWithChartView();
radarChartView.SetBinding(IsVisibleProperty, "IsStudent");
//radarChartView.SetBinding(IsVisibleProperty, "IsStudent");

return new StackLayout {
Padding = _headerPadding,
Expand Down
Loading

0 comments on commit 0372c0f

Please sign in to comment.