def map_event_section(events, patterns, text = "\n"):
	"""
		Map each event to a section in the text. Sections are provided by patterns.
	"""
	def make_event_data(pad, revs, event, args = ()):
		return pad, revs, event, args

	for event_data in events:
		pad, revs, event, data = make_event_data(*event_data)
		event_changeset = text_events.parse_event_changeset(event[u'changeset'])

		text, changes, new_changes = text_events.text_apply_event(text, event_changeset)

		range_sections = []

		for start, end, section in make_sections_mapping(patterns, text):
			for change_start, change_end in new_changes:
				if start <= change_start < end or start < change_end <= end:
					if section and (start, end, section) not in range_sections:
						range_sections.append((start, end, section))

		sections = []

		for s_start, s_end, s_section in range_sections:
			for e_start, e_end, e_section in range_sections:
				if s_section != e_section and s_start <= e_start and e_end <= s_end:
					if e_end - e_start < s_end - s_start:
						break
			else:
				sections.append(s_section[-1]) # get only last part

		(section,) = sections if len(sections) == 1 else (None,)

		yield pad, revs, event, data + (section,)
def make_events(events):
	"""
		Make event objects from the raw event data. Event gets it own changeset,
		case and section mappings, bindings with texts before and after the event.

		Changeset is a list of operations parsed from event changeset text, timestamp is converted to seconds.
	"""
	for pad, revision, data, (case, section) in events:
		timestamp = data[u'meta'][u'timestamp'] / 1000
		author = data[u'meta'][u'author']
		changeset = data[u'changeset']

		changeset_data = text_events.parse_event_changeset(changeset)

		event = Event(pad, revision, timestamp, author, changeset, changeset_data)
		event.case = case
		event.section = section

		yield event
Exemple #3
0
def map_event_section(events, patterns, text="\n"):
    """
		Map each event to a section in the text. Sections are provided by patterns.
	"""
    def make_event_data(pad, revs, event, args=()):
        return pad, revs, event, args

    for event_data in events:
        pad, revs, event, data = make_event_data(*event_data)
        event_changeset = text_events.parse_event_changeset(
            event[u'changeset'])

        text, changes, new_changes = text_events.text_apply_event(
            text, event_changeset)

        range_sections = []

        for start, end, section in make_sections_mapping(patterns, text):
            for change_start, change_end in new_changes:
                if start <= change_start < end or start < change_end <= end:
                    if section and (start, end, section) not in range_sections:
                        range_sections.append((start, end, section))

        sections = []

        for s_start, s_end, s_section in range_sections:
            for e_start, e_end, e_section in range_sections:
                if s_section != e_section and s_start <= e_start and e_end <= s_end:
                    if e_end - e_start < s_end - s_start:
                        break
            else:
                sections.append(s_section[-1])  # get only last part

        (section, ) = sections if len(sections) == 1 else (None, )

        yield pad, revs, event, data + (section, )