I am trying to create links for each agent with 7 other agents
my study area is divided in two sides "east and west"
I am using GIS extension and the side of the city is an attribute within the Shapefile,
I want to ask my agent to check the side of the city where it is in and create links with 7 other agents from the same side I am using two if statements
here's my code :
to Neighbour-network
ask households [
if patch-here [CitySide = "EAST"] [ create-links-with min-n-of 7 other households with [CitySide = "EAST"] [distance myself][
if patch-here [CitySide = "WEST"] [ create-links-with min-n-of 7 other households with [CitySide = "WEST"] [distance myself]]]]]
ask one-of households with [count link-neighbors > 1] [
ask link-neighbors [communicate]]
end
the error that i get is related to patch-here the message error is : if expected this input to be a True/False but got a patch instead
however when change it to patches with the error become : if expected this input to be a True/False but got an agentset instead
I am not sure how to fix it
CitySide seems to be a households-own variable. Is it also a patches-own variable? If so, then your if statements should be
if [CitySide] of patch-here = 'EAST` [ create-links .....
and
if [CitySide] of patch-here = 'WEST` [ create-links .....
But, if the household has its own CitySide variable that tells it where it is, why does it need to look at the patch it is on? Can't it just look at its own CitySide variable?
Related
To keep this short, i m working on a small discord bot. The bot is supposed to grab a servers banlist and then put it into its database. The problem is, to make a bulk insert, you appearently need an array that is stuctured like this
[
["blah 1", "bluh 1"],
["blah 2", "bluh 2"]
]
The problem that i m facing is, it distorts the formatting of the array for some reason
[
["blah 1", "bluh 1"],
[
"blah 1",
"bluh 1"
],
]
This is the code i use to create the array
list.forEach(element => {
if(element.reason === null){ var reason = "No reason Given"}else{ var reason = element.reason}
var userArray = [
element.user.id,
element.user.username,
element.user.discriminator,
reason,
element.user.bot
]
banArray.push(userArray)
})
Okay, to put this short again (its 4:11 am here right now, and i m lacking a lot of sleep). I found the problem i was having. I tried to use an array in my prepared statement while putting the unknown value into brackets.
queryStmt = "INSERT INTO tbl_bans (dtUserId, dtUserName, dtDiscriminator, dtReason, dtBot) VALUES (?)";
Notice the (?). The problem is, that i simply didnt look correctly at the code sample, and overlooked that there were no () around the ? in the sample.
Im new to angularJS and web designing as a whole. Im trying to get a data field(or element) from a JSON. For example, this is what the JSON looks like
{
"Name":"Raymond Eugene Monce",
"Dateofbirth":"1924-0308T00:00:00Z",
"Ethnicity":"Caucasian",
"Languages":["{English}"],
},
and I'm trying to get the "Name" data field. This is what my .js file looks like,
var profile = angular.module('profile', ['ui.bootstrap','ngResource']);
profile.controller("profileController", ["$scope","$resource", function($scope, $resource) {
// get the user id
$scope.userid = sessionStorage["cerestiuserid"];
// json we get from server
$scope.apicall = sessionStorage["cerestihome"]; // NEED TO CHANGE API
// grabs the user we want
$scope.userResource = $resource($scope.apicall + "/api/userprofile/",
{Userid:21},
{'get':{method: 'POST'}}
);
// fetch JSON
$scope.userResource.get(function(result) {
// get the name field
$scope.name = result;
sessionStorage["name"] = JSON.stringify(result);
});
and my .html file,
<div ng-controller = "profileController" style="float:left">
<!-- profile pic -->
<div class="pull-left">
<div class="container-fluid">
<div class="profile">
<div class="row">
<div class="center-block">
<div class="profilePic">
<img ng-src="{{profilePic()}}" class="img-responsive">
<!-- name field -->
<label class="caption">
<h4>{{name.name}}</h4>
</label>
</div>
Again, Im not having problems with the Database or API calls. I just want to know how I can get and display the name field of the JSON. Thanks.
strelok2010's comment above should work although that depends on if your result really looks like the one defined at the top of your question.
Your result seems to be a normal javascript object not JSON. (yeah they are different, and that confused me when I learned it.) I assume that because you stringify the result from a javascript object into JSON. Therefore if that is working right your result is either a javascript object or an array of javascript objects. I'm assuming an array. You might want to check though.
I noticed your earlier post had a related problem.
In that one you were asking to access a property of an object that was in an array. In that case it was result as well. Here was the answer from your previous question
var result = [{"name": "Jason"
"date of birth": "february 23, 2985"
....
}];
var firstResultsName = result[0].name;
There are two things I am unsure of due to the inconsistency between this and your last question.
First your name property in your results object is spelled with a capital N here as opposed to a lower case n in your last question.
Keep in mind that capitilization matters in javascript.
Second your result in your last question was an array of objects and in this it seems to be just an object.
So depending on which one it is will determine your solution. So instead of writing every possible solution I'll show you how to determine the solution.
Remember we are dealing with a normal array of javascript objects. I'll try to go into detail so it's extra clear (sorry I heard you were new to web developement, I'm assuming JavaScript too.), but sorry if it's a little too detailed. I will also be breaking it into parts to go deeper into the array of objects that I'll use in my example, but traversing into the data structure can all be done in a single line as I will show.
You can only do actions on the 'outermost-form' (by the way 'outermost-form' is just a term I'll use for clarification it's not really a technical term.) and work your way into the collection (object/array/string)
As an example we have an array of people, with the array being the 'outermost-form'
var people = [
{
"name": "Bob",
"occupation": "Architect",
"date of birth": "01/23/83"
},
{
"name": "Timothy",
"Occupation": "Accountant",
"date of birth": "02/23/78"
}
];
If we saw the value of people at this moment it not surprisingly be.
[
{
"name": "Bob",
"occupation": "Architect",
"date of birth": "01/23/83"
},
{
"name": "Timothy",
"Occupation": "Accountant",
"date of birth": "02/23/78"
}
]
Start with the Array
Since it's an array as the 'outermost-form' we can get one of its values using an index. Just like any other array. Just for a bit of contrast I'll show you how what we are doing is similar to any other array by showing an example of an array by itself
// simple array example
var array = ["foo", "bar", "baz"];
array[0] // returns "foo"
// more simple array example, but less practical (it's more just for showing how javascript can work.)
["foo", "bar", "baz"][2] // returns "baz"
Back to our main example. Let's make a variable person and store our first person in the people array in that value.
var person = people[0];
Now if saw our person variable it would equal the following
{
"name": "Bob",
"occupation": "Architect",
"date of birth": "01/23/83"
}
You can see just like the normal array it grabs the first item in the array. You can see how we are slowly traversing into our people data structure. (that being an array of objects.)
Enter the Object
Okay so now we have the person object, but we want the name of that person so since we are dealing with an object we have to access its properties we can do this with either 'dot notation', e.g. <object>.<property>, or 'bracket notation' which can be done with either a variable or a string for the property name. e.g. <object>.["<property>"] or <object>.[<variable>]
So just as a side example I will show you what it normally takes to get the value of a property of an object just so you can compare and see there's no 'magic' going on. Keep in mind javascript is case-sensitive. Also javascript objects properties can go with or without surrounding quotes unlike JSON. One last thing having a space in the property name forces us to use quotes, and also forces us to access that property via bracket notation.
var result;
var obj = { foo: 1, Bar: 2, "foo bar": 3 };
var randomVarName = "Bar"; // notice the capital B in Bar is important since it was declared that way.
result = obj.foo; // result equals 1
result = obj[randomVarName]; // result equals 2
result = obj["foo bar"]; // result equals 3
Back again to our main train of thought. So we have traversed into our people array to find the person object now let's get their name.
var name = person.name;
The value of name would be.
"Bob"
You can do with that what you wish. You could have also used any of the previous ways to get an objects property including bracket notation.
Do Everything we just did in a Single Line
So to write that all in one line you would just write
people[0].name
Apply to your Question
So to apply to your question if your result looks like this
var result = [
{
"name": "Jason"
"date of birth": "february 23, 2985"
....
}
];
Then you need this to get the name
result[0].name
If it's just this
var result = {
"name": "Jason"
"date of birth": "february 23, 2985"
....
}
Then you just need
result.name
As asked in the comment if you want to get the date of birth property out of the object you need to use bracket notation to get the element out of an object. Bracket notation is one of the two object property accessors the other being dot notation. I covered both at the enter the object section. It can be used at anytime, but is usable in some cases that dot notation does not work.
An example and quote from MDN:
get = object[property_name];
object[property_name] = set;
property_name is a string. The string does not have to be a valid identifier; > it can have any value, e.g. "1foo", "!bar!", or even " " (a space).
So since certain character like spaces can't be used in dot notation bracket notation must be used in those special cases when those characters are present.
Below is the bracket notation of the date of birth.
result["date of birth"]
Like I said before it can be used anywhere, but generally dot notation is preferred for its brevity. So just to show that, we will show the name field being accessed using bracket notation:
result["name"]
One additional reason you may want to use bracket notation is for its ability to use variables like so.
var prop_name = "date of birth";
result[prop_name];
which actually if you understand the principle of that example the MDN example might make more sense.
If you have a question feel free to leave me a comment.
I am facing a query performance issue. Do let me know if I am making any mistake here.
I have created around 1700 (Router nodes) and around 4000 (interface nodes) where interfaces are connected to their respective routers using relation (has_interface).
Now I want to create a link between these interfaces. A link will be a relation. Every interface has an IfIPAddress prop associated with it.
When I try to create a link using this query, it runs for a very long time, takes a lot of CPU and then do not create any link.
Here is my query
MATCH (I:Interface), (I2:Interface)
FOREACH(p in FILTER(z in {props} WHERE z.OrigIPAddress = I.IfIPAddress and z.TermIPAddress = I2.IfIPAddress) |
MERGE (:Interface {IfIPAddress:p.OrigIPAddress})-[r:link]->(:Interface {IfIPAddress:p.TermIPAddress})
ON CREATE SET r = p
ON MATCH SET r = p)
Here is what I provide to neo4j using json and curl
{
"params" : {
"props" : [
{
"AreaId" : "",
"OrigIPAddress" : "172.16.42.9",
"OrigNodeID" : "192.168.1.221",
"TermIPAddress" : "172.16.42.10",
"TermNodeID" : "10.229.140.28",
"eEntityStatus" : "1",
"iTotalBW" : "0"
}
]
},
"query" : "MATCH (I:Interface), (I2:Interface) FOREACH(p in FILTER(z in {props} WHERE z.OrigIPAddress = I.IfIPAddress and z.TermIPAddress = I2.IfIPAddress) | MERGE (:Interface {IfIPAddress:p.OrigIPAddress})-[r:link]->(:Interface {IfIPAddress:p.TermIPAddress}) ON CREATE SET r = p ON MATCH SET r = p)"
}
This is what I am doing in the query
First in the FILTER I am removing all those links whose OrigIPAddress or TermIPAddress are not present in the neo4j
After that for every props, I am creating a link between the interfaces.
I am using neo4j 2.1. When neo4j server was running with default configurations it gave error as "OutOFMemory Exception"
I increased the heap size of the server and it is taking a lot of time
Let me know if anything I have missed.
Do let me know if you need logs.
First of all: your query creates a cross product, i.e. it pulls in 8M pairs.
Try something like this first, and report back if it does not work.
FOREACH(p in {props} |
MERGE (I:Interface{IfIPAddress:p.OrigIPAddress})
MERGE (I2:Interface {IfIPAddress:p.TermIPAddress})
MERGE (I)-[r:link]->(I2)
SET r = p
)
You should not set all the properties on r that's just a waste. Only set the properties there that you really need.
Instead of:
SET r = p
do something like this:
SET r.uptime = p.uptime
How many elements do you have in {props} ?
What is your current server configuration? In terms of heap, mmio etc?
Best to share path/to/neo4j/data/graph.db/messages.log for diagnostics.
Earlier I asked about gathering information from API-Link, and I have managed to get out most of the details by using the answar I got.
Now ny problem is when another API to get more information
This time the file will contain this information:
{
"username":"UserName",
"confirmed_rewards":"0",
"round_estimate":"0.00000000",
"total_hashrate":"0.000",
"payout_history":"0",
"round_shares":"0",
"workers":{
"UserName.1":{
"alive":"0",
"hashrate":"0.000"
},
"UserName.2":{
"alive":"0",
"hashrate":"0.000"
},
"UserName.3":{
"alive":"1",
"hashrate":"1517.540",
"last_share_timestamp":1369598007
},
"UserName.4":{
"alive":"0",
"hashrate":"0.000"
}
}
}
And I want to gather each of the workers and print them out. This "workers" could contain multiple information, but always start with "UserName.x", where the username come from the "username" paramter each time.
The numbers will always vary from 0 and up
I want to gether the information in the same way by accessing the document, and decode and print out all the workers, whatever the numbers of them are.
By using the script provided in my last question(look at the link in the start), i was thinking that it would be something like
local t = json.decode( txt )
print("Workers: ".. t["workers.UserName.1"])
But this was not the way.
Due to the username changing all the time, I was also thinking somthing like
print("Workers: ".. t["workers" .. "." .. "username" .. "." .. "1"])
From here I have no clue about how I should gather the information, even when the names and numbers vary
Thanks in advance
Here is the perfect solution:
local json = require "json"
local t = json.decode( jsonFile( "data.json" )
local workers = t.workers
for name, user in pairs(workers) do
print("--------------------")
print(name)
for tag, value in pairs(user) do
print(tag , value)
end
end
Here are some more info:
http://www.coronalabs.com/blog/2011/08/03/tutorial-exploring-json-usage-in-corona/
http://www.coronalabs.com/blog/2011/06/21/understanding-lua-tables-in-corona-sdk/
http://lua-users.org/wiki/TablesTutorial
Writing a Reporting Service (2005) report
My DataSet returns something like this:
DESCRIPTION COUNT
Total Properties 12345
Demolished 1243
Non-Demolished 11102
:
:
I have this displayed as a table and this is fine.
Now I also want to display the data like this:
[ 12345 ] Total Properties
/ \
/ \
Non-Demolished [ 11102 ] [ 1243 ] Demolished
I can add the text-boxes and lines but what expression do I need to fill in the values?
Need somethig that returns the count based on a match to the description in the row.
Here is the way to do it.
First(Fields!FieldName.Value,"DataSetName")
Maybe you could do something like this:
=Iif(Fields!Description.Value = "Demolished", Fields!Count.Value, "Value not found")