<commit_before>import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import {
  Config,
  CoreApiResponseService,
  LoaderDataTypeEnum,
  ChartRangesIntervalInterface
} from '../../../core/index';
import { ChartStateService } from './state/index';
declare let _:any;
declare let moment:any;

@Injectable()
export class ChartApiService extends CoreApiResponseService {
  private params:any = {};
  constructor(public http:Http,
              private chartState:ChartStateService) {
    super(http, chartState);
  }

  load(stock:string, range:string, interval:string) {
    this.params = {stock:stock, range:range, interval:interval};
    this.chartState.fetchLoader(true);

    let url:string = Config.paths.charts.replace('$stock', stock);
    url = url.replace('$range', this.getDateRange(interval));
    if(Config.env === 'PROD') {
      this.post(Config.paths.proxy, 'url=' + encodeURIComponent(url), LoaderDataTypeEnum.CSV)
        .subscribe(
          data => this.complete(this.transform(data)),
          () => this.failed()
        );
    } else {
      this.get(url, LoaderDataTypeEnum.CSV)
        .subscribe(
          data => this.complete(this.transform(data)),
          () => this.failed()
        );
    }
  }

  reload() {
    this.load(this.params.stock, this.params.range, this.params.interval);
  }

  private transform(rawData:any):any[] {
    let data:any[] = [];
    if (rawData) {
      let timestamp:number;
      rawData.forEach((row:string[]) => {
        timestamp = moment(row[0], 'YYYY-MM-DD').unix();
        data.push({
          timestamp: timestamp,
          date: new Date(timestamp * 1000),
          close: Number(row[4]),
          high: Number(row[2]),
          low: Number(row[3]),
          open: Number(row[1]),
          volume: Number(row[5])
        });
      });
    }
    return data;
  }

  private getDateRange(interval:ChartRangesIntervalInterface):string {
    let previousDate:any = moment().subtract(interval.value, interval.type);
    return 'a=' + previousDate.month() + '&b=' + previousDate.format('DD') + '&c=' + previousDate.format('YYYY');
  }
}
<commit_msg>Added ratio adjuster to display correct price based on split data.<commit_after>import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import {
  Config,
  CoreApiResponseService,
  LoaderDataTypeEnum,
  ChartRangesIntervalInterface
} from '../../../core/index';
import { ChartStateService } from './state/index';
declare let _:any;
declare let moment:any;

@Injectable()
export class ChartApiService extends CoreApiResponseService {
  private params:any = {};
  constructor(public http:Http,
              private chartState:ChartStateService) {
    super(http, chartState);
  }

  load(stock:string, range:string, interval:string) {
    this.params = {stock:stock, range:range, interval:interval};
    this.chartState.fetchLoader(true);

    let url:string = Config.paths.charts.replace('$stock', stock);
    url = url.replace('$range', this.getDateRange(interval));
    if(Config.env === 'PROD') {
      this.post(Config.paths.proxy, 'url=' + encodeURIComponent(url), LoaderDataTypeEnum.CSV)
        .subscribe(
          data => this.complete(this.transform(data)),
          () => this.failed()
        );
    } else {
      this.get(url, LoaderDataTypeEnum.CSV)
        .subscribe(
          data => this.complete(this.transform(data)),
          () => this.failed()
        );
    }
  }

  reload() {
    this.load(this.params.stock, this.params.range, this.params.interval);
  }

  private transform(rawData:any):any[] {
    let data:any[] = [];
    if (rawData) {
      let timestamp:number;
      let ratio:number;
      let close:number;
      rawData.forEach((row:string[]) => {
        timestamp = moment(row[0], 'YYYY-MM-DD').unix();
        close = Number(row[4]);
        ratio = Number(row[6])/close;
        data.push({
          timestamp: timestamp,
          date: new Date(timestamp * 1000),
          close: Number(row[4])*ratio,
          high: Number(row[2])*ratio,
          low: Number(row[3])*ratio,
          open: Number(row[1])*ratio,
          volume: Number(row[5])
        });
      });
    }
    return data;
  }

  private getDateRange(interval:ChartRangesIntervalInterface):string {
    let previousDate:any = moment().subtract(interval.value, interval.type);
    return 'a=' + previousDate.month() + '&b=' + previousDate.format('DD') + '&c=' + previousDate.format('YYYY');
  }
}

{'fraction_non_alphanumeric': 0.15668818161584688, 'fraction_numerical': 0.004896505675495215, 'mean_word_length': 3.001780943900267, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '2140535', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1364, 'n_words': 256}