db.c von event auf task geändert
parent
9a9dddaad0
commit
06a81ad27e
34
src/db.c
34
src/db.c
|
@ -18,7 +18,7 @@
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
write a complete linkedlist to a Event csv file.
|
write a complete linkedlist to a task csv file.
|
||||||
*/
|
*/
|
||||||
void write_linkedlist_to_csv(llist* head, const char* filename) {
|
void write_linkedlist_to_csv(llist* head, const char* filename) {
|
||||||
//Open file with write permision
|
//Open file with write permision
|
||||||
|
@ -29,27 +29,20 @@ void write_linkedlist_to_csv(llist* head, const char* filename) {
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
//write the file header
|
//write the file header
|
||||||
fprintf(file, "TaskName, Created, Deadline, Priority, Spare, EventStartTime, EventEndTime, EventSpare\n");
|
fprintf(file, "TaskName, Created, Deadline, Priority, Spare\n");
|
||||||
|
|
||||||
// Iterate through the linked list and write the data to the CSV
|
// Iterate through the linked list and write the data to the CSV
|
||||||
llist* current = head;
|
llist* current = head;
|
||||||
while (current != NULL) {
|
while (current != NULL) {
|
||||||
// Extract data from the current node
|
|
||||||
Event* event = (Event*)current->data; // Assumed that current->data holds an Event pointer
|
|
||||||
|
|
||||||
// Extract the associated task from the event
|
// Write the task data to the CSV file
|
||||||
Task* task = event->task;
|
fprintf(file, "%s, %lu, %lu, %d, %lu\n",
|
||||||
|
|
||||||
// Write the task and event data to the CSV file
|
|
||||||
fprintf(file, "%s, %lu, %lu, %d, %lu, %lu, %lu, %lu\n",
|
|
||||||
task->name,
|
task->name,
|
||||||
task->created,
|
task->created,
|
||||||
task->deadline,
|
task->deadline,
|
||||||
task->priority,
|
task->priority,
|
||||||
task->spare,
|
task->spare,
|
||||||
event->plannedStartTime,
|
|
||||||
event->plannedEndTime,
|
|
||||||
event->spare);
|
|
||||||
|
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +51,7 @@ void write_linkedlist_to_csv(llist* head, const char* filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
read an event csv file and write the data in a linked list
|
read a task csv file and write the data in a linked list
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void write_csv_to_llist(const char* filename) {
|
void write_csv_to_llist(const char* filename) {
|
||||||
|
@ -83,18 +76,12 @@ void write_csv_to_llist(const char* filename) {
|
||||||
char *tsakdeadline_dateSTR = strtok(NULL, ",");
|
char *tsakdeadline_dateSTR = strtok(NULL, ",");
|
||||||
char *tsakprioritySTR = strtok(NULL, ",");
|
char *tsakprioritySTR = strtok(NULL, ",");
|
||||||
char *tsakspareSTR = strtok(NULL, ",");
|
char *tsakspareSTR = strtok(NULL, ",");
|
||||||
char *eventStartTimeSTR = strtok(NULL, ",");
|
|
||||||
char *eventEndTimeSTR = strtok(NULL, ",");
|
|
||||||
char *eventSpareSTR = strtok(NULL, ",");
|
|
||||||
|
|
||||||
// convert char in integer and date
|
// convert char in integer and date
|
||||||
unsigned long int taskcreation_date = strtoul(taskcreation_dateSTR,NULL,10);
|
unsigned long int taskcreation_date = strtoul(taskcreation_dateSTR,NULL,10);
|
||||||
unsigned long int taskdeadline_date = strtoul(taskdeadline_dateSTR,NULL,10);
|
unsigned long int taskdeadline_date = strtoul(taskdeadline_dateSTR,NULL,10);
|
||||||
unsigned long int taskspare = strtoul(taskspareSTR,NULL,10);
|
unsigned long int taskspare = strtoul(taskspareSTR,NULL,10);
|
||||||
unsigned long int eventStartTime = strtoul(eventStartTimeSTR,NULL,10);
|
|
||||||
unsigned long int eventEndTime = strtoul(eventEndTimeSTR,NULL,10);
|
|
||||||
unsigned long int eventSpare = strtoul(eventSpareSTR,NULL,10);
|
|
||||||
|
|
||||||
int priority = atoi(prioritySTR);
|
int priority = atoi(prioritySTR);
|
||||||
|
|
||||||
|
|
||||||
|
@ -102,17 +89,16 @@ void write_csv_to_llist(const char* filename) {
|
||||||
//create Task
|
//create Task
|
||||||
Task *task = newTask(taskname, taskcreation_date, taskdeadline_date, taskpriority, taskspare);
|
Task *task = newTask(taskname, taskcreation_date, taskdeadline_date, taskpriority, taskspare);
|
||||||
|
|
||||||
//create Event
|
|
||||||
Event *event = newEvent(task,eventStartTime, eventEndTime, eventSpare);
|
|
||||||
|
|
||||||
// Insert task into the linked list
|
// Insert task into the linked list
|
||||||
if (list == NULL) {
|
if (list == NULL) {
|
||||||
// If the list is empty, initialize it with the first task
|
// If the list is empty, initialize it with the first task
|
||||||
list = llistNew(event, NULL);
|
list = llistNew(task, cmpTaskN);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Append the task to the linked list
|
// Append the task to the linked list
|
||||||
llistAppend(list, event);
|
llistAppend(list, task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue