<commit_before>import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { Http } from '@angular/http';
import { SearchService, ValueKey } from '../search/search.service';
import { BASE_URL } from '../../constants';

@Injectable()
export class ChartService {
    public data: Subject<any> = new Subject();

    constructor(private searchService: SearchService, private http: Http) {

        this.searchService.queriedItems
            .asObservable()
            .concatMap(vk =>
                vk.length > 0 ? this.getSearchResult(vk[vk.length - 1]) : []
            )
            .do(console.log)

            .subscribe(d => {
                console.log(d)
                this.data.next({
                    "name": "Gey",
                    "series": [
                        {
                            "name": "2010",
                            "value": 700000
                        },
                        {
                            "name": "2011",
                            "value": 8940000
                        }
                    ]
                })
            })
    }

    public getSearchResult(d: ValueKey): Observable<SearchResults> {
        const request = BASE_URL.BASE_URL_BACKEND + 'stats/' + d.key;
        return this.http.get(request)
            .map(response => response.json())

            .map(resultList => {
                console.log(resultList)

                return new LineChartModel(resultList)
            });
    }
}

export class SearchResults {
    public key: string;
    public sum: number;

    constructor(searchResult: any) {
        this.key = searchResult.key;
        this.sum = searchResult.sum.value;
    }

}

export class LineChartModel {
    public name: string;
    public series: ValueName[] = [];

    constructor(resultList: any[]) {
        this.name = "hi";
        Observable.from(resultList)
            .map(result => new SearchResults(result))
            .subscribe(resultList => this.series.push(resultList))

    }

}


export class ValueName {
    public value: string;
    public name: string;

    constructor(searchResult: any) {
        this.value = searchResult.key;<commit_msg>map line name to datamodel<commit_after>import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
import { Http } from '@angular/http';
import { SearchService, ValueKey } from '../search/search.service';
import { BASE_URL } from '../../constants';

@Injectable()
export class ChartService {
    public data: Subject<any> = new Subject();

    constructor(private searchService: SearchService, private http: Http) {

        this.searchService.queriedItems
            .asObservable()
            .concatMap(vk =>
                vk.length > 0 ? this.getSearchResult(vk[vk.length - 1]) : []
            )
            .do(console.log)

            .subscribe(d => {
                console.log(d)
                this.data.next({
                    "name": "Gey",
                    "series": [
                        {
                            "name": "2010",
                            "value": 700000
                        },
                        {
                            "name": "2011",
                            "value": 8940000
                        }
                    ]
                })
            })
    }

    public getSearchResult(d: ValueKey): Observable<SearchResults> {
        const request = BASE_URL.BASE_URL_BACKEND + 'stats/' + d.key;
        return this.http.get(request)
            .map(response => response.json())

            .map(resultList => {
                console.log(resultList)

                return new LineChartModel(resultList,d.value)
            });
    }
}

export class SearchResults {
    public key: string;
    public sum: number;

    constructor(searchResult: any) {
        this.key = searchResult.key;
        this.sum = searchResult.sum.value;
    }

}

export class LineChartModel {
    public name: string;
    public series: ValueName[] = [];

    constructor(resultList: any[],value:string) {
        this.name = value;
        Observable.from(resultList)
            .map(result => new SearchResults(result))
            .subscribe(resultList => this.series.push(resultList))

    }

}


export class ValueName {
    public value: string;
    public name: string;

    constructor(searchResult: any) {
        this.value = searchResult.key;
{'fraction_non_alphanumeric': 0.11596149541079023, 'fraction_numerical': 0.01029773897470338, 'mean_word_length': 1.5531428571428572, 'pattern_counts': {'":': 12, '<': 7, '<?xml version=': 0, '>': 21, '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': '5039851', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1155, 'n_words': 251}