<commit_before>import {Component, View, NgFor} from 'angular2/angular2';
import {Http, Headers} from 'angular2/http'
import {RouteParams} from 'angular2/router';
import {ROUTER_DIRECTIVES} from 'angular2/router';
import {Location} from 'angular2/router';
import { Grid } from '../grid/grid';
import { Column } from '../grid/column';
import {Myjsonio} from '../myjsonio/myjsonio';
import {Dynamodbio} from '../dynamodbio/dynamodbio';
import {Versioning} from '../versioning/versioning';

declare var AWS:any;

@Component({
  selector: 'playerpowers',
  templateUrl: 'app/components/playerpowers/playerpowers.html',
  styleUrls: ['app/components/playerpowers/playerpowers.css'],
  providers: [Myjsonio, Dynamodbio, Versioning],
  directives: [ROUTER_DIRECTIVES, Grid],
  pipes: []
})

export class Playerpowers {

  private result: Object = { 'json':{}, 'text':'loading...'};
  private http: Http;
  private myJsonUrl: string = 'https://api.myjson.com/bins/457gd?pretty=1';
  private googleDocJsonFeedUrl: string ='https://spreadsheets.google.com/feeds/list/1xP0aCx9S4wG_3XN9au5VezJ6xVTnZWNlOLX8l6B69n4/o7sqgzj/public/values?alt=json';
  private playerpowers;
  private columns: Array<Column>;
  private myjsonio : Myjsonio;
  private dynamodbio : Dynamodbio;
  private versioning : Versioning;

  constructor(params: RouteParams, http: Http, myjsonio : Myjsonio, dynamodbio : Dynamodbio, versioning: Versioning){
      this.http = http;
      this.myjsonio  = myjsonio;
      this.dynamodbio  = dynamodbio;
      this.dynamodbio.import(this.myJsonUrl, this.onDynamodbImport, this);
      this.versioning = versioning;
  }
  
  onDynamodbImport( myresult : Object, _this) {
    _this.result = myresult;
    _this.playerpowers = _this.getPlayerpowers();
    _this.columns = _this.getColumns();
  }

  handleImportFromGoogleDocs() {  
    this.http
      .get(this.googleDocJsonFeedUrl)
      .map(res => res.json())
      .subscribe(
        res => this.result  = this.parseGoogleDocJSON(res)
        );
  }
  
  handleExportToMyJSON() {
         this.versioning.verify( function( verified: number) {
            if (verified===1) {
              this.myjsonio.export2(this.myJsonUrl, this.result, 'playerPowers');
            } else {
              window.alert('FAILED: you do not have the latest dataminer app version loaded:' + this.versioning.liveVersion);
            }
          }.bind(this)
        );
  }
  
  handleExportToDynamoDB() {
        this.result = this.dynamodbio.export2(this.myJsonUrl, this.result, 'playerPowers');
  }

  parseGoogleDocJSON(res) {
    let playerPowersValues = this.result['json'];
    let title = playerPowersValues['title'];
    let version = playerPowersValues['version'];
    let lastEditDate = playerPowersValues['lastEditDate'];

    playerPowersValues['data'] = {};
    playerPowersValues['title'] = title;
    playerPowersValues['version'] = version;
    playerPowersValues['lastEditDate'] = lastEditDate;

    for (var rowIndex = 0; rowIndex < res.feed.entry.length; rowIndex++) { 
      var row: Object = {};
      
      let rowKeys = Object.keys(res.feed.entry[rowIndex]);
      rowKeys.forEach(function(thisKey) {
        if ((thisKey.indexOf('gsx$') === 0) && (thisKey !== 'gsx$playerpower')) {
            let truncatedKeyName = thisKey.replace('gsx$', '');

//            let levelStrippedKeyName = truncatedKeyName.match(/([a-z]+)\d+$/)[1];
//            let level = truncatedKeyName.match(/[a-z]+(\d+)$/)[1];
      
            let value = res.feed.entry[rowIndex][thisKey].$t;
            
            if (!row.hasOwnProperty(truncatedKeyName)) {
              row[truncatedKeyName] = {};<commit_msg>Hard-coding a version number to fix the export exception being thrown<commit_after>import {Component, View, NgFor} from 'angular2/angular2';
import {Http, Headers} from 'angular2/http'
import {RouteParams} from 'angular2/router';
import {ROUTER_DIRECTIVES} from 'angular2/router';
import {Location} from 'angular2/router';
import { Grid } from '../grid/grid';
import { Column } from '../grid/column';
import {Myjsonio} from '../myjsonio/myjsonio';
import {Dynamodbio} from '../dynamodbio/dynamodbio';
import {Versioning} from '../versioning/versioning';

declare var AWS:any;

@Component({
  selector: 'playerpowers',
  templateUrl: 'app/components/playerpowers/playerpowers.html',
  styleUrls: ['app/components/playerpowers/playerpowers.css'],
  providers: [Myjsonio, Dynamodbio, Versioning],
  directives: [ROUTER_DIRECTIVES, Grid],
  pipes: []
})

export class Playerpowers {

  private result: Object = { 'json':{}, 'text':'loading...'};
  private http: Http;
  private myJsonUrl: string = 'https://api.myjson.com/bins/457gd?pretty=1';
  private googleDocJsonFeedUrl: string ='https://spreadsheets.google.com/feeds/list/1xP0aCx9S4wG_3XN9au5VezJ6xVTnZWNlOLX8l6B69n4/o7sqgzj/public/values?alt=json';
  private playerpowers;
  private columns: Array<Column>;
  private myjsonio : Myjsonio;
  private dynamodbio : Dynamodbio;
  private versioning : Versioning;

  constructor(params: RouteParams, http: Http, myjsonio : Myjsonio, dynamodbio : Dynamodbio, versioning: Versioning){
      this.http = http;
      this.myjsonio  = myjsonio;
      this.dynamodbio  = dynamodbio;
      this.dynamodbio.import(this.myJsonUrl, this.onDynamodbImport, this);
      this.versioning = versioning;
  }
  
  onDynamodbImport( myresult : Object, _this) {
    _this.result = myresult;
    _this.playerpowers = _this.getPlayerpowers();
    _this.columns = _this.getColumns();
  }

  handleImportFromGoogleDocs() {  
    this.http
      .get(this.googleDocJsonFeedUrl)
      .map(res => res.json())
      .subscribe(
        res => this.result  = this.parseGoogleDocJSON(res)
        );
  }
  
  handleExportToMyJSON() {
         this.versioning.verify( function( verified: number) {
            if (verified===1) {
              this.myjsonio.export2(this.myJsonUrl, this.result, 'playerPowers');
            } else {
              window.alert('FAILED: you do not have the latest dataminer app version loaded:' + this.versioning.liveVersion);
            }
          }.bind(this)
        );
  }
  
  handleExportToDynamoDB() {
        this.result = this.dynamodbio.export2(this.myJsonUrl, this.result, 'playerPowers');
  }

  parseGoogleDocJSON(res) {
    let playerPowersValues = this.result['json'];
    let title = playerPowersValues['title'];
    let version = playerPowersValues['version'];
    let lastEditDate = playerPowersValues['lastEditDate'];

    playerPowersValues['data'] = {};
    playerPowersValues['title'] = title;
    playerPowersValues['version'] = version;
    playerPowersValues['version'] = '0.0.0.3';
    playerPowersValues['lastEditDate'] = lastEditDate;

    for (var rowIndex = 0; rowIndex < res.feed.entry.length; rowIndex++) { 
      var row: Object = {};
      
      let rowKeys = Object.keys(res.feed.entry[rowIndex]);
      rowKeys.forEach(function(thisKey) {
        if ((thisKey.indexOf('gsx$') === 0) && (thisKey !== 'gsx$playerpower')) {
            let truncatedKeyName = thisKey.replace('gsx$', '');

//            let levelStrippedKeyName = truncatedKeyName.match(/([a-z]+)\d+$/)[1];
//            let level = truncatedKeyName.match(/[a-z]+(\d+)$/)[1];
      
            let value = res.feed.entry[rowIndex][thisKey].$t;
            
            if (!row.hasOwnProperty(truncatedKeyName)) {
              row[truncatedKeyName] = {};
{'fraction_non_alphanumeric': 0.141643059490085, 'fraction_numerical': 0.008903278025091057, 'mean_word_length': 3.439520958083832, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '1208325', 'n_tokens_mistral': 2478, 'n_tokens_neox': 2385, 'n_words': 446}