<commit_before>//
//  NavigationResolver.swift
//  Eurofurence
//
//  Copyright © 2017 Eurofurence. All rights reserved.
//

import Foundation

class NavigationResolver: NavigationResolverProtocol {
	func resolve(dataContext: DataContextProtocol) {
		var linkFragments: [LinkFragment] = []

		print("\(#function): Resolving Dealers")
		dataContext.Dealers.modify({ value in
			for e in value {
				e.ArtistImage = dataContext.Images.value.first(where: { $0.Id == e.ArtistImageId })
				e.ArtistThumbnailImage = dataContext.Images.value.first(where: { $0.Id == e.ArtistThumbnailImageId })
				e.ArtPreviewImage = dataContext.Images.value.first(where: { $0.Id == e.ArtPreviewImageId })

				linkFragments.append(contentsOf: e.Links)
			}
		})

		print("\(#function): Resolving EventConferenceDays")
		dataContext.EventConferenceDays.modify({ value in
			for e in value {
				e.Events.removeAll()
			}
		})
		print("\(#function): Resolving EventConferenceRooms")
		dataContext.EventConferenceRooms.modify({ value in
			for e in value {
				e.Events.removeAll()
			}
		})
		print("\(#function): Resolving EventConferenceTracks")
		dataContext.EventConferenceTracks.modify({ value in
			for e in value {
				e.Events.removeAll()
			}
		})
		print("\(#function): Resolving Events")
		dataContext.Events.modify({ value in
			for e in value {
				e.BannerImage = dataContext.Images.value.first(where: { $0.Id == e.BannerImageId })
				e.PosterImage = dataContext.Images.value.first(where: { $0.Id == e.PosterImageId })

				e.ConferenceDay = dataContext.EventConferenceDays.value.first(where: { $0.Id == e.ConferenceDayId })
				e.ConferenceRoom = dataContext.EventConferenceRooms.value.first(where: { $0.Id == e.ConferenceRoomId })
				e.ConferenceTrack = dataContext.EventConferenceTracks.value.first(where: { $0.Id == e.ConferenceTrackId })

				e.ConferenceDay?.Events.append(e)
				e.ConferenceRoom?.Events.append(e)
				e.ConferenceTrack?.Events.append(e)
			}
		})

		print("\(#function): Resolving KnowledgeGroups")
		dataContext.KnowledgeGroups.modify({ value in
			for e in value {
				e.KnowledgeEntries.removeAll()
			}
		})
		print("\(#function): Resolving KnowledgeEntries")
		dataContext.KnowledgeEntries.modify({ value in
			for e in value {
				e.KnowledgeGroup = dataContext.KnowledgeGroups.value.first(where: { $0.Id == e.KnowledgeGroupId })
				e.KnowledgeGroup?.KnowledgeEntries.append(e)

				if !e.ImageIds.isEmpty {
					let images = dataContext.Images.value.filter({e.ImageIds.contains($0.Id)})
					if !images.isEmpty {<commit_msg>Resolve connection between EventFavorite and Event entities #10<commit_after>//
//  NavigationResolver.swift
//  Eurofurence
//
//  Copyright © 2017 Eurofurence. All rights reserved.
//

import Foundation

class NavigationResolver: NavigationResolverProtocol {
	func resolve(dataContext: DataContextProtocol) {
		var linkFragments: [LinkFragment] = []

		print("\(#function): Resolving Dealers")
		dataContext.Dealers.modify({ value in
			for e in value {
				e.ArtistImage = dataContext.Images.value.first(where: { $0.Id == e.ArtistImageId })
				e.ArtistThumbnailImage = dataContext.Images.value.first(where: { $0.Id == e.ArtistThumbnailImageId })
				e.ArtPreviewImage = dataContext.Images.value.first(where: { $0.Id == e.ArtPreviewImageId })

				linkFragments.append(contentsOf: e.Links)
			}
		})

		print("\(#function): Resolving EventConferenceDays")
		dataContext.EventConferenceDays.modify({ value in
			for e in value {
				e.Events.removeAll()
			}
		})
		print("\(#function): Resolving EventConferenceRooms")
		dataContext.EventConferenceRooms.modify({ value in
			for e in value {
				e.Events.removeAll()
			}
		})
		print("\(#function): Resolving EventConferenceTracks")
		dataContext.EventConferenceTracks.modify({ value in
			for e in value {
				e.Events.removeAll()
			}
		})
		print("\(#function): Resolving Events")
		var eventFavorites: [EventFavorite] = []
		dataContext.Events.modify({ value in
			for e in value {
				e.BannerImage = dataContext.Images.value.first(where: { $0.Id == e.BannerImageId })
				e.PosterImage = dataContext.Images.value.first(where: { $0.Id == e.PosterImageId })

				e.ConferenceDay = dataContext.EventConferenceDays.value.first(where: { $0.Id == e.ConferenceDayId })
				e.ConferenceRoom = dataContext.EventConferenceRooms.value.first(where: { $0.Id == e.ConferenceRoomId })
				e.ConferenceTrack = dataContext.EventConferenceTracks.value.first(where: { $0.Id == e.ConferenceTrackId })

				e.ConferenceDay?.Events.append(e)
				e.ConferenceRoom?.Events.append(e)
				e.ConferenceTrack?.Events.append(e)

				e._EventFavorite = dataContext.EventFavorites.value.first(where: { $0.EventId == e.Id })
				if let eventFavorite = e._EventFavorite {
					eventFavorites.append(eventFavorite)
				} else {
					let eventFavorite = EventFavorite(for: e)
					e._EventFavorite = eventFavorite
					dataContext.EventFavorites.value.append(eventFavorite)
					eventFavorites.append(eventFavorite)
				}
			}
		})
		dataContext.EventFavorites.swap(eventFavorites)

		print("\(#function): Resolving KnowledgeGroups")
		dataContext.KnowledgeGroups.modify({ value in
			for e in value {
				e.KnowledgeEntries.removeAll()
			}
		})
		print("\(#function): Resolving KnowledgeEntries")
		dataContext.KnowledgeEntries.modify({ value in
			for e in value {
				e.KnowledgeGroup = dataContext.KnowledgeGroups.value.first(where: { $0.Id == e.KnowledgeGroupId })
				e.KnowledgeGroup?.KnowledgeEntries.append(e)

				if !e.ImageIds.isEmpty {
					let images = dataContext.Images.value.filter({e.ImageIds.contains($0.Id)})
					if !images.isEmpty {
{'fraction_non_alphanumeric': 0.13235032865517854, 'fraction_numerical': 0.005507194883638301, 'mean_word_length': 4.0, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5099050', 'n_tokens_mistral': 2146, 'n_tokens_neox': 1824, 'n_words': 317}