Compare commits

...

9 Commits

Author SHA1 Message Date
ketrptr 6bf5d08b9b modified: src/planner.c 2024-12-17 11:05:26 +01:00
ketrptr 7f487016dc modified: .gitignore 2024-12-17 10:45:33 +01:00
ketrptr cd7094263a Merge branch 'carla'
modified:   src/iCal.c
	modified:   src/iCal.h
	modified:   src/planner.c
	modified:   src/planner.h
	modified:   src/ui.c
2024-12-17 10:45:05 +01:00
ketrptr cb6571a0d6 modified: Makefile 2024-12-17 10:33:49 +01:00
ketrptr bc53d5bcf3 modified: Makefile
modified:   src/StudyPlanner.h
	modified:   src/ui.c
bugfix
2024-12-16 19:46:40 +01:00
ketrptr c616b98589 modified: Makefile
modified:   README.md
	new file:   src/StudyPlanner.h
	modified:   src/db.h
	modified:   src/ui.c
bugfixes. added release target to Makefile to use in other tools.
2024-12-16 18:23:24 +01:00
ketrptr 0922b8d6b8 modified: .gitignore
deleted:    .run/StudyPlanner.run.xml
2024-12-16 17:45:59 +01:00
ketrptr bcb08c6da9 modified: src/ui.c 2024-12-16 17:35:23 +01:00
ketrptr e5b5fd3b50 bugfixes 2024-12-16 17:29:07 +01:00
8 changed files with 213 additions and 269 deletions

2
.gitignore vendored
View File

@ -1,6 +1,8 @@
testing testing
debugOut debugOut
.idea .idea
.run
.vscode
# ---> C # ---> C
# Prerequisites # Prerequisites
*.d *.d

View File

@ -1,7 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="StudyPlanner" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" RUN_PATH="$PROJECT_DIR$/Makefile" EXPLICIT_BUILD_TARGET_NAME="all">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
</component>

View File

@ -12,10 +12,17 @@ CALF=src/iCal.c src/iCal.h
LLST=src/llist.c src/llist.h LLST=src/llist.c src/llist.h
CONFIG=src/config.h #config file CONFIG=src/config.h #config file
ALLF=$(UIF) $(PLF) $(DBF) $(LLST)
all: debug
#targets #targets
debug: test ui planner db iCal llist debug: test ui planner db iCal llist
gcc test.o ui.o planner.o db.o iCal.o llist.o -o debugOut gcc -DDEBUG test.o ui.o planner.o db.o iCal.o llist.o -o debugOut
# release: $(ALLF)
# gcc -DRELEASE -fPIC -shared -o $(ALLF)
# config: $(CONFIG) # config: $(CONFIG)
llist: $(LLST) llist: $(LLST)
@ -25,7 +32,7 @@ test: src/test.c
iCal: $(CALF) iCal: $(CALF)
gcc -c $(CFLAGS) $(CALF) gcc -c $(CFLAGS) $(CALF)
ui: $(UIF) ui: $(UIF)
gcc -c $(CFLAGS) $(UIF) gcc -DDEBUG -c $(CFLAGS) $(UIF)
planner: $(PLF) planner: $(PLF)
gcc -c $(CFLAGS) $(PLF) gcc -c $(CFLAGS) $(PLF)
db: $(DBF) db: $(DBF)
@ -33,10 +40,10 @@ db: $(DBF)
edit: edit:
nvim $(PLF) Makefile $(LLST) src/test.c nvim $(PLF) Makefile $(ALLF)
clean: clean:
rm -rf *.o debugOut src/*.gch *.csv *.ics rm -rf *.o debugOut src/*.gch *.csv *.ics *.so

View File

@ -13,6 +13,16 @@
Time management optimisation tool. Time management optimisation tool.
# How to use
- to use program directly compile with
make debug
. this creates executable binary.
- to integrate in other software use:
make release
. This creates shared library. use StudyPlanner.h (untested)
# Procedure # Procedure
## User input ## User input

6
src/StudyPlanner.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef SPLANNER
#define SPLANNER
int StudyPlanner();
#endif // StudyPlanner

View File

@ -3,7 +3,6 @@
#include "planner.h" #include "planner.h"
#endif
void write_linkedlist_to_csv(llist *head, const char *filename); void write_linkedlist_to_csv(llist *head, const char *filename);
llist *write_csv_to_llist(const char *filename); llist *write_csv_to_llist(const char *filename);
#endif

View File

@ -161,6 +161,14 @@ int cmpEvent(const void *a, const void *b) {
return cmpTaskN(aa->task, bb->task); 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) { llist *genPlan(llist *head, time_t timeAvail) {
// map llist to pointer arr & sort by priority // map llist to pointer arr & sort by priority
@ -170,7 +178,7 @@ llist *genPlan(llist *head, time_t timeAvail) {
printf("len: %d\n", lLen); printf("len: %d\n", lLen);
llistPrintT(head); llistPrintT(head);
// Task *sortedNames = calloc(lLen, sizeof(Task)); time_t now = time(NULL);
Task *sortedPrio = calloc(lLen, sizeof(Task)); Task *sortedPrio = calloc(lLen, sizeof(Task));
if (/*sortedNames == NULL ||*/ sortedPrio == NULL) { if (/*sortedNames == NULL ||*/ sortedPrio == NULL) {
planLog("gen plan : calloc failed!!\n", true); planLog("gen plan : calloc failed!!\n", true);
@ -180,23 +188,16 @@ llist *genPlan(llist *head, time_t timeAvail) {
// add Tasks from llist to arr // add Tasks from llist to arr
llist *c = head; llist *c = head;
for (int i = 0; c != NULL; i++) { 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; sortedPrio[i] = *(Task *)c->data;
if (sortedPrio[i].deadline + 1 < now) {
sortedPrio[i].priority = -1; // ignore past deadlines
}
c = c->next; c = c->next;
} }
// sort // sort
// qsort(sortedNames, lLen, sizeof(Task), cmpTaskN);
qsort(sortedPrio, lLen, sizeof(Task), cmpTaskP); qsort(sortedPrio, lLen, sizeof(Task), cmpTaskP);
// // test print
// planLog("sortendName", 0);
// for (int i = 0; i < lLen; i++) {
// printTask(sortedNames + i);
// }
planLog("sortendPrio", 0); planLog("sortendPrio", 0);
for (int i = 0; i < lLen; i++) { for (int i = 0; i < lLen; i++) {
printTask(sortedPrio + i); printTask(sortedPrio + i);
@ -205,16 +206,20 @@ llist *genPlan(llist *head, time_t timeAvail) {
planLog("creating eventList", false); planLog("creating eventList", false);
// genertate plan based on priorities and available time // genertate plan based on priorities and available time
time_t now = time(NULL); now = time(NULL);
struct tm *lc = localtime(&now); struct tm *lc = localtime(&now);
llist *events_ll = llistNew(NULL, cmpEvent); llist *events_ll = llistNew(NULL, cmpEvent);
if (events_ll == NULL) { if (events_ll == NULL) {
exit(1); exit(1);
} }
// time_t avail = mktime(timeAvail);
time_t start, end; time_t start, end;
// (mktime(lc) < mktime(timeAvail))
do { 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 start = mktime(lc); // start now
lc->tm_min += intervalLen; lc->tm_min += intervalLen;
end = mktime(lc); // end = mktime(lc); //
@ -225,9 +230,9 @@ llist *genPlan(llist *head, time_t timeAvail) {
c = newEvent(tmp->data, start, end, c = newEvent(tmp->data, start, end,
0); // use elem with wighest priority 0); // use elem with wighest priority
} }
llistAppend(events_ll, c); llistAppend(events_ll, c);
printEvent(c); printEvent(c);
// printEvent((Event *)((events_ll)->next)->data);
// decrement priority of first elem and resort list // decrement priority of first elem and resort list
(*sortedPrio).priority -= 1; (*sortedPrio).priority -= 1;
@ -237,29 +242,12 @@ llist *genPlan(llist *head, time_t timeAvail) {
} while (mktime(lc) < 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 // free empty head
llist *tmp = events_ll; llist *tmp = events_ll;
events_ll = events_ll->next; events_ll = events_ll->next;
tmp->next = NULL; tmp->next = NULL;
llistFreeE(tmp); llistFreeE(tmp);
printf("====EVENTSLL:\n"); // llistPrintE(events_ll);
llistPrintE(events_ll);
printf("====EVENTSLL:\n");
// update prioriteis in original llist // update prioriteis in original llist
for (int i = 0; i < lLen; i++) { for (int i = 0; i < lLen; i++) {
llist *tmp = llistGet(head, sortedPrio + i); llist *tmp = llistGet(head, sortedPrio + i);
@ -270,77 +258,7 @@ llist *genPlan(llist *head, time_t timeAvail) {
free(sortedPrio); free(sortedPrio);
planLog("END GEN PLAN", 0); planLog("END GEN PLAN", 0);
// llistFreeT(head);
// send updated tasks to db for storage // send updated tasks to db for storage
return events_ll; return events_ll;
} }
//
// const char *iCalHeader = "BEGIN:VCALENDAR\r\n"
// "VERSION:2.0\r\n"
// "PRODID:-//hacksw/handcal//NONSGML v1.0//EN\r\n";
// const char *iCalEvent = "BEGIN:VEVENT\r\n"
// "UID:%s%d\r\n"
// "DTSTAMP:%s\r\n"
// "DTSTART:%s\r\n"
// "DTEND:%s\r\n"
// "SUMMARY:%s\r\n"
// "END:VEVENT\r\n";
//
// int exportiCal(llist *events_ll) {
//
// llist *ev_ll = events_ll;
//
// llistPrintE(ev_ll);
//
// printf("%s", iCalHeader);
//
// time_t now = time(NULL);
// struct tm lc;
// localtime_r(&now, &lc);
//
// // gen filename & open for write
// char nameBuf[32];
// strftime(nameBuf, 32 - 12, "%F", &lc);
// strcat(nameBuf, "dayplan.ics");
// FILE *fp = fopen(nameBuf, "w");
// if (fp == NULL) {
// planLog("fopen failed!!", 1);
// return 1;
// }
// // write iCal header to file
// fprintf(fp, "%s", iCalHeader);
//
// // for every event in events_ll create VEVENT str and write to fp
// int count = 0;
// while (ev_ll != NULL) {
// // gen iCal compatible time str
// Event *current = ev_ll->data;
// struct tm startlc;
// struct tm endlc;
// localtime_r(&current->plannedStartTime, &startlc);
// localtime_r(&current->plannedEndTime, &endlc);
// char timeStartBuf[17];
// char timeEndBuf[17];
// char timeStamp[17];
// strftime(timeStamp, 17, "%Y%m%dT%k%M%SZ", &lc);
// printf("%s\n", timeStamp);
// strftime(timeStartBuf, 17, "%Y%m%dT%k%M%SZ", &startlc);
// printf("%s\n", timeStartBuf);
// strftime(timeEndBuf, 17, "%Y%m%dT%k%M%SZ", &endlc);
// printf("%s\n", timeEndBuf);
//
// fprintf(fp, iCalEvent, current->task->name, count, timeStamp,
// timeStartBuf,
// timeEndBuf, current->task->name);
// ev_ll = ev_ll->next;
// count += 1;
// }
//
// // after all events are written end cal with
// // END:VCALENDAR
// fprintf(fp, "END:VCALENDAR\r\n");
// fclose(fp);
//
// return 0;
// }

View File

@ -6,6 +6,7 @@
*/ */
#define _GNU_SOURCE #define _GNU_SOURCE
#include "ui.h" #include "ui.h"
#include "StudyPlanner.h"
#include "db.h" #include "db.h"
#include "iCal.h" #include "iCal.h"
#include "llist.h" #include "llist.h"
@ -20,9 +21,18 @@
#define localtime_r(T, Tm) (_localtime64_s(Tm, T) ? NULL : Tm) #define localtime_r(T, Tm) (_localtime64_s(Tm, T) ? NULL : Tm)
#endif #endif
const char *dbName = "db.csv"; #define minutes(n) (60 * n)
#define hours(n) (60 * minutes(n))
#define days(n) (24 * hours(n))
const char *dbName = "db.csv";
#define DEBUG
#ifdef DEBUG
int main(void) { int main(void) {
#endif
#ifdef RELEASE
int StudyPlanner() {
#endif
int taskcreation_date = 0; int taskcreation_date = 0;
int taskdeadline_date = 0; int taskdeadline_date = 0;
int taskpriority = 0; int taskpriority = 0;
@ -84,8 +94,7 @@ int main(void) {
// } // }
// create deadline timestamp // create deadline timestamp
lc.tm_yday += taskdeadline_date; time_t deadline = now + days(taskdeadline_date);
time_t deadline = mktime(&lc);
Task *newT = newTask(taskname, now, deadline, taskpriority, 0); Task *newT = newTask(taskname, now, deadline, taskpriority, 0);
if (listT == NULL) { if (listT == NULL) {
listT = llistNew(newT, cmpTaskN); listT = llistNew(newT, cmpTaskN);
@ -189,4 +198,4 @@ int main(void) {
// case 4: iCAl();break; // case 4: iCAl();break;
} }
} while (choice < 6); } while (choice < 6);
} }