<commit_before>//
//  DataChunkViewController.swift
//  Keymochi
//
//  Created by <NAME> on 4/7/16.
//  Copyright © 2016 Cornell Tech. All rights reserved.
//

import UIKit
import Parse

class DataChunkViewController: UITableViewController {
  
  var dataChunk: DataChunk!
  var emotionSegmentedControl: UISegmentedControl!
  
  @IBOutlet weak var emotionContainer: UIView!
  
  
  override func viewDidLoad() {
    super.viewDidLoad()
    
    // Do any additional setup after loading the view.
    let segmentedControlWidth = UIScreen.mainScreen().bounds.width - 30
    emotionSegmentedControl = UISegmentedControl.init(frame: CGRect(x: 15, y: 7, width: segmentedControlWidth, height: 30))
    for (index, emotion) in Emotion.all.enumerate() {
      emotionSegmentedControl
        .insertSegmentWithTitle(emotion.description, atIndex: index, animated: false)
    }
    
    emotionContainer.addSubview(emotionSegmentedControl)
  }
  
  @IBAction func uploadDataChunk(sender: AnyObject) {
    let object = PFObject(className: "DataChunk")
    
    if let userId = NSUserDefaults.standardUserDefaults().objectForKey("userid_preference") {
      object.setObject(userId, forKey: "userId")
    }
    
    if emotionSegmentedControl.selectedSegmentIndex != -1 {
      let emotion = Emotion.all[emotionSegmentedControl.selectedSegmentIndex]
      object.setObject(emotion.description, forKey: "emotion")
    } else {
      let alert = UIAlertController.init(title: "Error", message: "Please specify the associated emotion for this data chunk.", preferredStyle: .Alert)
      alert.addAction(UIAlertAction.init(title: "OK", style: .Default, handler: nil))
      self.presentViewController(alert, animated: true, completion: nil)
      return
    }
    
    
    if let symbolCounts = dataChunk.symbolCounts {
      for (symbol, count) in symbolCounts {
        object.setObject(count, forKey: "symbol_\(symbol)")
      }
    }
    
    if let totalNumberOfDeletions = dataChunk.totalNumberOfDeletions {
      object.setObject(totalNumberOfDeletions, forKey: "totalNumberOfDeletions")
    }
    
    if let interTapDistances = dataChunk.interTapDistances {
      object.setObject(interTapDistances, forKey: "interTapDistances")
    }
    
    if let tapDurations = dataChunk.tapDurations {
      object.setObject(tapDurations, forKey: "tapDurations")
    }
    <commit_msg>Fix Parse column naming.<commit_after>//
//  DataChunkViewController.swift
//  Keymochi
//
//  Created by <NAME> on 4/7/16.
//  Copyright © 2016 Cornell Tech. All rights reserved.
//

import UIKit
import Parse

class DataChunkViewController: UITableViewController {
  
  var dataChunk: DataChunk!
  var emotionSegmentedControl: UISegmentedControl!
  
  @IBOutlet weak var emotionContainer: UIView!
  
  
  override func viewDidLoad() {
    super.viewDidLoad()
    
    // Do any additional setup after loading the view.
    let segmentedControlWidth = UIScreen.mainScreen().bounds.width - 30
    emotionSegmentedControl = UISegmentedControl.init(frame: CGRect(x: 15, y: 7, width: segmentedControlWidth, height: 30))
    for (index, emotion) in Emotion.all.enumerate() {
      emotionSegmentedControl
        .insertSegmentWithTitle(emotion.description, atIndex: index, animated: false)
    }
    
    emotionContainer.addSubview(emotionSegmentedControl)
  }
  
  @IBAction func uploadDataChunk(sender: AnyObject) {
    let object = PFObject(className: "DataChunk")
    
    if let userId = NSUserDefaults.standardUserDefaults().objectForKey("userid_preference") {
      object.setObject(userId, forKey: "userId")
    }
    
    if emotionSegmentedControl.selectedSegmentIndex != -1 {
      let emotion = Emotion.all[emotionSegmentedControl.selectedSegmentIndex]
      object.setObject(emotion.description, forKey: "emotion")
    } else {
      let alert = UIAlertController.init(title: "Error", message: "Please specify the associated emotion for this data chunk.", preferredStyle: .Alert)
      alert.addAction(UIAlertAction.init(title: "OK", style: .Default, handler: nil))
      self.presentViewController(alert, animated: true, completion: nil)
      return
    }
    
    
    if let symbolCounts = dataChunk.symbolCounts {
      for (symbol, count) in symbolCounts {
        if symbol == " " {
          object.setObject(count, forKey: "symbol_space")
        } else {
          for scalar in symbol.unicodeScalars {
            let value = scalar.value
            if (value >= 65 && value <= 90) || (value >= 97 && value <= 122) || (value >= 48 && value <= 57) {
              object.setObject(count, forKey: "symbol_\(symbol)")
            } else {
              object.setObject(count, forKey: "symbol_punctuation")
            }
          }
        }
      }
    }
    
    if let totalNumberOfDeletions = dataChunk.totalNumberOfDeletions {
      object.setObject(totalNumberOfDeletions, forKey: "totalNumberOfDeletions")
    }
    
    if let interTapDistances = dataChunk.interTapDistances {
      object.setObject(interTapDistances, forKey: "interTapDistances")
    }
    
    if let tapDurations = dataChunk.tapDurations {
      object.setObject(tapDurations, forKey: "tapDurations")
    }
    
{'fraction_non_alphanumeric': 0.09810737736577829, 'fraction_numerical': 0.00869061413673233, 'mean_word_length': 3.238134206219313, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '4923380', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1522, 'n_words': 349}