minor adjustments
This commit is contained in:
parent
e12fe8d1f7
commit
3c77eb8afb
|
@ -0,0 +1,5 @@
|
|||
#include "display.c"
|
||||
|
||||
void generate_colles_v1(creneau* edt, int len_edt, int n_groups, colleur* chads, int n_chads) {
|
||||
|
||||
}
|
22
display.c
22
display.c
|
@ -238,7 +238,7 @@ void drawDateToRenderer(SDL_Renderer* renderer, date d, int X, int Y, int W, int
|
|||
drawNumberToRenderer(renderer, d.year, cX, Y, W, H, 0);
|
||||
}
|
||||
|
||||
void print_one_week(SDL_Renderer* renderer, creneau* edt, int len_creneau, date start, int w, int h, int offset_x, int offset_y) { /*
|
||||
void print_one_week(SDL_Renderer* renderer, creneau* edt, int len_creneau, date start) { /*
|
||||
1) print names
|
||||
2) print weeks
|
||||
3) print groups */
|
||||
|
@ -249,20 +249,32 @@ void print_one_week(SDL_Renderer* renderer, creneau* edt, int len_creneau, date
|
|||
|
||||
int i = 0;
|
||||
|
||||
//printf("%d \n", date_dist(start, edt[i].date));
|
||||
|
||||
// locate the specified week in edt
|
||||
while(i < len_creneau && (date_dist(start, edt[i].date) == -1)) {
|
||||
i++;
|
||||
}
|
||||
|
||||
drawStringToRenderer(renderer, "from", 10, 10, wd, ht);
|
||||
drawDateToRenderer(renderer, start, 10+5*wd, 10, wd, ht);
|
||||
drawDateToRenderer(renderer, edt[i].date, 10+5*wd, 10, wd, ht);
|
||||
|
||||
// print the corresponding week
|
||||
while(i < len_creneau && (date_dist(start, edt[i].date) < 7)) {
|
||||
printf("%d %d %d %d\n", edt[i].date.hour, edt[i].date.day, edt[i].date.month, edt[i].date.year);
|
||||
printf("Colle at [%d-%d-%d] (%dh) with group ", edt[i].date.day, edt[i].date.month, edt[i].date.year, edt[i].date.hour);
|
||||
if(edt[i].group == 0) {
|
||||
printf("NONE ");
|
||||
} else {
|
||||
printf("%d ", edt[i].group);
|
||||
}
|
||||
printf("and colleur ");
|
||||
if(str_equal(edt[i].name, "empty")) {
|
||||
printf("NONE");
|
||||
} else {
|
||||
printf("%s", edt[i].name);
|
||||
}
|
||||
printf("\n");
|
||||
i++;
|
||||
}
|
||||
|
||||
if(i < len_creneau) {
|
||||
drawStringToRenderer(renderer, "to", width/2+3*wd, 10, wd, ht);
|
||||
drawDateToRenderer(renderer, edt[i].date, width/2+5*wd, 10, wd, ht);
|
||||
|
|
133
file.txt
133
file.txt
|
@ -1,22 +1,113 @@
|
|||
18 1 1 2024
|
||||
18 2 1 2024
|
||||
13 3 1 2024
|
||||
14 3 1 2024
|
||||
15 3 1 2024
|
||||
17 3 1 2024
|
||||
17 4 1 2024
|
||||
18 4 1 2024
|
||||
16 5 1 2024
|
||||
17 5 1 2024
|
||||
18 5 1 2024
|
||||
17 7 1 2024
|
||||
18 7 1 2024
|
||||
18 8 1 2024
|
||||
14 9 1 2024
|
||||
15 9 1 2024
|
||||
16 9 1 2024
|
||||
17 10 1 2024
|
||||
18 10 1 2024
|
||||
18 11 1 2024
|
||||
|
||||
12 5 2 2024
|
||||
13 5 2 2024
|
||||
18 5 2 2024
|
||||
17 6 2 2024
|
||||
18 6 2 2024
|
||||
14 7 2 2024
|
||||
15 7 2 2024
|
||||
16 7 2 2024
|
||||
17 7 2 2024
|
||||
18 7 2 2024
|
||||
14 8 2 2024
|
||||
15 8 2 2024
|
||||
18 8 2 2024
|
||||
16 9 2 2024
|
||||
17 9 2 2024
|
||||
18 9 2 2024
|
||||
12 12 2 2024
|
||||
13 12 2 2024
|
||||
18 12 2 2024
|
||||
17 13 2 2024
|
||||
18 13 2 2024
|
||||
14 14 2 2024
|
||||
15 14 2 2024
|
||||
16 14 2 2024
|
||||
17 14 2 2024
|
||||
18 14 2 2024
|
||||
14 15 2 2024
|
||||
15 15 2 2024
|
||||
18 15 2 2024
|
||||
16 16 2 2024
|
||||
17 16 2 2024
|
||||
18 16 2 2024
|
||||
12 19 2 2024
|
||||
13 19 2 2024
|
||||
18 19 2 2024
|
||||
17 20 2 2024
|
||||
18 20 2 2024
|
||||
14 21 2 2024
|
||||
15 21 2 2024
|
||||
16 21 2 2024
|
||||
17 21 2 2024
|
||||
18 21 2 2024
|
||||
14 22 2 2024
|
||||
15 22 2 2024
|
||||
18 22 2 2024
|
||||
16 23 2 2024
|
||||
17 23 2 2024
|
||||
18 23 2 2024
|
||||
12 26 2 2024
|
||||
13 26 2 2024
|
||||
18 26 2 2024
|
||||
17 27 2 2024
|
||||
18 27 2 2024
|
||||
14 28 2 2024
|
||||
15 28 2 2024
|
||||
16 28 2 2024
|
||||
17 28 2 2024
|
||||
18 28 2 2024
|
||||
14 29 2 2024
|
||||
15 29 2 2024
|
||||
18 29 2 2024
|
||||
16 1 3 2024
|
||||
17 1 3 2024
|
||||
18 1 3 2024
|
||||
12 4 3 2024
|
||||
13 4 3 2024
|
||||
18 4 3 2024
|
||||
17 5 3 2024
|
||||
18 5 3 2024
|
||||
14 6 3 2024
|
||||
15 6 3 2024
|
||||
16 6 3 2024
|
||||
17 6 3 2024
|
||||
18 6 3 2024
|
||||
14 7 3 2024
|
||||
15 7 3 2024
|
||||
18 7 3 2024
|
||||
16 8 3 2024
|
||||
17 8 3 2024
|
||||
18 8 3 2024
|
||||
12 11 3 2024
|
||||
13 11 3 2024
|
||||
18 11 3 2024
|
||||
17 12 3 2024
|
||||
18 12 3 2024
|
||||
14 13 3 2024
|
||||
15 13 3 2024
|
||||
16 13 3 2024
|
||||
17 13 3 2024
|
||||
18 13 3 2024
|
||||
14 14 3 2024
|
||||
15 14 3 2024
|
||||
18 14 3 2024
|
||||
16 15 3 2024
|
||||
17 15 3 2024
|
||||
18 15 3 2024
|
||||
12 18 3 2024
|
||||
13 18 3 2024
|
||||
18 18 3 2024
|
||||
17 19 3 2024
|
||||
18 19 3 2024
|
||||
14 20 3 2024
|
||||
15 20 3 2024
|
||||
16 20 3 2024
|
||||
17 20 3 2024
|
||||
18 20 3 2024
|
||||
14 21 3 2024
|
||||
15 21 3 2024
|
||||
18 21 3 2024
|
||||
16 22 3 2024
|
||||
17 22 3 2024
|
||||
18 22 3 2024
|
||||
$
|
17
main.c
17
main.c
|
@ -1,4 +1,4 @@
|
|||
#include "display.c"
|
||||
#include "algorithm.c"
|
||||
|
||||
// gcc -g -Wall -Wextra -Wpedantic main.c -lSDL2 -lSDL2_image -lm -o main
|
||||
|
||||
|
@ -12,23 +12,22 @@ int main() {
|
|||
SDL_Renderer* rend = SDL_CreateRenderer(win, -1, render_flags);
|
||||
SDL_SetRenderDrawBlendMode(rend, SDL_BLENDMODE_BLEND);
|
||||
|
||||
creneau* edt = import_creneaux("file.txt", 20);
|
||||
creneau* edt = import_creneaux("file.txt", 112);
|
||||
int len_creneau = 112;
|
||||
|
||||
//printf("%d %d %d %d\n", edt[10].date.hour, edt[10].date.day, edt[10].date.month, edt[10].date.year);
|
||||
|
||||
date d1 = {17, 4, 1, 2024};
|
||||
//printf("%d %d %d %d\n", edt[0].date.hour, edt[0].date.day, edt[0].date.month, edt[0].date.year);
|
||||
date d1 = {17, 1, 3, 2024};
|
||||
//printf("%d %d %d %d\n", edt[70].date.hour, edt[70].date.day, edt[70].date.month, edt[70].date.year);
|
||||
|
||||
print_one_week(rend, edt, 20, d1, 10, 10, 10, 10);
|
||||
|
||||
print_one_week(rend, edt, 112, d1);
|
||||
|
||||
/*
|
||||
date d1 = {19, 20, 2, 2023};
|
||||
date d2 = {18, 3, 4, 2023};
|
||||
date d1 = {19, 1, 3, 2024};
|
||||
date d2 = {18, 1, 4, 2024};
|
||||
|
||||
printf("%d\n", date_dist(d1, d2));
|
||||
*/
|
||||
|
||||
|
||||
SDL_DestroyRenderer(rend);
|
||||
SDL_DestroyWindow(win);
|
||||
|
|
32
structure.c
32
structure.c
|
@ -7,14 +7,14 @@
|
|||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
typedef enum topic {MATH, PHYSICS, ENGLISH, FRENCH, INFO} topic;
|
||||
typedef enum topic {NOTHING, MATH, PHYSICS, ENGLISH, FRENCH, INFO} topic;
|
||||
// colles subjects
|
||||
|
||||
typedef struct date {int hour; int day; int month; int year;} date;
|
||||
// nothing to say here
|
||||
|
||||
typedef struct creneau {date date; int group; char* name; topic mat;} creneau;
|
||||
// créneau de colle
|
||||
// one créneau de colle
|
||||
// /!\ creneau has to be sorted by ascending dates
|
||||
|
||||
typedef struct colleur {char* name; topic mat; date* disp; int n_disp;} colleur;
|
||||
|
@ -57,6 +57,17 @@ int date_dist(date d1, date d2) {
|
|||
}
|
||||
}
|
||||
|
||||
bool is_sorted(creneau* edt, int len) {
|
||||
for(int i = 1; i < len; i++) {
|
||||
if(date_dist(edt[i-1].date, edt[i].date) == -1) {
|
||||
printf("Anomaly detected at lane %d (dates are not sorted in ascending order)\n", i);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
printf("No problem detected\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
creneau* import_creneaux(char* filename, int size) {
|
||||
// import creneau data from a file
|
||||
// see file.txt for an example
|
||||
|
@ -76,6 +87,9 @@ creneau* import_creneaux(char* filename, int size) {
|
|||
} else {
|
||||
if(to_fill == 0) {
|
||||
edt[i].date.hour = buffer;
|
||||
edt[i].group = 0;
|
||||
edt[i].name = "empty";
|
||||
edt[i].mat = NOTHING;
|
||||
} else if(to_fill == 1) {
|
||||
edt[i].date.day = buffer;
|
||||
} else if(to_fill == 2) {
|
||||
|
@ -94,5 +108,19 @@ creneau* import_creneaux(char* filename, int size) {
|
|||
}
|
||||
|
||||
fclose(ptr);
|
||||
|
||||
if(!is_sorted(edt, size)) {
|
||||
assert(0);
|
||||
}
|
||||
return edt;
|
||||
}
|
||||
|
||||
bool str_equal(char* s1, char* s2) {
|
||||
// note : s1 and s2 must be valid strings (aka have (int)(0) at the end)
|
||||
if((int)(s1[0]) == 0 || (int)(s2[0]) == 0) {
|
||||
return ((int)(s1[0]) == 0 && (int)(s2[0]) == 0);
|
||||
} else if(s1[0] != s2[0]) {
|
||||
return false;
|
||||
}
|
||||
return str_equal(&s1[1], &s2[1]);
|
||||
}
|
Loading…
Reference in New Issue