<commit_before>//
//  VenueTableCell.swift
//  PartyUP
//
//  Created by <NAME> on 2015-12-29.
//  Copyright © 2015 Sandcastle Application Development. All rights reserved.
//

import UIKit

class VenueTableCell: UITableViewCell {

    @IBOutlet weak var vitalityDot: UILabel!
	@IBOutlet weak private var venueLabel: UILabel!
	@IBOutlet weak private var detailLabel: UILabel!
	@IBOutlet weak private var vitalityLabel: UILabel!

	var venue: Venue? {
		willSet {
			NSNotificationCenter.defaultCenter().removeObserver(self)
		}

		didSet {
			if let venue = venue {
				let nc = NSNotificationCenter.defaultCenter()
				nc.addObserver(self, selector: Selector("updateVitalityDisplay"), name: Venue.VitalityUpdateNotification, object: venue)
				nc.addObserver(self, selector: Selector("updatePromotionalMaterial"), name: Venue.PromotionUpdateNotification, object: venue)
				venueLabel.text = venue.name ?? NSLocalizedString("Mysterious Venue", comment: "Default in cell when venue name is nil")
				updateVitalityDisplay()
				updatePromotionalMaterial()
			}
		}
	}

	func updatePromotionalMaterial() {
		detailLabel.text = venue?.promotion?.tagline
	}

	func updateVitalityDisplay() {
		if let venue = venue {
			var vitality = ""
			switch venue.vitality {
			case 0:
				vitality = "🎈"
			case 1...5:
				vitality = "💃🏻"
			default:
				vitality = "🔥"
			}

			vitalityDot.text = vitality
			updateVitalityTime()
		}
	}

	func updateVitalityTime() {
		if let time = venue?.samples?.first?.time, calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian) {
			let components = calendar.components([NSCalendarUnit.Hour, NSCalendarUnit.Minute],
				fromDate: time,
				toDate: NSDate(),
				options: [])

			vitalityLabel.text = components.hour > 0 ? "\(components.hour)h" : components.minute > 0 ? "\(components.minute)m" : "<1m"
		} else {<commit_msg>Play with background colouring of promoted venues.<commit_after>//
//  VenueTableCell.swift
//  PartyUP
//
//  Created by <NAME> on 2015-12-29.
//  Copyright © 2015 Sandcastle Application Development. All rights reserved.
//

import UIKit

class VenueTableCell: UITableViewCell {

    @IBOutlet weak var vitalityDot: UILabel!
	@IBOutlet weak private var venueLabel: UILabel!
	@IBOutlet weak private var detailLabel: UILabel!
	@IBOutlet weak private var vitalityLabel: UILabel!

	var venue: Venue? {
		willSet {
			NSNotificationCenter.defaultCenter().removeObserver(self)
		}

		didSet {
			if let venue = venue {
				let nc = NSNotificationCenter.defaultCenter()
				nc.addObserver(self, selector: Selector("updateVitalityDisplay"), name: Venue.VitalityUpdateNotification, object: venue)
				nc.addObserver(self, selector: Selector("updatePromotionalMaterial"), name: Venue.PromotionUpdateNotification, object: venue)
				venueLabel.text = venue.name ?? NSLocalizedString("Mysterious Venue", comment: "Default in cell when venue name is nil")
				updateVitalityDisplay()
				updatePromotionalMaterial()
			}
		}
	}

	func updatePromotionalMaterial() {
		detailLabel.text = venue?.promotion?.tagline
		switch venue?.promotion?.placement {
		case .Some(2):
			contentView.backgroundColor = UIColor.redColor()
		case .Some(1):
			contentView.backgroundColor = UIColor.orangeColor()
		default:
			contentView.backgroundColor = UIColor.whiteColor()
		}
		
	}

	func updateVitalityDisplay() {
		if let venue = venue {
			var vitality = ""
			switch venue.vitality {
			case 0:
				vitality = "🎈"
			case 1...5:
				vitality = "💃🏻"
			default:
				vitality = "🔥"
			}

			vitalityDot.text = vitality
			updateVitalityTime()
		}
	}

	func updateVitalityTime() {
		if let time = venue?.samples?.first?.time, calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian) {
			let components = calendar.components([NSCalendarUnit.Hour, NSCalendarUnit.Minute],
				fromDate: time,
				toDate: NSDate(),
				options: [])

			vitalityLabel.text = components.hour > 0 ? "\(components.hour)h" : components.minute > 0 ? "\(components.minute)m" : "<1m"
		} else {
{'fraction_non_alphanumeric': 0.11403726708074534, 'fraction_numerical': 0.009440993788819876, 'mean_word_length': 3.9950372208436726, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1852460', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1270, 'n_words': 303}