Change model dir structure

This commit is contained in:
LollipopKit
2021-10-28 21:04:59 +08:00
parent 6426277406
commit 6db223ec5a
24 changed files with 71 additions and 51 deletions

View File

@@ -0,0 +1,47 @@
import 'package:toolbox/data/model/server/cpu_status.dart';
class Cpu2Status {
List<CpuStatus> pre;
List<CpuStatus> now;
String temp;
Cpu2Status(this.pre, this.now, this.temp);
double usedPercent({int coreIdx = 0}) {
if (now.length != pre.length) return 0;
final idleDelta = now[coreIdx].idle - pre[coreIdx].idle;
final totalDelta = now[coreIdx].total - pre[coreIdx].total;
final used = idleDelta / totalDelta;
return used.isNaN ? 0 : 100 - used * 100;
}
Cpu2Status update(List<CpuStatus> newStatus, String newTemp) {
return Cpu2Status(now, newStatus, newTemp);
}
int get coresCount => now.length;
int get totalDelta => now[0].total - pre[0].total;
double get user {
if (now.length != pre.length) return 0;
final delta = now[0].user - pre[0].user;
final used = delta / totalDelta;
return used.isNaN ? 0 : used * 100;
}
double get sys {
if (now.length != pre.length) return 0;
final delta = now[0].sys - pre[0].sys;
final used = delta / totalDelta;
return used.isNaN ? 0 : used * 100;
}
double get nice {
if (now.length != pre.length) return 0;
final delta = now[0].nice - pre[0].nice;
final used = delta / totalDelta;
return used.isNaN ? 0 : used * 100;
}
double get idle => 100 - usedPercent();
}

View File

@@ -0,0 +1,60 @@
///
/// Code generated by jsonToDartModel https://ashamp.github.io/jsonToDartModel/
///
class CpuStatus {
/*
{
"user": 0,
"sys": 0,
"nice": 0,
"idel": 0,
"wa": 0,
"hi": 0,
"si": 0,
"st": 0
}
*/
late String id;
late int user;
late int sys;
late int nice;
late int idle;
late int iowait;
late int irq;
late int softirq;
CpuStatus(
this.id,
this.user,
this.sys,
this.nice,
this.idle,
this.iowait,
this.irq,
this.softirq,
);
CpuStatus.fromJson(Map<String, dynamic> json) {
id = json["id"];
user = json["user"]?.toInt();
sys = json["sys"]?.toInt();
nice = json["nice"]?.toInt();
idle = json["idle"]?.toInt();
iowait = json["iowait"]?.toInt();
irq = json["irq"]?.toInt();
softirq = json["softirq"]?.toInt();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data["id"] = id;
data["user"] = user;
data["sys"] = sys;
data["nice"] = nice;
data["idle"] = idle;
data["iowait"] = iowait;
data["irq"] = irq;
data["softirq"] = softirq;
return data;
}
int get total => user + sys + nice + idle + iowait + irq + softirq;
}

View File

@@ -0,0 +1,47 @@
class DiskInfo {
/*
{
"mountPath": "",
"mountLocation": "",
"usedPercent": 0,
"used": "",
"size": "",
"avail": ""
}
*/
late String mountPath;
late String mountLocation;
late int usedPercent;
late String used;
late String size;
late String avail;
DiskInfo(
this.mountPath,
this.mountLocation,
this.usedPercent,
this.used,
this.size,
this.avail,
);
DiskInfo.fromJson(Map<String, dynamic> json) {
mountPath = json["mountPath"].toString();
mountLocation = json["mountLocation"].toString();
usedPercent = int.parse(json["usedPercent"]);
used = json["used"].toString();
size = json["size"].toString();
avail = json["avail"].toString();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data["mountPath"] = mountPath;
data["mountLocation"] = mountLocation;
data["usedPercent"] = usedPercent;
data["used"] = used;
data["size"] = size;
data["avail"] = avail;
return data;
}
}

View File

@@ -0,0 +1,14 @@
class LinuxIcons {
List<String> db;
LinuxIcons(this.db);
String? search(String sysVer) {
for (var item in db) {
if (sysVer.toLowerCase().contains(item)) {
return 'assets/linux/$item.png';
}
}
return null;
}
}

View File

@@ -0,0 +1,48 @@
import 'dart:convert';
///
/// Code generated by jsonToDartModel https://ashamp.github.io/jsonToDartModel/
///
class PrivateKeyInfo {
/*
{
"id": "",
"private_key": "",
"password": ""
}
*/
late String id;
late String privateKey;
late String password;
PrivateKeyInfo(
this.id,
this.privateKey,
this.password,
);
PrivateKeyInfo.fromJson(Map<String, dynamic> json) {
id = json["id"].toString();
privateKey = json["private_key"].toString();
password = json["password"].toString();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data["id"] = id;
data["private_key"] = privateKey;
data["password"] = password;
return data;
}
}
List<PrivateKeyInfo>? getPrivateKeyInfoList(dynamic data) {
List<PrivateKeyInfo> ss = [];
if (data is String) {
data = json.decode(data);
}
for (var t in data) {
ss.add(PrivateKeyInfo.fromJson(t));
}
return ss;
}

View File

@@ -0,0 +1,13 @@
import 'package:ssh2/ssh2.dart';
import 'package:toolbox/data/model/server/server_connection_state.dart';
import 'package:toolbox/data/model/server/server_private_info.dart';
import 'package:toolbox/data/model/server/server_status.dart';
class ServerInfo {
ServerPrivateInfo info;
ServerStatus status;
SSHClient client;
ServerConnectionState connectionState;
ServerInfo(this.info, this.status, this.client, this.connectionState);
}

View File

@@ -0,0 +1 @@
enum ServerConnectionState { disconnected, connecting, connected, failed }

View File

@@ -0,0 +1,57 @@
import 'dart:convert';
///
/// Code generated by jsonToDartModel https://ashamp.github.io/jsonToDartModel/
///
class ServerPrivateInfo {
/*
{
"ip": "",
"port": 1,
"user": "",
"authorization": ""
}
*/
String? name;
String? ip;
int? port;
String? user;
Object? authorization;
ServerPrivateInfo({
this.name,
this.ip,
this.port,
this.user,
this.authorization,
});
ServerPrivateInfo.fromJson(Map<String, dynamic> json) {
name = json["name"]?.toString();
ip = json["ip"]?.toString();
port = json["port"]?.toInt();
user = json["user"]?.toString();
authorization = json["authorization"];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data["name"] = name;
data["ip"] = ip;
data["port"] = port;
data["user"] = user;
data["authorization"] = authorization;
return data;
}
}
List<ServerPrivateInfo>? getServerInfoList(dynamic data) {
List<ServerPrivateInfo> ss = [];
if (data is String) {
data = json.decode(data);
}
for (var t in data) {
ss.add(ServerPrivateInfo.fromJson(t));
}
return ss;
}

View File

@@ -0,0 +1,40 @@
import 'package:toolbox/data/model/server/cpu_2_status.dart';
import 'package:toolbox/data/model/server/disk_info.dart';
import 'package:toolbox/data/model/server/tcp_status.dart';
///
/// Code generated by jsonToDartModel https://ashamp.github.io/jsonToDartModel/
///
class ServerStatus {
/*
{
"cpuPercent": 0,
"memList": [
1
],
"sysVer": "",
"uptime": "",
"disk": [
{
"mountPath": "",
"mountLocation": "",
"usedPercent": 0,
"used": "",
"size": "",
"avail": ""
}
]
}
*/
late Cpu2Status cpu2Status;
late List<int> memList;
late String sysVer;
late String uptime;
late List<DiskInfo> disk;
late TcpStatus tcp;
ServerStatus(this.cpu2Status, this.memList, this.sysVer, this.uptime,
this.disk, this.tcp);
}

View File

@@ -0,0 +1,41 @@
///
/// Code generated by jsonToDartModel https://ashamp.github.io/jsonToDartModel/
///
class TcpStatus {
/*
{
"maxConn": 0,
"active": 1,
"passive": 2,
"fail": 3
}
*/
late int maxConn;
late int active;
late int passive;
late int fail;
TcpStatus(
this.maxConn,
this.active,
this.passive,
this.fail,
);
TcpStatus.fromJson(Map<String, dynamic> json) {
maxConn = json["maxConn"].toInt();
active = json["active"].toInt();
passive = json["passive"].toInt();
fail = json["fail"].toInt();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data["maxConn"] = maxConn;
data["active"] = active;
data["passive"] = passive;
data["fail"] = fail;
return data;
}
}