Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1658 new exam type fixed time and set of random tasks for alpha #1540

Open
wants to merge 5 commits into
base: v2-development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Common/OJS.Common/Enumerations/ContestType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public enum ContestType
OnsitePracticalExam = 1,
OnlinePracticalExam = 2,
Lab = 3,
OnsitePracticalExamWithRandomTasks = 4,
}
}
4 changes: 2 additions & 2 deletions Common/OJS.Common/Resources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ public static class ProblemGroupsControllers
{
public const string ActiveContestCannotAddProblemGroup = "The contest is аctive and you cannot add problem groups";
public const string ActiveContestCannotDeleteProblemGroup = "The contest is аctive and you cannot delete problem groups";
public const string CanCreateOnlyInOnlineContest = "You can create problem groups only in a contest which is of type {0}";
public const string CanEditOrderbyOnlyInOnlineContest = "You can edit problem groups order only in a contest which is of type {0}.";
public const string CanCreateOnlyInContestWithRandomTasks = "You can create problem groups only in a contest with random tasks";
public const string CanEditOrderByOnlyInContestWithRandomTasks = "You can edit problem groups order only in a contest with random tasks.";
public const string ContestDoesNotExist = "The selected contest does not exist";
public const string ContestRequired = "Contest is required";
public const string CopyAllProblemGroupsSuccessMessage = "Successfully copied all problem groups from the contest \"{0}\" into the contest \"{1}\"";
Expand Down
6 changes: 3 additions & 3 deletions Data/OJS.Data.Models/Contests/Contest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ public bool ResultsArePubliclyVisible
public bool HasPracticePassword => this.PracticePassword != null;

[NotMapped]
public bool IsOnlineExam => this.Type == ContestType.OnlinePracticalExam;
public bool IsOnlineExam => this.Type is ContestType.OnlinePracticalExam;

[NotMapped]
public bool IsOnsiteExam => this.Type == ContestType.OnsitePracticalExam;
public bool IsWithRandomTasks => this.Type is ContestType.OnlinePracticalExam or ContestType.OnsitePracticalExamWithRandomTasks;

[NotMapped]
public bool IsExam => this.IsOnlineExam || this.IsOnsiteExam;
public bool IsOnsiteExam => this.Type is ContestType.OnsitePracticalExam;

public static IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum ContestVariation {
OnsitePracticalExam = 1,
OnlinePracticalExam = 2,
Lab = 3,
OnsitePracticalExamWithRandomTasks = 4,
}

export type {
Expand Down
3 changes: 3 additions & 0 deletions Servers/UI/OJS.Servers.Ui/ClientApp/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ interface IContestDetailsResponseType {
problems: IProblemType[];
canViewResults: boolean;
isOnlineExam: boolean;
isWithRandomTasks: boolean;
isActive: boolean;
canBeCompeted: boolean;
canBePracticed: boolean;
Expand All @@ -211,6 +212,7 @@ interface IContestDetailsSliceType {
canViewCompeteResults?: boolean;
canViewPracticeResults?: boolean;
isOnlineExam?: boolean;
isWithRandomTasks?: boolean;
canBeCompeted?: boolean;
canBePracticed?: boolean;
isAdminOrLecturerInContest?: boolean;
Expand All @@ -237,6 +239,7 @@ interface IIndexContestsType {
hasContestPassword: boolean;
hasPracticePassword: boolean;
isOnlineExam: boolean;
isWithRandomTasks: boolean;
category: string;
isLoading: boolean;
numberOfProblems: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ interface ISubmitContestSolutionParams {
problemId: number;
submissionTypeId: number;
contestId: number;
isOnlineExam?: boolean;
isWithRandomTasks?: boolean;
}

interface IRegisterUserForContestParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ const ContestEdit = (props:IContestEditProps) => {
isLoading: isCreating,
} ] = useCreateContestMutation();

const isVariation =
(value: string, variation: ContestVariation) => value === getEnumMemberName(ContestVariation, variation).toString();

const isOnlineExam = isVariation(contest.type, ContestVariation.OnlinePracticalExam);

const isWithRandomTasks = isOnlineExam || isVariation(contest.type, ContestVariation.OnsitePracticalExamWithRandomTasks);

const getDefaultContestCategory = useCallback(() => {
const defaultCategory = contestCategories![0];
const categoryName = defaultCategory.name;
Expand Down Expand Up @@ -273,7 +280,9 @@ const ContestEdit = (props:IContestEditProps) => {
const isValid = !!Object.keys(ContestVariation).filter((key) => isNaN(Number(key))).some((x) => x === value);
currentContestValidations.isTypeValid = isValid;

if (value === getEnumMemberName(ContestVariation, ContestVariation.OnlinePracticalExam).toString()) {
const isOnlineExamValue = isVariation(value, ContestVariation.OnlinePracticalExam);
const isWithRandomTasksValue = isVariation(value, ContestVariation.OnsitePracticalExamWithRandomTasks);
if (isOnlineExamValue || isWithRandomTasksValue) {
numberOfProblemGroups = 2;
}
break;
Expand Down Expand Up @@ -530,7 +539,7 @@ const ContestEdit = (props:IContestEditProps) => {
</FormControl>
</Box>
<Box className={formStyles.row}>
{ contest.type === getEnumMemberName(ContestVariation, ContestVariation.OnlinePracticalExam) && (
{ isWithRandomTasks && (
<TextField
className={formStyles.inputRow}
type="number"
Expand Down Expand Up @@ -624,7 +633,7 @@ const ContestEdit = (props:IContestEditProps) => {
/>
</Box>
<Box className={formStyles.row}>
{contest.type === getEnumMemberName(ContestVariation, ContestVariation.OnlinePracticalExam) && (
{isOnlineExam && (
<TextField
className={formStyles.inputRow}
type="string"
Expand All @@ -636,7 +645,7 @@ const ContestEdit = (props:IContestEditProps) => {
: undefined}
name="duration"
onChange={(e) => onChange(e)}
disabled={contest.type !== getEnumMemberName(ContestVariation, ContestVariation.OnlinePracticalExam)}
disabled={!isOnlineExam}
InputLabelProps={{ shrink: true }}
error={(contestValidations.isDurationTouched && !contestValidations.isDurationValid)}
helperText={(contestValidations.isDurationTouched && !contestValidations.isDurationValid) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ const ContestSolutionSubmitPage = () => {
id: data!.contest!.id,
name: data.contest.name,
categoryId: data!.contest!.categoryId,
isOnlineExam: data?.contest?.isOnlineExam,
isWithRandomTasks: data?.contest?.isWithRandomTasks,
}));
}
}, [ contestDetails, contestId, data, dispatch ]);
Expand Down Expand Up @@ -397,7 +397,7 @@ const ContestSolutionSubmitPage = () => {
problemId: selectedContestDetailsProblem?.id!,
submissionTypeId: selectedSubmissionType?.id!,
contestId: Number(contestId!),
isOnlineExam: contestDetails?.isOnlineExam,
isWithRandomTasks: contestDetails?.isWithRandomTasks,
}).then((d) => {
if (!(d as any).error) {
refetch();
Expand All @@ -413,7 +413,7 @@ const ContestSolutionSubmitPage = () => {
submissionCode,
submitSolution,
contestId,
contestDetails?.isOnlineExam,
contestDetails?.isWithRandomTasks,
]);

const onSolutionSubmitFile = useCallback(async () => {
Expand All @@ -429,7 +429,7 @@ const ContestSolutionSubmitPage = () => {
problemId: selectedContestDetailsProblem?.id!,
submissionTypeId: selectedSubmissionType?.id!,
contestId: Number(contestId!),
isOnlineExam: contestDetails?.isOnlineExam,
isWithRandomTasks: contestDetails?.isWithRandomTasks,
});
refetch();
getSubmissionsData();
Expand All @@ -442,7 +442,7 @@ const ContestSolutionSubmitPage = () => {
submitSolutionFile,
uploadedFile,
contestId,
contestDetails?.isOnlineExam,
contestDetails?.isWithRandomTasks,
]);

const sumMyPoints = useMemo(() => contest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export const contestSlice = createSlice({
state.breadcrumbItems = [];
},
setContestDetailsIdAndCategoryId: (state, action: PayloadAction<{
id: number; name: string; categoryId: number; isOnlineExam?: boolean;
id: number; name: string; categoryId: number; isWithRandomTasks?: boolean;
}>) => {
const { id, name, categoryId, isOnlineExam } = action.payload;
state.contestDetails = { id, name, categoryId, isOnlineExam };
const { id, name, categoryId, isWithRandomTasks } = action.payload;
state.contestDetails = { id, name, categoryId, isWithRandomTasks };
},
setSelectedContestDetailsProblem: (state, action: PayloadAction<{ selectedProblem: IProblemType | null }>) => {
const { selectedProblem } = action.payload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ export const contestsService = createApi({
keepUnusedDataFor: 0,
}),
submitContestSolution: builder.mutation<void, ISubmitContestSolutionParams>({
query: ({ content, official, problemId, submissionTypeId, contestId, isOnlineExam }) => ({
query: ({ content, official, problemId, submissionTypeId, contestId, isWithRandomTasks }) => ({
url: '/Compete/Submit',
method: 'POST',
body: { content, official, problemId, submissionTypeId, contestId, isOnlineExam },
body: { content, official, problemId, submissionTypeId, contestId, isWithRandomTasks },
}),
}),
submitContestSolutionFile: builder.mutation<void, ISubmitContestSolutionParams>({
query: ({ content, official, submissionTypeId, problemId, contestId, isOnlineExam }) => {
query: ({ content, official, submissionTypeId, problemId, contestId, isWithRandomTasks }) => {
const formData = new FormData();
formData.append('content', content);
formData.append('official', official
Expand All @@ -119,7 +119,7 @@ export const contestsService = createApi({
formData.append('problemId', problemId.toString());
formData.append('submissionTypeId', submissionTypeId.toString());
formData.append('contestId', contestId.toString());
formData.append('isOnlineExam', isOnlineExam
formData.append('isWithRandomTasks', isWithRandomTasks
? 'true'
: 'false');

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class SubmissionRequestModel : IMapExplicitly

public bool IsOnlineExam { get; set; }

public bool IsWithRandomTasks { get; set; }

public int SubmissionTypeId { get; set; }

public string? Content { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class SubmitFileSubmissionRequestModel : IMapExplicitly

public bool IsOnlineExam { get; set; }

public bool IsWithRandomTasks { get; set; }

public int SubmissionTypeId { get; set; }

public IFormFile? Content { get; set; } = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public override async Task<ContestAdministrationModel> Edit(ContestAdministratio

contest.MapFrom(model);

if (model.IsOnlineExam && contest.ProblemGroups.Count == 0)
if (model.IsWithRandomTasks && contest.ProblemGroups.Count == 0)
{
AddProblemGroupsToContest(contest, model.NumberOfProblemGroups);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static bool BeAValidContestType(string? type)

private static bool ValidateOnlineContestProblemGroups(ContestAdministrationModel model)
{
if (model.IsOnlineExam)
if (model.IsWithRandomTasks)
{
if (model.NumberOfProblemGroups <= 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

public class ProblemGroupAdministrationModelValidator : BaseAdministrationModelValidator<ProblemGroupsAdministrationModel, int, ProblemGroup>
{
private readonly IContestsActivityService contestsActivityService;
private readonly IContestsDataService contestsDataService;
private readonly IProblemGroupsDataService problemGroupsDataService;

Expand All @@ -24,7 +23,6 @@ public ProblemGroupAdministrationModelValidator(
IProblemGroupsDataService problemGroupsDataService)
: base(problemGroupsDataService)
{
this.contestsActivityService = contestsActivityService;
this.contestsDataService = contestsDataService;
this.problemGroupsDataService = problemGroupsDataService;

Expand All @@ -36,19 +34,20 @@ public ProblemGroupAdministrationModelValidator(

this.RuleFor(model => model)
.MustAsync(async (model, _) => await this.NotBeActiveOrOnlineContest(model))
.WithMessage($"{string.Format(Resources.ProblemGroupsControllers.CanEditOrderbyOnlyInOnlineContest, ContestType.OnlinePracticalExam.ToString())}")
.WithMessage($"{Resources.ProblemGroupsControllers.CanEditOrderByOnlyInContestWithRandomTasks}")
.When(x => x.OperationType is CrudOperationType.Update or CrudOperationType.Delete);

this.RuleFor(model => model)
.MustAsync(async (model, _) => await this.IsOnline(model.Contest.Id) && !await this.contestsActivityService.IsContestActive(model.Contest.Id))
.MustAsync(async (model, _) => await this.contestsDataService.IsWithRandomTasksById(model.Contest.Id) &&
!await contestsActivityService.IsContestActive(model.Contest.Id))
.WithMessage($"" +
$"{string.Format(Resources.ProblemGroupsControllers.CanCreateOnlyInOnlineContest, ContestType.OnlinePracticalExam.ToString())}" +
$"{Resources.ProblemGroupsControllers.CanCreateOnlyInContestWithRandomTasks}" +
$" or " +
$"{Resources.ProblemGroupsControllers.ActiveContestCannotAddProblemGroup}")
.When(x => x.OperationType == CrudOperationType.Create);

this.RuleFor(x => x.Contest.Id)
.MustAsync(async (id, _) => !await this.contestsActivityService.IsContestActive(id))
.MustAsync(async (id, _) => !await contestsActivityService.IsContestActive(id))
.WithMessage("Cannot delete problem group when the related contest is active")
.When(x => x.OperationType is CrudOperationType.Update);
}
Expand All @@ -60,14 +59,7 @@ private async Task<bool> NotBeActiveOrOnlineContest(ProblemGroupsAdministrationM
var contestIdToCheck =
model.OperationType is CrudOperationType.Update ? model.Contest.Id : problemGroup!.ContestId;

if (Math.Abs(problemGroup!.OrderBy - model.OrderBy) > 0 && !await this.IsOnline(contestIdToCheck))
{
return false;
}

return true;
return Math.Abs(problemGroup!.OrderBy - model.OrderBy) <= 0 ||
await this.contestsDataService.IsWithRandomTasksById(contestIdToCheck);
}

private async Task<bool> IsOnline(int id)
=> await this.contestsDataService.IsOnlineById(id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public override async Task Delete(int id)
IsolationLevel.RepeatableRead,
TransactionScopeAsyncFlowOption.Enabled);

if (!await this.contestsData.IsOnlineById(problem.ContestId))
if (!await this.contestsData.IsWithRandomTasksById(problem.ContestId))
{
await this.problemGroupsBusiness.DeleteById(problem.ProblemGroupId);
}
Expand Down Expand Up @@ -240,7 +240,7 @@ public override async Task<ProblemAdministrationModel> Edit(ProblemAdministratio

problem.ProblemGroup.Type = (ProblemGroupType)Enum.Parse(typeof(ProblemGroupType), model.ProblemGroupType!);

if (!problem.ProblemGroup.Contest.IsOnlineExam)
if (!problem.ProblemGroup.Contest.IsWithRandomTasks)
{
problem.ProblemGroup.OrderBy = model.OrderBy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class ProblemAdministrationValidator : BaseAdministrationModelValidator<P
private readonly IContestsActivityService contestsActivityService;
private readonly ISubmissionTypesDataService submissionTypesDataService;
private readonly IProblemGroupsDataService problemGroupsDataService;
private readonly IContestsDataService contestsDataService;

public ProblemAdministrationValidator(
IProblemsDataService problemsDataService,
Expand All @@ -37,7 +36,6 @@ public ProblemAdministrationValidator(
this.contestsActivityService = contestsActivityService;
this.submissionTypesDataService = submissionTypesDataService;
this.problemGroupsDataService = problemGroupsDataService;
this.contestsDataService = contestsDataService;

this.RuleFor(model => model.Name)
.Length(1, ConstraintConstants.Problem.NameMaxLength)
Expand Down Expand Up @@ -82,7 +80,7 @@ public ProblemAdministrationValidator(
.MustAsync(async (model, _) => await this.MustHaveValidProblemGroupId(model))
.WithMessage("Invalid value for \"Problem Group Order By\" has been provided.")
.WhenAsync(async (x, _) => x.OperationType is CrudOperationType.Create or CrudOperationType.Update &&
await this.IsOnline(x.ContestId));
await contestsDataService.IsWithRandomTasksById(x.ContestId));
}

private async Task<bool> ContestMustNotBeActive(int problemId)
Expand Down Expand Up @@ -142,7 +140,4 @@ private async Task<bool> MustHaveValidProblemGroupId(ProblemAdministrationModel

return new HashSet<int>(problemGroups).Contains(model.ProblemGroupId);
}

private async Task<bool> IsOnline(int contestId)
=> await this.contestsDataService.IsOnlineById(contestId);
}
Loading
Loading