<commit_before>/**
 * Copyright (c) 2015, Cloudera, Inc. All Rights Reserved.
 *
 * Cloudera, Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"). You may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for
 * the specific language governing permissions and limitations under the
 * License.
 */

package com.cloudera.finance

import com.cloudera.sparkts.TimeSeries
import com.cloudera.sparkts.TimeSeries._

import org.joda.time.DateTime

object YahooParser {
  def yahooStringToTimeSeries(text: String, keyPrefix: String = ""): TimeSeries[String] = {
    val lines = text.split('\n')
    val labels = lines(0).split(',').tail.map(keyPrefix + _)
    val samples = lines.tail.map { line =>
      val tokens = line.split(',')
      val dt = new DateTime(tokens.head)
      (dt, tokens.tail.map(_.toDouble).toArray)
    }
    timeSeriesFromSamples(samples, labels)
  }
}<commit_msg>Fix time order in YahooParser<commit_after>/**
 * Copyright (c) 2015, Cloudera, Inc. All Rights Reserved.
 *
 * Cloudera, Inc. licenses this file to you under the Apache License,
 * Version 2.0 (the "License"). You may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for
 * the specific language governing permissions and limitations under the
 * License.
 */

package com.cloudera.finance

import com.cloudera.sparkts.TimeSeries
import com.cloudera.sparkts.TimeSeries._

import org.joda.time.DateTime

object YahooParser {
  def yahooStringToTimeSeries(text: String, keyPrefix: String = ""): TimeSeries[String] = {
    val lines = text.split('\n')
    val labels = lines(0).split(',').tail.map(keyPrefix + _)
    val samples = lines.tail.map { line =>
      val tokens = line.split(',')
      val dt = new DateTime(tokens.head)
      (dt, tokens.tail.map(_.toDouble).toArray)
    }.reverse
    timeSeriesFromSamples(samples, labels)
  }
}
{'fraction_non_alphanumeric': 0.11059322033898306, 'fraction_numerical': 0.007627118644067797, 'mean_word_length': 3.6294117647058823, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5708583', 'n_tokens_mistral': 725, 'n_tokens_neox': 705, 'n_words': 239}