Skip to content

Commit

Permalink
complete timetable printout
Browse files Browse the repository at this point in the history
  • Loading branch information
Kay-Gyasi committed Jun 23, 2023
1 parent 352ad98 commit 3e1ab5e
Show file tree
Hide file tree
Showing 27 changed files with 52 additions and 16 deletions.
17 changes: 17 additions & 0 deletions UMaTLMS.API/_logs/logs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2431,3 +2431,20 @@
{"Timestamp":"2023-06-22T23:53:47.2742296+00:00","Level":"Warning","MessageTemplate":"The query uses a row limiting operator ('Skip'/'Take') without an 'OrderBy' operator. This may lead to unpredictable results. If the 'Distinct' operator is used after 'OrderBy', then make sure to use the 'OrderBy' operator after 'Distinct' as the ordering would otherwise get erased.","Properties":{"EventId":{"Id":10102,"Name":"Microsoft.EntityFrameworkCore.Query.RowLimitingOperationWithoutOrderByWarning"},"SourceContext":"Microsoft.EntityFrameworkCore.Query","ActionId":"25f15e74-f0f7-4d30-bc03-b82f8798634b","ActionName":"UMaTLMS.API.Controllers.LecturesController.GetPage (UMaTLMS.API)","RequestId":"0HMRJFFF11OU2:00000003","RequestPath":"/api/lectures/getpage","ConnectionId":"0HMRJFFF11OU2","MachineName":"YOGA-X1","ProcessId":21856,"ThreadId":17}}
{"Timestamp":"2023-06-22T23:54:08.8795012+00:00","Level":"Warning","MessageTemplate":"The query uses a row limiting operator ('Skip'/'Take') without an 'OrderBy' operator. This may lead to unpredictable results. If the 'Distinct' operator is used after 'OrderBy', then make sure to use the 'OrderBy' operator after 'Distinct' as the ordering would otherwise get erased.","Properties":{"EventId":{"Id":10102,"Name":"Microsoft.EntityFrameworkCore.Query.RowLimitingOperationWithoutOrderByWarning"},"SourceContext":"Microsoft.EntityFrameworkCore.Query","ActionId":"25f15e74-f0f7-4d30-bc03-b82f8798634b","ActionName":"UMaTLMS.API.Controllers.LecturesController.GetPage (UMaTLMS.API)","RequestId":"0HMRJFFF11OU4:00000003","RequestPath":"/api/lectures/getpage","ConnectionId":"0HMRJFFF11OU4","MachineName":"YOGA-X1","ProcessId":21856,"ThreadId":6}}
{"Timestamp":"2023-06-22T23:54:08.8885053+00:00","Level":"Warning","MessageTemplate":"The query uses a row limiting operator ('Skip'/'Take') without an 'OrderBy' operator. This may lead to unpredictable results. If the 'Distinct' operator is used after 'OrderBy', then make sure to use the 'OrderBy' operator after 'Distinct' as the ordering would otherwise get erased.","Properties":{"EventId":{"Id":10102,"Name":"Microsoft.EntityFrameworkCore.Query.RowLimitingOperationWithoutOrderByWarning"},"SourceContext":"Microsoft.EntityFrameworkCore.Query","ActionId":"25f15e74-f0f7-4d30-bc03-b82f8798634b","ActionName":"UMaTLMS.API.Controllers.LecturesController.GetPage (UMaTLMS.API)","RequestId":"0HMRJFFF11OU4:00000003","RequestPath":"/api/lectures/getpage","ConnectionId":"0HMRJFFF11OU4","MachineName":"YOGA-X1","ProcessId":21856,"ThreadId":6}}
{"Timestamp":"2023-06-23T00:16:15.6813776+00:00","Level":"Information","MessageTemplate":"App starting...","Properties":{"MachineName":"YOGA-X1","ProcessId":12240,"ThreadId":1}}
{"Timestamp":"2023-06-23T00:16:15.9920616+00:00","Level":"Information","MessageTemplate":"App running!","Properties":{"MachineName":"YOGA-X1","ProcessId":12240,"ThreadId":1}}
{"Timestamp":"2023-06-23T00:16:18.3014023+00:00","Level":"Warning","MessageTemplate":"Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data; this mode should only be enabled during development.","Properties":{"EventId":{"Id":10400,"Name":"Microsoft.EntityFrameworkCore.Infrastructure.SensitiveDataLoggingEnabledWarning"},"SourceContext":"Microsoft.EntityFrameworkCore.Model.Validation","MachineName":"YOGA-X1","ProcessId":12240,"ThreadId":1}}
{"Timestamp":"2023-06-23T00:17:37.8576711+00:00","Level":"Warning","MessageTemplate":"The query uses a row limiting operator ('Skip'/'Take') without an 'OrderBy' operator. This may lead to unpredictable results. If the 'Distinct' operator is used after 'OrderBy', then make sure to use the 'OrderBy' operator after 'Distinct' as the ordering would otherwise get erased.","Properties":{"EventId":{"Id":10102,"Name":"Microsoft.EntityFrameworkCore.Query.RowLimitingOperationWithoutOrderByWarning"},"SourceContext":"Microsoft.EntityFrameworkCore.Query","ActionId":"23a8c646-2441-4ce9-9bda-4a49b8274032","ActionName":"UMaTLMS.API.Controllers.LecturesController.GetPage (UMaTLMS.API)","RequestId":"0HMRJFSAQGT50:00000007","RequestPath":"/api/lectures/getpage","ConnectionId":"0HMRJFSAQGT50","MachineName":"YOGA-X1","ProcessId":12240,"ThreadId":25}}
{"Timestamp":"2023-06-23T00:17:37.8689507+00:00","Level":"Warning","MessageTemplate":"The query uses a row limiting operator ('Skip'/'Take') without an 'OrderBy' operator. This may lead to unpredictable results. If the 'Distinct' operator is used after 'OrderBy', then make sure to use the 'OrderBy' operator after 'Distinct' as the ordering would otherwise get erased.","Properties":{"EventId":{"Id":10102,"Name":"Microsoft.EntityFrameworkCore.Query.RowLimitingOperationWithoutOrderByWarning"},"SourceContext":"Microsoft.EntityFrameworkCore.Query","ActionId":"23a8c646-2441-4ce9-9bda-4a49b8274032","ActionName":"UMaTLMS.API.Controllers.LecturesController.GetPage (UMaTLMS.API)","RequestId":"0HMRJFSAQGT50:00000007","RequestPath":"/api/lectures/getpage","ConnectionId":"0HMRJFSAQGT50","MachineName":"YOGA-X1","ProcessId":12240,"ThreadId":25}}
{"Timestamp":"2023-06-23T00:17:43.1326275+00:00","Level":"Warning","MessageTemplate":"The query uses a row limiting operator ('Skip'/'Take') without an 'OrderBy' operator. This may lead to unpredictable results. If the 'Distinct' operator is used after 'OrderBy', then make sure to use the 'OrderBy' operator after 'Distinct' as the ordering would otherwise get erased.","Properties":{"EventId":{"Id":10102,"Name":"Microsoft.EntityFrameworkCore.Query.RowLimitingOperationWithoutOrderByWarning"},"SourceContext":"Microsoft.EntityFrameworkCore.Query","ActionId":"23a8c646-2441-4ce9-9bda-4a49b8274032","ActionName":"UMaTLMS.API.Controllers.LecturesController.GetPage (UMaTLMS.API)","RequestId":"0HMRJFSAQGT51:00000003","RequestPath":"/api/lectures/getpage","ConnectionId":"0HMRJFSAQGT51","MachineName":"YOGA-X1","ProcessId":12240,"ThreadId":3}}
{"Timestamp":"2023-06-23T00:17:43.1356938+00:00","Level":"Warning","MessageTemplate":"The query uses a row limiting operator ('Skip'/'Take') without an 'OrderBy' operator. This may lead to unpredictable results. If the 'Distinct' operator is used after 'OrderBy', then make sure to use the 'OrderBy' operator after 'Distinct' as the ordering would otherwise get erased.","Properties":{"EventId":{"Id":10102,"Name":"Microsoft.EntityFrameworkCore.Query.RowLimitingOperationWithoutOrderByWarning"},"SourceContext":"Microsoft.EntityFrameworkCore.Query","ActionId":"23a8c646-2441-4ce9-9bda-4a49b8274032","ActionName":"UMaTLMS.API.Controllers.LecturesController.GetPage (UMaTLMS.API)","RequestId":"0HMRJFSAQGT51:00000003","RequestPath":"/api/lectures/getpage","ConnectionId":"0HMRJFSAQGT51","MachineName":"YOGA-X1","ProcessId":12240,"ThreadId":3}}
{"Timestamp":"2023-06-23T00:39:42.9553416+00:00","Level":"Information","MessageTemplate":"App starting...","Properties":{"MachineName":"YOGA-X1","ProcessId":26764,"ThreadId":1}}
{"Timestamp":"2023-06-23T00:39:43.3615203+00:00","Level":"Information","MessageTemplate":"App running!","Properties":{"MachineName":"YOGA-X1","ProcessId":26764,"ThreadId":1}}
{"Timestamp":"2023-06-23T00:39:47.0660420+00:00","Level":"Warning","MessageTemplate":"Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data; this mode should only be enabled during development.","Properties":{"EventId":{"Id":10400,"Name":"Microsoft.EntityFrameworkCore.Infrastructure.SensitiveDataLoggingEnabledWarning"},"SourceContext":"Microsoft.EntityFrameworkCore.Model.Validation","MachineName":"YOGA-X1","ProcessId":26764,"ThreadId":1}}
{"Timestamp":"2023-06-23T00:42:02.0223787+00:00","Level":"Error","MessageTemplate":"An unhandled exception has occurred while executing the request.","Exception":"System.InvalidOperationException: A worksheet with this name already exists in the workbook : Thursday\r\n at OfficeOpenXml.ExcelWorksheets.AddSheet(String Name, Boolean isChart, Nullable`1 chartType, ExcelPivotTable pivotTableSource, XmlElement sheetElement)\r\n at OfficeOpenXml.ExcelWorksheets.Add(String Name)\r\n at UMaTLMS.Core.Helpers.TimetableGenerator.GetTimetable(IExcelReader excelReader, IEnumerable`1 lectureSchedules, IEnumerable`1 onlineLectureSchedules, List`1 rooms, String file) in C:\\Users\\admin\\source\\repos\\UMaTLMS\\UMaTLMS.Core\\Helpers\\TimetableGenerator.cs:line 101\r\n at UMaTLMS.Core.Processors.TimetableProcessor.Generate() in C:\\Users\\admin\\source\\repos\\UMaTLMS\\UMaTLMS.Core\\Processors\\TimetableProcessor.cs:line 77\r\n at UMaTLMS.API.Controllers.TimetableController.Generate() in C:\\Users\\admin\\source\\repos\\UMaTLMS\\UMaTLMS.API\\Controllers\\TimetableController.cs:line 16\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)\r\n at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)\r\n at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)\r\n at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)\r\n at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)\r\n at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)\r\n at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)\r\n at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)","Properties":{"EventId":{"Id":1,"Name":"UnhandledException"},"SourceContext":"Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware","RequestId":"0HMRJG9EORB86:00000001","RequestPath":"/api/Timetable/Generate","ConnectionId":"0HMRJG9EORB86","MachineName":"YOGA-X1","ProcessId":26764,"ThreadId":9}}
{"Timestamp":"2023-06-23T00:46:36.3037427+00:00","Level":"Information","MessageTemplate":"App starting...","Properties":{"MachineName":"YOGA-X1","ProcessId":2484,"ThreadId":1}}
{"Timestamp":"2023-06-23T00:46:36.6198639+00:00","Level":"Information","MessageTemplate":"App running!","Properties":{"MachineName":"YOGA-X1","ProcessId":2484,"ThreadId":1}}
{"Timestamp":"2023-06-23T00:46:38.9351801+00:00","Level":"Warning","MessageTemplate":"Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data; this mode should only be enabled during development.","Properties":{"EventId":{"Id":10400,"Name":"Microsoft.EntityFrameworkCore.Infrastructure.SensitiveDataLoggingEnabledWarning"},"SourceContext":"Microsoft.EntityFrameworkCore.Model.Validation","MachineName":"YOGA-X1","ProcessId":2484,"ThreadId":1}}
{"Timestamp":"2023-06-23T00:52:47.4464869+00:00","Level":"Information","MessageTemplate":"App starting...","Properties":{"MachineName":"YOGA-X1","ProcessId":12988,"ThreadId":1}}
{"Timestamp":"2023-06-23T00:52:47.8210344+00:00","Level":"Information","MessageTemplate":"App running!","Properties":{"MachineName":"YOGA-X1","ProcessId":12988,"ThreadId":1}}
{"Timestamp":"2023-06-23T00:52:49.9682509+00:00","Level":"Warning","MessageTemplate":"Sensitive data logging is enabled. Log entries and exception messages may include sensitive application data; this mode should only be enabled during development.","Properties":{"EventId":{"Id":10400,"Name":"Microsoft.EntityFrameworkCore.Infrastructure.SensitiveDataLoggingEnabledWarning"},"SourceContext":"Microsoft.EntityFrameworkCore.Model.Validation","MachineName":"YOGA-X1","ProcessId":12988,"ThreadId":1}}
Binary file modified UMaTLMS.API/bin/Debug/net7.0/UMaTLMS.API.dll
Binary file not shown.
Binary file modified UMaTLMS.API/bin/Debug/net7.0/UMaTLMS.API.pdb
Binary file not shown.
Binary file modified UMaTLMS.API/bin/Debug/net7.0/UMaTLMS.Core.dll
Binary file not shown.
Binary file modified UMaTLMS.API/bin/Debug/net7.0/UMaTLMS.Core.pdb
Binary file not shown.
Binary file modified UMaTLMS.API/bin/Debug/net7.0/UMaTLMS.Infrastructure.dll
Binary file not shown.
Binary file modified UMaTLMS.API/bin/Debug/net7.0/UMaTLMS.Infrastructure.pdb
Binary file not shown.
Binary file not shown.
Binary file modified UMaTLMS.API/obj/Debug/net7.0/UMaTLMS.API.dll
Binary file not shown.
Binary file modified UMaTLMS.API/obj/Debug/net7.0/UMaTLMS.API.pdb
Binary file not shown.
7 changes: 7 additions & 0 deletions UMaTLMS.Core/Entities/LectureSchedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,12 @@ public LectureSchedule HasLecture(int? firstLectureId, int? secondLectureId)
if (secondLectureId is not null) SecondLectureId = secondLectureId;
return this;
}

public LectureSchedule Reset()
{
FirstLectureId = null;
SecondLectureId = null;
return this;
}
}

6 changes: 6 additions & 0 deletions UMaTLMS.Core/Entities/OnlineLectureSchedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@ public OnlineLectureSchedule AddLecture(Lecture lecture)
_lectures.Add(lecture);
return this;
}

public OnlineLectureSchedule Reset()
{
_lectures.Clear();
return this;
}
}

37 changes: 21 additions & 16 deletions UMaTLMS.Core/Helpers/TimetableGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using LinqKit;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using UMaTLMS.Core.Entities;
using UMaTLMS.Core.Processors;
using UMaTLMS.Core.Services;
using UMaTLMS.SharedKernel.Helpers;

Expand All @@ -16,9 +12,7 @@ public static class TimetableGenerator
{
public static (List<LectureSchedule>, List<OnlineLectureSchedule>) Generate(List<LectureSchedule> schedules, List<OnlineLectureSchedule> onlineSchedules, List<Lecture> lectures)
{
if (schedules.Any(x => x.FirstLecture is not null || x.SecondLecture is not null))
return (schedules, onlineSchedules);

ResetSchedules(schedules, onlineSchedules);
Shuffle(schedules);
lectures = lectures.OrderByDescending(x => x.Duration)
.OrderByDescending(x => x.PreferredRoom is not null)
Expand Down Expand Up @@ -285,18 +279,16 @@ private static string GetVleCellName(ExcelWorksheet worksheet, OnlineLectureSche

for (int i = 0; i < columns.Count; i++)
{
var cellValue = worksheet.Cells[$"{columns[i]}{i}"].Value?.ToString();
var cellValue = worksheet.Cells[$"{columns[i]}{7}"].Value?.ToString(); // 7th row has the time periods
if (string.IsNullOrEmpty(cellValue)) continue;

if (cellValue == GetTimeMapping(lectureSchedule.TimePeriod, 1))
{
var name = $"{columns[i]}{i}";
if (!string.IsNullOrWhiteSpace(worksheet.Cells[name].Value?.ToString())) break;
if (cellValue != GetTimeMapping(lectureSchedule.TimePeriod, 1)) continue;
var name = $"{columns[i]}{row}";
if (!string.IsNullOrWhiteSpace(worksheet.Cells[name].Value?.ToString())) break;

cellName.Item1 = columns[i];
cellName.Item2 = i.ToString();
break;
}
cellName.Item1 = columns[i];
cellName.Item2 = row.ToString();
break;
}
}

Expand Down Expand Up @@ -377,6 +369,19 @@ private static string GetTimeMapping(string key, int period)
return secondPeriodMapping[key];
}

private static void ResetSchedules(List<LectureSchedule> schedules, List<OnlineLectureSchedule> onlineSchedules)
{
foreach (var s in schedules.Where(x => x.FirstLecture is not null || x.SecondLecture is not null))
{
s.Reset();
}

foreach (var o in onlineSchedules.Where(x => x.Lectures.Any()))
{
o.Reset();
}
}

private static void Shuffle<T>(List<T> list)
{
var random = new Random();
Expand Down
1 change: 1 addition & 0 deletions UMaTLMS.Core/Processors/TimetableProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public TimetableProcessor(ILogger<TimetableProcessor> logger, ILectureScheduleRe
var schedules = (await _lectureScheduleRepository.GetAll())
.Where(x => x.Room.IsIncludedInGeneralAssignment)
.ToList();

var onlineSchedules = await _onlineLectureScheduleRepository.GetAll();
var rooms = await _roomRepository.GetAllAsync();

Expand Down
Binary file modified UMaTLMS.Core/bin/Debug/net7.0/UMaTLMS.Core.dll
Binary file not shown.
Binary file modified UMaTLMS.Core/bin/Debug/net7.0/UMaTLMS.Core.pdb
Binary file not shown.
Binary file modified UMaTLMS.Core/obj/Debug/net7.0/UMaTLMS.Core.dll
Binary file not shown.
Binary file modified UMaTLMS.Core/obj/Debug/net7.0/UMaTLMS.Core.pdb
Binary file not shown.
Binary file modified UMaTLMS.Core/obj/Debug/net7.0/ref/UMaTLMS.Core.dll
Binary file not shown.
Binary file modified UMaTLMS.Core/obj/Debug/net7.0/refint/UMaTLMS.Core.dll
Binary file not shown.
Binary file modified UMaTLMS.Infrastructure/bin/Debug/net7.0/UMaTLMS.Core.dll
Binary file not shown.
Binary file modified UMaTLMS.Infrastructure/bin/Debug/net7.0/UMaTLMS.Core.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 3e1ab5e

Please sign in to comment.