<commit_before>const model = require('../model');

var fn_add = async (ctx, next) => {
    var
        cpu_temp = ctx.request.body.cpu_temp,
        gpu_temp = ctx.request.body.gpu_temp;
        battery_temp = ctx.request.body.battery_temp;
        
    ctx.response.type = 'application/json';    

    if (!cpu_temp && !gpu_temp && !battery_temp) {
        ctx.response.body = {
            code: "0",
            message: "数据为空"
        };
        return;
    }    
    
    let Pi = model.pi_satus;
    var obj = await Pi.create({
        cpu_temp: cpu_temp,
        gpu_temp: gpu_temp,
        battery_temp: battery_temp
    });
    ctx.response.body = obj;
};

var fn_list = async (ctx, next) => {
    let Pi = model.pi_satus;

    ctx.response.type = 'application/json';

    let page = ctx.request.query.page;
    console.log(ctx.request.query)
    if (!isNaN(page)) {
        const pageNum = 20;
        var objs = await Pi.findAll({
            limit: pageNum,
            offset: pageNum * page
        });
        ctx.response.body = objs;
    } else {
        var objs = await Pi.findAll({ limit: 100 });
        ctx.response.body = objs;
    }
}


module.exports = {
    'POST /api/pi/status': fn_add,
    'GET /api/pi/status': fn_list
};<commit_msg>添加时间段查询接口<commit_after>const model = require('../model');

var fn_add = async (ctx, next) => {
    var
        cpu_temp = ctx.request.body.cpu_temp,
        gpu_temp = ctx.request.body.gpu_temp;
        battery_temp = ctx.request.body.battery_temp;
        
    ctx.response.type = 'application/json';    

    if (!cpu_temp && !gpu_temp && !battery_temp) {
        ctx.response.body = {
            code: "0",
            message: "数据为空"
        };
        return;
    }    
    
    let Pi = model.pi_satus;
    var obj = await Pi.create({
        cpu_temp: cpu_temp,
        gpu_temp: gpu_temp,
        battery_temp: battery_temp
    });
    ctx.response.body = obj;
};

var fn_time_search = async (ctx, next) => {

    if (typeof ctx.request.body.start_time != "string" || typeof ctx.request.body.end_time != "string") {
        ctx.response.body = { message: "格式错误" };
        return;
    }

    var start_time = new Date(ctx.request.body.start_time).getTime();
    var end_time = new Date(ctx.request.body.end_time).getTime();

    let Pi = model.pi_satus;
    var objs = await Pi.findAll({
        where: {
            created_time: {
                $gte: start_time,
                $lte: end_time
            }
        }
    })

    ctx.response.body = objs;
}

var fn_list = async (ctx, next) => {
    let Pi = model.pi_satus;

    ctx.response.type = 'application/json';

    let page = ctx.request.query.page;
    console.log(ctx.request.query)
    if (!isNaN(page)) {
        const pageNum = 20;
        var objs = await Pi.findAll({
            limit: pageNum,
            offset: pageNum * page
        });
        ctx.response.body = objs;
    } else {
        var objs = await Pi.findAll({ limit: 100 });
        ctx.response.body = objs;
    }
}


module.exports = {
    'POST /api/pi/status': fn_add,
    'GET /api/pi/status': fn_list,
    'POST /api/pi/search': fn_time_search
};
{'fraction_non_alphanumeric': 0.13626304141637685, 'fraction_numerical': 0.0037938665823585203, 'mean_word_length': 1.8947849954254345, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '2245472', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1079, 'n_words': 218}