<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import Foundation
import Firebase
import CoreLocation

private let PROVIDERS_PATH = "providers/"
private let YELP_PATH = PROVIDERS_PATH + "yelp"

class Place {

    let name: String
    let summary: String
    let latLong: CLLocationCoordinate2D

    // Optional values.
    let categories: [String]?
    let url: String?

    let address: String?
    var travelTimeMins: Int {
        // TODO: get travel time – need to be async?
        return -1
    }

    let yelpProvider: ReviewProvider?
    let tripAdvisorProvider: ReviewProvider?

    let photoURLs: [String]?

    // todo: hours

    init?(fromFirebaseSnapshot data: FIRDataSnapshot) {
        guard data.exists(), data.hasChildren(),
                let value = data.value as? NSDictionary,
                let summary = value["description"] as? String ?? value["pullQuote"] as? String,
                let name = value["id"] as? String, // TODO: change to name from id
                let coords = value["coordinates"] as? [String:Double],
                let lat = coords["lat"], let lon = coords["lon"] else {
            return nil
        }

        self.name = name

        self.summary = summary

        self.latLong = CLLocationCoordinate2D(latitude: lat, longitude: lon)

        self.address = (value["address"] as? [String])?.joined(separator: " ")

        self.yelpProvider = ReviewProvider(fromFirebaseSnapshot: data.childSnapshot(forPath: YELP_PATH))

        // TODO: get data from DB. Below are currently using default values.
        self.categories = [String]()
        self.url = ""

        self.tripAdvisorProvider = nil

        self.photoURLs = []
    }
}
<commit_msg>Add hours property to Place model.<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import Foundation
import Firebase
import CoreLocation

private let PROVIDERS_PATH = "providers/"
private let YELP_PATH = PROVIDERS_PATH + "yelp"

class Place {

    let name: String
    let summary: String
    let latLong: CLLocationCoordinate2D

    // Optional values.
    let categories: [String]?
    let url: String?

    let address: String?
    var travelTimeMins: Int {
        // TODO: get travel time – need to be async?
        return -1
    }

    let yelpProvider: ReviewProvider?
    let tripAdvisorProvider: ReviewProvider?

    let photoURLs: [String]?

    /*
     * Notes:
     *   - Times are 24hr, e.g. 1400 for 2pm
     *   - Times are in the timezone of the place
     *   - "end" < "start" if a location is open overnight
     *   - An entry for DayOfWeek will be missing if a location is not open that day
     */
    let hours: [DayOfWeek:OpenHours]?

    init?(fromFirebaseSnapshot data: FIRDataSnapshot) {
        guard data.exists(), data.hasChildren(),
                let value = data.value as? NSDictionary,
                let summary = value["description"] as? String ?? value["pullQuote"] as? String,
                let name = value["id"] as? String, // TODO: change to name from id
                let coords = value["coordinates"] as? [String:Double],
                let lat = coords["lat"], let lon = coords["lon"] else {
            return nil
        }

        self.name = name

        self.summary = summary

        self.latLong = CLLocationCoordinate2D(latitude: lat, longitude: lon)

        self.address = (value["address"] as? [String])?.joined(separator: " ")

        self.yelpProvider = ReviewProvider(fromFirebaseSnapshot: data.childSnapshot(forPath: YELP_PATH))

        // TODO: get data from DB. Below are currently using default values.
        self.categories = [String]()
        self.url = ""

        self.tripAdvisorProvider = nil

        self.photoURLs = []

        self.hours = nil // TODO: verify dict is not empty
    }
}

enum DayOfWeek: Int {
    case monday = 0 // matches server representation
    case tuesday, wednesday, thursday, friday
    case saturday, sunday
}

struct OpenHours {
    let startTime: Int
    let endTime: Int
}

{'fraction_non_alphanumeric': 0.09824723247232472, 'fraction_numerical': 0.00507380073800738, 'mean_word_length': 2.4338875692794932, 'pattern_counts': {'":': 0, '<': 4, '<?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': '5540268', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1217, 'n_words': 428}