From d216f72ca36c20dd79fe147c6d4c76367f2d365d Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 13 Dec 2024 22:01:43 +0100 Subject: [PATCH] deleted: doc/.$overview.drawio.bkp modified: src/config.h modified: src/llist.h modified: src/planner.c --- doc/.$overview.drawio.bkp | 116 -------------------------------------- src/config.h | 2 +- src/llist.h | 2 +- src/planner.c | 54 ++++++++---------- src/test.c | 6 +- 5 files changed, 29 insertions(+), 151 deletions(-) delete mode 100644 doc/.$overview.drawio.bkp diff --git a/doc/.$overview.drawio.bkp b/doc/.$overview.drawio.bkp deleted file mode 100644 index a3a924e..0000000 --- a/doc/.$overview.drawio.bkp +++ /dev/null @@ -1,116 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/config.h b/src/config.h index 85f65c0..621c2bf 100644 --- a/src/config.h +++ b/src/config.h @@ -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 diff --git a/src/llist.h b/src/llist.h index 34f5a67..629e6b8 100644 --- a/src/llist.h +++ b/src/llist.h @@ -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 diff --git a/src/planner.c b/src/planner.c index 656414f..7980ca9 100644 --- a/src/planner.c +++ b/src/planner.c @@ -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 diff --git a/src/test.c b/src/test.c index fa215e7..afa7130 100644 --- a/src/test.c +++ b/src/test.c @@ -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