Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ical processing: first event in event list ignored #451

Closed
andiempettJISC opened this issue Dec 9, 2016 · 13 comments
Closed

Ical processing: first event in event list ignored #451

andiempettJISC opened this issue Dec 9, 2016 · 13 comments
Assignees
Labels
Milestone

Comments

@andiempettJISC
Copy link
Collaborator

relates to work done for #384 and #443
in the ical util, function get_events_from_string_ical(ical_data, limit=0) has, what i make out as superfluous code added to it using a counter count.
the behaviour of this function is changed to add a limit, which is a great idea but the counter being used to define how many events are used from the ical stops the zeroth event in the events list being picked up.
this becomes a problem when using the checkrepo plugin.

i propose a pull request changing from:

count = 0

def get_events_from_string_ical(ical_data, limit=0):
    global count
    # See https://github.com/collective/icalendar#api-change
    f = getattr(Calendar, 'from_ical', getattr(Calendar, 'from_string', None))
    cal = f(ical_data)
    if limit > 0:
	events = cal.walk('vevent')[count:limit+count]
	for event in events:
	    if event['DTSTART'].dt.replace(tzinfo=None) < datetime.utcnow():
	        count += 1
	if count > 0:
	    events = cal.walk('vevent')[count:limit+count]
    else:
	events = cal.walk('vevent')
    return events

to:

def get_events_from_string_ical(ical_data, limit=0):
    # See https://github.com/collective/icalendar#api-change
    f = getattr(Calendar, 'from_ical', getattr(Calendar, 'from_string', None))
    cal = f(ical_data)
    if limit > 0:
	events = cal.walk('vevent')[0:limit]
	print events
    else:
	events = cal.walk('vevent')
    return events

let me know if i'm missing something.
thanks
-andy

andiempettJISC pushed a commit to UoM-Podcast/Galicaster that referenced this issue Dec 9, 2016
@Alfro
Copy link
Contributor

Alfro commented Dec 12, 2016

@androidwiltron I think I know what the issue is. It's not simply that the zeroth element is not being picked up.

I think the intention behind the changes added in #384 was to prevent the get_events_from_string_ical function from returning events that are already over. However, since the function compares the current date with the beginning date of the event, an ongoing event will be filtered out.

@Alfro
Copy link
Contributor

Alfro commented Dec 12, 2016

Reverting the changes would fix that, but it would reintroduce the #384 issue.

@andiempettJISC
Copy link
Collaborator Author

andiempettJISC commented Dec 12, 2016 via email

andiempettJISC pushed a commit to UoM-Podcast/Galicaster that referenced this issue Jan 4, 2017
@andiempettJISC
Copy link
Collaborator Author

andiempettJISC commented Jan 4, 2017

hi

how about this:

count = 0

def get_events_from_string_ical(ical_data, limit=0):
    global count
    # See https://github.com/collective/icalendar#api-change
    f = getattr(Calendar, 'from_ical', getattr(Calendar, 'from_string', None))
    cal = f(ical_data)
    if limit > 0:
        events = cal.walk('vevent')[count:limit + count]
        for event in events:
            if event['DTSTART'].dt.replace(tzinfo=None) < datetime.utcnow():
                count += 1
        count -= 1
        if count > 0:
            events = cal.walk('vevent')[count:limit + count]
    else:
        events = cal.walk('vevent')
    return events

all i've added is count -=1 this makes sure the correct range is passed to the cal.walk.

does this look right?
-andy

@Alfro
Copy link
Contributor

Alfro commented Jan 6, 2017

That would return the correct range when there is an ongoing event, but an extra finished event when not.
Instead, I would change the following if statement:

if event['DTSTART'].dt.replace(tzinfo=None) < datetime.utcnow():
    count += 1

to check against the END time of the event before skipping it instead of the start, this way ongoing events will still be listed.

I don't remember the event data structure by heart, but if there is no "DTEND", it could be computed adding the "DTSTART" and the "DURATION" of the event.

@andiempettJISC
Copy link
Collaborator Author

andiempettJISC commented Jan 6, 2017 via email

@Alfro Alfro self-assigned this Jan 16, 2017
@Alfro Alfro added the bug label Jan 16, 2017
@Alfro Alfro added this to the 2.0.0 milestone Jan 16, 2017
@dpeite dpeite modified the milestones: 2.0.1, 2.0.0 Feb 10, 2017
@Alfro
Copy link
Contributor

Alfro commented Mar 21, 2017

@androidwiltron Hi! Could you take a look at this?

@andiempettJISC
Copy link
Collaborator Author

this is the best i've gotten so far. I think this ensures the correct count is returned to be used filtering cal.walk('vevent')


count = 0

def get_events_from_string_ical(ical_data, limit=0):
    global count
    # See https://github.com/collective/icalendar#api-change
    f = getattr(Calendar, 'from_ical', getattr(Calendar, 'from_string', None))
    cal = f(ical_data)
    if limit > 0:
        events = cal.walk('vevent')[count:limit + count]
        for event in events:
            if event['DTSTART'].dt.replace(tzinfo=None) < datetime.utcnow():
                count += 1
        count -= 1
        if count > 0:
            events = cal.walk('vevent')[count:limit + count]
    else:
        events = cal.walk('vevent')
    # reset the counter
    count = 0
    return events

it also resets the count to stop the count persisting between long heartbeats

Alfro added a commit that referenced this issue Apr 17, 2017
This will allow get_events_from_string_ical() to return an 'ongoing' event
dpeite added a commit that referenced this issue May 30, 2017
Also decrease the number of files opened #441
Alfro added a commit that referenced this issue May 30, 2017
Added __del__ in recorder to remove bus_signal_watch #451
@smarquard
Copy link

Why not just declare count inside the function and set it to 0 at the top, as it's only used in that function?

Also I don't understand the count -= 1 in the @androidwiltron code snippet above?

@smarquard
Copy link

The logic of this seems to be flawed, because Opencast (certainly in 4.x) can return in the iCal feed:

  • events that have passed
  • events in any order

So you can have an ical with:

new event
old event

(rather than the expected old event, new event).

In this case, the filtering will set count=1 and then get the old event and not the new event. You could also have old events in the middle of a list.

So unless Opencast changes to return events strictly in order (and preferably exclude old events), there's no safe way to restrict to a limit.

@smarquard
Copy link

Related #569

smarquard added a commit to cilt-uct/Galicaster that referenced this issue Jan 11, 2018
Ignore the limit parameter: see teltek#451
dpeite added a commit that referenced this issue Feb 15, 2018
@Alfro
Copy link
Contributor

Alfro commented Aug 24, 2018

Doing some clean-up on issues. This issue was not updated, but I did a major refactor of this logic on the 2.1.x branch. It now loops over all events, filter past events out and sort them, then return all of them, or a number of them, if there's a limit set.

I think this issue should be fixed now, but please feel free to reopen if there are more things I might have missed.

@Alfro Alfro closed this as completed Aug 24, 2018
@mliradelc
Copy link

Hi Alfonso, Here at Uni Köln we still have problems with the Galicaster Scheduling. We found this problem only occurs "sometimes" so it's very difficult to track it.

We think that this is happening when the event is modified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants