package
0.0.0-20240428160657-20992a5c4ff8
Repository: https://github.com/codeafix/orgnetsim.git
Documentation: pkg.go.dev

# README

srvr GoDoc

This package contains all of the code for the web server that wraps the simulator

Routes

GET /

Route for the website.

GET /api/simulation

Return the list of simulations on the server.

POST /api/simulation

Create a new simulation.

PUT /api/simulation/notes

Updates notes recorded about this list of simulations.

GET /api/simulation/{sim_id}

Return a specific simulation. Contains the network options for the network if set.

PUT /api/simulation/{sim_id}

Updates details about the specified simulation.

DELETE /api/simulation/{sim_id}

Deletes the specified simulation

POST /api/simulation/{sim_id}/generate

Generates a hierarchical network to be simulated in an existing simulation. There should be no existing steps within the simulation otherwise this request will fail. Returns the created first step that contains the generated network and the initial color results for the generated network.

POST /api/simulation/{sim_id}/parse

Parses a network from a byte array to be simulated in an existing simulation. There should be no existing steps within the simulation otherwise this request will fail. Returns the created first step that contains the generated network and the initial color results for the generated network.

POST /api/simulation/{sim_id}/copy

Creates a new copy of the specified simulation and the initial simulation step if it exists. This will not copy any subsequent steps in the simulation being copied.

PUT /api/simulation/{sim_id}/links

Parses a list of relationships from a byte array and adds them to the network on the latest step of the simulation. This modifies the network in the latest step. Unlike parse and generate this will not fail if steps exist, this will fail if at least one step with a valid network does not already exist. Note also this can only be used to add new edges to the network. If any of the parsed links reference an agent that doesn't already exist on the network, this will fail.

POST /api/simulation/{sim_id}/run

Runs the simulation for a specified number of steps, each step runs a specified number of iterations.

GET /api/simulation/{sim_id}/step

Returns the list of steps in this simulation. This returns the actual content of the steps as opposed to the list of step paths that is returned in GET /api/simulation/{sim_id}

GET /api/simulation/{sim_id}/results

Returns the concatenated set of results for all the steps in this simulation.

GET /api/simulation/{sim_id}/step/{step_id}

Returns the specified step which contains the results for that step and the state of the network at the end of that step.

PUT /api/simulation/{sim_id}/step/{step_id}

Updates the results and network state in the specified step

DELETE /api/simulation/{sim_id}/step/{step_id}

Deletes the specified step

# Functions

CreateRouter registers the route handlers.
CreateSimInfo creates a new SimInfo object with a new ID.
CreateSimStep creates a new SimStep object with a new ID.
ListenAndServe launches the web server rootpath is the root directory where data served by this server is persisted webpath is the root directory of the static website served by this server webfs is the embedded copy of the static website that will be served if the webpath is an empty string port is the port to listen on.
NewFileManager returns a new instance of FileManager.
NewSimHandler returns a new instance of SimHandler.
NewSimInfo returns a SimInfo object for the passed ID.
NewSimList returns a SimList object that will be persisted.
NewSimListHandler returns a new instance of SimListHandler.
NewSimStep returns a SimStep object for the passed ID that will be persisted in directory root.
NewSimStepFromRelPath returns a SimStep object extracting IDs from the relative path in thepassed string.
NewStepHandler returns a new instance of StepHandler.

# Structs

FileDetails contains information about a file that will be managed by the FileUpdater.
ListHandlerState holds state information for a ListHandler.
ParseBody is the payload struct for uploading a network in a text file to be parsed together with the options that specify how to parse the text file.
PersistableHandlerState holds state information for a PersistableHandlerState.
RunSpec specifies the number of simulation steps to run, and the number of iterations that should be performed within each step.
SimHandlerState holds state data for the SimHandler.
SimInfo contains all relevant information about a simulation.
SimList is the list of simulations in the root directory.
SimListExt is the struct that embeds SimInfo objects into the SimList.
SimListHandlerState holds state data for the SimListHandler.
SimStep holds the results of each simulation step.
StaticRouter is a derived version of mango.Router that also serves an embedded copy of the orgnetsim UI.
StepHandlerState holds state data for the StepHandler.
TimestampHolder holds the current timestamp on a persistable object.
UpdaterRepo contains all FileUpdaters in use in this instance.

# Interfaces

FileManager is a repository for all instances of FileUpdater.
FileUpdater manages a file and provides Read and Update methods that allow the rest ofthe package to read and update a file.FileUpdater contains a lock to prevent multiple goroutines from trying to write at thesame time and also prevents Reads from occuring whilst an update is being performed.The Update function checks the last modified time of the file before it updates it,if it has been modified since the last copy was read, then Update will return anerror, and the Update method will attempt to re-read the contents of the file intothe object supplied.
ListHolder is an interface that any persistable that contains a list must implement.
ListItem is an interface that any persistable that can be added to a list must implement.
Persistable must be implemented by any obj that requires to be saved in a file usingFileUpdater.
SimHandler provides Read/Update methods for simulations on the simulation list.
SimListHandler provides Create/Delete methods for simulations on the simulation list.
StepHandler provides Read/Update methods for steps of a simulation.
Updateable must be implemented by any persistable object that can be updated.