<commit_before>//
//  ViewController.swift
//  TheForecaster
//
//  Created by <NAME> on 5/12/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import UIKit
import WeatherShare

class ViewController: UIViewController {
  
  @IBOutlet weak var temperatureLabel: UILabel!
  @IBOutlet weak var locationLabel: UILabel!
  @IBOutlet weak var weatherImageView: UIImageView!
  @IBOutlet weak var weatherConditionsLabel: UILabel!
  @IBOutlet weak var updateDateLabel: UILabel!
  
  override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "locationDidUpdate:", name: GlobalConstants.NotificationNames.locationDidUpdate, object: nil)
  }
  
  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
  }
  
  @IBAction func refreshWeatherButtonPressed(sender: UIButton) {
  }
  
  func locationDidUpdate(notification: NSNotification) {
    println("locationAvaliable")
    
    let locationDictionary = notification.userInfo as! Dictionary<String,AnyObject>
    let latitude = locationDictionary[GlobalConstants.LocationDictionary.latitude] as! Double
    let longitude = locationDictionary[GlobalConstants.LocationDictionary.longitude] as! Double
    let city = locationDictionary[GlobalConstants.LocationDictionary.city] as! String
    let state = locationDictionary[GlobalConstants.LocationDictionary.state] as! String
    let country = locationDictionary[GlobalConstants.LocationDictionary.country] as! String
    let lastUpdatedAt = locationDictionary[GlobalConstants.LocationDictionary.timestamp] as! NSDate
    println(locationDictionary)
    
    locationLabel.text = "\(city), \(state) (\(country))"
    
    ForecastNetwork.requestWeather(latitude: latitude, longitude: longitude) { (responseDictionary) -> () in
      println(responseDictionary)
      
      if responseDictionary != nil {
        dispatch_async(dispatch_get_main_queue()) {
          let currentConditionsDictionary = responseDictionary![GlobalConstants.ForecastNetwork.currently] as! NSDictionary
          let iconName = currentConditionsDictionary[GlobalConstants.ForecastNetwork.icon] as! String
          self.weatherImageView.image = UIImage(named: iconName)
          <commit_msg>Refresh button now works<commit_after>//
//  ViewController.swift
//  TheForecaster
//
//  Created by <NAME> on 5/12/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import UIKit
import WeatherShare

class ViewController: UIViewController {
  
  @IBOutlet weak var temperatureLabel: UILabel!
  @IBOutlet weak var locationLabel: UILabel!
  @IBOutlet weak var weatherImageView: UIImageView!
  @IBOutlet weak var weatherConditionsLabel: UILabel!
  @IBOutlet weak var updateDateLabel: UILabel!
  
  override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "locationDidUpdate:", name: GlobalConstants.NotificationNames.locationDidUpdate, object: nil)
  }
  
  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
  }
  
  @IBAction func refreshWeatherButtonPressed(sender: UIButton) {
    let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
    appDelegate.locationController?.locationManager.stopUpdatingLocation()
    appDelegate.locationController?.locationManager.startUpdatingLocation()
  }
  
  func locationDidUpdate(notification: NSNotification) {
    println("locationAvaliable")
    
    let locationDictionary = notification.userInfo as! Dictionary<String,AnyObject>
    let latitude = locationDictionary[GlobalConstants.LocationDictionary.latitude] as! Double
    let longitude = locationDictionary[GlobalConstants.LocationDictionary.longitude] as! Double
    let city = locationDictionary[GlobalConstants.LocationDictionary.city] as! String
    let state = locationDictionary[GlobalConstants.LocationDictionary.state] as! String
    let country = locationDictionary[GlobalConstants.LocationDictionary.country] as! String
    let lastUpdatedAt = locationDictionary[GlobalConstants.LocationDictionary.timestamp] as! NSDate
    
    println(locationDictionary)
    //locationLabel.text = "\(city), \(state) (\(country))"
    
    ForecastNetwork.requestWeather(latitude: latitude, longitude: longitude) { (responseDictionary) -> () in
      println(responseDictionary)
      
      if responseDictionary != nil {
        dispatch_async(dispatch_get_main_queue()) {
          let currentConditionsDictionary = responseDictionary![GlobalConstants.ForecastNetwork.currently] as! NSDictionary
          let iconName = currentConditionsDictionary[GlobalConstants.ForecastNetwork.icon] as! String
          self.weatherImageView.image = UIImage(named: iconName)
          
{'fraction_non_alphanumeric': 0.08374875373878365, 'fraction_numerical': 0.003589232303090728, 'mean_word_length': 4.548672566371682, 'pattern_counts': {'":': 0, '<': 9, '<?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': '4991527', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1277, 'n_words': 318}