<commit_before>/*
 * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
 */

#include "base/logging.h"
#include "redis_processor_vizd.h"
#include "redis_connection.h"
#include <boost/assign/list_of.hpp>

#include "seqnum_lua.cpp"
#include "delrequest_lua.cpp"
#include "uveupdate_lua.cpp"
#include "uveupdate_st_lua.cpp"
#include "uvedelete_lua.cpp"
#include "expiredgens_lua.cpp"
#include "withdrawgen_lua.cpp"

using std::string;
using std::vector;
using std::pair;
using std::map;
using std::make_pair;
using boost::assign::list_of;

void 
RedisProcessorExec::RefreshGenerator(RedisAsyncConnection * rac,
            const std::string &source, const std::string &module,
            const std::string &coll, int timeout) {
    string gkey = string("GENERATOR:") + source + ":" + module;
    std::ostringstream tstr;
    tstr << timeout;

    assert(timeout);
    rac->RedisAsyncArgCmd(NULL,
            list_of(string("SET"))(gkey)(coll)(string("EX"))(tstr.str()));

}

void 
RedisProcessorExec::WithdrawGenerator(RedisAsyncConnection * rac,
            const std::string &source, const std::string &module,
            const std::string &coll) {

    string lua_scr(reinterpret_cast<char *>(withdrawgen_lua), withdrawgen_lua_len);
    rac->RedisAsyncArgCmd(NULL,
        list_of(string("EVAL"))(lua_scr)("0")(source)(module)(coll));
}

void
RedisProcessorExec::UVEUpdate(RedisAsyncConnection * rac, RedisProcessorIf *rpi,
                       const std::string &type, const std::string &attr,
                       const std::string &source, const std::string &module,
                       const std::string &key, const std::string &msg,
                       int32_t seq, const std::string &agg,
                       const std::string &hist, int64_t ts) {

    size_t sep = key.find(":");
    string table = key.substr(0, sep);
    std::ostringstream seqstr;
    seqstr << seq;
    std::ostringstream tsstr;
    tsstr << "{\"ts\":" << ts << "}";

    if (agg == "stats") {
        std::string sc,sp,ss;
        int64_t tsbin = (ts / 3600000000) * 3600000000;
        std::ostringstream tsbinstr;
        tsbinstr << tsbin;
        std::string lhist = hist;
        if (hist == "") {
            lhist = string("1");
        }
        ss = string("HISTORY-10:") + key + ":" + source + ":" + module + ":" + type + ":" + attr;  
        sc = string("S-3600-TOPVALS:") + key + ":" + source + ":" + module + ":" + type + ":" + attr + ":" + tsbinstr.str();
        sp = string("S-3600-SUMMARY:") + key + ":" + source + ":" + module + ":" + type + ":" + attr + ":" + tsbinstr.str();

        string lua_scr(reinterpret_cast<char *>(uveupdate_st_lua), uveupdate_st_lua_len);
        rac->RedisAsyncArgCmd(rpi,
            list_of(string("EVAL"))(lua_scr)("8")(
                string("TYPES:") + source + ":" + module)(
                string("ORIGINS:") + key)(
                string("TABLE:") + table)(
                string("UVES:") + source + ":" + module + ":" + type)(
                string("VALUES:") + key + ":" + source + ":" + module + ":" + type)(
                ss)(sc)(sp)(
                source)(module)(type)(attr)(key)(seqstr.str())(lhist)(tsstr.str())(msg));<commit_msg>Add ULL postfix to large number constants to avoid compile error on 32-bit systems<commit_after>/*
 * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
 */

#include "base/logging.h"
#include "redis_processor_vizd.h"
#include "redis_connection.h"
#include <boost/assign/list_of.hpp>

#include "seqnum_lua.cpp"
#include "delrequest_lua.cpp"
#include "uveupdate_lua.cpp"
#include "uveupdate_st_lua.cpp"
#include "uvedelete_lua.cpp"
#include "expiredgens_lua.cpp"
#include "withdrawgen_lua.cpp"

using std::string;
using std::vector;
using std::pair;
using std::map;
using std::make_pair;
using boost::assign::list_of;

void 
RedisProcessorExec::RefreshGenerator(RedisAsyncConnection * rac,
            const std::string &source, const std::string &module,
            const std::string &coll, int timeout) {
    string gkey = string("GENERATOR:") + source + ":" + module;
    std::ostringstream tstr;
    tstr << timeout;

    assert(timeout);
    rac->RedisAsyncArgCmd(NULL,
            list_of(string("SET"))(gkey)(coll)(string("EX"))(tstr.str()));

}

void 
RedisProcessorExec::WithdrawGenerator(RedisAsyncConnection * rac,
            const std::string &source, const std::string &module,
            const std::string &coll) {

    string lua_scr(reinterpret_cast<char *>(withdrawgen_lua), withdrawgen_lua_len);
    rac->RedisAsyncArgCmd(NULL,
        list_of(string("EVAL"))(lua_scr)("0")(source)(module)(coll));
}

void
RedisProcessorExec::UVEUpdate(RedisAsyncConnection * rac, RedisProcessorIf *rpi,
                       const std::string &type, const std::string &attr,
                       const std::string &source, const std::string &module,
                       const std::string &key, const std::string &msg,
                       int32_t seq, const std::string &agg,
                       const std::string &hist, int64_t ts) {

    size_t sep = key.find(":");
    string table = key.substr(0, sep);
    std::ostringstream seqstr;
    seqstr << seq;
    std::ostringstream tsstr;
    tsstr << "{\"ts\":" << ts << "}";

    if (agg == "stats") {
        std::string sc,sp,ss;
        int64_t tsbin = (ts / 3600000000ULL) * 3600000000ULL;
        std::ostringstream tsbinstr;
        tsbinstr << tsbin;
        std::string lhist = hist;
        if (hist == "") {
            lhist = string("1");
        }
        ss = string("HISTORY-10:") + key + ":" + source + ":" + module + ":" + type + ":" + attr;  
        sc = string("S-3600-TOPVALS:") + key + ":" + source + ":" + module + ":" + type + ":" + attr + ":" + tsbinstr.str();
        sp = string("S-3600-SUMMARY:") + key + ":" + source + ":" + module + ":" + type + ":" + attr + ":" + tsbinstr.str();

        string lua_scr(reinterpret_cast<char *>(uveupdate_st_lua), uveupdate_st_lua_len);
        rac->RedisAsyncArgCmd(rpi,
            list_of(string("EVAL"))(lua_scr)("8")(
                string("TYPES:") + source + ":" + module)(
                string("ORIGINS:") + key)(
                string("TABLE:") + table)(
                string("UVES:") + source + ":" + module + ":" + type)(
                string("VALUES:") + key + ":" + source + ":" + module + ":" + type)(
                ss)(sc)(sp)(
                source)(module)(type)(attr)(key)(seqstr.str())(lhist)(tsstr.str())(msg));
{'fraction_non_alphanumeric': 0.17203141845063916, 'fraction_numerical': 0.013861081164330817, 'mean_word_length': 2.854005934718101, 'pattern_counts': {'":': 46, '<': 33, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '6630550', 'n_tokens_mistral': 2210, 'n_tokens_neox': 2083, 'n_words': 422}