<commit_before>/**
 * Created by alvinm on 7/25/16.
 */
import { Component, Input, ViewChild } from '@angular/core';
import { SpotifyComponent } from './apps/spotify/spotify.component';
import { TtsService } from './apps/tts/tts.service';
import { TodoistService } from './apps/todoist/todoist.service';
import { PushbulletService } from './apps/pushbullet/pushbullet.service';
import { NluResponse } from './apps/nlu/nlu';
import { config } from './config';
const PythonShell = require('python-shell');

@Component({
  selector: 'dashboard',
  templateUrl: './dashboard.component.html'
})

export class DashboardComponent {
  @ViewChild(SpotifyComponent) private spotify: SpotifyComponent;
  window: any;
  audio: HTMLAudioElement; 
  destination: string;
  app: string;
  nluResponse: NluResponse;
  showSpotify: boolean = false;
  video: string;
  location: string;
  date: string;
  sendUrl: string;
  sendObj: Object;

  constructor(private tts: TtsService, private todoist: TodoistService, private push: PushbulletService) { }

  getNLUResponse(response: NluResponse) {
    this.nluResponse = response;
    console.log(response);
    this.app = this.nluResponse.result.parameters.app;

    if (this.nluResponse.result.action === 'input.unknown') {
      this.tts.synthesizeSpeech('I didn\'t get that. Can you try again?');
      this.app = '';
    }
    
    switch(this.app) {
      case 'weather':    this.getWeather();
                         break;
      case 'todo':       this.addTodo;
                         break;
      case 'spotify':    this.playSpotify();
                         break;
      case 'directions': this.getDirections();
                         break;        
      case 'video':      this.getVideo();
                         break;
      case 'close':      this.app = '';
                         break;
      case 'send':       this.send();
                         break; 
    }
  }

  send() {
    if (this.sendObj) {
      console.log(this.sendObj);
      this.push.sendToDevice(this.sendObj);
    } else {
      console.log('Nothing to send');
    }
  }

  getVideo() {
    try {
      this.video = this.nluResponse.result.parameters.query;
    } catch (err) {
      this.tts.synthesizeSpeech('I could not find that video');
    }    
  }

  getDirections() {
    this.destination = this.nluResponse.result.parameters.location ||
                       this.nluResponse.result.parameters.address ||
                       this.nluResponse.result.parameters['geo-city'];
                  
    this.sendObj = {
      type: 'link',
      title: 'Maps',
      body: 'Open in Google Maps',
      url: this.sendUrl
    };
  }


  playSpotify() {
    this.showSpotify = true;

    let song = this.nluResponse.result.parameters.song
    if (this.nluResponse.result.parameters.artist) {
      song += ' artist:' + this.nluResponse.result.parameters.artist;
    }

    if (this.nluResponse.result.parameters.action === 'play') {
      this.spotify.playSong(song);
    } else if (this.nluResponse.result.parameters.action === 'pause') {
      this.spotify.pauseSong();
    } else if (this.nluResponse.result.parameters.action === 'hide') {
      this.spotify.pauseSong();
      this.showSpotify = false;
    } else if (this.nluResponse.result.parameters.action === 'resume') {
      this.spotify.resumeSong();
    }
  }

  getWeather() {
    this.location = this.nluResponse.result.parameters.location;
    this.date = this.nluResponse.result.parameters.date;    
  }

  addTodo(todo: string) {
    this.todoist.addTodo(this.nluResponse.result.parameters.query);
    this.tts.synthesizeSpeech('Adding' + this.nluResponse.result.parameters.query);    
  }<commit_msg>Fix add todo bug<commit_after>/**
 * Created by alvinm on 7/25/16.
 */
import { Component, Input, ViewChild } from '@angular/core';
import { SpotifyComponent } from './apps/spotify/spotify.component';
import { TtsService } from './apps/tts/tts.service';
import { TodoistService } from './apps/todoist/todoist.service';
import { PushbulletService } from './apps/pushbullet/pushbullet.service';
import { NluResponse } from './apps/nlu/nlu';
import { config } from './config';
const PythonShell = require('python-shell');

@Component({
  selector: 'dashboard',
  templateUrl: './dashboard.component.html'
})

export class DashboardComponent {
  @ViewChild(SpotifyComponent) private spotify: SpotifyComponent;
  window: any;
  audio: HTMLAudioElement; 
  destination: string;
  app: string;
  nluResponse: NluResponse;
  showSpotify: boolean = false;
  video: string;
  location: string;
  date: string;
  sendUrl: string;
  sendObj: Object;

  constructor(private tts: TtsService, private todoist: TodoistService, private push: PushbulletService) { }

  getNLUResponse(response: NluResponse) {
    this.nluResponse = response;
    console.log(response);
    this.app = this.nluResponse.result.parameters.app;

    if (this.nluResponse.result.action === 'input.unknown') {
      this.tts.synthesizeSpeech('I didn\'t get that. Can you try again?');
      this.app = '';
    }
    
    switch(this.app) {
      case 'weather':    this.getWeather();
                         break;
      case 'todo':       this.addTodo();
                         break;
      case 'spotify':    this.playSpotify();
                         break;
      case 'directions': this.getDirections();
                         break;        
      case 'video':      this.getVideo();
                         break;
      case 'close':      this.app = '';
                         break;
      case 'send':       this.send();
                         break; 
    }
  }

  send() {
    if (this.sendObj) {
      console.log(this.sendObj);
      this.push.sendToDevice(this.sendObj);
    } else {
      console.log('Nothing to send');
    }
  }

  getVideo() {
    try {
      this.video = this.nluResponse.result.parameters.query;
    } catch (err) {
      this.tts.synthesizeSpeech('I could not find that video');
    }    
  }

  getDirections() {
    this.destination = this.nluResponse.result.parameters.location ||
                       this.nluResponse.result.parameters.address ||
                       this.nluResponse.result.parameters['geo-city'];
                  
    this.sendObj = {
      type: 'link',
      title: 'Maps',
      body: 'Open in Google Maps',
      url: this.sendUrl
    };
  }


  playSpotify() {
    this.showSpotify = true;

    let song = this.nluResponse.result.parameters.song
    if (this.nluResponse.result.parameters.artist) {
      song += ' artist:' + this.nluResponse.result.parameters.artist;
    }

    if (this.nluResponse.result.parameters.action === 'play') {
      this.spotify.playSong(song);
    } else if (this.nluResponse.result.parameters.action === 'pause') {
      this.spotify.pauseSong();
    } else if (this.nluResponse.result.parameters.action === 'hide') {
      this.spotify.pauseSong();
      this.showSpotify = false;
    } else if (this.nluResponse.result.parameters.action === 'resume') {
      this.spotify.resumeSong();
    }
  }

  getWeather() {
    this.location = this.nluResponse.result.parameters.location;
    this.date = this.nluResponse.result.parameters.date;    
  }

  addTodo() {
    this.todoist.addTodo(this.nluResponse.result.parameters.query);
    this.tts.synthesizeSpeech('Adding' + this.nluResponse.result.parameters.query);    
  }
{'fraction_non_alphanumeric': 0.13384761131411557, 'fraction_numerical': 0.0013533631073216945, 'mean_word_length': 2.4356113435611344, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5417988', 'n_tokens_mistral': 2339, 'n_tokens_neox': 2241, 'n_words': 424}