Major Change Inputs & Co

This commit is contained in:
mr
2025-02-04 17:02:49 +01:00
parent 2c86e90b76
commit 05854c84d8
43 changed files with 2837 additions and 1809 deletions

View File

@@ -0,0 +1,222 @@
import 'package:flutter/material.dart';
import 'package:oc_front/core/services/enum_service.dart';
import 'package:oc_front/models/abstract.dart';
import 'package:oc_front/models/resources/processing.dart';
import 'package:oc_front/models/resources/resources.dart';
class ComputeItem extends AbstractItem<ComputePricing, ComputePartnership, ComputeInstance, ComputeItem> {
// special attributes
int? infrastructureEnum;
String? architecture;
ComputeItem({
this.infrastructureEnum,
this.architecture
}): super();
@override String get topic => "compute";
@override deserialize(dynamic data) {
try { data = data as Map<String, dynamic>;
} catch (e) { return ComputeItem(); }
var w = ComputeItem(
infrastructureEnum: data.containsKey("infrastructure") ? EnumService.get("infrastructure", data["infrastructure"]) : null,
architecture: data.containsKey("architecture") && data["architecture"] != null ? data["architecture"] : null,
);
w.mapFromJSON(data, ComputeInstance());
if (w.logo != null) { // get image dimensions
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> infos() {
return {
"infrastructure": EnumService.enums["infrastructure"] != null
&& EnumService.enums["infrastructure"]!["$infrastructureEnum"] != null ? EnumService.enums["infrastructure"]!["$infrastructureEnum"] : infrastructureEnum,
"architecture": architecture,
};
}
@override Map<String, dynamic> serialize() {
Map<String, dynamic> obj = infos();
obj["infrastructure"] = infrastructureEnum;
obj.addAll(toJSON());
return obj;
}
}
class ComputeInstance extends AbstractInstance<ComputePricing, ComputePartnership> {
String? securityLevel;
List<String>? powerSources = [];
double? annualEnergyConsumption;
Map<String,CPU> cpus = {};
Map<String,GPU> gpus = {};
List<ComputeNode> nodes = [];
ComputeInstance({
this.securityLevel,
this.powerSources = const [],
this.annualEnergyConsumption,
this.cpus = const {},
this.gpus = const {},
this.nodes = const [],
}): super();
@override
Map<String, dynamic> infos() {
return {
"security_level": securityLevel,
"power_sources": powerSources,
"annual_co2_emissions": annualEnergyConsumption,
"cpus": toMapJson(cpus),
"gpus": toMapJson(gpus),
"nodes": toListJson(nodes),
"inputs": toListJson(inputs),
"outputs": toListJson(outputs),
};
}
@override
ComputeInstance deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return ComputeInstance(); }
var w = ComputeInstance(
securityLevel: json.containsKey("security_level") && json["security_level"] != null ? json["security_level"] : null,
powerSources: json.containsKey("power_sources") && json["power_sources"] != null ? List<String>.from(json["power_sources"]) : [],
annualEnergyConsumption: json.containsKey("annual_co2_emissions") && json["annual_co2_emissions"] != null ? json["annual_co2_emissions"] : null,
//cpus: json.containsKey("cpus") && json["cpus"] != null ? fromMapJson(json["cpus"], CPU()) : {},
// gpus: json.containsKey("gpus") && json["gpus"] != null ? fromMapJson(json["gpus"], GPU()) : {},
//nodes: json.containsKey("nodes") && json["nodes"] != null ? fromListJson(json["nodes"], ComputeNode()) : [],
);
w.mapFromJSON(json, ComputePartnership());
return w;
}
@override
Map<String, dynamic> serialize() {
var obj = infos();
obj.addAll(toJSON());
return obj;
}
}
class ComputePartnership extends AbstractPartnerShip<ComputePricing> {
Map<String, dynamic> maxAllowedCPUsCores = {};
Map<String, dynamic> maxAllowedGPUsMemoryGB = {};
double? maxAllowedRAM;
ComputePartnership({
this.maxAllowedCPUsCores = const {},
this.maxAllowedGPUsMemoryGB = const {},
this.maxAllowedRAM,
}): super();
@override
ComputePartnership deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return ComputePartnership(); }
var w = ComputePartnership(
maxAllowedCPUsCores: json.containsKey("allowed_cpus") && json["allowed_cpus"] != null ? json["allowed_cpus"] : {},
maxAllowedGPUsMemoryGB: json.containsKey("allowed_gpus") && json["allowed_gpus"] != null ? json["allowed_gpus"] : {},
maxAllowedRAM: json.containsKey("allowed_ram") && json["allowed_ram"] != null ? double.parse("${json["allowed_ram"]}") : null,
);
w.mapFromJSON(json, ComputePricing());
return w;
}
@override
Map<String, dynamic> serialize() {
Map<String, dynamic> obj = {
"allowed_cpus": maxAllowedCPUsCores,
"allowed_gpus": maxAllowedGPUsMemoryGB,
"allowed_ram": maxAllowedRAM,
};
obj.addAll(toJSON());
return obj;
}
}
class ComputePricing extends AbstractPricing {
Map<String, dynamic> cpusPrice = {};
Map<String, dynamic> gpusPrice = {};
double? ramPrice;
ComputePricing({
this.cpusPrice = const {},
this.gpusPrice = const {},
this.ramPrice,
});
@override ComputePricing deserialize(json) {
var w = ComputePricing(
cpusPrice: json.containsKey("cpus") && json["cpus"] != null ? json["cpus"] : {},
gpusPrice: json.containsKey("gpus") && json["gpus"] != null ? json["gpus"] : {},
ramPrice: json.containsKey("ram") && json["ram"] != null ? json["ram"] : null,
);
w.mapFromJSON(json);
return w;
}
@override
Map<String, dynamic> serialize() {
var obj = {
"cpus": cpusPrice,
"gpus": gpusPrice,
"ram": ramPrice,
};
obj.addAll(toJSON());
return obj;
}
}
class ComputeNode extends SerializerDeserializer<ComputeNode> {
String? name;
int? quantity;
Map<String,dynamic> cpus = {};
Map<String,dynamic> gpus = {};
RAM? ram;
ComputeNode({
this.cpus = const {},
this.gpus = const {},
this.ram,
this.name,
this.quantity,
});
@override
ComputeNode deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return ComputeNode(); }
return ComputeNode(
name: json.containsKey("name") && json["name"] != null ? json["name"] : null,
quantity: json.containsKey("quantity") && json["quantity"] != null ? json["quantity"] : null,
cpus: json.containsKey("cpus") && json["cpus"] != null ? fromMapJson(json["cpus"], CPU()) : {},
gpus: json.containsKey("gpus") && json["gpus"] != null ? fromMapJson(json["gpus"], GPU()) : {},
ram: json.containsKey("ram") && json["ram"] != null ? RAM().deserialize(json["ram"]) : null,
);
}
@override
Map<String, dynamic> serialize() {
return {
"name": name,
"quantity": quantity,
"cpus": cpus,
"gpus": gpus,
"ram": ram!.serialize(),
};
}
}

View File

@@ -0,0 +1,166 @@
import 'package:flutter/material.dart';
import 'package:oc_front/models/abstract.dart';
import 'package:oc_front/models/resources/resources.dart';
class DataItem extends AbstractItem<DataPricing, DataPartnership, DataInstance, DataItem> {
// special attributes
String? type;
String? source;
String? quality;
bool openData = false;
bool static = false;
bool personalData = false;
bool anonymizedPersonalData = false;
double? size;
String? example;
DateTime? updatePeriod;
DataItem({
this.type,
this.source,
this.quality,
this.openData = false,
this.static = false,
this.personalData = false,
this.anonymizedPersonalData = false,
this.size,
this.example,
this.updatePeriod,
}): super();
@override String get topic => "data";
@override deserialize(dynamic data) {
try { data = data as Map<String, dynamic>;
} catch (e) { return DataItem(); }
var w = DataItem(
type: data.containsKey("type") && data["type"] != null ? data["type"] : null,
source: data.containsKey("source") && data["source"] != null ? data["source"] : null,
quality: data.containsKey("quality") && data["quality"] != null ? data["quality"] : null,
openData: data.containsKey("open_data") && data["open_data"] != null ? data["open_data"] : false,
static: data.containsKey("static") && data["static"] != null ? data["static"] : false,
personalData: data.containsKey("personal_data") && data["l"] != null ? data["personal_data"] : false,
anonymizedPersonalData: data.containsKey("anonymized_personal_data") && data["anonymized_personal_data"] != null ? data["anonymized_personal_data"] : false,
size: data.containsKey("size") && data["size"] != null ? data["size"] : null,
example: data.containsKey("example") && data["example"] != null ? data["example"] : null,
updatePeriod: data.containsKey("update_period") && data["update_period"] != null ? DateTime.parse(data["update_period"]) : null,
);
w.mapFromJSON(data, DataInstance());
if (w.logo != null) { // get image dimensions
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> infos() {
return {
"type": type,
"quality": quality,
"open_data": openData,
"static": static,
"personal_data": personalData,
"anonymized_personal_data": anonymizedPersonalData,
"size": size,
"example": example,
"update_period": updatePeriod?.toIso8601String(),
};
}
@override Map<String, dynamic> serialize() {
var obj = infos();
obj.addAll(toJSON());
return obj;
}
}
class DataInstance extends AbstractInstance<DataPricing, DataPartnership> {
String? source;
DataInstance(
{this.source}
): super();
@override
Map<String, dynamic> infos() {
return {
"inputs": toListJson(inputs),
"outputs": toListJson(outputs),
};
}
@override
DataInstance deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return DataInstance(); }
var w = DataInstance(
source: json.containsKey("source") && json["source"] != null ? json["source"] : null,
);
w.mapFromJSON(json, DataPartnership());
return w;
}
@override
Map<String, dynamic> serialize() {
var obj = toJSON();
obj["source"] = source;
obj.addAll(infos());
return obj;
}
}
class DataPartnership extends AbstractPartnerShip<DataPricing> {
double? maxDownloadableGBAllowed;
bool personalDataAllowed = false;
bool anonymizedPersonalDataAllowed = false;
DataPartnership({
this.maxDownloadableGBAllowed,
this.personalDataAllowed = false,
this.anonymizedPersonalDataAllowed = false,
}): super();
@override
DataPartnership deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return DataPartnership(); }
var w = DataPartnership(
maxDownloadableGBAllowed: json.containsKey("max_downloadable_gb_allowed") && json["max_downloadable_gb_allowed"] != null ? json["max_downloadable_gb_allowed"] : null,
personalDataAllowed: json.containsKey("personal_data_allowed") && json["personal_data_allowed"] != null ? json["personal_data_allowed"] : false,
anonymizedPersonalDataAllowed: json.containsKey("anonymized_personal_data_allowed") && json["anonymized_personal_data_allowed"] != null ? json["anonymized_personal_data_allowed"] : false,
);
w.mapFromJSON(json, DataPricing());
return w;
}
@override
Map<String, dynamic> serialize() {
Map<String, dynamic> obj = {
"max_downloadable_gb_allowed": maxDownloadableGBAllowed,
"personal_data_allowed": personalDataAllowed,
"anonymized_personal_data_allowed": anonymizedPersonalDataAllowed,
};
obj.addAll(toJSON());
return obj;
}
}
class DataPricing extends AbstractPricing {
@override DataPricing deserialize(json) {
var w = DataPricing();
w.mapFromJSON(json);
return w;
}
@override
Map<String, dynamic> serialize() {
return toJSON();
}
}

View File

@@ -0,0 +1,357 @@
import 'package:flutter/material.dart';
import 'package:oc_front/core/services/enum_service.dart';
import 'package:oc_front/models/abstract.dart';
import 'package:oc_front/models/resources/resources.dart';
class ProcessingItem extends AbstractItem<ProcessingPricing, ProcessingPartnership, ProcessingInstance, ProcessingItem> {
// special attributes
int? infrastructureEnum;
bool isService = false;
bool openSource = false;
String? license;
String? maturity;
ProcessingUsage? usage;
ProcessingItem({
this.infrastructureEnum,
this.isService = false,
this.openSource = false,
this.license,
this.maturity,
this.usage,
}): super();
@override String get topic => "processing";
@override deserialize(dynamic data) {
try { data = data as Map<String, dynamic>;
} catch (e) { return ProcessingItem(); }
var w = ProcessingItem(
infrastructureEnum: data.containsKey("infrastructure") ? EnumService.get("infrastructure", data["infrastructure"]) : null,
isService: data.containsKey("is_service") && data["is_service"] != null ? data["is_service"] : false,
openSource: data.containsKey("open_source") && data["open_source"] != null ? data["open_source"] : false,
license: data.containsKey("license") && data["license"] != null ? data["license"] : null,
maturity: data.containsKey("maturity") && data["maturity"] != null ? data["maturity"] : null,
usage: data.containsKey("usage") && data["usage"] != null ? ProcessingUsage().deserialize(data["usage"]) : null,
);
w.mapFromJSON(data, ProcessingInstance());
if (w.logo != null) { // get image dimensions
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> infos() {
return {
"infrastructure": EnumService.enums["infrastructure"] != null
&& EnumService.enums["infrastructure"]!["$infrastructureEnum"] != null ?
EnumService.enums["infrastructure"]!["$infrastructureEnum"] : infrastructureEnum,
"is_service": isService,
"open_source": openSource,
"license": license,
"maturity": maturity,
};
}
@override Map<String, dynamic> serialize() {
var obj = infos();
obj["infrastructure"] = infrastructureEnum;
obj["usage"] = usage?.serialize();
obj.addAll(toJSON());
return obj;
}
}
class ProcessingAccess extends SerializerDeserializer<ProcessingAccess> {
Containered? container;
ProcessingAccess({
this.container,
});
@override ProcessingAccess deserialize(dynamic json) {
try {
json = json as Map<String, dynamic>;
} catch (e) {
return ProcessingAccess();
}
return ProcessingAccess(
container: json.containsKey("container") && json["container"] != null ? Containered().deserialize(json["container"]) : null,
);
}
@override Map<String, dynamic> serialize() {
return {
"container": container?.serialize(),
};
}
}
class ProcessingInstance extends AbstractInstance<ProcessingPricing, ProcessingPartnership> {
ProcessingAccess? access;
ProcessingInstance(
{this.access}
): super();
@override
ProcessingInstance deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return ProcessingInstance(); }
var w = ProcessingInstance();
w.access = json.containsKey("access") && json["access"] != null ? ProcessingAccess().deserialize(json['access']) : null;
w.mapFromJSON(json, ProcessingPartnership());
return w;
}
@override
Map<String, dynamic> serialize() {
var obj = toJSON();
obj["access"] = access?.serialize();
return obj;
}
@override
Map<String, dynamic> infos() {
return {
"inputs": toListJson(inputs),
"outputs": toListJson(outputs),
};
}
}
class ProcessingPartnership extends AbstractPartnerShip<ProcessingPricing> {
ProcessingPartnership(): super();
@override
ProcessingPartnership deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return ProcessingPartnership(); }
var w = ProcessingPartnership();
w.mapFromJSON(json, ProcessingPricing());
return w;
}
@override
Map<String, dynamic> serialize() {
return toJSON();
}
}
class ProcessingPricing extends AbstractPricing {
@override ProcessingPricing deserialize(json) {
var w = ProcessingPricing();
w.mapFromJSON(json);
return w;
}
@override
Map<String, dynamic> serialize() {
return toJSON();
}
}
class ProcessingUsage extends SerializerDeserializer<ProcessingUsage> {
Map<String,CPU> cpus = {};
Map<String,GPU> gpus = {};
RAM? ram;
double? storageSize;
String? hypothesis;
String? scalingModel;
ProcessingUsage({
this.cpus = const {},
this.gpus = const {},
this.ram,
this.storageSize,
this.hypothesis,
this.scalingModel,
});
@override
ProcessingUsage deserialize(json) {
return ProcessingUsage(
cpus: json.containsKey("cpus") && json["cpus"] != null ? fromMapJson(json["cpus"], CPU()) : {},
gpus: json.containsKey("gpus") && json["gpus"] != null ? fromMapJson(json["gpus"], GPU()) : {},
ram: json.containsKey("ram") && json["ram"] != null ? RAM().deserialize(json["ram"]) : null,
storageSize: json.containsKey("storage_size") && json["storage_size"] != null ? json["storage_size"]?.toDouble() : null,
hypothesis: json.containsKey("hypothesis") && json["hypothesis"] != null ? json["hypothesis"] : null,
scalingModel: json.containsKey("scaling_model") && json["scaling_model"] != null ? json["scaling_model"] : null,
);
}
@override
Map<String, dynamic> serialize() {
return {
"cpus": toMapJson(cpus),
"gpus": toMapJson(gpus),
"ram": ram?.serialize(),
"storage_size": storageSize,
"hypothesis": hypothesis,
"scaling_model": scalingModel,
};
}
}
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"] != null ? json["cores"]?.toDouble() : null,
platform: json.containsKey("platform") && json["platform"] != null ? json["platform"] : null,
architecture: json.containsKey("architecture") && json["architecture"] != null ? json["architecture"] : null,
minimumMemory: json.containsKey("minimumMemory") && json["minimumMemory"] != null ? json["minimumMemory"]?.toDouble() : null,
shared: json.containsKey("shared") && json["shared"] != null ? 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"] != null ? json["cuda_cores"]?.toDouble() : null,
memory: json.containsKey("memory") && json["memory"] != null ? json["memory"]?.toDouble() : null,
model: json.containsKey("model") && json["model"] != null ? json["model"] : null,
tensorCores: json.containsKey("tensor_cores") && json["tensor_cores"] != null ? 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"] != null ? json["ecc"] : false,
size: json.containsKey("size") && json["size"] != null ? json["size"]?.toDouble() : null,
);
}
@override Map<String, dynamic> serialize() => {
"ecc": ecc,
"size": size,
};
}
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 ? json["port"] : null,
PAT: json.containsKey("PAT") && json["PAT"] != null ? json["PAT"] : null,
path: json.containsKey("reverse") && json["reverse"] != null ? 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,
this.exposes = const [],
});
String? args;
String? image;
String? command;
Map<String, dynamic>? env;
Map<String, dynamic>? volumes;
List<Expose> exposes = [];
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Containered(); }
return Containered(
args: json.containsKey("args") && json["args"] != null ? json["args"] : null,
image: json.containsKey("image") && json["image"] != null ? json["image"] : null,
command: json.containsKey("command") && json["command"] != null ? json["command"] : null,
env: json.containsKey("env") && json["env"] != null ? json["env"] : null,
volumes: json.containsKey("volumes") && json["volumes"] != null ? json["volumes"] : null,
exposes: json.containsKey("exposes") && json["exposes"] != null ? fromListJson(json["exposes"], Expose()) : [],
);
}
@override Map<String, dynamic> serialize() {
var w = {
"args": args,
"image": image,
"command": command,
"env": env,
"volumes": volumes,
"exposes": toListJson(exposes),
};
return w;
}
}

View File

@@ -0,0 +1,497 @@
import 'package:flutter/material.dart';
import 'package:flutter_flow_chart/flutter_flow_chart.dart';
import 'package:oc_front/main.dart';
import 'package:oc_front/models/abstract.dart';
import 'package:oc_front/models/resources/compute.dart';
import 'package:oc_front/models/resources/data.dart';
import 'package:oc_front/models/resources/processing.dart';
import 'package:oc_front/models/resources/storage.dart';
import 'package:oc_front/models/resources/workflow.dart';
class Resource implements SerializerDeserializer<Resource> {
List<DataItem> datas = [];
List<ProcessingItem> processings = [];
List<StorageItem> storages = [];
List<ComputeItem> computes = [];
List<WorkflowItem> workflows = [];
Resource({
this.datas = const [],
this.processings = const [],
this.storages = const [],
this.computes = const [],
this.workflows = const [],
});
@override Resource deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Resource(); }
return Resource(
computes: json.containsKey("compute_resource") ? fromListJson(json["compute_resource"], ComputeItem()) : [],
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 {
"compute_resource": toListJson<ComputeItem>(computes),
"data_resource": toListJson<DataItem>(datas),
"processing_resource": toListJson<ProcessingItem>(processings),
"storage_resource": toListJson<StorageItem>(storages),
"workflow_resource": toListJson<WorkflowItem>(workflows),
};
}
}
class Owner extends SerializerDeserializer<Owner> {
String? name;
String? logo;
Owner({
this.name,
this.logo,
});
@override Owner deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Owner(); }
return Owner(
name: json.containsKey("name") ? json["name"] : null,
logo: json.containsKey("logo") ? json["logo"] : null,
);
}
@override Map<String, dynamic> serialize() {
return {
"name": name,
"logo": logo,
};
}
}
abstract class Infos {
Map<String, dynamic> infos();
}
class Artifact extends SerializerDeserializer<Artifact> {
String? attrPath;
String? attrFrom;
bool readOnly = true;
Artifact({
this.attrPath,
this.attrFrom,
this.readOnly = true,
});
@override Artifact deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Artifact(); }
return Artifact(
attrPath: json.containsKey("attr_path") ? json["attr_path"] : null,
attrFrom: json.containsKey("attr_from") ? json["attr_from"] : null,
readOnly: json.containsKey("readonly") ? json["readonly"] : true,
);
}
@override Map<String, dynamic> serialize() {
return {
"attr_path": attrPath,
"attr_from": attrFrom,
"readonly": readOnly,
};
}
}
class Param extends SerializerDeserializer<Param> {
String? name;
String? attr;
dynamic value;
String? origin;
bool optionnal = false;
bool readOnly = true;
Param({
this.name,
this.attr,
this.value,
this.origin,
this.optionnal = false,
this.readOnly = true,
});
@override Param deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return Param(); }
return Param(
name: json.containsKey("name") ? json["name"] : null,
attr: json.containsKey("attr") ? json["attr"] : null,
value: json.containsKey("value") ? json["value"] : null,
origin: json.containsKey("origin") ? json["origin"] : null,
optionnal: json.containsKey("optionnal") ? json["optionnal"] : false,
readOnly: json.containsKey("readonly") ? json["readonly"] : false,
);
}
@override Map<String, dynamic> serialize() {
return {
"name": name,
"attr": attr,
"value": value,
"origin": origin,
"optionnal": optionnal,
"readonly": readOnly,
};
}
}
abstract class AbstractItem<X extends AbstractPricing, Y extends AbstractPartnerShip<X>, S extends AbstractInstance<X,Y>, T extends FlowData> extends FlowData implements SerializerDeserializer<T>, Infos {
String? id;
String? name;
String? logo;
String? type;
String? creatorID;
String? updaterID;
DateTime? createdAt;
DateTime? updatedAt;
List<Owner> owners;
String? description;
String? restrictions;
String? shortDescription;
int selectedInstance = -1;
List<AbstractInstance<X,Y>> instances = [];
String get topic => "";
AbstractItem({
this.id,
this.type,
this.name,
this.logo,
this.creatorID,
this.updaterID,
this.createdAt,
this.updatedAt,
this.description,
this.shortDescription,
this.owners = const [],
this.selectedInstance = -1,
});
void addEnv(List<dynamic> infos) {
var inst = getSelectedInstance();
if (inst == null) { return; }
inst.env = [];
for (var info in infos) {
inst.env.add(Param(name: info["name"], attr: info["attr"], value: info["value"],
origin: info["origin"], optionnal: info["optionnal"], readOnly: info["readonly"]));
}
}
AbstractInstance<X,Y>? getSelectedInstance() {
if (selectedInstance == -1) { return instances.isEmpty ? null : instances[0]; }
return instances[selectedInstance];
}
@override String getID() {
return id ?? "";
}
@override String getType() {
return type ?? "";
}
@override String getName() {
return name ?? "";
}
@override
Map<String, dynamic> infos();
double? width;
double? height;
@override
double? getWidth() {
return width;
}
@override
double? getHeight() {
return height;
}
Map<String, dynamic> setVariable(String key, dynamic value, Map<String, dynamic> map) {
map[key] = value;
return map;
}
dynamic getVariable(String key, Map<String, dynamic> map) {
return map[key];
}
Map<String, dynamic> toJSON() {
return {
"id": id,
"type": type ?? topic,
"name": name,
"logo": logo,
"owners": toListJson(owners),
"creator_id": creatorID,
"updater_id": updaterID,
"creation_date": createdAt?.toIso8601String(),
"update_date": updatedAt?.toIso8601String(),
"description": description,
"short_description": shortDescription,
"selected_instance": selectedInstance,
"instances": instances.map((e) => e.serialize()).toList(),
};
}
void mapFromJSON(dynamic json, S ex) {
try { json = json as Map<String, dynamic>;
} catch (e) { return; }
this.id = json.containsKey("id") ? json["id"] : null;
this.type = json.containsKey("type") ? json["type"] : topic;
this.name = json.containsKey("name") ? json["name"] : null;
this.logo = json.containsKey("logo") ? json["logo"] : null;
this.creatorID = json.containsKey("creator_id") ? json["creator_id"] : null;
this.updaterID = json.containsKey("updater_id") ? json["updater_id"] : null;
this.description = json.containsKey("description") ? json["description"] : null;
this.owners = json.containsKey("owners") ? fromListJson(json["owners"], Owner()) : [];
this.instances = json.containsKey("instances") ? fromListJson(json["instances"], ex) : [];
this.updatedAt = json.containsKey("update_date") ? DateTime.parse(json["update_date"]) : null;
this.selectedInstance = json.containsKey("selected_instance") ? json["selected_instance"] : -1;
this.shortDescription = json.containsKey("short_description") ? json["short_description"] : null;
this.createdAt = json.containsKey("creation_date") ? DateTime.parse(json["creation_date"]) : null;
}
}
class Location extends SerializerDeserializer<Location> {
double? latitude;
double? longitude;
Location({
this.latitude,
this.longitude,
});
@override
Location deserialize(json) {
return Location(
latitude: json.containsKey("latitude") ? json["latitude"] : null,
longitude: json.containsKey("longitude") ? json["longitude"] : null,
);
}
@override
Map<String, dynamic> serialize() {
return {
"latitude": latitude,
"longitude": longitude,
};
}
}
abstract class AbstractInstance<X extends AbstractPricing, S extends AbstractPartnerShip<X>> extends SerializerDeserializer<AbstractInstance<X,S>> implements Infos {
String? id;
String? name;
int? countryCode;
Location? location;
List<S> partnerships = [];
List<Param> env = [];
List<Param> inputs = [];
List<Param> outputs = [];
bool isEnv(String key) {
for (var e in env) {
if (e.name?.contains(key) ?? false || key.contains(e.name ?? "none")) { return true; }
}
return false;
}
bool isEnvAttr(String attr, String origin, bool isOrigin) {
for (var e in env) {
if (e.attr == attr && ((isOrigin && e.origin != null) || (!isOrigin && e.origin == origin))) { return true; }
}
return false;
}
@override
Map<String, dynamic> infos();
void mapFromJSON(dynamic json, S ex) {
try { json = json as Map<String, dynamic>;
} catch (e) { return; }
this.countryCode = json.containsKey("country_code") ? json["country_code"] : null;
this.id = json.containsKey("id") ? json["id"] : null;
this.name = json.containsKey("name") ? json["name"] : null;
this.env = json.containsKey("env") ? fromListJson(json["env"], Param()) : [];
this.inputs = json.containsKey("inputs") ? fromListJson(json["inputs"], Param()) : [];
this.outputs = json.containsKey("outputs") ? fromListJson(json["outputs"], Param()) : [];
this.location = json.containsKey("location") ? Location().deserialize(json["location"]) : null;
this.partnerships = json.containsKey("partnerships") ? fromListJson(json["partnerships"], ex) : [];
}
Map<String, dynamic> toJSON() {
return {
"country_code": countryCode,
"id": id,
"name": name,
"location": location?.serialize(),
"env": toListJson(env),
"inputs": toListJson(inputs),
"outputs": toListJson(outputs),
"partnerships": partnerships.map((e) => e.serialize()).toList(),
};
}
}
abstract class AbstractPartnerShip<S extends AbstractPricing> extends SerializerDeserializer<AbstractPartnerShip<S>> {
String? namespace;
List<AbstractPricing> pricings = [];
void mapFromJSON(dynamic json, S ex) {
try { json = json as Map<String, dynamic>;
} catch (e) { return; }
this.namespace = json.containsKey("namespace") ? json["namespace"] : null;
this.pricings = json.containsKey("pricings") ? fromListJson(json["pricings"], ex) : [];
}
Map<String, dynamic> toJSON() {
return {
"namespace": namespace,
"pricings": pricings,
};
}
}
abstract class AbstractPricing extends SerializerDeserializer<AbstractPricing> {
PricingStrategy? pricing;
int? refundTypeEnum;
int? refundRatio;
List<dynamic> additionnalRefundTypeEnum = [];
int? privilegeStrategyEnum;
int? garantedDelaySecond;
bool exceeding = false;
int? exceedingRatio;
void mapFromJSON(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return; }
pricing = json.containsKey("pricing") ? PricingStrategy().deserialize(json["pricing"]) : null;
refundTypeEnum = json.containsKey("refund_type") ? json["refund_type"] : null;
refundRatio = json.containsKey("refund_ratio") ? json["refund_ratio"] : null;
additionnalRefundTypeEnum = json.containsKey("additionnal_refund_type") ? json["additionnal_refund_type"] : [];
privilegeStrategyEnum = json.containsKey("privilege_strategy") ? json["privilege_strategy"] : null;
garantedDelaySecond = json.containsKey("garanted_delay") ? json["garanted_delay"] : null;
exceeding = json.containsKey("exceeding") ? json["exceeding"] : false;
exceedingRatio = json.containsKey("exceeding_ratio") ? json["exceeding_ratio"] : null;
}
Map<String, dynamic> toJSON() {
return {
"pricing": pricing?.serialize(),
"refund_type": refundTypeEnum,
"refund_ratio": refundRatio,
"additionnal_refund_type": additionnalRefundTypeEnum,
"privilege_strategy": privilegeStrategyEnum,
"garanted_delay": garantedDelaySecond,
"exceeding": exceeding,
"exceeding_ratio": exceedingRatio,
};
}
}
class PricingStrategy extends SerializerDeserializer<PricingStrategy> {
double? price;
String? currency;
int? buyingStrategyEnum;
int? timeStrategyEnum;
int? overrideStrategyEnum;
PricingStrategy({
this.price,
this.currency,
this.buyingStrategyEnum,
this.timeStrategyEnum,
this.overrideStrategyEnum,
});
@override
PricingStrategy deserialize(dynamic json) {
return PricingStrategy(
price: json.containsKey("price") && json["price"] != null ? json["price"] : null,
currency: json.containsKey("currency") && json["currency"] != null ? json["currency"] : null,
buyingStrategyEnum: json.containsKey("buying_strategy") ? json["buying_strategy"] : null,
timeStrategyEnum: json.containsKey("time_strategy") ? json["time_strategy"] : null,
overrideStrategyEnum: json.containsKey("override_strategy") ? json["override_strategy"] : null,
);
}
@override
Map<String, dynamic> serialize() {
return {
"price": price,
"currency": currency,
"buying_strategy": buyingStrategyEnum,
"time_strategy": timeStrategyEnum,
"override_strategy": overrideStrategyEnum,
};
}
}
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,
};
}
Type? getTopicType(String topic) {
if (topic == "processing") { return ProcessingItem; }
else if (topic == "data") { return DataItem; }
else if (topic == "compute") { return ComputeItem; }
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 == ComputeItem) { return "compute"; }
if (type == StorageItem) { return "storage"; }
if (type == WorkflowItem) { return "workflow"; }
return "";
}
bool isComputing(String topic) => topic == "processing";
bool isData(String topic) => topic == "data";
bool isCompute(String topic) => topic == "compute";
bool isStorage(String topic) => topic == "storage";
bool isWorkflow(String topic) => topic == "workflow";
Color getColor(String topic) => isData(topic) ? Colors.blue : isComputing(topic) ? Colors.green :
isCompute(topic) ? Colors.orange : isStorage(topic) ? redColor : Colors.grey;

View File

@@ -0,0 +1,166 @@
import 'package:flutter/material.dart';
import 'package:oc_front/core/services/enum_service.dart';
import 'package:oc_front/models/abstract.dart';
import 'package:oc_front/models/resources/resources.dart';
class StorageItem extends AbstractItem<StoragePricing, StoragePartnership, StorageInstance, StorageItem> {
StorageItem({
this.acronym,
this.typeEnum,
}): super();
@override String get topic => "storage";
// special attributes
String? acronym;
int? typeEnum;
@override deserialize(dynamic data) {
try { data = data as Map<String, dynamic>;
} catch (e) { return StorageItem(); }
var w = StorageItem(
acronym: data.containsKey("acronym") && data["acronym"] != null ? data["acronym"] : null,
typeEnum: data.containsKey("storage_type") && data["storage_type"] != null ? EnumService.get("storage/type", data["storage_type"]) : null,
);
w.mapFromJSON(data, StorageInstance());
if (w.logo != null) { // get image dimensions
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> infos() {
return {
"acronym": acronym,
"storage_type": EnumService.enums["storage/type"] != null
&& EnumService.enums["storage/type"]!["$typeEnum"] != null ?
EnumService.enums["storage/type"]!["$typeEnum"] : typeEnum,
};
}
@override Map<String, dynamic> serialize() {
var obj = infos();
obj.addAll(toJSON());
return obj;
}
}
class StorageInstance extends AbstractInstance<StoragePricing, StoragePartnership> {
String? source;
bool local = false;
String? securityLevel;
int? storageSizeEnum;
int? size;
bool encryption = false;
String? redundancy;
String? throughput;
StorageInstance({
this.source,
this.local = false,
this.securityLevel,
this.storageSizeEnum,
this.size,
this.encryption = false,
this.redundancy,
this.throughput,
}): super();
@override
StorageInstance deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return StorageInstance(); }
var w = StorageInstance(
source: json.containsKey("source") && json["source"] != null ? json["source"] : null,
local: json.containsKey("local") && json["local"] != null ? json["local"] : false,
securityLevel: json.containsKey("security_level") && json["security_level"] != null ? json["security_level"] : null,
storageSizeEnum: json.containsKey("size_type") ? EnumService.get("storage/size", json["size_type"]) : null,
size: json.containsKey("size") && json["size"] != null ? json["size"] : null,
encryption: json.containsKey("encryption") && json["encryption"] != null ? json["encryption"] : false,
redundancy: json.containsKey("redundancy") && json["redundancy"] != null ? json["redundancy"] : null,
throughput: json.containsKey("throughput") && json["throughput"] != null ? json["throughput"] : null,
);
w.mapFromJSON(json, StoragePartnership());
return w;
}
@override
Map<String, dynamic> infos() {
return {
"local": local,
"security_level": securityLevel,
"size_type": EnumService.enums["storage/size"] != null
&& EnumService.enums["storage/size"]!["$storageSizeEnum"] != null ?
EnumService.enums["storage/size"]!["$storageSizeEnum"] : storageSizeEnum,
"size": size,
"encryption": encryption,
"redundancy": redundancy,
"throughput": throughput,
"inputs": toListJson(inputs),
"outputs": toListJson(outputs),
};
}
@override
Map<String, dynamic> serialize() {
var obj = infos();
obj["source"] = source;
obj["size_type"] = storageSizeEnum;
obj.addAll(toJSON());
return obj;
}
}
class StoragePartnership extends AbstractPartnerShip<StoragePricing> {
double? maxSizeGBAllowed;
bool onlyEncryptedAllowed = false;
StoragePartnership({
this.maxSizeGBAllowed,
this.onlyEncryptedAllowed = false,
}): super();
@override
StoragePartnership deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return StoragePartnership(); }
var w = StoragePartnership(
maxSizeGBAllowed: json.containsKey("allowed_gb") && json["allowed_gb"] != null ? json["allowed_gb"] : null,
onlyEncryptedAllowed: json.containsKey("personal_data_allowed") && json["personal_data_allowed"] != null ? json["personal_data_allowed"] : false,
);
w.mapFromJSON(json, StoragePricing());
return w;
}
@override
Map<String, dynamic> serialize() {
Map<String, dynamic> obj = {
"allowed_gb": maxSizeGBAllowed,
"personal_data_allowed": onlyEncryptedAllowed,
};
obj.addAll(toJSON());
return obj;
}
}
class StoragePricing extends AbstractPricing {
@override StoragePricing deserialize(json) {
var w = StoragePricing();
w.mapFromJSON(json);
return w;
}
@override
Map<String, dynamic> serialize() {
return toJSON();
}
}

View File

@@ -0,0 +1,101 @@
import 'package:flutter/material.dart';
import 'package:oc_front/models/resources/resources.dart';
class WorkflowItem extends AbstractItem<WorkflowPricing, WorkflowPartnership, WorkflowInstance, WorkflowItem> {
// special attributes
String? workflowID;
WorkflowItem({
this.workflowID,
}): super();
@override String get topic => "workflow";
@override deserialize(dynamic data) {
try { data = data as Map<String, dynamic>;
} catch (e) { return WorkflowItem(); }
var w = WorkflowItem(
workflowID: data.containsKey("workflow_id") && data["workflow_id"] != null ? data["workflow_id"] : null,
);
w.mapFromJSON(data, WorkflowInstance());
if (w.logo != null) { // get image dimensions
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> infos() {
return {};
}
@override Map<String, dynamic> serialize() {
Map<String, dynamic> obj ={
"workflow_id": workflowID,
};
obj.addAll(toJSON());
return obj;
}
}
class WorkflowInstance extends AbstractInstance<WorkflowPricing, WorkflowPartnership> {
WorkflowInstance(): super();
@override
WorkflowInstance deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return WorkflowInstance(); }
var w = WorkflowInstance();
w.mapFromJSON(json, WorkflowPartnership());
return w;
}
@override
Map<String, dynamic> infos() {
return {};
}
@override
Map<String, dynamic> serialize() {
return toJSON();
}
}
class WorkflowPartnership extends AbstractPartnerShip<WorkflowPricing> {
WorkflowPartnership(): super();
@override
WorkflowPartnership deserialize(json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return WorkflowPartnership(); }
var w = WorkflowPartnership();
w.mapFromJSON(json, WorkflowPricing());
return w;
}
@override
Map<String, dynamic> serialize() {
return toJSON();
}
}
class WorkflowPricing extends AbstractPricing {
@override WorkflowPricing deserialize(json) {
var w = WorkflowPricing();
w.mapFromJSON(json);
return w;
}
@override
Map<String, dynamic> serialize() {
return toJSON();
}
}