<commit_before>/**
 * Created by aleckim on 2015. 12. 26..
 */

'use strict';

var MidRssModel = require('../models/modelMidRss');

function midRssKmaController() {

}

midRssKmaController.getData = function(regId, callback) {
    log.input('midRssKmaController getData '+regId);

    MidRssModel.find({regId:regId}, {_id: 0}).limit(1).lean().exec(function(err, midRssList) {
        if (err) {
            return callback(err);
        }
        if (midRssList.length === 0) {
            err = new Error("Fail to find midRss regId="+regId);
            return callback(err);
        }

        callback(err, midRssList[0]);
    });

    return this;
};

midRssKmaController.overwriteData = function(reqMidData, regId, callback) {
    log.input('midRssKmaController overwriteData '+regId);

    if (!reqMidData.hasOwnProperty('dailyData') || !Array.isArray(reqMidData.dailyData)) {
        log.warn('make dailyData array');
        reqMidData.dailyData = [];
    }

    this.getData(regId, function(err, midRssData) {
        if (err) {
            return callback(err);
        }

        reqMidData.pubDate = midRssData.pubDate;
        reqMidData.province = midRssData.province;
        reqMidData.city = midRssData.city;
        reqMidData.stnId = midRssData.stnId;
        reqMidData.regId = midRssData.regId;

        var dailyData = reqMidData.dailyData;
        midRssData.midData.forEach(function (midData) {
            if (parseInt(midData.date)  < parseInt(dailyData[0].date) ) {
                //skip old data
                return;
            }

            for (var i = 0; i < dailyData.length; i++) {
                if (dailyData[i].date === midData.date) {
                    dailyData[i].taMin = midData.taMin;
                    dailyData[i].taMax = midData.taMax;
                    dailyData[i].wfAm = midData.wfAm;
                    dailyData[i].wfPm = midData.wfPm;
                    dailyData[i].reliability = midData.reliability;
                    break;
                }
            }
            if (i === dailyData.length) {
                //create object for removing _id of midData
                dailyData.push({date:midData.date, taMin:midData.taMin, taMax:midData.taMax, wfAm:midData.wfAm,<commit_msg>부산지역 500 error #580<commit_after>/**
 * Created by aleckim on 2015. 12. 26..
 */

'use strict';

var MidRssModel = require('../models/modelMidRss');

function midRssKmaController() {

}

midRssKmaController.getData = function(regId, callback) {
    log.input('midRssKmaController getData '+regId);

    MidRssModel.find({regId:regId}, {_id: 0}).limit(1).lean().exec(function(err, midRssList) {
        if (err) {
            return callback(err);
        }
        if (midRssList.length === 0) {
            err = new Error("Fail to find midRss regId="+regId);
            return callback(err);
        }

        callback(err, midRssList[0]);
    });

    return this;
};

midRssKmaController.overwriteData = function(reqMidData, regId, callback) {
    log.input('midRssKmaController overwriteData '+regId);

    if (!reqMidData.hasOwnProperty('dailyData') || !Array.isArray(reqMidData.dailyData)) {
        log.warn('make dailyData array');
        reqMidData.dailyData = [];
    }

    this.getData(regId, function(err, midRssData) {
        if (err) {
            return callback(err);
        }

        reqMidData.pubDate = midRssData.pubDate;
        reqMidData.province = midRssData.province;
        reqMidData.city = midRssData.city;
        reqMidData.stnId = midRssData.stnId;
        reqMidData.regId = midRssData.regId;

        var dailyData = reqMidData.dailyData;
        midRssData.midData.forEach(function (midData) {
            if (dailyData.length > 0) {
                if (parseInt(midData.date)  < parseInt(dailyData[0].date) ) {
                    //skip old data
                    return;
                }
            }

            for (var i = 0; i < dailyData.length; i++) {
                if (dailyData[i].date === midData.date) {
                    dailyData[i].taMin = midData.taMin;
                    dailyData[i].taMax = midData.taMax;
                    dailyData[i].wfAm = midData.wfAm;
                    dailyData[i].wfPm = midData.wfPm;
                    dailyData[i].reliability = midData.reliability;
                    break;
                }
            }

            if (i === dailyData.length) {
                //create object for removing _id of midData
                dailyData.push({date:midData.date, taMin:midData.taMin, taMax:midData.taMax, wfAm:midData.wfAm,
{'fraction_non_alphanumeric': 0.12426293950644246, 'fraction_numerical': 0.007643590303559729, 'mean_word_length': 2.001310615989515, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, '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': '120252', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1443, 'n_words': 251}