<commit_before>//
//  StoresDataStruct.swift
//  BlackNectar
//
//  Created by <NAME> on 11/19/16.
//  Copyright © 2017 BlackSource. All rights reserved.
//

import Archeota
import CoreLocation
import Foundation
import UIKit

// Creates data structure for JSON Request
struct Store {
    
    let storeID: String
    let storeName: String
    let location: CLLocationCoordinate2D
    let address: Address
    let storeImage: URL?
    let isFarmersMarket: Bool
    
    var notFarmersMarket: Bool { return !isFarmersMarket }
    
    static func getStoreJsonData(from storeDictionary: NSDictionary) -> Store? {
        
        return Store(json: storeDictionary)
    }
    
}

extension Store {
    
    init?(json: NSDictionary) {
        
        let storeImageString = json ["main_image_url"] as? String
        
        if storeImageString == nil {

            storeImageURL = URL(string:"https://s3.amazonaws.com/ODNUploads/5404f487678f1532dfdbcc6479placeholder_food_item_2.png")
        }
        else {
            
            storeImageURL = URL(string: storeImageString ?? "")
        }
        
        guard let storeID = json ["store_id"] as? String,
            let storeName = json ["store_name"] as? String,
            let addressJSON = json ["address"] as? NSDictionary
            else {
                
                LOG.error("Failed to parse Store: \(json)")
                return nil
        }
        
        guard let address = Address(from: addressJSON) else { return nil }
        
        guard let coordinatesDictionary = json ["location"] as? NSDictionary,
            let latitude = coordinatesDictionary ["latitude"] as? CLLocationDegrees,
            let longitude = coordinatesDictionary ["longitude"] as? CLLocationDegrees
            else {
                
                LOG.warn("Failed to get Store location information: \(json)")
                return nil
        }
        
        let coordinatesObject = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
        
        let isFarmersMarket: Bool = json ["is_farmers_market"] as? Bool ?? false
        
        self.storeID = storeID
        self.storeName = storeName
        self.address = address
        self.location = coordinatesObject
        self.isFarmersMarket = isFarmersMarket
        self.storeImage = storeImageURL!
        
    }
    
}

extension Store : CustomStringConvertible {
    
    var description: String {
        return "{storeName: \(storeName), address: \(address), location: \(location), isFarmersMarket: \(isFarmersMarket)}"
    }
    
}

struct Address {
    
    let addressLineOne: String
    let addressLineTwo: String?
    let city: String
    let state: String
    let county: String
    let zipCode: String
    let localZipCode: String?
    
}

extension Address {
    
    init?(from storeDictionary: NSDictionary) {
        
        guard let addressLineOne = storeDictionary ["address_line_1"] as? String else { return nil }
        let addressLineTwo = storeDictionary ["address_line_2"] as? String
        
        guard let city = storeDictionary ["city"] as? String else { return nil }
        guard let state = storeDictionary ["state"] as? String else { return nil }
        guard let county = storeDictionary ["county"] as? String else { return nil }
        guard let zipCode = storeDictionary ["zip_code"] as? String else { return nil }
        
        let localZipCode = storeDictionary ["local_zip_code"] as? String
        
        self.addressLineOne = addressLineOne
        self.addressLineTwo = addressLineTwo
        
        self.city = city
        self.state = state
        self.county = county
        self.zipCode = zipCode
        self.localZipCode = localZipCode
        
    }
    
}
<commit_msg>Modifies code for placeholder image<commit_after>//
//  StoresDataStruct.swift
//  BlackNectar
//
//  Created by <NAME> on 11/19/16.
//  Copyright © 2017 BlackSource. All rights reserved.
//

import Archeota
import CoreLocation
import Foundation
import UIKit

// Creates data structure for JSON Request
struct Store {
    
    let storeID: String
    let storeName: String
    let location: CLLocationCoordinate2D
    let address: Address
    let storeImage: URL?
    let isFarmersMarket: Bool
    
    var notFarmersMarket: Bool { return !isFarmersMarket }
    
    static func getStoreJsonData(from storeDictionary: NSDictionary) -> Store? {
        
        return Store(json: storeDictionary)
    }
    
}

extension Store {
    
    init?(json: NSDictionary) {
        
        if let storeImageString = json["main_image_url"] as? String  {
            
            storeImage = URL(string: storeImageString)
        }
        else {
            
            self.storeImage = nil
        }
        
        guard let storeID = json ["store_id"] as? String,
            let storeName = json ["store_name"] as? String,
            let addressJSON = json ["address"] as? NSDictionary
            else {
                
                LOG.error("Failed to parse Store: \(json)")
                return nil
        }
        
        guard let address = Address(from: addressJSON) else { return nil }
        
        guard let coordinatesDictionary = json ["location"] as? NSDictionary,
            let latitude = coordinatesDictionary ["latitude"] as? CLLocationDegrees,
            let longitude = coordinatesDictionary ["longitude"] as? CLLocationDegrees
            else {
                
                LOG.warn("Failed to get Store location information: \(json)")
                return nil
        }
        
        let coordinatesObject = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
        
        let isFarmersMarket: Bool = json ["is_farmers_market"] as? Bool ?? false
        
        self.storeID = storeID
        self.storeName = storeName
        self.address = address
        self.location = coordinatesObject
        self.isFarmersMarket = isFarmersMarket
        self.storeImage = storeImageURL!
        
    }
    
}

extension Store : CustomStringConvertible {
    
    var description: String {
        return "{storeName: \(storeName), address: \(address), location: \(location), isFarmersMarket: \(isFarmersMarket)}"
    }
    
}

struct Address {
    
    let addressLineOne: String
    let addressLineTwo: String?
    let city: String
    let state: String
    let county: String
    let zipCode: String
    let localZipCode: String?
    
}

extension Address {
    
    init?(from storeDictionary: NSDictionary) {
        
        guard let addressLineOne = storeDictionary ["address_line_1"] as? String else { return nil }
        let addressLineTwo = storeDictionary ["address_line_2"] as? String
        
        guard let city = storeDictionary ["city"] as? String else { return nil }
        guard let state = storeDictionary ["state"] as? String else { return nil }
        guard let county = storeDictionary ["county"] as? String else { return nil }
        guard let zipCode = storeDictionary ["zip_code"] as? String else { return nil }
        
        let localZipCode = storeDictionary ["local_zip_code"] as? String
        
        self.addressLineOne = addressLineOne
        self.addressLineTwo = addressLineTwo
        
        self.city = city
        self.state = state
        self.county = county
        self.zipCode = zipCode
        self.localZipCode = localZipCode
        
    }
    
}

{'fraction_non_alphanumeric': 0.07921589688506982, 'fraction_numerical': 0.00644468313641246, 'mean_word_length': 2.0947237224761115, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 1, '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': '925445', 'n_tokens_mistral': 2038, 'n_tokens_neox': 1967, 'n_words': 583}