<commit_before>//
//  Tweet.swift
//  TweetsCounter
//
//  Created by <NAME> on 12/24/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation
import Unbox
import RealmSwift

class Tweet: Object, Unboxable {

    dynamic var userId: String = ""
    dynamic var createdAt: Date = Date()
    dynamic var tweetId: String = ""
    dynamic var text: String = ""
    dynamic var language: String = ""
    dynamic var retweetsCount: Int = 0
    dynamic var likesCount: Int = 0
    dynamic var retweeted: Bool = false

    override static func primaryKey() -> String? {
        return "tweetId"
    }

    override static func indexedProperties() -> [String] {
        return ["tweetId", "userId"]
    }

    convenience required init(unboxer: Unboxer) {
        self.init()
        do {
            userId = try unboxer.unbox(keyPath: "user.id")
            tweetId = try unboxer.unbox(key: "id_str")
            createdAt = try unboxer.unbox(key: "created_at", formatter: DateFormatter.twitterDateFormatter())
            text = try unboxer.unbox(key: "text")
            language = try unboxer.unbox(key: "lang")
            retweeted = try unboxer.unbox(key: "is_quote_status")
            retweetsCount = try unboxer.unbox(key: "retweet_count")

            do {
                if retweeted {
                    likesCount = try unboxer.unbox(keyPath: "retweeted_status.favorite_count")
                } else {
                    likesCount = try unboxer.unbox(key: "favorite_count")
                }

            } catch {
                print(error)
            }
            if text.hasPrefix("RT") {
                print(likesCount)
                print(unboxer.dictionary)

            }
            createUser(unboxer: unboxer)
        } catch {
            print(error)
        }
    }

    /// Create a user if its not in the Realm.
    ///
    /// - Parameter unboxer: The object used to decode the JSON.
    private func createUser(unboxer: Unboxer) {
        let realm = DataManager.realm()
        let user = realm.object(ofType: User.self, forPrimaryKey: userId)
        // If no user is found with the userID, create it.
        if user == nil {<commit_msg>Fix stats about retweeted tweets<commit_after>//
//  Tweet.swift
//  TweetsCounter
//
//  Created by <NAME> on 12/24/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation
import Unbox
import RealmSwift

class Tweet: Object, Unboxable {

    dynamic var userId: String = ""
    dynamic var createdAt: Date = Date()
    dynamic var tweetId: String = ""
    dynamic var text: String = ""
    dynamic var language: String = ""
    dynamic var retweetsCount: Int = 0
    dynamic var likesCount: Int = 0
    dynamic var retweeted: Bool = false

    override static func primaryKey() -> String? {
        return "tweetId"
    }

    override static func indexedProperties() -> [String] {
        return ["tweetId", "userId"]
    }

    convenience required init(unboxer: Unboxer) {
        self.init()
        do {
            userId = try unboxer.unbox(keyPath: "user.id")
            tweetId = try unboxer.unbox(key: "id_str")
            createdAt = try unboxer.unbox(key: "created_at", formatter: DateFormatter.twitterDateFormatter())
            text = try unboxer.unbox(key: "text")
            language = try unboxer.unbox(key: "lang")
            do {
                likesCount = try unboxer.unbox(keyPath: "retweeted_status.favorite_count")
                retweetsCount = try unboxer.unbox(key: "retweet_count")
                retweeted = true
                print("Retweet: \(retweetsCount) retweets and \(likesCount) likes: \(text)")
            } catch {
                likesCount = try unboxer.unbox(key: "favorite_count")
                retweetsCount = try unboxer.unbox(key: "retweet_count")
                retweeted = false
                print("Normal: \(retweetsCount) retweets and \(likesCount) likes: \(text)")
            }
            createUser(unboxer: unboxer)
        } catch {
            print(error)
        }
    }

    /// Create a user if its not in the Realm.
    ///
    /// - Parameter unboxer: The object used to decode the JSON.
    private func createUser(unboxer: Unboxer) {
        let realm = DataManager.realm()
        let user = realm.object(ofType: User.self, forPrimaryKey: userId)
        // If no user is found with the userID, create it.
        if user == nil {
{'fraction_non_alphanumeric': 0.10521562429442312, 'fraction_numerical': 0.005418830435764281, 'mean_word_length': 1.9932432432432432, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '6579779', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1312, 'n_words': 370}