deleted: doc/.$overview.drawio.bkp

modified:   src/config.h
	modified:   src/llist.h
	modified:   src/planner.c
This commit is contained in:
simon committed 2024-12-13 22:01:43 +01:00
1 parent 5bbfc52403
commit a4f31f9414
5 files changed
+29 -151

No files matched your search

+1 -1
View File
@@ -9,7 +9,7 @@
#define hours(n) (60 * minutes(n))
#define days(n) (24 * hours(n))
static const time_t pauseLenght = minutes(15);
static const time_t pauseLenght = minutes(10);
static const time_t minIntervalLen = minutes(30);
#endif
+1 -1
View File
@@ -24,6 +24,6 @@ void llistFree(llist *head);
int llistLen(llist *head);
void llistPrintT(llist *head);
void llistPrintH(llist *head);
void llistPrintE(llist *head);
#endif
+22 -32
View File
@@ -38,7 +38,7 @@ void printEvent(Event *s) {
ctime_r(&s->plannedStartTime, st);
ctime_r(&s->plannedEndTime, e);
printf(eventFormat, s->task->name, st, e, s->spare);
// printTask(s->task);
printTask(s->task);
}
void llistPrintE(llist *head) {
llist *c = head;
@@ -146,7 +146,9 @@ int cmpTaskN(const void *a, const void *b) {
int cmpTaskP(const void *a, const void *b) {
Task *aa = (Task *)a;
Task *bb = (Task *)b;
return bb->priority - aa->priority;
if (bb->priority - aa->priority != 0)
return bb->priority - aa->priority;
return aa->spare - bb->spare;
}
// cmp event by task name
@@ -173,12 +175,14 @@ llist *genPlan(llist *head, time_t timeAvail) {
}
// add Tasks from llist to arr
// ignore tasks after deadline
llist *c = head;
time_t now = time(NULL);
for (int i = 0; c != NULL; i++) {
// sortedNames[i] = *copyTask(c->data);
// sortedPrio[i] = *copyTask(c->data);
// sortedNames[i] = *(Task *)c->data;
sortedPrio[i] = *(Task *)c->data;
if (sortedPrio[i].deadline <= now)
sortedPrio[i].priority = 0;
c = c->next;
}
@@ -186,12 +190,6 @@ llist *genPlan(llist *head, time_t timeAvail) {
// qsort(sortedNames, lLen, sizeof(Task), cmpTaskN);
qsort(sortedPrio, lLen, sizeof(Task), cmpTaskP);
// // test print
// planLog("sortendName", 0);
// for (int i = 0; i < lLen; i++) {
// printTask(sortedNames + i);
// }
planLog("sortendPrio", 0);
for (int i = 0; i < lLen; i++) {
printTask(sortedPrio + i);
@@ -200,15 +198,12 @@ llist *genPlan(llist *head, time_t timeAvail) {
planLog("creating eventList", false);
// genertate plan basen on priorities and available time
time_t now = time(NULL);
struct tm *lc = localtime(&now);
llist *events_ll = llistNew(NULL, cmpEvent);
if (events_ll == NULL) {
exit(1);
}
// time_t avail = mktime(timeAvail);
time_t start, end;
// (mktime(lc) < mktime(timeAvail))
do {
start = mktime(lc); // start now
lc->tm_min += intervalLen;
@@ -222,37 +217,31 @@ llist *genPlan(llist *head, time_t timeAvail) {
}
llistAppend(events_ll, c);
// printEvent(c);
// printEvent((Event *)((events_ll)->next)->data);
// decrement priority of first elem and resort list
(*sortedPrio).priority -= 1;
// increment spare(used as counter)
// counter counts how often a task hsa been in addet to event list
// this is used to break ties if priorites are equal
(*sortedPrio).spare += 1;
// sort again
qsort(sortedPrio, lLen, sizeof(Task), cmpTaskP);
planLog("sortendPrio", 0);
for (int i = 0; i < lLen; i++) {
printTask(sortedPrio + i);
}
lc->tm_min += pauseLen; // add pause
} while (mktime(lc) < timeAvail);
// for (int i = 0; i < lLen; i++) {
// time_t start = mktime(lc);
//
// printf("start:: %s\n", ctime(&start));
// lc->tm_min += 45;
// time_t end = mktime(lc);
// printf("end:: %s\n", ctime(&end));
//
// Event *c = newEvent(sortedPrio + i, start, end, 0);
// printEvent(c);
// lc->tm_min += 15;
// llistAppend(events_ll, c);
// }
//
} while (mktime(lc) < timeAvail && (*sortedPrio).priority > 0);
// free empty head
llist *tmp = events_ll;
events_ll = events_ll->next;
tmp->next = NULL;
llistFreeE(tmp);
llistPrintE(events_ll);
// llistPrintE(events_ll);
// update prioriteis in original llist
for (int i = 0; i < lLen; i++) {
@@ -264,6 +253,7 @@ llist *genPlan(llist *head, time_t timeAvail) {
free(sortedPrio);
planLog("END GEN PLAN", 0);
// llistFreeT(head);
// send updated tasks to db for storage
+5 -1
View File
@@ -25,6 +25,8 @@ int main() {
assert(t3 != NULL);
Task *t4 = newTask("TM1", now, now + days(1), 9, 0);
assert(t4 != NULL);
Task *t5 = newTask("Akt1", now, now, 9, 0);
assert(t5 != NULL);
printf("%s\n", ctime(&now));
@@ -33,12 +35,14 @@ int main() {
llistAppend(list1, t2);
llistAppend(list1, t3);
llistAppend(list1, t4);
llistAppend(list1, t5);
// gnerate plan from task list in time
struct tm *lc = localtime(&now);
lc->tm_hour += 9; // add available time;
lc->tm_hour += 12; // add available time;
time_t maxTime = mktime(lc); // create timestamp
llist *l1 = genPlan(list1, maxTime); // return inked list of event;
llistPrintE(l1);
llistFreeE(l1);
// print test tasks