You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
General-AI-Platform-Web/mock/pools/businessStateData.ts

241 lines
6.6 KiB
TypeScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*
* @Author: donghao donghao@supervision.ltd
* @Date: 2024-03-01 16:34:06
* @LastEditors: donghao donghao@supervision.ltd
* @LastEditTime: 2024-05-10 15:23:17
* @FilePath: \General-AI-Platform-Web\mock\pools\serverData.ts
* @Description: mock服务器数据
*/
import { generateRandomString } from '../utils/mockHash';
import { generateRandomDateTimeByYear } from '../utils/mockMoment';
const generateRandomTwoDecimal = () => {
// 生成一个在 [0, 1) 范围内的随机数
const randomFraction = Math.random();
// 乘以一个倍数,例如 100以增加小数位数
const multipliedValue = randomFraction * 100;
// 使用 Math.round() 进行四舍五入,并将结果除以倍数,得到两位小数
return Math.round(multipliedValue) / 100;
};
const progressData = () => {
const finalArr = [
{
label: 'CPU',
percent: generateRandomTwoDecimal(),
strokeColor: 'rgb(243,48,5)',
usedColors: ['#FFAB00', '#FF4409'],
freeColors: ['#477BFF', '#0048FE'],
},
{
label: '内存',
percent: (15 + Math.floor(Math.random() * 85)) / 100,
strokeColor: 'rgb(33,169,122)',
usedColors: ['#47A3FF', '#0D6EFF'],
freeColors: ['#00C45A ', '#4AE003'],
},
{
label: '存储',
percent: (15 + Math.floor(Math.random() * 85)) / 100,
strokeColor: 'rgb(33,169,122)',
usedColors: ['#FF8110', '#EB0404'],
freeColors: ['#4200FF', '#9520F0'],
},
{
label: 'GPU',
percent: (85 + Math.floor(Math.random() * 15)) / 100,
strokeColor: 'rgb(250,173,20)',
usedColors: ['#AE47FF', '#F008AF'],
freeColors: ['#FF4D00', '#F2B721'],
},
];
return finalArr;
};
// 服务器状态列表生成数据
const fetchServerList = () => {
const currList: Record<string, any>[] = [];
const count = 30;
const baseVersion = 'V' + Math.floor(Math.random() * 10);
const currFileTime = new Date().getTime();
const randomString = generateRandomString(20);
const ip1 = Math.floor(Math.random() * 255);
const ip2 = Math.floor(Math.random() * 255);
let onlineCount = 0;
let outlineCount = 0;
for (let i = 0; i < count; i++) {
const currState = Math.floor(Math.random() * 8) % 2 === 0 ? '1' : '2';
if (currState === '1') {
onlineCount++;
} else {
outlineCount++;
}
currList.push({
id: i + '1',
createTime: generateRandomDateTimeByYear(2022),
updateTime: generateRandomDateTimeByYear(2023),
isEnable: Math.floor(Math.random() * 8) % 2 === 0,
deviceSort: '服务器' + (i + 1),
index: i,
provider: '苏胜天',
type: 4,
banner: 'https://tdesign.gtimg.com/tdesign-pro/cloud-server.jpg',
state: currState,
IP: `192.168.${ip1}.${ip2}`,
port: 80,
userName: 'admin',
pwd: '123456',
description:
'SSL证书又叫服务器证书腾讯云为您提供证书的一站式服务包括免费、付费证书的申请、管理及部',
progressData: progressData(),
});
}
return {
count,
data: currList,
onlineCount,
outlineCount,
};
};
// 设备状态列表生成数据
const fetchDeviceList = () => {
const currList: Record<string, any>[] = [];
const count = 120;
const baseVersion = 'V' + Math.floor(Math.random() * 10);
const currFileTime = new Date().getTime();
const randomString = generateRandomString(20);
const ip1 = Math.floor(Math.random() * 255);
const ip2 = Math.floor(Math.random() * 255);
let onlineCount = 0;
let outlineCount = 0;
let processCount = 0;
let errorCount = 0;
for (let i = 0; i < count; i++) {
const currState = 1 + (Math.floor(Math.random() * 30) % 4) + '';
switch (currState) {
case '1':
onlineCount++;
break;
case '2':
outlineCount++;
break;
case '3':
processCount++;
break;
default:
errorCount++;
break;
}
currList.push({
id: i + '1',
createTime: generateRandomDateTimeByYear(2022),
updateTime: generateRandomDateTimeByYear(2023),
isEnable: Math.floor(Math.random() * 8) % 2 === 0,
name: '设备' + (i + 1),
groupName: '设备组0' + ((Math.floor(Math.random() * 8) % 3) + 1),
deviceType: '设备分类' + ((Math.floor(Math.random() * 8) % 4) + 1),
index: i,
provider: '苏胜天',
type: 4,
banner: 'https://tdesign.gtimg.com/tdesign-pro/cloud-server.jpg',
state: currState,
IP: `192.168.${ip1}.${ip2}`,
port: 80,
remark: '暂无',
description:
'SSL证书又叫服务器证书腾讯云为您提供证书的一站式服务包括免费、付费证书的申请、管理及部',
progressData: progressData(),
});
}
return {
count,
data: currList,
onlineCount,
outlineCount,
processCount,
errorCount,
};
};
// 服务器日志列表数据生成
const fetchServerStateLogList = () => {
const count = 1 + Math.floor(Math.random() * 80);
let currList = [];
for (let i = 0; i < count; i++) {
const ip1 = Math.floor(Math.random() * 255);
const ip2 = Math.floor(Math.random() * 255);
const port = 80;
currList.push({
id: i + '1',
createTime: generateRandomDateTimeByYear(2022),
updateTime: generateRandomDateTimeByYear(2023),
IP: `192.168.${ip1}.${ip2}`,
port,
deviceSort: '服务器',
provider: '苏胜天',
});
}
return {
count: currList.length,
data: currList,
};
};
// 设备日志列表数据生成
const fetchDeviceStateLogList = () => {
const count = 1 + Math.floor(Math.random() * 80);
let currList = [];
for (let i = 0; i < count; i++) {
const ip1 = Math.floor(Math.random() * 255);
const ip2 = Math.floor(Math.random() * 255);
const port = 80;
currList.push({
id: i + '1',
createTime: generateRandomDateTimeByYear(2022),
updateTime: generateRandomDateTimeByYear(2023),
IP: `192.168.${ip1}.${ip2}`,
port,
deviceSort: '设备',
provider: '苏胜天',
runTime: `${Math.floor(Math.random() * 100)}${Math.floor(Math.random() * 24)}小时`,
});
}
return {
count: currList.length,
data: currList,
};
};
/**服务器 */
export const serverListData = {
data: {
...fetchServerList(),
},
};
export const serverParamsListData = {
data: {
data: progressData(),
},
};
export const serverStateLogListData = {
data: {
...fetchServerStateLogList(),
},
};
/**设备 */
export const deviceListData = {
data: {
...fetchDeviceList(),
},
};
export const deviceStateLogListData = {
data: {
...fetchDeviceStateLogList(),
},
};