+ 进样序列更名为进样时间

+ 进样时间可计算全序列的开始与结束时间
This commit is contained in:
2023-01-02 20:52:03 +08:00
parent d0b8fb9f67
commit 5fd5440966
4 changed files with 4986 additions and 60 deletions

View File

@@ -25,7 +25,7 @@
"location": "./roi.html" "location": "./roi.html"
}, },
{ {
"name": "进样序列", "name": "进样时间",
"location": "./injection-sequence.html" "location": "./injection-sequence.html"
}, },
{ {

View File

@@ -5,50 +5,61 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>进样序列</title> <title>进样时间</title>
<link rel="stylesheet" href="./github.css"> <link rel="stylesheet" href="./github.css">
<link rel="stylesheet" href="./theme.css"> <link rel="stylesheet" href="./theme.css">
<script src="./decimal.js"></script> <script src="./modules/dayjs.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script> <script type="module">
let decimal = Decimal.set({ import { Decimal } from "./modules/decimal.mjs"
const decimal = Decimal.set({
rounding: Decimal.ROUND_HALF_EVEN, rounding: Decimal.ROUND_HALF_EVEN,
precision: 12 precision: 12
}) })
$(document).ready(() => { $(document).ready(() => {
let tip = ` let tip = `
计算每一针走完的时间。<br> <p>此功能用于计算批处理中每一针样品运行的时间。</p>
设置时间提前量可以将每针的时间提前,用于给看样及配样等操作留时间。` <p>设置时间偏移量可以将每针的结束时间提前,用于给看样品图谱及现配现进等操作留时间。</p>
<p>仪器进样需要一定的时间,该部分时间虽然短,积累起来却不可忽视。<br>
此功能以当前运行样品的时间为起点,再向前/向后计算其他针的时间。所以,越远离当前运行的样品,则误差越大。
</p>`
$("#output").append(tip) $("#output").append(tip)
$("#ok").click(() => { $("#ok").click(() => {
let time = $("#time").val() let allId = new Decimal($("#allId").val()).toNumber()
let num = $("#num").val() let nowId = new Decimal($("#nowId").val()).toNumber()
let ptime = $("#ptime").val() let time = new Decimal($("#time").val()).toNumber()
let stime = $("#stime").val() let nowTime = new Decimal($("#nowTime").val()).toNumber()
let offset = new Decimal($("#offset").val()).toNumber()
let data = [] let data = []
// 生成数据 // 生成数据
for (let i = 1; i <= num; i++) { let array = genData(allId, nowId, time, nowTime, offset)
let t = injectionSequenceToDate(time, ptime, stime, i) let formatString = 'YYYY-MM-DD HH:mm'
array.forEach((value, index) => {
data.push({ data.push({
"id": i, "id": index + 1,
"time": t "startTime": value.format(formatString),
"endTime": value.add(time, 'minute').format(formatString),
"offsetTime": value.add(time - offset, 'minute').format(formatString)
})
}) })
}
// 未生成数据,不进行结果展示 // 未生成数据,不进行结果展示
if (data.length == 0) return if (data.length == 0) return
$("#output").empty() $("#output").empty()
$("#output").append(createTable(data)) $("#output").append(createTable(data))
}) })
$("#clear").click(() => { $("#clear").click(() => {
$("#allId").val("")
$("#nowId").val("")
$("#time").val("") $("#time").val("")
$("#num").val("") $("#nowTime").val("")
$("#ptime").val("") $("#offset").val("")
$("#stime").val("")
$("#output").empty() $("#output").empty()
$("#output").append(tip) $("#output").append(tip)
}) })
@@ -59,65 +70,80 @@
}) })
/** /**
* 计算进样时间,返回 yyyy-MM-dd hh:mm 格式的字符串 * 生成数据
* @author <a href="mailto:3243430237@qq.com" target="_blank">hbk01</a>
* @param {Number} allId 总针数(即需要计算多少条数据)
* @param {Number} nowId 当前针数(当前仪器运行到第几针)
* @param {Number} time 一针有多少分钟(包括后运行)
* @param {Number} nowTime 当前这针已经运行了多少分钟
* @param {Number} offset 每一针需偏移多少分钟
* @return {Array} dayjs
*/ */
function injectionSequenceToDate(time, ptime, stime, num) { function genData(allId, nowId, time, nowTime, offset) {
let t = injectionSequence(time, ptime, stime, num) let array = new Array(allId)
let t_hour = Math.floor(Math.abs(t) / 60) let now = new dayjs()
let t_min = t % 60 // 将当前这针的开始时间先设置好
let date = new Date() array[nowId - 1] = now.subtract(nowTime, 'minute')
let dateAfter = new Date(date.getFullYear(), date.getMonth(), date.getDate(), // 计算当前这针前面的时间
date.getHours() + t_hour, date.getMinutes() + t_min).format("yyyy-MM-dd hh:mm") for (let index = nowId - 2; index >= 0; index--) {
return dateAfter array[index] = array[index + 1].subtract(time, 'minute')
}
// 计算当前这针后面的时间
for (let index = nowId; index < allId; index++) {
array[index] = array[index - 1].add(time, 'minute')
}
return array
} }
/** /**
* 创建表格元素并将数据填入其中。 * 创建表格元素并将数据填入其中。
*/ */
function createTable(data) { function createTable(data) {
let nowId = new Decimal($("#nowId").val()).toNumber()
let table = document.createElement("table") let table = document.createElement("table")
table.setAttribute("style", "width: 100%; text-align: center;") table.setAttribute("style", "width: 100%; text-align: center; font-size: smaller;")
table.setAttribute("class", "pure-table") table.setAttribute("class", "pure-table")
let row = document.createElement("tr") let row = document.createElement("tr")
let th1 = document.createElement("th") let lineNum = document.createElement("th")
let th2 = document.createElement("th") let startTime = document.createElement("th")
th1.innerText = "第几针" let endTime = document.createElement("th")
th2.innerText = "进样时间" let offset = document.createElement("th")
row.appendChild(th1) lineNum.innerText = "序号"
row.appendChild(th2) startTime.innerText = "开始时间"
endTime.innerText = "结束时间"
offset.innerText = "偏移后"
row.appendChild(lineNum)
row.appendChild(startTime)
row.appendChild(endTime)
// row.appendChild(offset)
table.appendChild(row) table.appendChild(row)
let highlight = 'background-color: #ffffcc;'
data.forEach(element => { data.forEach(element => {
let tr = document.createElement("tr") let tr = document.createElement("tr")
let td_id = document.createElement("td") let td_id = document.createElement("td")
let td_time = document.createElement("td") let td_start_time = document.createElement("td")
let td_end_time = document.createElement("td")
let td_offset_time = document.createElement("td")
td_id.innerText = element.id td_id.innerText = element.id
td_time.innerText = element.time td_start_time.innerText = element.startTime
// td_end_time.innerText = element.endTime
td_end_time.innerText = element.offsetTime
td_offset_time.innerText = element.offsetTime
if (element.id == nowId) tr.style = highlight
tr.appendChild(td_id) tr.appendChild(td_id)
tr.appendChild(td_time) tr.appendChild(td_start_time)
tr.appendChild(td_end_time)
// tr.appendChild(td_offset_time)
table.appendChild(tr) table.appendChild(tr)
}) })
return table return table
} }
/**
* 计算总共的进样时间
* @param time 多少分钟一针
* @param ptime 时间需要提前多少分钟
* @param stime 现在这针运行多少分钟
* @param num 计算第n针后的时间
*/
function injectionSequence(time, ptime, stime, num) {
// formal: InjectionSequence = time * num - ptime - stime
let t = new Decimal(time)
let p = new Decimal(ptime)
let s = new Decimal(stime)
let n = new Decimal(num)
return decimal.mul(t, n).sub(p).sub(s).toString()
}
// 为 Date 创建日期格式化方法 // 为 Date 创建日期格式化方法
Date.prototype.format = function (fmt) { Date.prototype.format = function (fmt) {
let o = { let o = {
@@ -144,13 +170,14 @@
</head> </head>
<body> <body>
<h3>进样序列</h3> <h3>进样时间</h3>
<div class="input"> <div class="input">
<div class="inputbox"> <div class="inputbox">
<input type="number" id="time" placeholder="多少分钟一针" inputmode="decimal" autocomplete="off"> <input type="number" id="allId" placeholder="批处理中样品的总数" inputmode="decimal" autocomplete="off">
<input type="number" id="num" placeholder="一共有多少针(包括正在运行的)" inputmode="decimal" autocomplete="off"> <input type="number" id="time" placeholder="每一针的运行时间" inputmode="decimal" autocomplete="off">
<input type="number" id="stime" placeholder="现在这针运行多少分钟" inputmode="decimal" autocomplete="off"> <input type="number" id="nowId" placeholder="当前运行到第几针" inputmode="decimal" autocomplete="off">
<input type="number" id="ptime" placeholder="时间提前量(分钟" inputmode="decimal" autocomplete="off"> <input type="number" id="nowTime" placeholder="现在这针运行多少分钟" inputmode="decimal" autocomplete="off">
<input type="number" id="offset" placeholder="时间偏移量" inputmode="decimal" autocomplete="off">
</div> </div>
<br> <br>
<div class="buttons"> <div class="buttons">

1
modules/dayjs.min.js vendored Normal file

File diff suppressed because one or more lines are too long

4898
modules/decimal.mjs Normal file

File diff suppressed because it is too large Load Diff