<commit_before>//
//  ViewController.swift
//  BetterReminders
//
//  Created by <NAME> on 2/28/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit

class MainTableViewController: UITableViewController {
    
    let defaults = UserDefaults.standard
    var classes: [JHSchoolClass]?
    var classesByDay: [String: [JHSchoolClass]]!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        title = "Schedule"
        
        getData()

    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "ClassCell")
        let c = classes![indexPath.row]
        cell.textLabel?.text = "\(c.name!)"
        cell.detailTextLabel?.text = "\(c.startTime!)-\(c.endTime!)"
        return cell
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
    }
    
    override func numberOfSections(in tableView: UITableView) -> Int {
        return classesByDay.keys.count
    }
    
    override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        let days: [String] = Array(classesByDay.keys).reversed()    //Reversed so "A" day is first
        return "\(days[section]) Day"
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        let days: [String] = Array(classesByDay.keys).reversed()    //Reversed so "A" day is first
        return classesByDay[days[section]]!.count
    }
    
    
    func loadJSON(fromFile file: String, ofType type: String) -> JSON? {
        if let path = Bundle.main.path(forResource: file, ofType: type) {
            do {
                let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .alwaysMapped)
                let jsonObj = JSON(data: data)
                if jsonObj != JSON.null {
                    return jsonObj
                } else {
                    print("Couldn't get JSON from file, check to make sure the file is correct")
                }
            } catch let error {
                print(error.localizedDescription)
            }
        } else {
            print("Invlaide file name/path")
        }
        return nil
    }
    
    func getData() {
        let launchedBefore = defaults.bool(forKey: "launchedBefore")
        if !launchedBefore {
            //First Launch
            defaults.set(true, forKey: "launchedBefore")
            parseScheduleJSON()
        } else {
            //Not first launch
            let data = defaults.object(forKey: "classes") as! Data
            classes = NSKeyedUnarchiver.unarchiveObject(with: data) as? [JHSchoolClass]
        }
        sortClassesByDay()
    }
    
    func parseScheduleJSON() {
        if let json = loadJSON(fromFile: "Classes", ofType: "json") {
            classes = [JHSchoolClass]()
            for item in json["Classes"].arrayValue {
                if let name = item["name"].string {
                    if let day = item["day"].string {
                        if let startTime = item["startTime"].string {
                            if let endTime = item["endTime"].string {
                                let c = JHSchoolClass(name: name, startTime: startTime, endTime: endTime, day: day)
                                classes!.append(c)
                                let data: Data = NSKeyedArchiver.archivedData(withRootObject: classes!)
                                defaults.set(data, forKey: "classes")
                            } else {
                                print("Error parsing JSON")
                            }
                        } else {
                            print("Error parsing JSON")
                        }
                    } else {
                        print("Error parsing JSON")
                    }
                } else {
                    print("Error parsing JSON")
                }
            }
        } else {
            print("JSON not parsed properly")
        }
    }
    
    func sortClassesByDay() {
        //Organizes classes into which class scheduele day in order for tableView organization
        classesByDay = [String: [JHSchoolClass]]()
        for c in classes! {
            if classesByDay[c.day] == nil {
                classesByDay[c.day] = [c]
            } else {
                classesByDay[c.day]?.append(c)
            }
        }
    }
}

<commit_msg>Detail disclosure indicator added<commit_after>//
//  ViewController.swift
//  BetterReminders
//
//  Created by <NAME> on 2/28/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit

class MainTableViewController: UITableViewController {
    
    let defaults = UserDefaults.standard
    var classes: [JHSchoolClass]?
    var classesByDay: [String: [JHSchoolClass]]!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        title = "Schedule"
        
        getData()

    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "ClassCell")
        let c = classes![indexPath.row]
        cell.textLabel?.text = "\(c.name!)"
        cell.detailTextLabel?.text = "\(c.startTime!)-\(c.endTime!)"
        cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
        return cell
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
    }
    
    override func numberOfSections(in tableView: UITableView) -> Int {
        return classesByDay.keys.count
    }
    
    override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        let days: [String] = Array(classesByDay.keys).reversed()    //Reversed so "A" day is first
        return "\(days[section]) Day"
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        let days: [String] = Array(classesByDay.keys).reversed()    //Reversed so "A" day is first
        return classesByDay[days[section]]!.count
    }
    
    
    func loadJSON(fromFile file: String, ofType type: String) -> JSON? {
        if let path = Bundle.main.path(forResource: file, ofType: type) {
            do {
                let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .alwaysMapped)
                let jsonObj = JSON(data: data)
                if jsonObj != JSON.null {
                    return jsonObj
                } else {
                    print("Couldn't get JSON from file, check to make sure the file is correct")
                }
            } catch let error {
                print(error.localizedDescription)
            }
        } else {
            print("Invlaide file name/path")
        }
        return nil
    }
    
    func getData() {
        let launchedBefore = defaults.bool(forKey: "launchedBefore")
        if !launchedBefore {
            //First Launch
            defaults.set(true, forKey: "launchedBefore")
            parseScheduleJSON()
        } else {
            //Not first launch
            let data = defaults.object(forKey: "classes") as! Data
            classes = NSKeyedUnarchiver.unarchiveObject(with: data) as? [JHSchoolClass]
        }
        sortClassesByDay()
    }
    
    func parseScheduleJSON() {
        if let json = loadJSON(fromFile: "Classes", ofType: "json") {
            classes = [JHSchoolClass]()
            for item in json["Classes"].arrayValue {
                if let name = item["name"].string {
                    if let day = item["day"].string {
                        if let startTime = item["startTime"].string {
                            if let endTime = item["endTime"].string {
                                let c = JHSchoolClass(name: name, startTime: startTime, endTime: endTime, day: day)
                                classes!.append(c)
                                let data: Data = NSKeyedArchiver.archivedData(withRootObject: classes!)
                                defaults.set(data, forKey: "classes")
                            } else {
                                print("Error parsing JSON")
                            }
                        } else {
                            print("Error parsing JSON")
                        }
                    } else {
                        print("Error parsing JSON")
                    }
                } else {
                    print("Error parsing JSON")
                }
            }
        } else {
            print("JSON not parsed properly")
        }
    }
    
    func sortClassesByDay() {
        //Organizes classes into which class scheduele day in order for tableView organization
        classesByDay = [String: [JHSchoolClass]]()
        for c in classes! {
            if classesByDay[c.day] == nil {
                classesByDay[c.day] = [c]
            } else {
                classesByDay[c.day]?.append(c)
            }
        }
    }
}


{'fraction_non_alphanumeric': 0.09789383193638512, 'fraction_numerical': 0.0019342359767891683, 'mean_word_length': 1.593201448871552, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1767', 'n_tokens_mistral': 2563, 'n_tokens_neox': 2413, 'n_words': 625}