change the value of a link - hyperlink

I try to change the values of links for only the links to particular agents. So, I want to set the links of myself to every agent in the agent set relatedPersons to 0.6 and keep all other links unchanged. Can I achieve this using ask my-out-links? My code is:
breed [ persons person ]
undirected-link-breed [ connections connection]
connections-own [ trust ]
to setup
clear-all
create-persons 10
[
set grouped false
]
create-connections
reset-ticks
end
to create-connections
ask persons
[ setup-connection ]
end
to setup-connection
create-connections-with other persons
[ set trust 0.4 ]
end
to increaseConnection
let alonePersons count persons with [grouped = false]
let relatedPersons n-of (random alonePersons) persons
ask relatedPersons [
ask my-out-links [ set trust 0.6 ]
]
end
to go
increaseConnection
tick
end

I think that this is the line that you want. Not terribly efficient as the intimacy value is set by both members of the pair, but it is intuitive and unless you have a lot of protesters, it should not be a problem.
ask my-out-links with [member? other-end NRelatedProtesters] [ set intimacy 0.8 ]
Each protester is looking for its links where the other end is a member of the NRelatedProtesters group.
Actually, to be consistent with your model, it should be
ask my-out-relationships with [member? other-end NRelatedProtesters] [ set intimacy 0.8 ]
Do note that your code is not complete. If one wanted to test it, they would have to fill in a number of missing parts.

Related

Swift $sort order for BSON RealmSwift document

TLDR:
how can I write a document with a definitive order for the key value pairs to pass as key to the $sort stage?
I stumbled across very strange behaviour in my aggregate query that I am running in Swift (using RealmSwift package) through:
db.collection(withName: "Example")..aggregate(pipeline: aggregatePipeline) { ... }
This is the stage that is behaving very strangely:
let aggregatePipeline: [Document] = [
[
"$sort": [ "seen": 1 , "score": -1, "_id": -1 ]
]
]
The results I get are sorted by these three keys, but in seemingly arbitrary sorting order each time I run the query. So sometimes the "seen" sorting is prioritised (as it should be) but sometimes it sorts first by "_id", or "score". When I print the stage right after defining it by running:
print(aggregatePipeline[0])
I do see a the probable reason for those odd results...
first run:
["$sort": Optional(RealmSwift.AnyBSON.document(["_id": Optional(RealmSwift.AnyBSON.int64(-1)), "seen": Optional(RealmSwift.AnyBSON.int64(1)), "score": Optional(RealmSwift.AnyBSON.int64(-1))]))]
second run:
["$sort": Optional(RealmSwift.AnyBSON.document(["seen": Optional(RealmSwift.AnyBSON.int64(1)), "score": Optional(RealmSwift.AnyBSON.int64(-1)), "_id": Optional(RealmSwift.AnyBSON.int64(-1))]))]
how can I write this query with a definitive sorting order? Or more simply: how can I write a document with a definitive order for the key value pairs to pass as key to the $sort stage? I found nothing in the relevant docs or especially this where it should definitely be stated how this could be accomplished, since this would be the most sensible way, but obviously is the wrong way of doing it.

How to move to a linked agent which has a particular value for the link

I am trying to select the agents to which I link that have a high value for my link to that agent. Then, I want to move to one of those agents. I cannot figure out how to select the agents at the other end of my link, where the link has a particular value and then move to one-of those agents with a high value of 0.9 for the link. How can I achieve this?
breed [ people ]
undirected-link-breed [ connections connection ]
connections-own [ trust ]
to setup-all-connections
ask people [setup-connection]
end
to setup-connection
create-connections-with other people [set trust 0.4]
end
to go
move-people
tick
end
to move-people
ask people [
let chance random 100
if chance < 80
[
let highTrust my-out-connections with [trust = 0.9]
move-to one-of people with [member? other-end highTrust]
]
]
end
How about
let highTrust turtle-set [other-end] of my-out-connections with [trust = 0.9]
move-to one-of highTrust
I.e., get a list of the appropriate other-ends, turn that list into an agentset, and then move to one of them. Or, more economically
move-to one-of [other-end] of my-out-connections with [trust = 0.9]
since one-of works on lists of agents as well as agentsets. You may need to be sure that their is at least one such trusted agent before applying one-of. You might also want to check if there is already a trusted agent at the same location so that it does not move away from it.

Conditional grep/ack searches?

What I mean by this is that I want to search for "thing1", and then I want to search for "thing2" based on the position of the "thing1". And I want to display both of them in the result in the order that they are in the coede.
eg. I find "thing1" on line 100. I want to then search for the first "thing2" that occurs before "thing1". Then I want to display both of these in the order "thing2" then "thing1". I want to do this for every instance of "thing1" that I find.
The reason for this is that I want to search for certain strings which I know will be in lists (python), and I want to know the name of the lists too. So I thought that I could search for the string and then also display the first "= [" sign that occurs before the string.
So if a file has:
my_list = [
'item1',
'item2',
'item3',
]
my_other_list = [
'item4',
'item5',
'item3',
]
and create a search which looks for 'item3' and then to looks back to find the previous '= ['
then the output should be (not including line numbers which grep and ack will put):
my_list = [
'item3',
my_other_list = [
'item3',
I think you want this:
awk '/=/{thing2=$0} /item3/{print thing2;print $0,"\n"}' YourFile
So, every time you see an =, you remember the line as thing2. When you see item3 you print the last thing2 you saw and the current line.
Sample Output
my_list = [
'item3',
my_other_list = [
'item3',

Report Filtering With Adobe Analytics API

I am queuing and getting a report through the API and javascript, but now I want to start filtering the report. I want the results that come back to apply only to the user (other filters are needed too) who is requesting the report. What is the best way to put a filter on the initial report queue?
The way I am doing it now is adding a selected element to the report description:
...
"elements": [
{ "id": "page" },{ "id": "evar23" , "selected": ["295424","306313"]}
...
But this only seems to apply to the breakdown section of the results, not the top level count that is returned. I would expect the top level count in the below example be 66, not 68:
...
"counts":[
"68"
],
"breakdown":[
{
"name":"306313",
"url":"",
"counts":[
"43"
]
},
{
"name":"295424",
"url":"",
"counts":[
"23"
]
}
]
}
,...
I know I can just crawl through the breakdown array and total up what I need, but the more filters I apply the messier it becomes. All of a sudden I am three levels deep in a nested array, making sure that all 3 breakdown names match my conditions. There must be a better way to do this, any ideas? Many thanks.
Although there are some possible limitations to them that I am still working through, it seems that segments is what I need, not elements.
"segments": [
{
"element": "evar23","selected": ["295424","306313"]
}]
https://marketing.adobe.com/developer/forum/reporting/report-filtering-with-api

how to get the distance or radian between two point on the earth with lng and lat?

how to get the distance or radian between two point on the earth with lng and lat?
You probably don't want mapReduce in this case but actually the aggregation framework. Apart from the general first stage query you can run via $geoNear which is more efficient in your purpose.
db.places.aggregate([
{ "$geoNear": {
"near": {
"type": "Point",
"coordinates": [ -88 , 30 ]
},
"distanceField": "dist"
}},
{ "$match": {
"loc": {
"$centerSphere": [ [ -88 , 30 ] , 0.1 ]
}
}}
])
Or frankly, because the initial $geoNear stage will "project" an additional field into the document containing the "distance" from the queried "point of origin", then you can just "filter" on that element in a subsequent stage:
db.places.aggregate([
{ "$geoNear": {
"near": {
"type": "Point",
"coordinates": [ -88 , 30 ]
},
"distanceField": "dist"
}},
{ "$match": {
"dist": { "$lte": 0.1 }
}}
])
Since this is one option that can "produce/project" a value representing the distance in the result then that satisfies your first criteria. The "chaining" nature of the "aggregation framework" allows "additional filtering" or any other operation you need to perform after the filtering of the initial query.
So $geoWithin works just as well in the aggregation framework under a $match stage as it would in any standard query since it is not "dependant" on an "index" of geospatial origin to be present. It performs better in an initial query with one, but it does not need it.
Since your requirement is the "distance" from the point of origin, then the most logical thing to do is to perform an operation that will return such information. Such as this does.
Would love to include all of the relevant links in this response, but as a new responder then two links is all I am allowed for now.
One more relevant note:
The measurement of "distance" or "radius" in any operation is dependant on how your data is stored. If it is in a "legacy" or "key/pair or plain array" format then the value will be expressed in "radians", otherwise where the data is expressed in GeoJSON format on the "location" then the "distance data" is expressed in "meters" instead.
That is an important consideration given the libraries implemented by the MongoDB service and how this interacts with the data as you have it stored. There is of course documentation on this in the official resources should you care to look at that properly. And again, I cannot add those links at this time, unless this response sees some much needed love.
https://github.com/mongodb/mongo/blob/master/src/third_party/s2/s2latlng.cc#L37
GetDistance() return a S1Angle, S1Angle::radians() will return the radians.
This belong to s2-geometry-library(google code will close,i export it to my github. Java).

Resources