oc-front/lib/models/search.dart

1145 lines
33 KiB
Dart
Raw Normal View History

2024-08-22 15:46:16 +02:00
import 'dart:async';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
2024-08-08 08:42:32 +02:00
import 'package:flutter_flow_chart/flutter_flow_chart.dart';
import 'package:oc_front/models/abstract.dart';
2024-08-08 08:42:32 +02:00
const List<ProcessingItem> _emptyComputing = [];
const List<DataItem> _emptyData = [];
2024-11-08 13:59:22 +01:00
const List<ComputeItem> _emptyCompute = [];
const List<StorageItem> _emptyStorage = [];
class Search extends SerializerDeserializer<Search> {
Search({
this.computing = _emptyComputing,
2024-11-08 13:59:22 +01:00
this.compute = _emptyCompute,
this.data = _emptyData,
this.storage = _emptyStorage,
});
2024-08-08 08:42:32 +02:00
List<ProcessingItem> computing;
2024-11-08 13:59:22 +01:00
List<ComputeItem> compute;
List<DataItem> data;
List<StorageItem> storage;
@override deserialize(dynamic json) {
json = json as Map<String, dynamic>;
return Search(
2024-08-08 08:42:32 +02:00
computing: json.containsKey("processing") ? fromListJson(json["processing"], ProcessingItem()) : [],
2024-11-08 13:59:22 +01:00
compute: json.containsKey("compute") ? fromListJson(json["compute"], ComputeItem()) : [],
data: json.containsKey("data") ? fromListJson(json["data"], DataItem()) : [],
storage: json.containsKey("storage") ? fromListJson(json["storage"], StorageItem()) : [],
);
}
2024-08-08 08:42:32 +02:00
@override Map<String, dynamic> serialize() => {
"processing": toListJson<ProcessingItem>(computing),
2024-11-08 13:59:22 +01:00
"compute": toListJson<ComputeItem>(compute),
2024-08-08 08:42:32 +02:00
"data": toListJson<DataItem>(data),
"storage": toListJson<StorageItem>(storage),
};
}
const List<String> _empty = [];
2024-08-08 08:42:32 +02:00
class Resource implements SerializerDeserializer<Resource> {
List<DataItem> datas = [];
List<ProcessingItem> processings = [];
List<StorageItem> storages = [];
2024-11-08 13:59:22 +01:00
List<ComputeItem> computes = [];
2024-08-08 08:42:32 +02:00
List<WorkflowItem> workflows = [];
Resource({
this.datas = const [],
this.processings = const [],
this.storages = const [],
2024-11-08 13:59:22 +01:00
this.computes = const [],
2024-08-08 08:42:32 +02:00
this.workflows = const [],
});
@override Resource deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Resource(); }
return Resource(
2024-11-08 13:59:22 +01:00
computes: json.containsKey("compute_resource") ? fromListJson(json["compute_resource"], ComputeItem()) : [],
2024-08-08 08:42:32 +02:00
datas: json.containsKey("data_resource") ? fromListJson(json["data_resource"], DataItem()) : [],
processings: json.containsKey("processing_resource") ? fromListJson(json["processing_resource"], ProcessingItem()) : [],
storages: json.containsKey("storage_resource") ? fromListJson(json["storage_resource"], StorageItem()) : [],
workflows: json.containsKey("workflow_resource") ? fromListJson(json["workflow_resource"], WorkflowItem()) : [],
);
}
@override Map<String, dynamic> serialize() {
return {
2024-11-08 13:59:22 +01:00
"compute_resource": toListJson<ComputeItem>(computes),
2024-08-08 08:42:32 +02:00
"data_resource": toListJson<DataItem>(datas),
"processing_resource": toListJson<ProcessingItem>(processings),
"storage_resource": toListJson<StorageItem>(storages),
"workflow_resource": toListJson<WorkflowItem>(workflows),
};
}
}
abstract class AbstractItem<T extends FlowData> extends FlowData implements SerializerDeserializer<T> {
String? id;
String? name;
String? logo;
String? owner;
2024-08-08 08:42:32 +02:00
String? ownerLogo;
String? source;
String? description;
String? shortDescription;
2024-08-08 08:42:32 +02:00
double? price;
String? licence;
List<dynamic> inputs = [];
List<dynamic> outputs = [];
ResourceModel? model;
String topic = "";
2024-08-08 08:42:32 +02:00
AbstractItem({
this.id,
this.name,
this.logo,
this.owner,
this.ownerLogo,
this.price,
this.source,
this.licence,
this.description,
this.model,
this.shortDescription,
this.inputs = const [],
this.outputs = const [],
});
@override String getID() {
return id ?? "";
}
@override String getName() {
return name ?? "";
}
2024-11-19 15:06:22 +01:00
String getTopic() {
return topic;
}
2024-08-08 08:42:32 +02:00
}
class Model extends SerializerDeserializer<Model> {
dynamic value;
String? type;
bool readonly = false;
Model({
this.value,
this.type,
this.readonly = false,
});
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Model(); }
return Model(
value: json.containsKey("value") ? json["value"] : null,
type: json.containsKey("type") ? json["type"] : null,
readonly: json.containsKey("readonly") ? json["readonly"] : false,
);
}
@override Map<String, dynamic> serialize() => {
"value": value,
"type": type,
"readonly": readonly,
};
}
class ResourceModel extends SerializerDeserializer<ResourceModel> {
String? id;
String? type;
2024-10-15 11:28:29 +02:00
Map<String, dynamic> refs;
Map<String, Map<String,Model>>? model;
2024-08-08 08:42:32 +02:00
ResourceModel({
this.id,
this.type,
2024-10-15 11:28:29 +02:00
this.refs = const {},
2024-08-08 08:42:32 +02:00
this.model,
});
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return ResourceModel(); }
2024-10-15 11:28:29 +02:00
var w = ResourceModel(
2024-08-08 08:42:32 +02:00
id: json.containsKey("id") ? json["id"] : null,
type: json.containsKey("type") ? json["type"] : null,
2024-10-15 11:28:29 +02:00
refs: json.containsKey("var_refs") ? json["var_refs"] : {},
2024-08-08 08:42:32 +02:00
);
2024-10-15 11:28:29 +02:00
if (json.containsKey("model")) {
w.model = {};
for (var key in (json["model"] as Map<dynamic, dynamic>).keys) {
w.model![key] = {};
for (var k2 in (json["model"][key] as Map<dynamic, dynamic>).keys) {
w.model![key]![k2] = Model().deserialize(json["model"][key][k2]);
}
}
}
return w;
}
@override Map<String, dynamic> serialize() {
Map<String, dynamic> t = {
"id": id,
"type": type,
"var_refs": refs,
};
t["model"] = {};
if (model != null) {
for (var key in model!.keys) {
t["model"][key] = {};
for (var k2 in model![key]!.keys) {
t["model"][key]![k2] = model![key]![k2]!.serialize();
}
}
}
return t;
2024-08-08 08:42:32 +02:00
}
}
Type? getTopicType(String topic) {
2024-08-08 08:42:32 +02:00
if (topic == "processing") { return ProcessingItem; }
else if (topic == "data") { return DataItem; }
2024-11-08 13:59:22 +01:00
else if (topic == "compute") { return ComputeItem; }
else if (topic == "storage") { return StorageItem; }
2024-08-08 08:42:32 +02:00
else if (topic == "workflow") { return WorkflowItem; }
else { return null; }
}
String getTopic(Type type) {
2024-08-08 08:42:32 +02:00
if (type == AbstractItem) { return "resource"; }
if (type == ProcessingItem) { return "processing"; }
if (type == DataItem) { return "data"; }
2024-11-08 13:59:22 +01:00
if (type == ComputeItem) { return "compute"; }
if (type == StorageItem) { return "storage"; }
2024-08-08 08:42:32 +02:00
if (type == WorkflowItem) { return "workflow"; }
return "";
}
2024-08-08 08:42:32 +02:00
bool isComputing(String topic) => topic == "processing";
bool isData(String topic) => topic == "data";
2024-11-08 13:59:22 +01:00
bool isCompute(String topic) => topic == "compute";
bool isStorage(String topic) => topic == "storage";
2024-08-08 08:42:32 +02:00
bool isWorkflow(String topic) => topic == "workflow";
2024-10-15 11:28:29 +02:00
class Expose extends SerializerDeserializer<Expose> {
Expose({
this.PAT,
this.port,
this.path,
});
int? port;
int? PAT;
String? path;
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Expose(); }
return Expose(
port: json.containsKey("port") ? json["port"] : null,
PAT: json.containsKey("PAT") ? json["PAT"] : null,
path: json.containsKey("reverse") ? json["reverse"] : null,
);
}
@override Map<String, dynamic> serialize() => {
"port": port,
"PAT": PAT,
"reverse": path,
};
}
class Containered extends SerializerDeserializer<Containered> {
Containered({
this.image,
this.args,
this.command,
this.env,
this.volumes,
});
String? args;
String? image;
String? command;
Map<String, dynamic>? env;
Map<String, dynamic>? volumes;
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Containered(); }
return Containered(
args: json.containsKey("args") ? json["args"] : null,
image: json.containsKey("image") ? json["image"] : null,
command: json.containsKey("command") ? json["command"] : null,
env: json.containsKey("env") ? json["env"] : null,
volumes: json.containsKey("volumes") ? json["volumes"] : null,
);
}
@override Map<String, dynamic> serialize() {
var w = {
"args": args,
"image": image,
"command": command,
"env": env,
"volumes": volumes,
};
return w;
}
}
2024-08-08 08:42:32 +02:00
class ProcessingItem extends SerializerDeserializer<ProcessingItem> implements AbstractItem<ProcessingItem> {
2024-11-19 15:06:22 +01:00
@override
String getTopic() {
return topic;
}
2024-08-08 08:42:32 +02:00
ProcessingItem({
this.id,
this.name,
this.logo,
this.owner,
2024-08-08 08:42:32 +02:00
this.ownerLogo,
this.price,
2024-08-08 08:42:32 +02:00
this.source,
this.licence,
this.description,
this.shortDescription,
2024-08-08 08:42:32 +02:00
this.inputs = _empty,
this.outputs = _empty,
this.cpus = const [],
this.gpus = const [],
this.ram,
this.storage,
this.parrallel = false,
this.scallingModel,
this.diskIO,
2024-10-15 11:28:29 +02:00
this.expose = const [],
this.container,
2024-08-08 08:42:32 +02:00
this.model,
});
2024-08-08 08:42:32 +02:00
@override ResourceModel? model;
@override String? id;
@override String? name;
@override String? logo;
2024-08-08 08:42:32 +02:00
@override String? source;
@override String? ownerLogo;
@override String? owner;
2024-08-08 08:42:32 +02:00
@override String topic = "processing";
@override double? price;
@override String? licence;
@override List<dynamic> inputs;
@override List<dynamic> outputs;
@override String? description;
@override String? shortDescription;
2024-10-15 11:28:29 +02:00
Containered? container;
List<Expose> expose = [];
2024-08-08 08:42:32 +02:00
// Special Attributes
List<CPU> cpus = [];
List<GPU> gpus = [];
RAM? ram;
int? storage;
bool parrallel = false;
int? scallingModel;
String? diskIO;
@override String getID() {
return id ?? "";
}
@override String getName() {
return name ?? "";
}
2024-08-22 15:46:16 +02:00
double? width;
double? height;
@override
double? getWidth() {
return width;
}
@override
double? getHeight() {
return height;
}
2024-10-15 11:28:29 +02:00
@override
Map<String, dynamic> setVariable(List<String> keys, dynamic value, Map<String, dynamic> map) {
if (keys.isEmpty) { return map; }
var key = keys[0];
if (keys.length > 1 && map[key] != null) {
map[key] = setVariable(keys.sublist(1), value, map[key]);
} else {
map[key] = value;
}
return map;
}
@override
dynamic getVariable(List<String> keys, Map<String, dynamic> map) {
if (keys.isEmpty) { return null; }
var key = keys[0];
if (keys.length > 1 && map[key] != null) {
return getVariable(keys.sublist(1), map[key]);
}
return map[key];
}
2024-08-22 15:46:16 +02:00
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
2024-08-08 08:42:32 +02:00
} catch (e) { return ProcessingItem(); }
2024-08-22 15:46:16 +02:00
var w = ProcessingItem(
2024-08-08 08:42:32 +02:00
id: json.containsKey("id") ? json["id"] : null,
name: json.containsKey("name") ? json["name"] : null,
logo: json.containsKey("logo") ? json["logo"] : null,
owner: json.containsKey("owner") ? json["owner"] : null,
2024-08-08 08:42:32 +02:00
ownerLogo: json.containsKey("owner_logo") ? json["owner_logo"] : null,
price: json.containsKey("price") ? json["price"]?.toDouble() : null,
licence: json.containsKey("licence") ? json["licence"] : null,
description: json.containsKey("description") ? json["description"] : null,
shortDescription: json.containsKey("short_description") ? json["short_description"] : null,
2024-08-08 08:42:32 +02:00
inputs: json["inputs"] ?? [],
outputs: json["outputs"] ?? [],
source: json.containsKey("source") ? json["source"] : null,
2024-10-15 11:28:29 +02:00
expose: json.containsKey("expose") ? fromListJson(json["expose"], Expose()) : [],
container: json.containsKey("container") ? Containered().deserialize(json["container"]) : null,
2024-08-08 08:42:32 +02:00
model: json.containsKey("resource_model") ? ResourceModel().deserialize(json["resource_model"]) : null,
cpus: json.containsKey("cpus") ? fromListJson(json["cpus"], CPU()) : [],
gpus: json.containsKey("gpus") ? fromListJson(json["gpus"], GPU()) : [],
ram: json.containsKey("ram") ? RAM().deserialize(json["ram"]) : null,
storage: json.containsKey("storage") ? json["storage"] : null,
parrallel: json.containsKey("parrallel") ? json["parrallel"] : false,
scallingModel: json.containsKey("scalling_model") ? json["scalling_model"] : null,
diskIO: json.containsKey("disk_io") ? json["disk_io"] : null,
);
2024-08-22 15:46:16 +02:00
if (w.logo != null) {
var image = Image.network(w.logo!);
image.image
.resolve(const ImageConfiguration())
.addListener(
ImageStreamListener(
(ImageInfo info, bool _) {
w.width = info.image.width.toDouble();
w.height = info.image.height.toDouble();
}));
}
return w;
}
2024-10-15 11:28:29 +02:00
@override Map<String, dynamic> serialize() {
return {
2024-08-08 08:42:32 +02:00
"id": id,
"name": name,
"logo": logo,
"owner": owner,
"owner_logo": ownerLogo,
"price": price,
"licence": licence,
"description": description,
"short_description": shortDescription,
"inputs": inputs,
"outputs": outputs,
"source": source,
"resource_model": model?.serialize(),
"cpus": toListJson<CPU>(cpus),
"gpus": toListJson<GPU>(gpus),
"ram": ram?.serialize(),
"storage": storage,
"parrallel": parrallel,
"scalling_model": scallingModel,
"disk_io": diskIO,
2024-10-15 11:28:29 +02:00
""
"expose": toListJson<Expose>(expose),
"container": container?.serialize(),
}; }
}
2024-08-08 08:42:32 +02:00
class WorkflowItem extends SerializerDeserializer<WorkflowItem> implements AbstractItem<WorkflowItem> {
2024-11-19 15:06:22 +01:00
@override
String getTopic() {
return topic;
}
2024-08-08 08:42:32 +02:00
WorkflowItem({
this.id,
this.name,
this.logo,
this.owner,
this.ownerLogo,
this.price,
this.source,
this.licence,
this.description,
this.shortDescription,
this.inputs = _empty,
this.outputs = _empty,
this.model,
this.workflowID,
});
2024-08-08 08:42:32 +02:00
@override ResourceModel? model;
@override String? id;
@override String? name;
@override String? logo;
@override String? source;
@override String? ownerLogo;
@override String? owner;
@override String topic = "workflow";
@override double? price;
@override String? licence;
@override List<dynamic> inputs;
@override List<dynamic> outputs;
@override String? description;
@override String? shortDescription;
2024-08-08 08:42:32 +02:00
String? workflowID;
@override String getID() {
return id ?? "";
}
2024-08-22 15:46:16 +02:00
double? width;
double? height;
@override
double? getWidth() {
return width;
}
@override
double? getHeight() {
return height;
}
2024-08-08 08:42:32 +02:00
@override String getName() {
return name ?? "";
}
2024-10-15 11:28:29 +02:00
@override
Map<String, dynamic> setVariable(List<String> keys, dynamic value, Map<String, dynamic> map) {
if (keys.isEmpty) { return map; }
var key = keys[0];
if (keys.length > 1 && map[key] != null) {
map[key] = setVariable(keys.sublist(1), value, map[key]);
} else {
map[key] = value;
}
return map;
}
@override
dynamic getVariable(List<String> keys, Map<String, dynamic> map) {
if (keys.isEmpty) { return null; }
var key = keys[0];
if (keys.length > 1 && map[key] != null) {
return getVariable(keys.sublist(1), map[key]);
}
return map[key];
}
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
2024-08-08 08:42:32 +02:00
} catch (e) { return WorkflowItem(); }
2024-08-22 15:46:16 +02:00
var w = WorkflowItem(
2024-08-08 08:42:32 +02:00
id: json.containsKey("id") ? json["id"] : null,
name: json.containsKey("name") ? json["name"] : null,
logo: json.containsKey("logo") ? json["logo"] : null,
owner: json.containsKey("owner") ? json["owner"] : null,
ownerLogo: json.containsKey("owner_logo") ? json["owner_logo"] : null,
price: json.containsKey("price") ? json["price"]?.toDouble() : null,
licence: json.containsKey("licence") ? json["licence"] : null,
description: json.containsKey("description") ? json["description"] : null,
shortDescription: json.containsKey("short_description") ? json["short_description"] : null,
inputs: json["inputs"] ?? [],
outputs: json["outputs"] ?? [],
source: json.containsKey("source") ? json["source"] : null,
model: json.containsKey("resource_model") ? ResourceModel().deserialize(json["resource_model"]) : null,
workflowID: json.containsKey("workflow_id") ? json["workflow_id"] : null,
);
2024-08-22 15:46:16 +02:00
if (w.logo != null) {
//
var image = Image.network(w.logo!);
image.image
.resolve(const ImageConfiguration())
.addListener(
ImageStreamListener(
(ImageInfo info, bool _) {
w.width = info.image.width.toDouble();
w.height = info.image.height.toDouble();
}));
}
return w;
}
2024-08-08 08:42:32 +02:00
@override Map<String, dynamic> serialize() => {
"id": id,
"name": name,
"logo": logo,
"owner": owner,
"owner_logo": ownerLogo,
"price": price,
"licence": licence,
"description": description,
"short_description": shortDescription,
"inputs": inputs,
"outputs": outputs,
"source": source,
"resource_model": model?.serialize(),
"workflow_id": workflowID,
};
}
2024-08-08 08:42:32 +02:00
class DataItem extends SerializerDeserializer<DataItem> implements AbstractItem<DataItem> {
2024-11-19 15:06:22 +01:00
@override
String getTopic() {
return topic;
}
DataItem({
this.id,
this.name,
this.logo,
this.owner,
2024-08-08 08:42:32 +02:00
this.ownerLogo,
this.price,
this.source,
this.licence,
this.description,
this.shortDescription,
2024-08-08 08:42:32 +02:00
this.inputs = _empty,
this.outputs = _empty,
this.model,
2024-10-15 11:28:29 +02:00
this.protocol,
this.path,
2024-08-08 08:42:32 +02:00
this.protocols = const [],
2024-10-15 11:28:29 +02:00
this.type,
2024-08-08 08:42:32 +02:00
this.exemple,
});
@override String? id;
@override String? name;
@override String? logo;
2024-08-08 08:42:32 +02:00
@override String? source;
@override String? ownerLogo;
@override String? owner;
@override String topic = "data";
2024-08-08 08:42:32 +02:00
@override double? price;
@override String? licence;
@override List<dynamic> inputs;
@override List<dynamic> outputs;
@override String? description;
@override String? shortDescription;
2024-08-08 08:42:32 +02:00
@override ResourceModel? model;
// Special Attributes
List<String> protocols = [];
2024-10-15 11:28:29 +02:00
String? type;
String? protocol;
String? path;
2024-08-08 08:42:32 +02:00
String? exemple;
@override String getName() {
return name ?? "";
}
@override String getID() {
return id ?? "";
}
2024-08-22 15:46:16 +02:00
double? width;
double? height;
@override
double? getWidth() {
return width;
}
@override
double? getHeight() {
return height;
}
2024-10-15 11:28:29 +02:00
@override
Map<String, dynamic> setVariable(List<String> keys, dynamic value, Map<String, dynamic> map) {
if (keys.isEmpty) { return map; }
var key = keys[0];
if (keys.length > 1 && map[key] != null) {
map[key] = setVariable(keys.sublist(1), value, map[key]);
} else {
map[key] = value;
}
return map;
}
@override
dynamic getVariable(List<String> keys, Map<String, dynamic> map) {
if (keys.isEmpty) { return null; }
var key = keys[0];
if (keys.length > 1 && map[key] != null) {
return getVariable(keys.sublist(1), map[key]);
}
return map[key];
}
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return DataItem(); }
2024-08-22 15:46:16 +02:00
var w = DataItem(
2024-08-08 08:42:32 +02:00
id: json.containsKey("id") ? json["id"] : null,
name: json.containsKey("name") ? json["name"] : null,
logo: json.containsKey("logo") ? json["logo"] : null,
owner: json.containsKey("owner") ? json["owner"] : null,
2024-08-08 08:42:32 +02:00
ownerLogo: json.containsKey("owner_logo") ? json["owner_logo"] : null,
price: json.containsKey("price") ? json["price"]?.toDouble() : null,
licence: json.containsKey("licence") ? json["licence"] : null,
description: json.containsKey("description") ? json["description"] : null,
2024-08-08 08:42:32 +02:00
shortDescription: json.containsKey("short_description") ? json["short_description"] : null,
inputs: json["inputs"] ?? [],
outputs: json["outputs"] ?? [],
source: json.containsKey("source") ? json["source"] : null,
model: json.containsKey("resource_model") ? ResourceModel().deserialize(json["resource_model"]) : null,
protocols: json.containsKey("protocols") ? json["protocols"] : [],
2024-10-15 11:28:29 +02:00
type: json.containsKey("type") ? json["type"] : null,
protocol: json.containsKey("protocol") ? json["protocol"] : null,
path: json.containsKey("path") ? json["path"] : null,
2024-08-08 08:42:32 +02:00
exemple: json.containsKey("exemple") ? json["exemple"] : null,
);
2024-08-22 15:46:16 +02:00
if (w.logo != null) {
//
var image = Image.network(w.logo!);
image.image
.resolve(const ImageConfiguration())
.addListener(
ImageStreamListener(
(ImageInfo info, bool _) {
w.width = info.image.width.toDouble();
w.height = info.image.height.toDouble();
}));
}
return w;
}
2024-10-15 11:28:29 +02:00
2024-08-08 08:42:32 +02:00
@override Map<String, dynamic> serialize() => {
"id": id,
"name": name,
"logo": logo,
"owner": owner,
"owner_logo": ownerLogo,
"price": price,
"licence": licence,
"description": description,
"short_description": shortDescription,
"inputs": inputs,
"outputs": outputs,
"source": source,
"resource_model": model?.serialize(),
"protocols": protocols,
2024-10-15 11:28:29 +02:00
"type": type,
"protocol": protocol,
"path": path,
2024-08-08 08:42:32 +02:00
"exemple": exemple,
};
}
2024-08-08 08:42:32 +02:00
2024-11-08 13:59:22 +01:00
class ComputeItem extends SerializerDeserializer<ComputeItem> implements AbstractItem<ComputeItem> {
2024-11-19 15:06:22 +01:00
@override
String getTopic() {
return topic;
}
2024-11-08 13:59:22 +01:00
ComputeItem({
this.id,
this.name,
this.logo,
this.owner,
2024-08-08 08:42:32 +02:00
this.ownerLogo,
this.price,
this.source,
this.licence,
this.description,
this.shortDescription,
2024-08-08 08:42:32 +02:00
this.inputs = _empty,
this.outputs = _empty,
this.model,
this.cpus = const [],
this.gpus = const [],
this.ram,
2024-11-08 13:59:22 +01:00
this.technology,
this.access,
this.architecture,
this.localisation,
this.isService = false,
});
@override String? id;
@override String? name;
@override String? logo;
2024-08-08 08:42:32 +02:00
@override String? source;
@override String? ownerLogo;
@override String? owner;
2024-11-08 13:59:22 +01:00
@override String topic = "compute";
2024-08-08 08:42:32 +02:00
@override double? price;
@override String? licence;
@override List<dynamic> inputs;
@override List<dynamic> outputs;
@override String? description;
@override String? shortDescription;
2024-08-08 08:42:32 +02:00
@override ResourceModel? model;
2024-11-08 13:59:22 +01:00
bool isService = false;
String? architecture;
int? access;
String? localisation;
2024-08-08 08:42:32 +02:00
// Special Attributes
List<CPU> cpus = [];
List<GPU> gpus = [];
2024-11-08 13:59:22 +01:00
int? technology;
2024-08-08 08:42:32 +02:00
RAM? ram;
@override String getID() {
return id ?? "";
}
@override String getName() {
return name ?? "";
}
2024-08-22 15:46:16 +02:00
double? width;
double? height;
@override
double? getWidth() {
return width;
}
@override
double? getHeight() {
return height;
}
2024-11-08 13:59:22 +01:00
String getTechnology() {
if (technology == 0) { return "docker"; }
if (technology == 1) { return "kubernetes"; }
if (technology == 2) { return "slurm"; }
if (technology == 3) { return "hardware"; }
if (technology == 4) { return "condor"; }
return "";
}
String getAccess() {
if (access == 0) { return "ssh"; }
if (access == 1) { return "ssh kube api"; }
if (access == 2) { return "ssh slurm"; }
if (access == 3) { return "ssh docker"; }
if (access == 4) { return "opencloud"; }
if (access == 5) { return "vpn"; }
return "";
}
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
2024-11-08 13:59:22 +01:00
} catch (e) { return ComputeItem(); }
var w = ComputeItem(
isService: json.containsKey("is_service") ? json["is_service"] : false,
2024-08-08 08:42:32 +02:00
id: json.containsKey("id") ? json["id"] : null,
name: json.containsKey("name") ? json["name"] : null,
logo: json.containsKey("logo") ? json["logo"] : null,
2024-11-08 13:59:22 +01:00
technology: json.containsKey("technology") ? json["technology"] : null,
owner: json.containsKey("owner") ? json["owner"] : null,
2024-08-08 08:42:32 +02:00
ownerLogo: json.containsKey("owner_logo") ? json["owner_logo"] : null,
price: json.containsKey("price") ? json["price"]?.toDouble() : null,
licence: json.containsKey("licence") ? json["licence"] : null,
description: json.containsKey("description") ? json["description"] : null,
shortDescription: json.containsKey("short_description") ? json["short_description"] : null,
2024-11-08 13:59:22 +01:00
access: json.containsKey("access") ? json["access"] : null,
architecture: json.containsKey("architecture") ? json["architecture"] : null,
localisation: json.containsKey("localisation") ? json["localisation"] : null,
2024-08-08 08:42:32 +02:00
inputs: json["inputs"] ?? [],
outputs: json["outputs"] ?? [],
source: json.containsKey("source") ? json["source"] : null,
model: json.containsKey("resource_model") ? ResourceModel().deserialize(json["resource_model"]) : null,
cpus: json.containsKey("cpus") ? fromListJson(json["cpus"], CPU()) : [],
gpus: json.containsKey("gpus") ? fromListJson(json["gpus"], GPU()) : [],
ram: json.containsKey("ram") ? RAM().deserialize(json["ram"]) : null,
);
2024-08-22 15:46:16 +02:00
if (w.logo != null) {
//
var image = Image.network(w.logo!);
image.image
.resolve(const ImageConfiguration())
.addListener(
ImageStreamListener(
(ImageInfo info, bool _) {
w.width = info.image.width.toDouble();
w.height = info.image.height.toDouble();
}));
}
return w;
}
2024-10-15 11:28:29 +02:00
@override
Map<String, dynamic> setVariable(List<String> keys, dynamic value, Map<String, dynamic> map) {
if (keys.isEmpty) { return map; }
var key = keys[0];
if (keys.length > 1 && map[key] != null) {
map[key] = setVariable(keys.sublist(1), value, map[key]);
} else {
map[key] = value;
}
return map;
}
@override
dynamic getVariable(List<String> keys, Map<String, dynamic> map) {
if (keys.isEmpty) { return null; }
var key = keys[0];
if (keys.length > 1 && map[key] != null) {
return getVariable(keys.sublist(1), map[key]);
}
return map[key];
}
2024-08-08 08:42:32 +02:00
@override Map<String, dynamic> serialize() => {
"id": id,
"name": name,
"logo": logo,
"owner": owner,
"owner_logo": ownerLogo,
"price": price,
2024-11-08 13:59:22 +01:00
"is_service": isService,
2024-08-08 08:42:32 +02:00
"licence": licence,
2024-11-08 13:59:22 +01:00
"access": access,
"architecture": architecture,
"localisation": localisation,
2024-08-08 08:42:32 +02:00
"description": description,
"short_description": shortDescription,
"inputs": inputs,
"outputs": outputs,
"source": source,
2024-11-08 13:59:22 +01:00
"technology": technology,
2024-08-08 08:42:32 +02:00
"resource_model": model?.serialize(),
"cpus": toListJson<CPU>(cpus),
"gpus": toListJson<GPU>(gpus),
"ram": ram?.serialize(),
};
}
class CPU extends SerializerDeserializer<CPU> {
CPU({
this.cores,
this.platform,
this.architecture,
this.minimumMemory,
this.shared = false,
});
double? cores;
String? platform;
bool shared = false;
String? architecture;
double? minimumMemory;
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return CPU(); }
return CPU(
cores: json.containsKey("cores") ? json["cores"]?.toDouble() : null,
platform: json.containsKey("platform") ? json["platform"] : null,
architecture: json.containsKey("architecture") ? json["architecture"] : null,
minimumMemory: json.containsKey("minimumMemory") ? json["minimumMemory"]?.toDouble() : null,
shared: json.containsKey("shared") ? json["shared"] : false,
);
}
2024-08-08 08:42:32 +02:00
@override Map<String, dynamic> serialize() => {
"cores": cores,
"platform": platform,
"architecture": architecture,
"minimumMemory": minimumMemory,
"shared": shared,
};
}
class GPU extends SerializerDeserializer<GPU> {
GPU({
this.cudaCores,
this.memory,
this.model,
this.tensorCores,
});
double? cudaCores;
double? memory;
String? model;
double? tensorCores;
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return GPU(); }
return GPU(
cudaCores: json.containsKey("cuda_cores") ? json["cuda_cores"]?.toDouble() : null,
memory: json.containsKey("memory") ? json["memory"]?.toDouble() : null,
model: json.containsKey("model") ? json["model"] : null,
tensorCores: json.containsKey("tensor_cores") ? json["tensor_cores"]?.toDouble() : null,
);
}
2024-08-08 08:42:32 +02:00
@override Map<String, dynamic> serialize() => {
"cuda_cores": cudaCores,
"memory": memory,
"model": model,
"tensor_cores": tensorCores,
};
}
class RAM extends SerializerDeserializer<RAM> {
RAM({
this.ecc = false,
this.size,
});
bool ecc = false;
double? size;
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return RAM(); }
return RAM(
ecc: json.containsKey("ecc") ? json["ecc"] : false,
size: json.containsKey("size") ? json["size"]?.toDouble() : null,
);
}
2024-08-08 08:42:32 +02:00
@override Map<String, dynamic> serialize() => {
"ecc": ecc,
"size": size,
};
}
2024-08-08 08:42:32 +02:00
class StorageItem extends SerializerDeserializer<StorageItem> implements AbstractItem<StorageItem> {
2024-11-19 15:06:22 +01:00
@override
String getTopic() {
return topic;
}
StorageItem({
this.id,
this.name,
this.logo,
this.owner,
2024-08-08 08:42:32 +02:00
this.ownerLogo,
this.price,
this.source,
this.licence,
this.description,
this.shortDescription,
2024-08-08 08:42:32 +02:00
this.inputs = _empty,
this.outputs = _empty,
this.acronym,
this.type,
this.size,
2024-10-15 11:28:29 +02:00
this.path,
this.protocol,
this.encryption = false,
2024-08-08 08:42:32 +02:00
this.redundancy,
this.throughput,
this.model,
2024-10-15 11:28:29 +02:00
this.local = false,
});
2024-10-15 11:28:29 +02:00
bool local = false;
2024-08-08 08:42:32 +02:00
@override String? id;
@override String? name;
@override String? logo;
@override String? source;
@override String? ownerLogo;
@override String? owner;
@override String topic = "storage";
2024-08-08 08:42:32 +02:00
@override double? price;
@override String? licence;
@override List<dynamic> inputs;
@override List<dynamic> outputs;
@override String? description;
@override String? shortDescription;
@override ResourceModel? model;
// special attributes
String? acronym;
2024-08-08 08:42:32 +02:00
String? type;
2024-10-15 11:28:29 +02:00
String? path;
String? protocol;
2024-08-08 08:42:32 +02:00
int? size;
bool encryption = false;
String? redundancy;
String? throughput;
2024-08-08 08:42:32 +02:00
@override String getName() {
return name ?? "";
}
@override String getID() {
return id ?? "";
}
2024-08-22 15:46:16 +02:00
double? width;
double? height;
@override
double? getWidth() {
return width;
}
@override
double? getHeight() {
return height;
}
2024-10-15 11:28:29 +02:00
@override
dynamic getVariable(List<String> keys, Map<String, dynamic> map) {
if (keys.isEmpty) { return null; }
var key = keys[0];
if (keys.length > 1 && map[key] != null) {
return getVariable(keys.sublist(1), map[key]);
}
return map[key];
}
@override
Map<String, dynamic> setVariable(List<String> keys, dynamic value, Map<String, dynamic> map) {
if (keys.isEmpty) { return map; }
var key = keys[0];
if (keys.length > 1 && map[key] != null) {
map[key] = setVariable(keys.sublist(1), value, map[key]);
} else {
map[key] = value;
}
return map;
}
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return StorageItem(); }
2024-08-22 15:46:16 +02:00
var w = StorageItem(
2024-08-08 08:42:32 +02:00
id: json.containsKey("id") ? json["id"] : null,
name: json.containsKey("name") ? json["name"] : null,
logo: json.containsKey("logo") ? json["logo"] : null,
owner: json.containsKey("owner") ? json["owner"] : null,
2024-08-08 08:42:32 +02:00
ownerLogo: json.containsKey("owner_logo") ? json["owner_logo"] : null,
price: json.containsKey("price") ? json["price"]?.toDouble() : null,
licence: json.containsKey("licence") ? json["licence"] : null,
description: json.containsKey("description") ? json["description"] : null,
shortDescription: json.containsKey("short_description") ? json["short_description"] : null,
2024-10-15 11:28:29 +02:00
local: json.containsKey("local") ? json["local"] : false,
2024-08-08 08:42:32 +02:00
inputs: json["inputs"] ?? [],
outputs: json["outputs"] ?? [],
source: json.containsKey("source") ? json["source"] : null,
model: json.containsKey("resource_model") ? ResourceModel().deserialize(json["resource_model"]) : null,
acronym: json.containsKey("acronym") ? json["acronym"] : null,
type: json.containsKey("type") ? json["type"] : null,
size: json.containsKey("size") ? json["size"] : null,
2024-10-15 11:28:29 +02:00
path: json.containsKey("path") ? json["path"] : null,
protocol: json.containsKey("protocol") ? json["protocol"] : null,
encryption: json.containsKey("encryption") ? json["encryption"] : false,
2024-08-08 08:42:32 +02:00
redundancy: json.containsKey("redundancy") ? json["redundancy"] : null,
throughput: json.containsKey("throughput") ? json["throughput"] : null,
);
2024-08-22 15:46:16 +02:00
if (w.logo != null) {
//
var image = Image.network(w.logo!);
image.image
.resolve(const ImageConfiguration())
.addListener(
ImageStreamListener(
(ImageInfo info, bool _) {
w.width = info.image.width.toDouble();
w.height = info.image.height.toDouble();
}));
}
return w;
}
2024-08-08 08:42:32 +02:00
@override Map<String, dynamic> serialize() => {
"id": id,
"name": name,
"logo": logo,
"owner": owner,
"owner_logo": ownerLogo,
"price": price,
2024-10-15 11:28:29 +02:00
"local": local,
2024-08-08 08:42:32 +02:00
"licence": licence,
"description": description,
"short_description": shortDescription,
"inputs": inputs,
"outputs": outputs,
"source": source,
"resource_model": model?.serialize(),
"acronym": acronym,
"type": type,
"size": size,
2024-10-15 11:28:29 +02:00
"path": path,
"protocol": protocol,
2024-08-08 08:42:32 +02:00
"encryption": encryption,
"redundancy": redundancy,
"throughput": throughput,
};
}