Skip to content

Commit

Permalink
- fixed code to remove outdated values from schedule forecast
Browse files Browse the repository at this point in the history
- append end event to schedules

Signed-off-by: Michael Zillgith <[email protected]>
  • Loading branch information
mzillgith committed Jan 18, 2024
1 parent e88adc7 commit 7ef6ecd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
43 changes: 41 additions & 2 deletions src/scheduler/schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2076,6 +2076,13 @@ Schedule_runSchedule(Schedule self, uint64_t startTime, uint64_t endTime)

scheduleEvents = LinkedList_create();

char valBuf[100];
valBuf[0] = 0;

if (curValue->mmsValue) {
MmsValue_printToBuffer(curValue->mmsValue, valBuf, 100);
}

ScheduleEvent event = ScheduleEvent_create(currentTime, MmsValue_clone(curValue->mmsValue), priority, self->startTime);

LinkedList_add(scheduleEvents, event);
Expand All @@ -2087,16 +2094,32 @@ Schedule_runSchedule(Schedule self, uint64_t startTime, uint64_t endTime)

uint64_t currentStrTm = schedule_getCurrentStartTime(self);

for (int i = idx + 1; i < noOfEntryValues; i++)
int i = 0;

for (i = idx + 1; i < noOfEntryValues; i++)
{
uint64_t eventTime = currentStrTm + (i * intvInMs);

MmsValue* eventValue = Schedule_getValueWithIdx(self, i);

char valBuf[100];
valBuf[0] = 0;

if (eventValue) {
MmsValue_printToBuffer(eventValue, valBuf, 100);
}

event = ScheduleEvent_create(eventTime, MmsValue_clone(eventValue), priority, currentStrTm);

LinkedList_add(scheduleEvents, event);
}

/* add end event */
uint64_t eventTime = currentStrTm + (i * intvInMs);

event = ScheduleEvent_create(eventTime, NULL, priority, currentStrTm);

LinkedList_add(scheduleEvents, event);
}
else
{
Expand Down Expand Up @@ -2126,16 +2149,32 @@ Schedule_runSchedule(Schedule self, uint64_t startTime, uint64_t endTime)

LinkedList_add(scheduleEvents, event);

for (int i = 1; i < noOfEntryValues; i++)
int i = 0;

for (i = 1; i < noOfEntryValues; i++)
{
uint64_t eventTime = nextStrTm + (i * intvInMs);

MmsValue* eventValue = Schedule_getValueWithIdx(self, i);

char valBuf[100];
valBuf[0] = 0;

if (eventValue) {
MmsValue_printToBuffer(eventValue, valBuf, 100);
}

event = ScheduleEvent_create(eventTime, MmsValue_clone(eventValue), priority, nextStrTm);

LinkedList_add(scheduleEvents, event);
}

/* add end event */
uint64_t eventTime = nextStrTm + (i * intvInMs);

event = ScheduleEvent_create(eventTime, NULL, priority, nextStrTm);

LinkedList_add(scheduleEvents, event);
}
}

Expand Down
15 changes: 11 additions & 4 deletions src/scheduler/schedule_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -844,13 +844,10 @@ ScheduleController_createForecast(ScheduleController self, uint64_t startTime, u

/* remove outdated values (values in the past that are no longer active)*/
int curIdx = 0;
while (tsList[curIdx] <= currentTime) {
while (tsList[curIdx] < startTime) {
curIdx++;
}

if (curIdx > 0)
curIdx--;

/* create the result schedule */
resultSchedule = LinkedList_create();

Expand All @@ -862,6 +859,8 @@ ScheduleController_createForecast(ScheduleController self, uint64_t startTime, u

ScheduleEvent currentEvent = NULL;

//printf("Calculate value for ts %lu\n", tsList[i]);

while (schedulesElem)
{
Schedule sched = (Schedule)LinkedList_getData(schedulesElem);
Expand All @@ -872,6 +871,12 @@ ScheduleController_createForecast(ScheduleController self, uint64_t startTime, u
{
if (event->value)
{
char val[200];

MmsValue_printToBuffer(event->value, val, 200);

//printf(" %s: %s\n", sched->scheduleLn->name, val);

if (currentEvent == NULL) {
currentEvent = event;
}
Expand All @@ -896,6 +901,8 @@ ScheduleController_createForecast(ScheduleController self, uint64_t startTime, u
}
}
else {
// printf(" %s: no value\n", sched->scheduleLn->name);

ScheduleEvent_destroy(event);
}
}
Expand Down

0 comments on commit 7ef6ecd

Please sign in to comment.