At model startup I manually instantiate each instance of my resource with parameters. Parameters are name, capacities, required number of employees and ResourceType. The ResourceType of each Resource is taken from an OptionList.
At the end of the simulation I want to retrieve data for each resource for a data extract. Since I don't want to query all resources manually and individually, I want to iterate through the different resources.
Should look like:
for (ResourceType rt : Resources) {
// export in excel
}
But for that I would have to create a list with all resources filled with ResourceType (OptionList). Is there a way to cast an OptionList to an AgentType within a List? The end product should be something like: Resources.listOfAllResources filled with the enums.
You need to loop through your OptionList entries and find all resources of that type:
for (int i=0; i<myOptionList.values().length; i++) {
myOptionList currentEntry = myOptionList.values()[i];
findAll(myResourcesInAList, r->r.getType().equals(currentEntry));
}
Related
I've searched a lot but can't find a clear answer anywhere for string list -> enum.
I've got a list of strings that I want to turn into an enum that I can select from in Unity inspector.
Specifically, I'm trying to make an enum list of all the currently set-up Input buttons from project settings. I've got all the names, just don't know how to make it an enum or similar. Ideally showing up like a KeyCode variable in inspector.
Currently trying (and failing) with:
foreach (string s in names)
{
if (Enum.TryParse(s, true, out list))
Debug.Log(list);
else Debug.Log("FAILED");
}
"names" = static List<string> names;
"list" = static MyList list;
"MyList" = enum MyList { Null }
Returns "FAILED" 58 times for only 29 Input axis.
I want a simple solution, so if its not possible or relatively simple, I'll work out something else.
Code for getting the "names" list of strings (Works correctly):
var inputManager = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0];
SerializedObject obj = new SerializedObject(inputManager);
SerializedProperty axisArray = obj.FindProperty("m_Axes");
if (axisArray.arraySize == 0)
Debug.Log("No Axes");
for (int i = 0; i < axisArray.arraySize; ++i)
{
var axis = axisArray.GetArrayElementAtIndex(i);
var name = axis.FindPropertyRelative("m_Name").stringValue;
names.Add(name);
}
Normally you can do
foreach (string colorName in Enum.GetNames(typeof(Colors))) which will iterate the names of the enums.
In your code above you havent shown what list is, nor where names has come from. However.
enum Things
{
Item1 = 0,
Item2 = 1
}
You can get the name from string name = Enum.GetName(typeof(Things), (int)Things.Item2) and you can get values from names with int value = (int)Enum.Parse(typeof(Things), nameOfThing)
So depending on what you actually want in a list and what you start with, iterate through and pick the relevant one
I ended up making my own solution, since (and please correct me if I'm wrong) the TryParse() and Parse() methods appear to need the enum to already contain entries with the same name (or index int) as the string to parse. This defeats the purpose for me, since I am doing this because I don't have the names in there already.
My solution ended up being to switch to having a single string input variable instead of an enum, then use Odin Inspector's ValidateInput attribute to check (for spelling errors, and) if the input variable matches any of the string entries in my dynamic list of InputManager input names (which I update manually using Odin Inspector's Button attribute and the code in the original post).
It's slightly less clean than I wanted, but does the job, so I'm satisfied.
Using the Terraform (v0.9.6) GitHub Provider, how can one separately assign multiple distinct issue labels to a list of GitHub repositories while using one resource?
With another language I'd probably write something along the lines of:
for i in repos {
for j in tags[i] {
make tag j on repo i
}
}
In this example below I am adding multiple tags to a single repository. The map keys are the repos, and the values are a list of strings.:
variable "issue-labels" {
type = "map"
default = {
"repo_0" = "tag1, tag2, tag3"
"repo_1" = "tag4"
"repo_2" = "tag5, tag6"
}
}
resource "github_issue_label" "issue_labels" {
count = "${length(split(", ", join(", ", lookup(issue-labels, "my-repo"))))}"
repository = "my-repo"
name = "${element(split(", ", join(", ", lookup(issue-labels, "my-repo"))), count.index)}"
color = "FFFFFF"
}
Currently seeking an answer to what feels like an inner loop in terraform. Either finding some way to iterate through the repositories and make multiple resource counts for each, or a workaround involving interpolation to assign the right repo when we iterate through the total number of labels.
Using list variables and other complex structures to "abstract away" resources is not idiomatic and tends to lead to configuration that is hard to read and maintain.
The idiomatic style is to manage repetitive constructs using multiple instances of a child module.
For example, one can make a subdirectory called repository that contains a repository.tf file such as the following:
variable "name" {
}
variable "labels" {
type = "list"
}
# can instead use github_team_repository here if appropriate
resource "github_repository" "this" {
name = "${var.name}"
# ...
}
resource "github_issue_label" "all" {
count = "${length(var.labels)}"
repository = "${var.name}"
name = "${var.labels[count.index]}"
color = "FFFFFF"
}
Now in the root module, rather than using variables to define the set of repositories, one can instead instantiate this resource once for each repository:
module "foo_repo" {
source = "./repository"
name = "foo"
labels = ["tag1", "tag2", "tag3"]
}
module "bar_repo" {
source = "./repository"
name = "bar"
labels = ["tag4"]
}
module "baz_repo" {
source = "./repository"
name = "baz"
labels = ["tag5", "tag6"]
}
With this style, the settings for each repository are kept together in a single module block each, thus making them easy to read and update. Adding a new repository is done by adding a new module block.
This style also allows removing a single repository without disturbing all of the ones after it, since the module states are stored by the module name rather than by index into a a list.
The general recommendation here is that count should be used sparingly, and that it's usually better to write config explicitly rather than generate it via variables. The result is often easier to read and maintain, and easier to adapt over time as requirements change.
I am having scenario in which i want to fetch all the values of a property under a specific path in AEM using QueryBuilder api.
This property can have single or multivalued.
Any help will be appreciated!!
Example that can help you. is below as it is just for illustration written in simple JSP scriptlets
<%
Iterator<Resource> iter = resourceResolver.findResources("/jcr:root/content/geometrixx-outdoors//element(*, nt:unstructured)[(#imageRotate = '0' or #imageRotate = '1')]","xpath");
while (iter.hasNext()) {
Resource child = iter.next();
out.println("</br>"+child.getPath());
Node node = child.adaptTo(Node.class);
Property nProp = node.getProperty("imageRotate");
if(nProp.isMultiple()) // This condition checks for properties whose type is String[](String array)
{
Value[] values = nProp.getValues();
out.println(" :: This is a multi valued property ::");
for (Value v : values) {
out.println("</br>"+"Property Name = "+nProp.getName()+" ; Property Value= "+v.getString());
}
}
else if(!nProp.getDefinition().isMultiple()){
out.println("</br>"+"Property Name = "+nProp.getName()+" ; Property Value= "+nProp.getString());
}
}
%>
Here i have used the Iterator<Resource> iter = resourceResolver.findResources(query,"xpath"); which can give you the query results which matches the imageRotate property under /content/geometrixx-outdoors/ path which consists combination of single and multivalued as shown in below screenshot.
There is no direct way to fetch the properties using query builder api. I would suggest you to create a servlet resource, which requires a path and property name.
Fetch the jcr node using the given path via QueryBuilder. Then, you need to loop through the results to check the property of the nodes. You can access the multiple property values, once you have a node.
We have two classes: Module and Resource, with a module having many resources:
class Module extends Model {
public function resources() {
return $this->hasMany('App\Models\Resource');
}
}
and a resource belonging to a Module:
class Resource extends Model {
public function module() {
return $this->belongsTo('App\Models\Module');
}
}
I need to show a list of all the modules with:
The number of resources for each each module
The average of resources per module
The first one is added to the Module model so it can be used with eager loading:
public function resourcesCount() {
return $this->hasMany('App\Models\Resource')
->selectRaw('module_id, count(*) AS aggregate')
->groupBy('module_id');
}
However, I can't find an efficient and elegant way to calculate the average of the counts calculated by resourcesCount. I know I could iterate through the results of
$modules = Module::with('resourcesCount')->get();
and do it manually, but I feel there's something better out there.
EDIT: forgot to say that I modified the accessor for the resourcesCountAttribute:
public function getResourcesCountAttribute() {
if (!$this->relationLoaded('resourcesCount'))
$this->load('resourcesCount');
$related = $this->getRelation('resourcesCount');
return ($related) ? (int) $related->aggregate : 0;
}
So I can use 'resourcesCount' (See my response), rather than having to use 'resourcesCount.aggregate'.
I found out an acceptable way to do so, using the collection's methods.
// Returns an elloquent collection
$modules = Module::with('resourcesCount')->get();
// counts sums divided by the number of
$avgResources = $modules->sum('resourcesCount') / $modules->count();
The only way would be to do it through iteration or in a separate DB::select() statement, relying on things like GROUP BY and AVERAGE().
I'm trying to create a new OpportunityProduct using this rest call:
XRMServices/2011/OrganizationData.svc/OpportunityProductSet
{"ProductId":"ef71ce8e-1ef3-e211-b252-984be17c47e4","Quantity":123,"ProductDescription":"Added from code - TEST123","OpportunityId":"8bdb3525-7274-e311-a90b-6c3be5be5f78"}
The call returns:
The request should be a valid top-level resource object.
This indicates that my arguments is not correct. I see to possible reasons for this:
I'm missing some required properties (How can I figure out which is required?)
It is not possible to do using rest
(both guids are returned via other call and should be correct)
Any help would be great!
Thanks
Larsi
For lookup references to other entities you need to specify both the GUID and the type. You also need to include the UOM when creating an Opportunity Product based on an existing Product. Your object should look something like this:
var entity = {};
entity.Quantity = parseFloat(4).toFixed(2);
entity.OpportunityId = {
Id: '69BB2236-B57F-E311-BB6D-6C3BE5A881A4',
LogicalName: 'opportunity'
};
entity.ProductId = {
Id: 'C8138483-DF81-E311-B542-6C3BE5A8362C',
LogicalName: 'product'
};
entity.UoMId = {
Id: 'BE0FB859-7E90-4B3E-B501-3AB3CD4DC8FC',
LogicalName: 'uom'
};