<commit_before>import {Injectable} from 'angular2/core';
import * as _ from 'lodash';
import {Http, Response} from 'angular2/http';
import {Observable}     from 'rxjs/Observable';

const _weatherAPIUrl = 'http://globalmapweather.azurewebsites.net:80/api/Weather';

@Injectable()
export class WeatherService {
    locations: Location[];

    constructor(private http: Http) {
        this.locations = [];
    }

    getLocations() : any[] {
        let result = this.locations.map(data => {
            return {
                city: data.City,
                temperature: data.Temperature
            };
        });

        return result;
    }

    getLocation(city: string) : Location {
        return _(this.locations).find({ City: city });
    }

    addLocation(location: Location) {
        if (_(this.locations).find({ City: location.City }))
            return false;

        this.locations.push(location);
        return true;
    }

    removeLocation(city: string) {
        if (_(this.locations).find({ City: city })) {
            _(this.locations).remove((location : Location) => {
                return location.City === city;
            });
            return true;
        }

        return false;
    }
}

export class Location {
    Latitude: number;
    Longtitude: number;
    Humidity: number;
    Temperature: number;
    City: string;

    constructor(private city: string,
                private temperature: number = null,
                private longtitude: number = null,
                private latitude: number = null,
                private humidity: number = null) {
        this.City = city;
        this.Temperature = temperature;
        this.Longtitude = longtitude;
        this.Latitude = latitude;
        this.Humidity = humidity;
    }
}
<commit_msg>refactored weather.data.service to use RxJs<commit_after>import {Injectable} from 'angular2/core';
import * as _ from 'lodash';
import {Http, Headers, RequestOptions} from 'angular2/http';
import {Observable}     from 'rxjs/Observable';

const _weatherAPIUrl = 'http://globalmapweather.azurewebsites.net:80/api/Weather';

@Injectable()
export class WeatherService {
    locations: Location[];

    constructor(private http: Http) {
        this.locations = [];
    }

    getLocations() : Observable<Location[]> {
        return this.http.get(_weatherAPIUrl)
            .map(res => this.locations = <Location[]> res.json().data)
            .catch(err => Observable.throw(err.json().error || 'Unable to get data'));
    }

    getLocation(city: string) : Observable<Location> {
        let location = _(this.locations).find({ City: city });
        return Observable.create(location);
    }

    addLocation(location: Location) : Observable<boolean> {
        if (_(this.locations).find({ City: location.City }))
            return Observable.create(false);

        let body = JSON.stringify(location);
        let headers = new Headers({ 'Content-Type': 'application/json' });
        let options = new RequestOptions({ headers: headers });

        return this.http.post(_weatherAPIUrl, body, options)
            .map(res => {
                this.locations.push(location);
                return Observable.create(true);
            })
            .catch(err => Observable.throw(err.json().error || 'Unable to post data'));
    }

    removeLastLocation() : Observable<boolean> {
        return this.http.delete(_weatherAPIUrl)
            .map(res => {
                this.locations.pop();
                return Observable.create(true);
            })
            .catch(err => Observable.throw(err.json().error || 'Unable to delete data'));
    }
}

export class Location {
    Latitude: number;
    Longtitude: number;
    Humidity: number;
    Temperature: number;
    City: string;

    constructor(private city: string,
                private temperature: number = null,
                private longtitude: number = null,
                private latitude: number = null,
                private humidity: number = null) {
        this.City = city;
        this.Temperature = temperature;
        this.Longtitude = longtitude;
        this.Latitude = latitude;
        this.Humidity = humidity;
    }
}

{'fraction_non_alphanumeric': 0.12099644128113879, 'fraction_numerical': 0.0018979833926453143, 'mean_word_length': 2.228177641653905, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 16, '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': '5208858', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1121, 'n_words': 270}