bugfixes
This commit is contained in:
		
							parent
							
								
									602da76bca
								
							
						
					
					
						commit
						e5b5fd3b50
					
				@ -161,6 +161,14 @@ int cmpEvent(const void *a, const void *b) {
 | 
			
		||||
  return cmpTaskN(aa->task, bb->task);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void resetPrio(Task **sortedPrio, int len) {
 | 
			
		||||
  for (int i = 0; i < len; i++) {
 | 
			
		||||
    if ((*sortedPrio)[i].priority < 0) // ignore past deadline
 | 
			
		||||
      continue;
 | 
			
		||||
    printf("incrementing prio!\n");
 | 
			
		||||
    (*sortedPrio)[i].priority += 10;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
llist *genPlan(llist *head, time_t timeAvail) {
 | 
			
		||||
 | 
			
		||||
  // map llist to pointer arr & sort by priority
 | 
			
		||||
@ -170,7 +178,7 @@ llist *genPlan(llist *head, time_t timeAvail) {
 | 
			
		||||
  printf("len: %d\n", lLen);
 | 
			
		||||
  llistPrintT(head);
 | 
			
		||||
 | 
			
		||||
  // Task *sortedNames = calloc(lLen, sizeof(Task));
 | 
			
		||||
  time_t now = time(NULL);
 | 
			
		||||
  Task *sortedPrio = calloc(lLen, sizeof(Task));
 | 
			
		||||
  if (/*sortedNames == NULL ||*/ sortedPrio == NULL) {
 | 
			
		||||
    planLog("gen plan : calloc failed!!\n", true);
 | 
			
		||||
@ -180,23 +188,16 @@ llist *genPlan(llist *head, time_t timeAvail) {
 | 
			
		||||
  // add Tasks from llist to arr
 | 
			
		||||
  llist *c = head;
 | 
			
		||||
  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 + 1 < now) {
 | 
			
		||||
      sortedPrio[i].priority = -1; // ignore past deadlines
 | 
			
		||||
    }
 | 
			
		||||
    c = c->next;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // sort
 | 
			
		||||
  // 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);
 | 
			
		||||
@ -205,16 +206,19 @@ 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 {
 | 
			
		||||
    if ((*sortedPrio).priority < 0) {
 | 
			
		||||
      continue;
 | 
			
		||||
    } else if ((*sortedPrio).priority == 0) {
 | 
			
		||||
      printf("All tasks have priority <0!!");
 | 
			
		||||
      resetPrio(&sortedPrio, lLen);
 | 
			
		||||
    }
 | 
			
		||||
    start = mktime(lc); // start now
 | 
			
		||||
    lc->tm_min += intervalLen;
 | 
			
		||||
    end = mktime(lc); //
 | 
			
		||||
@ -225,9 +229,9 @@ llist *genPlan(llist *head, time_t timeAvail) {
 | 
			
		||||
      c = newEvent(tmp->data, start, end,
 | 
			
		||||
                   0); // use elem with wighest priority
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    llistAppend(events_ll, c);
 | 
			
		||||
    printEvent(c);
 | 
			
		||||
    // printEvent((Event *)((events_ll)->next)->data);
 | 
			
		||||
 | 
			
		||||
    // decrement priority of first elem and resort list
 | 
			
		||||
    (*sortedPrio).priority -= 1;
 | 
			
		||||
@ -237,29 +241,12 @@ llist *genPlan(llist *head, time_t timeAvail) {
 | 
			
		||||
 | 
			
		||||
  } 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);
 | 
			
		||||
  // }
 | 
			
		||||
  //
 | 
			
		||||
 | 
			
		||||
  // free empty head
 | 
			
		||||
  llist *tmp = events_ll;
 | 
			
		||||
  events_ll = events_ll->next;
 | 
			
		||||
  tmp->next = NULL;
 | 
			
		||||
  llistFreeE(tmp);
 | 
			
		||||
  printf("====EVENTSLL:\n");
 | 
			
		||||
  llistPrintE(events_ll);
 | 
			
		||||
  printf("====EVENTSLL:\n");
 | 
			
		||||
  // llistPrintE(events_ll);
 | 
			
		||||
  // update prioriteis in original llist
 | 
			
		||||
  for (int i = 0; i < lLen; i++) {
 | 
			
		||||
    llist *tmp = llistGet(head, sortedPrio + i);
 | 
			
		||||
@ -270,7 +257,6 @@ llist *genPlan(llist *head, time_t timeAvail) {
 | 
			
		||||
  free(sortedPrio);
 | 
			
		||||
 | 
			
		||||
  planLog("END GEN PLAN", 0);
 | 
			
		||||
  // llistFreeT(head);
 | 
			
		||||
  // send updated tasks to db for storage
 | 
			
		||||
 | 
			
		||||
  return events_ll;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										4
									
								
								src/ui.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								src/ui.c
									
									
									
									
									
								
							@ -19,8 +19,6 @@
 | 
			
		||||
#define localtime_r(T, Tm) (localtime_s(Tm, T) ? NULL : Tm)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
const char *dbName = "db.csv";
 | 
			
		||||
 | 
			
		||||
int main(void) {
 | 
			
		||||
@ -85,7 +83,7 @@ int main(void) {
 | 
			
		||||
      // }
 | 
			
		||||
 | 
			
		||||
      // create deadline timestamp
 | 
			
		||||
      lc.tm_yday += taskdeadline_date;
 | 
			
		||||
      lc.tm_hour += (taskdeadline_date * 24);
 | 
			
		||||
      time_t deadline = mktime(&lc);
 | 
			
		||||
      Task *newT = newTask(taskname, now, deadline, taskpriority, 0);
 | 
			
		||||
      if (listT == NULL) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user