43 #define XXX_HACK_MAX_CATEGORIES 32
55 static struct timetable_aggregate_entry *
56 find_aggregate_category(
struct timetable_aggregate *a,
62 for(i = 0; i < a->ptr; ++i) {
63 acat = (a->entries[i].id[0] << 8) + a->entries[i].id[1];
66 return &a->entries[i];
74 a->entries[a->ptr].id =
NULL;
75 return &a->entries[a->ptr++];
83 static struct timetable_aggregate_entry *
84 find_aggregate(
struct timetable_aggregate *a,
88 for(i = 0; i < a->ptr; ++i) {
89 if(a->entries[i].id ==
id) {
90 return &a->entries[i];
96 a->entries[a->ptr].id =
NULL;
97 return &a->entries[a->ptr++];
101 timetable_aggregate_print_detailed(
struct timetable_aggregate *a)
105 for(i = 0; i < a->ptr; ++i) {
106 printf(
"-- %s: %lu / %u = %lu\n", a->entries[i].id,
108 a->entries[i].episodes,
109 a->entries[i].time / a->entries[i].episodes);
112 printf(
"Memory for entries: %d * %d = %d\n",
113 (
int)
sizeof(
struct timetable_aggregate), a->ptr,
114 (
int)
sizeof(
struct timetable_aggregate) * a->ptr);
118 timetable_aggregate_reset(
struct timetable_aggregate *a)
121 for(i = 0; i < a->ptr; ++i) {
122 a->entries[i].time = 0;
123 a->entries[i].episodes = 0;
128 timetable_aggregate_print_categories(
struct timetable_aggregate *a)
133 for(i = 0; i < a->ptr; ++i) {
134 printf(
"-- %c%c: %lu / %u = %lu\n",
135 a->entries[i].id[0], a->entries[i].id[1],
137 a->entries[i].episodes,
138 a->entries[i].time / a->entries[i].episodes);
141 printf(
"Memory for entries: %d * %d = %d\n",
142 (
int)
sizeof(
struct timetable_aggregate), a->ptr,
143 (
int)
sizeof(
struct timetable_aggregate) * a->ptr);
147 timetable_aggregate_compute_detailed(
struct timetable_aggregate *a,
148 struct timetable *timetable)
153 t = timetable->timestamps[0].time;
155 for(i = 1; i < *timetable->ptr; ++i) {
156 struct timetable_aggregate_entry *
entry;
157 entry = find_aggregate(a, timetable->timestamps[i - 1].id);
161 }
else if(entry->id ==
NULL) {
163 entry->id = timetable->timestamps[i - 1].id;
164 entry->time = (
unsigned long)(timetable->timestamps[i].time - t -
169 entry->time += (
unsigned long)(timetable->timestamps[i].time - t -
173 t = timetable->timestamps[i].time;
179 timetable_aggregate_compute_categories(
struct timetable_aggregate *a,
180 struct timetable *timetable)
185 uint16_t categories[XXX_HACK_MAX_CATEGORIES];
186 int categories_ptr = 0;
188 t = timetable->timestamps[0].time;
190 for(i = 1; i < *timetable->ptr; ++i) {
191 struct timetable_aggregate_entry *
entry;
196 cat = (timetable->timestamps[i - 1].id[0] << 8) +
197 (timetable->timestamps[i - 1].id[1] & 0xff);
198 entry = find_aggregate_category(a, cat);
202 }
else if(entry->id ==
NULL) {
204 entry->id = timetable->timestamps[i - 1].id;
205 entry->time = (
unsigned long)(timetable->timestamps[i].time - t -
213 entry->time += (
unsigned long)(timetable->timestamps[i].time - t -
226 for(j = 0; j < categories_ptr; ++j) {
227 if(categories[j] == cat) {
231 if(j == categories_ptr) {
237 t = timetable->timestamps[i].time;