oc-front/lib/models/search.dart
2024-08-22 15:46:16 +02:00

853 lines
26 KiB
Dart

import 'dart:async';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter_flow_chart/flutter_flow_chart.dart';
import 'package:oc_front/models/abstract.dart';
const List<ProcessingItem> _emptyComputing = [];
const List<DataItem> _emptyData = [];
const List<DataCenterItem> _emptyDataCenter = [];
const List<StorageItem> _emptyStorage = [];
class Search extends SerializerDeserializer<Search> {
Search({
this.computing = _emptyComputing,
this.datacenter = _emptyDataCenter,
this.data = _emptyData,
this.storage = _emptyStorage,
});
List<ProcessingItem> computing;
List<DataCenterItem> datacenter;
List<DataItem> data;
List<StorageItem> storage;
@override deserialize(dynamic json) {
json = json as Map<String, dynamic>;
return Search(
computing: json.containsKey("processing") ? fromListJson(json["processing"], ProcessingItem()) : [],
datacenter: json.containsKey("datacenter") ? fromListJson(json["datacenter"], DataCenterItem()) : [],
data: json.containsKey("data") ? fromListJson(json["data"], DataItem()) : [],
storage: json.containsKey("storage") ? fromListJson(json["storage"], StorageItem()) : [],
);
}
@override Map<String, dynamic> serialize() => {
"processing": toListJson<ProcessingItem>(computing),
"datacenter": toListJson<DataCenterItem>(datacenter),
"data": toListJson<DataItem>(data),
"storage": toListJson<StorageItem>(storage),
};
}
const List<String> _empty = [];
class Resource implements SerializerDeserializer<Resource> {
List<DataItem> datas = [];
List<ProcessingItem> processings = [];
List<StorageItem> storages = [];
List<DataCenterItem> datacenters = [];
List<WorkflowItem> workflows = [];
Resource({
this.datas = const [],
this.processings = const [],
this.storages = const [],
this.datacenters = const [],
this.workflows = const [],
});
@override Resource deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Resource(); }
return Resource(
datacenters: json.containsKey("datacenter_resource") ? fromListJson(json["datacenter_resource"], DataCenterItem()) : [],
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 {
"datacenter_resource": toListJson<DataCenterItem>(datacenters),
"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;
String? ownerLogo;
String? source;
String? description;
String? shortDescription;
double? price;
String? licence;
List<dynamic> inputs = [];
List<dynamic> outputs = [];
ResourceModel? model;
String topic = "";
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 ?? "";
}
}
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;
Map<String, Model>? model;
ResourceModel({
this.id,
this.type,
this.model,
});
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return ResourceModel(); }
return ResourceModel(
id: json.containsKey("id") ? json["id"] : null,
type: json.containsKey("type") ? json["type"] : null,
model: json.containsKey("model") ? fromMapJson(json["model"], Model()) : {},
);
}
@override Map<String, dynamic> serialize() => {
"id": id,
"type": type,
"model": toMapJson<Model>(model ?? {}),
};
}
Type? getTopicType(String topic) {
if (topic == "processing") { return ProcessingItem; }
else if (topic == "data") { return DataItem; }
else if (topic == "datacenter") { return DataCenterItem; }
else if (topic == "storage") { return StorageItem; }
else if (topic == "workflow") { return WorkflowItem; }
else { return null; }
}
String getTopic(Type type) {
if (type == AbstractItem) { return "resource"; }
if (type == ProcessingItem) { return "processing"; }
if (type == DataItem) { return "data"; }
if (type == DataCenterItem) { return "datacenter"; }
if (type == StorageItem) { return "storage"; }
if (type == WorkflowItem) { return "workflow"; }
return "";
}
bool isComputing(String topic) => topic == "processing";
bool isData(String topic) => topic == "data";
bool isDataCenter(String topic) => topic == "datacenter";
bool isStorage(String topic) => topic == "storage";
bool isWorkflow(String topic) => topic == "workflow";
class ProcessingItem extends SerializerDeserializer<ProcessingItem> implements AbstractItem<ProcessingItem> {
ProcessingItem({
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.cpus = const [],
this.gpus = const [],
this.ram,
this.storage,
this.parrallel = false,
this.scallingModel,
this.diskIO,
this.model,
});
@override ResourceModel? model;
@override String? id;
@override String? name;
@override String? logo;
@override String? source;
@override String? ownerLogo;
@override String? owner;
@override String topic = "processing";
@override double? price;
@override String? licence;
@override List<dynamic> inputs;
@override List<dynamic> outputs;
@override String? description;
@override String? shortDescription;
// 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 ?? "";
}
double? width;
double? height;
@override
double? getWidth() {
return width;
}
@override
double? getHeight() {
return height;
}
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return ProcessingItem(); }
var w = ProcessingItem(
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,
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,
);
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;
}
@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(),
"cpus": toListJson<CPU>(cpus),
"gpus": toListJson<GPU>(gpus),
"ram": ram?.serialize(),
"storage": storage,
"parrallel": parrallel,
"scalling_model": scallingModel,
"disk_io": diskIO,
};
}
class WorkflowItem extends SerializerDeserializer<WorkflowItem> implements AbstractItem<WorkflowItem> {
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,
});
@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;
String? workflowID;
@override String getID() {
return id ?? "";
}
double? width;
double? height;
@override
double? getWidth() {
return width;
}
@override
double? getHeight() {
return height;
}
@override String getName() {
return name ?? "";
}
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return WorkflowItem(); }
var w = WorkflowItem(
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,
);
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;
}
@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,
};
}
class DataItem extends SerializerDeserializer<DataItem> implements AbstractItem<DataItem> {
DataItem({
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.protocols = const [],
this.dataType,
this.exemple,
});
@override String? id;
@override String? name;
@override String? logo;
@override String? source;
@override String? ownerLogo;
@override String? owner;
@override String topic = "data";
@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
List<String> protocols = [];
String? dataType;
String? exemple;
@override String getName() {
return name ?? "";
}
@override String getID() {
return id ?? "";
}
double? width;
double? height;
@override
double? getWidth() {
return width;
}
@override
double? getHeight() {
return height;
}
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return DataItem(); }
var w = DataItem(
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,
protocols: json.containsKey("protocols") ? json["protocols"] : [],
dataType: json.containsKey("data_type") ? json["data_type"] : null,
exemple: json.containsKey("exemple") ? json["exemple"] : null,
);
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;
}
@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,
"data_type": dataType,
"exemple": exemple,
};
}
class DataCenterItem extends SerializerDeserializer<DataCenterItem> implements AbstractItem<DataCenterItem> {
DataCenterItem({
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.cpus = const [],
this.gpus = const [],
this.ram,
});
@override String? id;
@override String? name;
@override String? logo;
@override String? source;
@override String? ownerLogo;
@override String? owner;
@override String topic = "datacenter";
@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
List<CPU> cpus = [];
List<GPU> gpus = [];
RAM? ram;
@override String getID() {
return id ?? "";
}
@override String getName() {
return name ?? "";
}
double? width;
double? height;
@override
double? getWidth() {
return width;
}
@override
double? getHeight() {
return height;
}
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return DataCenterItem(); }
var w = DataCenterItem(
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,
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,
);
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;
}
@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(),
"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,
);
}
@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,
);
}
@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,
);
}
@override Map<String, dynamic> serialize() => {
"ecc": ecc,
"size": size,
};
}
class StorageItem extends SerializerDeserializer<StorageItem> implements AbstractItem<StorageItem> {
StorageItem({
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.acronym,
this.type,
this.size,
this.url,
this.encryption = false,
this.redundancy,
this.throughput,
this.model,
});
@override String? id;
@override String? name;
@override String? logo;
@override String? source;
@override String? ownerLogo;
@override String? owner;
@override String topic = "storage";
@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;
String? type;
int? size;
String? url;
bool encryption = false;
String? redundancy;
String? throughput;
@override String getName() {
return name ?? "";
}
@override String getID() {
return id ?? "";
}
double? width;
double? height;
@override
double? getWidth() {
return width;
}
@override
double? getHeight() {
return height;
}
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return StorageItem(); }
var w = StorageItem(
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,
acronym: json.containsKey("acronym") ? json["acronym"] : null,
type: json.containsKey("type") ? json["type"] : null,
size: json.containsKey("size") ? json["size"] : null,
url: json.containsKey("url") ? json["url"] : null,
encryption: json.containsKey("encryption") ? json["encryption"] : false,
redundancy: json.containsKey("redundancy") ? json["redundancy"] : null,
throughput: json.containsKey("throughput") ? json["throughput"] : null,
);
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;
}
@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(),
"acronym": acronym,
"type": type,
"size": size,
"url": url,
"encryption": encryption,
"redundancy": redundancy,
"throughput": throughput,
};
}