<commit_before>//
//  FeedItemFetchedResultsController.swift
//  MAGE
//
//  Created by <NAME> on 6/15/20.
//  Copyright © 2020 National Geospatial Intelligence Agency. All rights reserved.
//

import Foundation
import Kingfisher

extension UIImage {
    
    func colorized(color : UIColor) -> UIImage {
        let rect = CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height);
        UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0);
        let context = UIGraphicsGetCurrentContext();
        context!.translateBy(x: 0, y: self.size.height);
        context!.scaleBy(x: 1.0, y: -1.0);
        context!.draw(self.cgImage!, in: rect);
        context!.clip(to: rect, mask: self.cgImage!);
        context?.setFillColor(color.cgColor);
        context?.fill(rect);
        let colorizedImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return colorizedImage!;
    }
}

@objc protocol FeedItemDelegate {

    @objc func addFeedItem(feedItem: FeedItem);
    @objc func removeFeedItem(feedItem: FeedItem);

}

@objc class FeedItemRetriever : NSObject {
    
    @objc public static func setAnnotationImage(feedItem: FeedItem, annotationView: MKAnnotationView) {
        if let url: URL = feedItem.iconURL {
            let size = 24;
            
            let processor = DownsamplingImageProcessor(size: CGSize(width: size, height: size))
            KingfisherManager.shared.retrieveImage(with: url, options: [
                .processor(processor),
                .scaleFactor(UIScreen.main.scale),
                .transition(.fade(1)),
                .cacheOriginalImage
            ]) { result in
                switch result {
                case .success(let value):
                    
                    let image: UIImage = value.image.resized(to: CGSize(width: size, height: size));
                    annotationView.image = image;
                case .failure(_):
                    annotationView.image = UIImage.init(named: "observations")?.withRenderingMode(.alwaysTemplate).colorized(color: UIColor.mageBlue());
                }
            }
        } else {
            annotationView.image = UIImage.init(named: "observations")?.withRenderingMode(.alwaysTemplate).colorized(color: UIColor.mageBlue());
        }
    }
    <commit_msg>add the access token to feed icon retrieval<commit_after>//
//  FeedItemFetchedResultsController.swift
//  MAGE
//
//  Created by <NAME> on 6/15/20.
//  Copyright © 2020 National Geospatial Intelligence Agency. All rights reserved.
//

import Foundation
import Kingfisher

extension UIImage {
    
    func colorized(color : UIColor) -> UIImage {
        let rect = CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height);
        UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0);
        let context = UIGraphicsGetCurrentContext();
        context!.translateBy(x: 0, y: self.size.height);
        context!.scaleBy(x: 1.0, y: -1.0);
        context!.draw(self.cgImage!, in: rect);
        context!.clip(to: rect, mask: self.cgImage!);
        context?.setFillColor(color.cgColor);
        context?.fill(rect);
        let colorizedImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return colorizedImage!;
    }
}

@objc protocol FeedItemDelegate {

    @objc func addFeedItem(feedItem: FeedItem);
    @objc func removeFeedItem(feedItem: FeedItem);

}

@objc class FeedItemRetriever : NSObject {
    
    @objc public static func setAnnotationImage(feedItem: FeedItem, annotationView: MKAnnotationView) {
        if let url: URL = feedItem.iconURL {
            let size = 24;
            
            let processor = DownsamplingImageProcessor(size: CGSize(width: size, height: size))
            KingfisherManager.shared.retrieveImage(with: url, options: [
                .requestModifier(ImageCacheProvider.shared.accessTokenModifier),
                .processor(processor),
                .scaleFactor(UIScreen.main.scale),
                .transition(.fade(1)),
                .cacheOriginalImage
            ]) { result in
                switch result {
                case .success(let value):
                    
                    let image: UIImage = value.image.resized(to: CGSize(width: size, height: size));
                    annotationView.image = image;
                case .failure(_):
                    annotationView.image = UIImage.init(named: "observations")?.withRenderingMode(.alwaysTemplate).colorized(color: UIColor.mageBlue());
                }
            }
        } else {
            annotationView.image = UIImage.init(named: "observations")?.withRenderingMode(.alwaysTemplate).colorized(color: UIColor.mageBlue());
        }
    }
    
{'fraction_non_alphanumeric': 0.10969760166840459, 'fraction_numerical': 0.008759124087591242, 'mean_word_length': 2.3213296398891967, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '7298919', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1323, 'n_words': 288}