0
点赞
收藏
分享

微信扫一扫

预测目标 冷却时长 20231023

洛茄 2023-10-24 阅读 9

<!--输入时间预测料温-->
    <div id="target_time" style="position: absolute; left: 900px; top: 600px;">
        <div style="margin-bottom: 20px;">
            <label style="font-size: 20px;">目标时间</label>
        </div>
        <div style="margin-bottom: 20px;">
            <label style="font-size: 20px;">出炉时长</label>
        </div>
        <div style="margin-bottom: 20px;">
            <label style="font-size: 20px;">预测料温</label>
        </div>
    </div>

    <div id="target_time_input" style="position: absolute; left: 1000px; top: 550px; display: flex; justify-content: space-between;">
        <div style="margin-right: 60px;">
            <div style="display: flex; flex-direction: column; align-items: flex-start;">
                <label style="font-size: 20px;">请输入目标时间</label>
                <input type="datetime-local" id="id_target_time" value="" onchange="updateValue(this.id, this.value)" style="margin-top: 20px; font-size: 20px;">
                <label style="margin-top: 20px; font-size: 20px;">子标签2</label>
                <label style="margin-top: 20px; font-size: 20px;">子标签3</label>
            </div>
        </div>
        <div style="margin-right: 30px;">
            <div style="display: flex; flex-direction: column; align-items: flex-start;">
                <label style="font-size: 20px;">举例3 (当前时间)</label>
                <label style="margin-top: 20px; font-size: 20px;">当前时间</label>
                <label style="margin-top: 20px; font-size: 20px;">子标签2</label>
                <label style="margin-top: 20px; font-size: 20px;">子标签3</label>
            </div>
        </div>
        <div style="margin-right: 30px;">
            <div style="display: flex; flex-direction: column; align-items: flex-start;">
                <label style="font-size: 20px;">举例4 (出炉时间+50小时)</label>
                <label style="margin-top: 20px; font-size: 20px;">出炉时间+50小时</label>
                <label style="margin-top: 20px; font-size: 20px;">子标签2</label>
                <label style="margin-top: 20px; font-size: 20px;">子标签3</label>
            </div>
        </div>
    </div>

</body>
</html>
改进代码,需求:
1,根据y = (init_temp - ambi_temp) * Math.exp(window.k * x) + ambi_temp; 分别设置y=id_target_temp, y=50, y=40, 分别求x, 分别保存为变量x1, x2, x3; 然后再分别求id_init_tmp+x, 分别保存为变量time1, time2, time3(格式为“年-月-日 时-分”)
2, 将id_target_time 的默认值设置为当前时间+10小时,如果输入了id_target_time 则更新该值;
3,生成变量time2=当前时间,time3=出炉时间+50小时,(格式为“年-月-日 时-分”)
4,生成变量x1=id_target_time - init_time, x2 = time2-init_time, x3 = time3-init_time, 单位为小时, 效果类似python的(pd.Timestamp(time) - pd.Timestamp(initial_time)).total_seconds() / 3600, 其中pd为pandas模块
5,这些变量都随输入框的值的变化而变化
6,根据y = (init_temp - ambi_temp) * Math.exp(window.k * x) + ambi_temp; 分别设置x=x1, x=x2, x=x3, 分别求y,分别保存为变量y1, y2, y3

根据你的需求,我为你编写了以下的JavaScript代码。这段代码将在输入框的值发生变化时,更新你所需要的变量,并且会在页面加载完成后进行初始化。

// 在这里定义你需要的变量
var x1, x2, x3, time1, time2, time3, y1, y2, y3;

// 更新函数
function updateFormula() {
    // ... 你原来的代码 ...

    // 根据y = (init_temp - ambi_temp) * Math.exp(window.k * x) + ambi_temp; 分别设置y=id_target_temp, y=50, y=40, 分别求x
    x1 = Math.log((document.getElementById('id_target_temp').value - ambi_temp) / (init_temp - ambi_temp)) / window.k;
    x2 = Math.log((50 - ambi_temp) / (init_temp - ambi_temp)) / window.k;
    x3 = Math.log((40 - ambi_temp) / (init_temp - ambi_temp)) / window.k;

    // 然后再分别求id_init_tmp+x, 分别保存为变量time1, time2, time3(格式为“年-月-日 时-分”)
    var initDate = new Date(init_time);
    time1 = new Date(initDate.getTime() + x1 * 60 * 60 * 1000).toISOString().slice(0, 16);
    time2 = new Date(initDate.getTime() + x2 * 60 * 60 * 1000).toISOString().slice(0, 16);
    time3 = new Date(initDate.getTime() + x3 * 60 * 60 * 1000).toISOString().slice(0, 16);

    // 根据y = (init_temp - ambi_temp) * Math.exp(window.k * x) + ambi_temp; 分别设置x=x1, x=x2, x=x3, 分别求y
    y1 = (init_temp - ambi_temp) * Math.exp(window.k * x1) + ambi_temp;
    y2 = (init_temp - ambi_temp) * Math.exp(window.k * x2) + ambi_temp;
    y3 = (init_temp - ambi_temp) * Math.exp(window.k * x3) + ambi_temp;
}

function updateValue(elementId, elementValue) {
    // ... 你原来的代码 ...

    // 将id_target_time 的默认值设置为当前时间+10小时,如果输入了id_target_time 则更新该值;
    if (elementId === 'id_target_time' && elementValue === '') {
        var currentDate = new Date();
        currentDate.setHours(currentDate.getHours() + 10);
        document.getElementById('id_target_time').value = currentDate.toISOString().slice(0, 16);
    }

    // 更新函数
    updateFormula();
}

window.onload = function() {
    // ... 你原来的代码 ...

    // 更新函数
    updateFormula();
}

这段代码应该可以满足你的需求。如果有任何问题,或者需要进一步的帮助,请随时告诉我!

举报

相关推荐

0 条评论