Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Stojcheska Teodora
Programming_Project
Commits
e40a7462
Commit
e40a7462
authored
Jun 13, 2021
by
Stojcheska Teodora
Browse files
Adding Tasks
parent
5af4877a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Scheduler_Project/Calendar.cs
View file @
e40a7462
...
...
@@ -150,9 +150,11 @@ public class Calendar
{
nextDay
.
addTask
(
task
,
0
);
}
reorderCalendar
(
nextDay
,
hours
);
reorderCalendar
(
nextDay
,
nextDay
.
hoursToShift
);
}
// get the tasks that need to be shifted and remove them from the day
// TODO: should the removing part be done in the reorder caledar function?
List
<
Task
>
getTasksGivenHours
(
Day
day
,
int
hours
)
{
// I'm checking the task that needs to be added as well
...
...
@@ -172,24 +174,27 @@ public class Calendar
-Add hours equally to each day from the current date up until the deadline of the task
*/
}
// if the task is fixed, again, do not shift it, it must stay in that day
if
(
day
.
tasks
[
i
].
type
!=
Type
.
FIXED
)
{
// should never get a negative value?
if
(
hours
==
0
)
{
break
;
}
Task
curTask
=
day
.
tasks
[
i
];
if
(
curTask
.
duration
>
hours
)
{
int
additionalHours
=
0
;
// merge then split the task
if
(
curTask
.
isSplit
)
{
additionalHours
=
curTask
.
splitTaskPtr
.
duration
;
// TODO: take care of the case when the task would be split into multiple days/tasks
day
.
removeTask
(
curTask
.
splitTaskPtr
);
day
.
nextDay
.
removeTask
(
curTask
.
splitTaskPtr
);
curTask
.
mergeTasks
(
curTask
,
curTask
.
splitTaskPtr
);
}
// TODO: if curTask.duration - hours is 0 then the task should be removed from day and the merged task should be added to the next day
// hours is the value that needs to be removed, so, in that day we're left with curTask.duration - hours
int
[]
splitHours
=
{
curTask
.
duration
-
hours
,
h
ours
};
int
[]
splitHours
=
{
curTask
.
duration
-
hours
-
additionalHours
,
hours
+
additionalH
ours
};
curTask
.
splitTask
(
splitHours
,
0
,
curTask
);
hours
=
0
;
tasks
.
Add
(
curTask
.
splitTaskPtr
);
...
...
@@ -197,13 +202,22 @@ public class Calendar
else
{
// && hours -= curTask.duration == 0?
int
curTaskHours
=
curTask
.
duration
;
// oone special case: when the last task of the day is split and we need to shift the whole thing
if
(
curTask
.
isSplit
)
{
curTask
.
mergeTasks
(
curTask
,
curTask
.
splitTaskPtr
);
//day.nextDay.removeTask(curTask.splitTaskPtr);
// the curtask should be deleted and the curTask.splitTaskPtr should be merged in one
curTask
.
splitTaskPtr
.
duration
+=
curTask
.
duration
;
// P:TODO: is this correct?
//curTask.splitTaskPtr = curTask;
}
tasks
.
Add
(
curTask
);
hours
-=
curTask
.
duration
;
else
{
tasks
.
Add
(
curTask
);
}
hours
-=
curTaskHours
;
day
.
removeTask
(
curTask
);
}
}
}
...
...
Scheduler_Project/Day.cs
View file @
e40a7462
...
...
@@ -42,8 +42,28 @@ public class Day
tasks
.
Insert
(
index
,
task
);
}
public
void
changeTask
(
Task
task
,
Task
changedTask
)
{
for
(
int
i
=
0
;
i
<
tasks
.
Count
;
++
i
)
{
if
(
tasks
[
i
]
==
task
)
{
tasks
[
i
]
=
changedTask
;
return
;
}
}
WriteLine
(
"Problem while changing the task - task not found in day"
);
}
public
void
removeTask
(
Task
task
)
{
tasks
.
Remove
(
task
);
}
public
int
getTaskIndex
(
Task
task
)
{
for
(
int
i
=
0
;
i
<
tasks
.
Count
;
++
i
)
{
if
(
tasks
[
i
]
==
task
)
{
return
i
;
}
}
WriteLine
(
"No such task exists"
);
return
-
1
;
}
}
\ No newline at end of file
Scheduler_Project/Program.cs
View file @
e40a7462
...
...
@@ -10,14 +10,16 @@ static class Program
Task
task
=
new
Task
(
"kdb"
,
new
DateTime
(
2021
,
07
,
08
),
5
,
Type
.
NORMAL
,
false
);
Task
t
=
new
Task
(
"Test"
,
new
DateTime
(
2021
,
07
,
07
),
3
,
Type
.
NORMAL
,
false
);
// splitting tasks problem - try with task duration 4
Task
t1
=
new
Task
(
"Test1"
,
new
DateTime
(
2021
,
06
,
1
2
),
5
,
Type
.
NORMAL
,
false
);
Task
t1
=
new
Task
(
"Test1"
,
new
DateTime
(
2021
,
06
,
1
4
),
5
,
Type
.
NORMAL
,
false
);
Task
t2
=
new
Task
(
"Test2"
,
new
DateTime
(
2021
,
08
,
07
),
2
,
Type
.
NORMAL
,
false
);
Task
t3
=
new
Task
(
"Test3"
,
new
DateTime
(
2021
,
07
,
10
),
6
,
Type
.
NORMAL
,
false
);
// doesn't add task
// also try date 2021, 07, 07
Task
t4
=
new
Task
(
"Test4"
,
new
DateTime
(
2021
,
07
,
07
),
2
,
Type
.
NORMAL
,
false
);
Task
t5
=
new
Task
(
"Test5"
,
new
DateTime
(
2021
,
07
,
15
),
7
,
Type
.
NORMAL
,
false
);
Task
t6
=
new
Task
(
"Test6"
,
new
DateTime
(
2021
,
06
,
15
),
10
,
Type
.
NORMAL
,
false
);
// when t6 is 10 day1 has 15 hours
// TODO: Modify the error state
Task
t6
=
new
Task
(
"Test6"
,
new
DateTime
(
2021
,
06
,
15
),
7
,
Type
.
NORMAL
,
false
);
calendar
.
addTask
(
task
);
calendar
.
addTask
(
t
);
...
...
@@ -27,9 +29,11 @@ static class Program
// TODO: Check what happens when you add this task
calendar
.
print
();
calendar
.
addTask
(
t4
);
//calendar.addTask(t5);
calendar
.
addTask
(
t5
);
calendar
.
print
();
WriteLine
();
//
calendar.addTask(t6);
calendar
.
addTask
(
t6
);
calendar
.
print
();
}
}
\ No newline at end of file
Scheduler_Project/Task.cs
View file @
e40a7462
...
...
@@ -65,4 +65,13 @@ public class Task
//day.removeTask(secondTask);
firstTask
.
splitTaskPtr
=
secondTask
.
splitTaskPtr
;
}
// TODO: Think of delete, should I have single function for merge and delete?
public
void
splitAndMerge
(
Task
task
,
int
[]
hours
,
int
index
)
{
if
(
task
.
isSplit
)
{
//if(task.duration)
}
task
.
duration
=
hours
[
0
];
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment