<commit_before>import { Observable }     from 'rxjs/Observable';

import { Http } from 'angular2/http';

import { BaseApiService } from './api.base.service';
import { Monitoring } from '../model/monitoring';

import { QuestionBase } from '../model/question-base';
import { TextboxQuestion } from '../model/question-textbox';
import { DropdownQuestion } from '../model/question-dropdown';

import { isEqualConditional } from '../conditionals/conditional-is-equal'
import { isNullConditional } from '../conditionals/conditional-is-null'

import { isEqualCountCondition } from '../count.conditions/is-equal.cconditions'
import { BaseCountCondition } from '../count.conditions/cconditions.base'

import {CsrfService} from '../services/csrf.service';

export class MonitoringService extends BaseApiService {

    constructor(http: Http, csrf: CsrfService) {
        super(http, csrf);
    }

    saveMonitoring(monitoring: Monitoring){
        var data = monitoring.toPlainObject();
        return this.simple_post('monitoring/', data);
    }

    getMonitoring(id: number):Observable<Monitoring> {
        return this.simple_get(`/api/monitoring/${id}`)
            .map(data => {
                let questions = this.parseQuestionsList(data.questions);
                this.addConditions(data.questions, questions);
                return new Monitoring(
                    {
                        name: data.name,
                        description: data.description,
                        questions: questions
                    }
                );
            })
            .map(data => data)
    }

    parseQuestionsList(questions:any[]):QuestionBase<any>[]{
        // console.log('parseQuestionsList', questions);
        return questions.map(this.parseQuestion)
    }

    parseQuestion(question):QuestionBase<any>{
        // console.log('parseQuestion', question);
        switch(question.type){
            case 'short_text':<commit_msg>Change API entrypoint<commit_after>import { Observable }     from 'rxjs/Observable';

import { Http } from 'angular2/http';

import { BaseApiService } from './api.base.service';
import { Monitoring } from '../model/monitoring';

import { QuestionBase } from '../model/question-base';
import { TextboxQuestion } from '../model/question-textbox';
import { DropdownQuestion } from '../model/question-dropdown';

import { isEqualConditional } from '../conditionals/conditional-is-equal'
import { isNullConditional } from '../conditionals/conditional-is-null'

import { isEqualCountCondition } from '../count.conditions/is-equal.cconditions'
import { BaseCountCondition } from '../count.conditions/cconditions.base'

import {CsrfService} from '../services/csrf.service';

export class MonitoringService extends BaseApiService {

    constructor(http: Http, csrf: CsrfService) {
        super(http, csrf);
    }

    saveMonitoring(monitoring: Monitoring){
        var data = monitoring.toPlainObject();
        return this.simple_post('monitoring/', data);
    }

    getMonitoring(id: number):Observable<Monitoring> {
        return this.simple_get(`/monitorings/${id}/api`)
            .map(data => {
                let questions = this.parseQuestionsList(data.questions);
                this.addConditions(data.questions, questions);
                return new Monitoring(
                    {
                        name: data.name,
                        description: data.description,
                        questions: questions
                    }
                );
            })
            .map(data => data)
    }

    parseQuestionsList(questions:any[]):QuestionBase<any>[]{
        // console.log('parseQuestionsList', questions);
        return questions.map(this.parseQuestion)
    }

    parseQuestion(question):QuestionBase<any>{
        // console.log('parseQuestion', question);
        switch(question.type){
            case 'short_text':
{'fraction_non_alphanumeric': 0.1256063313760531, 'fraction_numerical': 0.0005105948429920858, 'mean_word_length': 2.5076096687555953, 'pattern_counts': {'":': 0, '<': 9, '<?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': '376164', 'n_tokens_mistral': 1043, 'n_tokens_neox': 998, 'n_words': 199}