Skip to content

threefold.grid4.farmingsimulator #

fn new #

fn new(args_ SimulatorArgs) !Simulator

is called from the play

fn node_template_new #

fn node_template_new(name string) NodeTemplate

a node template, holds the construction of a node as used in a grid

fn params_new #

fn params_new(parser playbook.PlayBook) !Params

Todo: check carefully

fn play #

fn play(mut plbook PlayBook) !

fn playmacro #

fn playmacro(action Action) !string

fn simulator_get #

fn simulator_get(name string) !&Simulator

get sheet from global

fn simulator_set #

fn simulator_set(sim Simulator)

remember sheet in global

struct CloudUnits #

struct CloudUnits {
pub mut:
	cu f64
	su f64
	nu f64 // GB per month
}

cu = min((mru - 1) / 4, cru * 4 / 2, sru / 50) su = hru / 1200 + sru * 0.8 / 200 https://library.threefold.me/info/threefold/#/tfgrid/farming/cloudunits

struct Component #

struct Component {
pub mut:
	name        string
	description string
	cost        f64 // cost always in USD
	rackspace   f64 // expressed in U, typical rack has 44 units
	power       f64 // expressed in watt
	cru         f64 // 1 logical core
	mru         f64 // 1 GB of memory
	hru         f64 // 1 GB of HD
	sru         f64 // 1 GB of SSD
}

is a component as used to create a node template see https://library.threefold.me/info/threefold/#/tfgrid/resource_units

struct ComponentGroup #

struct ComponentGroup {
pub mut:
	name      string
	nr        int // nr of components
	component Component
}

as used in node template

struct ComponentGroupArgs #

struct ComponentGroupArgs {
pub mut:
	nr        int // nr of components
	component Component
}

struct FarmingCapacity #

@[heap]
struct FarmingCapacity {
pub mut:
	resourceunits ResourceUnits
	cloudunits    CloudUnits
	cost          f64
	// consumption for 1 node in watt
	power f64
	// expressed in U, there are 44 in 1 rack
	rackspace f64
}

this is the calculation as result of defining the node template

struct NodeTemplate #

@[heap]
struct NodeTemplate {
pub mut:
	name       string
	components []ComponentGroup
	capacity   FarmingCapacity // the result for this node template
}

is a template which can be used for deploying threefold nodes a component group describes which components make up the node template

fn (NodeTemplate) components_add #

fn (mut nt NodeTemplate) components_add(cg ComponentGroupArgs)

struct Params #

struct Params {
pub mut:
	wiki_path   string = '/tmp/simulatorwiki'
	cultivation ParamsCultivation
	env         ParamsEnvironment
	farming     ParamsFarming
	tokens      ParamsTokens
}

struct ParamsCultivation #

struct ParamsCultivation {
pub mut:
	utilization_nodes  string = '1:0,24:70'
	revenue_per_cu_usd string = '1:5,60:4'
	revenue_per_su_usd string = '1:5,60:3'
	revenue_per_nu_usd string = '1:0.01,60:0.005'
	cost_per_cu_usd    string = '1:0'
	cost_per_su_usd    string = '1:0'
	cost_per_nu_usd    string = '1:0.005,60:0.0025'
}

struct ParamsEnvironment #

struct ParamsEnvironment {
pub mut:
	power_cost     string = '1:0.06,60:0.15'
	rackspace_cost string = '1:10,60:5'
}

struct ParamsFarming #

struct ParamsFarming {
pub mut:
	farming_lockup          int    = 24
	farming_min_utilizaton  int    = 30
	price_increase_nodecost string = '1:1,60:0.4'
	support_cost_node       string = '1:20'
}

struct ParamsTokens #

struct ParamsTokens {
pub mut:
	chi_total_tokens_million int    = 1000
	chi_price_usd            string = '1:0.1'
}

struct RegionalInternet #

struct RegionalInternet {
pub mut:
	name      string
	batches   []NodesBatch
	simulator &Simulator @[str: skip]
	sheet     spreadsheet.Sheet
}

fn (RegionalInternet) nodes_add #

fn (mut ri RegionalInternet) nodes_add(args RegionalInternetNodesAddArgs) !

add nodes to a regional internet: args: nodetemplate NodeTemplate nodegrowth string = '3:0,4:50,12:5000,24:50000,60:1000000'

fn (RegionalInternet) calc #

fn (mut ri RegionalInternet) calc() !

calculate how a regional internet will expand in relation to the arguments given

struct RegionalInternetNew #

struct RegionalInternetNew {
pub mut:
	name string
}

struct RegionalInternetNodesAddArgs #

struct RegionalInternetNodesAddArgs {
pub mut:
	template NodeTemplate
	growth   string = '3:0,4:50,12:100,24:1000,60:5000'
}

struct ResourceUnits #

struct ResourceUnits {
pub mut:
	cru f64 // 1 logical core
	mru f64 // 1 GB of memory
	hru f64 // 1 GB of HD
	sru f64 // 1 GB of SSD
}

https://library.threefold.me/info/threefold/#/tfgrid/resource_units

struct Simulator #

@[heap]
struct Simulator {
pub mut:
	name               string
	sheet              &spreadsheet.Sheet
	args               SimulatorArgs
	params             Params
	nrmonths           int = 6 * 12
	regional_internets map[string]&RegionalInternet
	node_templates     map[string]&NodeTemplate
	components         map[string]&Component
	// params             Params
}

fn (Simulator) node_template_wiki #

fn (mut s Simulator) node_template_wiki(name_ string) !string

fn (Simulator) nodetemplate_get #

fn (mut s Simulator) nodetemplate_get(name_ string) !&NodeTemplate

fn (Simulator) play #

fn (mut s Simulator) play(mut plbook PlayBook) !

fn (Simulator) regional_internet_wiki #

fn (mut s Simulator) regional_internet_wiki(name_ string) !string

fn (Simulator) regionalinternet_add #

fn (mut sim Simulator) regionalinternet_add(name string) !&RegionalInternet

fn (Simulator) regionalinternet_get #

fn (mut s Simulator) regionalinternet_get(name_ string) !&RegionalInternet

struct SimulatorArgs #

@[params]
struct SimulatorArgs {
pub mut:
	name      string = 'default' // name of simulation
	path      string
	git_url   string
	git_reset bool
	git_pull  bool
}