In netlogo v6, I'm trying to let agents interact with other agents in their network, and make new connections.
For that, I need them to check the current links that are also present at the meeting. Only if they are at the meeting, they can interact.
I use a reporter to do this: links_at_meeting.
The code is: (with the patches representing the meeting place)
to-report links_at_meeting
report my-links with [[patch-here] of other-end = one-of (patch-set patch 0 0 ([neighbors] of patch 0 0 ))]
end
I keep getting an error that is a bit too unrelated to explain in full, but I figured out that this is due to the fact that links_at_meeting keeps reporting a different number. I found this out because, when I got the error, I went to the command centre and asked for the links_at_meeting of the error-giving turtle, and then I got this (for 1 tick):
observer> ask id 39[show links_at_meeting]
(id 39): (agentset, 0 links)
observer> ask id 39[show links_at_meeting]
(id 39): (agentset, 1 link)
observer> ask id 39[show links_at_meeting]
(id 39): (agentset, 1 link)
observer> ask id 39[show links_at_meeting]
(id 39): (agentset, 2 links)
observer> ask id 39[show links_at_meeting]
(id 39): (agentset, 4 links)
observer> ask id 39[show links_at_meeting]
(id 39): (agentset, 0 links)
observer> ask id 39[show links_at_meeting]
(id 39): (agentset, 2 links)
observer> ask id 39[show links_at_meeting]
(id 39): (agentset, 3 links)
observer> ask id 39[show links_at_meeting]
(id 39): (agentset, 0 links)
observer> ask id 39[show links_at_meeting]
(id 39): (agentset, 0 links)
observer> ask id 39[show links_at_meeting]
(id 39): (agentset, 4 links)
Here you see that each time I call for links_at_meeting, I get a different agentset for a singular tick (links do not move out of the meeting place during this).
The same happens for a reporter neighbors_at_meeting, which reports the link-neighbors with patch-here = meeting place.
My question is: why? What couldve gone wrong?
Thanks a lot in advance.
I think I figured it out already -
The problem seems to be that this part:
my-links with [[patch-here] of other-end = one-of (patch-set patch 0 0 ([neighbors] of patch 0 0 ))]
produces a list of links that is on one of those patches, instead of producing a list of turtles that is on any of those patches.
Related
I am using neo4j for my social projects where User can create, like and share a post, and can follow each other and user can see their follower's created, liked and shared post on his timeline.
I want aggregated message like : "You, Harry and other 20 has shared this post"
MATCH (n:User {user_id:'5bbc7962b87e07476f6c04db'})-[:FOLLOWS]->(f:User)-[p:CREATED]-(d)
RETURN d,
SIZE( ()-[:LIKED]->(d) ) as likecount,
SIZE( ()-[:SHARED]->(d) ) as sharecount,
SIZE( (n)-[:LIKED]->(d) ) as likestatus,
SIZE( (n)-[:SHARED]->(d) ) as sharestatus,
count(*) as postcount,
CASE
WHEN sharestatus = 1
THEN "You"
WHEN sharecount > 1
THEN "abc and xyz share this post"
END
ORDER BY d.updated_at DESC
SKIP 0
LIMIT 25
I tried above query but didn't work.
Any help would be highly appreciated.
In a Rails app, I have a model named TopicEdition with 2 attributes:
edition and an associated Topic.
The topic_editions table may look like
id | edition | topic_id
1 | 1 | 1
2 | 2 | 1
3 | 1 | 2
Now I need to get the list of TopicEdition having the highest edition for each topic.
Referring the table above, I should get back record with id 2 and 3.
I have tried to play around with group and maximum but without success.
My last attempt has been
TopicEdition.group(:topic_id).maximum(:edition)
How can I get what I need?
The followings work but it is kind of ugly
TopicEdition.find_by_sql 'SELECT * FROM topic_editions WHERE (topic_id, edition)
IN (SELECT topic_id, MAX(edition) FROM topic_editions GROUP BY topic_id)'
I think the easiest would be to use normal SQL to sort your query like this:
TopicEdition.group(:topic_id).order('MAX(edition)')
That will return only the last edition of each topic.
I'm working on part of a project about authorize and authenticate.so,but I've problem in the the same type of user with different permission.for example,
UserPermission Table
------------------------
UserId(int) //this is a AUTO INCREMENT primary key
UserBasicInformation(bool)
UserOperation(bool)
UserEntrance(bool)
UserExit(bool)
UserReport(bool)
AdminBasicInformation(bool)
AdminOperation(bool)
AdminSettings(bool)
UserPermissionId(int) // in this field I've kept key of users from UserDefs table
UserTitle(nvarchar)
UserDefs (brief)
--------------------------
UserId ///this is a AUTO INCREMENT primary key
UserType(int) //1,2
UserName(nvarchar) // admin,user
UserTitle(nvarchar) // alex,sara,....
UserId UserType UserName UserTitle
--------------------------------------------
1 1 Admin alex
2 1 Admin sara
3 2 user steve
4 2 user nicolas
this is UserPermision table that I populate for better understand.
UserId UserBasicInformation UserOperation UserEntrance UserExit
-----------------------------------------------------------------------------
1 0 0 0 0
2 0 0 0 0
3 1 1 1
UserReport AdminBasicInformation AdminOperation AdminSettings
-----------------------------------------------------------------------------
0 1 1 0
0 0 1 1
0 0 0 0
UserPermissionId UserTitle
-------------------------------
1 alex
1 sara
2 steve
if you take a look at userDefs table I have a two admins or two users but they are different permission in UserPermission table.but now,I don't know how to implement it.some people said me I use sessions what is your idea about it? in fact,I will read userpermission table.
If I try to execute
create table TEST(testColumn VARCHAR(255));
grant insert on TEST to test_user;
revoke insert on TEST from test_user;
I get the following error message (translated from German by myself):
1) [REVOKE - 0 row(s), 0.000 secs] [Error Code: -580, SQL State: IX000]
Could not detract access rights.
2) [Error Code: -111, SQL State: IX000] ISAM-Error: No data record was found.
(English version of error -580: Cannot revoke permission.)
Do you have any idea what is going on here?
All the statements are issued with the same user?
Usually this happens when trying to revoke a table-level privilege that your account name did not grant.
To find the correct grantee use:
SELECT a.grantee, a.grantor
FROM systabauth a, systables t
WHERE a.tabid = t.tabid
AND UPPER(t.tabname) = 'TEST';
Then it's possible to issue:
REVOKE INSERT ON TEST FROM 'test_user' AS '<GRANTEE>';
The other possibility that I didn’t mention, but #chris311 figure it out, is that you cannot revoke privileges from yourself.
What is happening “behind it”, take the next example, a database named chris311, owned by chris, bear in mind that I'm using the informix user:
[infx1210#tardis ~]$ id
uid=501(informix) gid=501(informix) groups=501(informix)
[infx1210#tardis ~]$ dbaccess chris311 -
Database selected.
> SELECT name, owner
> FROM sysmaster:sysdatabases
> WHERE name = DBINFO('dbname') ;
name chris311
owner chris
1 row(s) retrieved.
>
Both chris and informix have the DBA database-level privilege, and ricardo was granted the CONNECT privilege:
> SELECT username, usertype
> FROM sysusers;
username usertype
chris D
informix D
ricardo C
3 row(s) retrieved.
>
There is a table, tab1, owned by chris that ricardo was granted, by chris, the ALL table-level privilege:
> SELECT t.tabname, t.owner, a.grantee, a.tabauth, a.grantor
> FROM systabauth a, systables t
> WHERE a.tabid = t.tabid
> AND t.tabname= 'tab1';
tabname tab1
owner chris
grantee ricardo
tabauth su-idxar-
grantor chris
1 row(s) retrieved.
>
Then if informix whant's to revoke the INSERT privilege it must use the AS clause to specify chris as the revoker:
> REVOKE INSERT ON tab1 FROM ricardo;
580: Cannot revoke permission.
111: ISAM error: no record found.
Error in line 1
Near character position 33
> REVOKE INSERT ON tab1 FROM ricardo AS chris;
Permission revoked.
> SELECT t.tabname, t.owner, a.grantee, a.tabauth, a.grantor
> FROM systabauth a, systables t
> WHERE a.tabid = t.tabid
> AND t.tabname = 'tab1';
tabname tab1
owner chris
grantee ricardo
tabauth su--dxar-
grantor chris
1 row(s) retrieved.
>
If he tries to revoke the INSERT privilege from himself an error will return also:
> REVOKE INSERT ON tab1 FROM informix;
580: Cannot revoke permission.
111: ISAM error: no record found.
Error in line 1
Near character position 34
>
Now if we see the meaning of the 580 error we get:
[infx1210#tardis ~]$ finderr 580
-580 Cannot revoke permission.
This REVOKE statement cannot be carried out. Either it revokes a
database-level privilege, but you are not a Database Administrator in
this database, or it revokes a table-level privilege that your account
name did not grant. Review the privilege and the user names in the
statement to ensure that they are correct. To summarize the table-level
privileges you have granted, query systabauth as follows:
SELECT A.grantee, T.tabname FROM systabauth A, systables T
WHERE A.grantor = USER AND A.tabid = T.tabid
[infx1210#tardis ~]$
It doesn't says anything about revoking privileges from himself, but the documentations mentions it. Also, if we think about the 111: ISAM error: no record found. and associate it to the fact that the DBA doesn´t appear on the systabauth it makes sence, kind of.
The grants doesn´t return an error/warning because the DBA already have the privileges, the revoke returns it because the action didn't take effect.
Now let's take the DBA role from chris, let's do it twice:
> REVOKE DBA FROM chris;
Permission revoked.
> REVOKE DBA FROM chris;
Permission revoked.
> SELECT username, usertype
> FROM sysusers;
username usertype
chris C
informix D
ricardo C
3 row(s) retrieved.
> SELECT t.tabname, t.owner, a.grantee, a.tabauth, a.grantor
> FROM systabauth a, systables t
> WHERE a.tabid = t.tabid
> AND t.tabname= 'tab1';
tabname tab1
owner chris
grantee ricardo
tabauth su--dxar-
grantor chris
1 row(s) retrieved.
>
Again, the second REVOKE didn't return an error/warning because it was in effect. The user still doesn´t appear on the systabauth table.
But what table-level privileges it has?
[infx1210#tardis ~]$ dbaccess chris311 -
Database selected.
> INSERT INTO tab1 VALUES(1);
1 row(s) inserted.
> SELECT * FROM tab1;
col1
1
1 row(s) retrieved.
> DROP TABLE tab1;
Table dropped.
>
He isn't a DBA but he is the owner.
Given these business rules:
Users have 0 or more accounts and all accounts are associated with a single user
Users have 0 or more assets and all assets are associated with a single user
An asset may be associated with a single account. If it is assigned to any account, that account must belong to the user associated with the asset.
Assume the following proposed schema:
User
-id
Account
-id
-user_id
Asset
-id
-user_id
-account_id (Nullable)
It appears there is a weakness in this schema since an asset could be
assigned to an account that belongs to a different user than that
asset. Is this addressed by one of the normal forms leading to a
better schema? If it is not covered via normalization is the best
constraint then on the business logic side?
The only part of this (below) that normalization might deal with is the nullable column. In Chris Date's understanding, if a column allows NULL, then the relation isn't in 1NF.
If you were trying to strictly follow the relational model, I think you'd handle this with an assertion. But most SQL platforms don't support assertions. In SQL, I believe you're looking for something along these lines. I tested this in PostgreSQL.
create table users (
user_id integer primary key
);
create table accounts (
user_id integer not null references users (user_id),
account_id integer not null unique,
primary key (user_id, account_id)
);
create table assets (
user_id integer not null references users (user_id),
asset_id integer not null unique,
account_id integer null,
primary key (user_id, asset_id),
foreign key (user_id, account_id) references accounts (user_id, account_id)
);
-- Insert 3 users.
insert into users values (1), (2), (3);
-- User 1 has two accounts, user 2 has 3 accounts, user 3 has none.
insert into accounts values
(1, 100),
(1, 101),
(2, 102),
(2, 103),
(2, 104);
-- User 1 has 1 asset not assocated with an account.
insert into assets values (1, 200, null);
-- User 1 has 1 asset associated with account 101
insert into assets values (1, 201, 101);
-- User 1 tries to associate an asset with account 102, which doesn't belong to user 1.
insert into assets values (1, 202, 102);
[Fails with foreign key violation]
-- User 2 has two assets not associated with an account.
insert into assets values
(2, 500, null),
(2, 501, null);
I would suggest dropping the account_id foreign key completely from table Asset. Since account_id is related to your user table, you can join asset and user, and then perform a left join from user to account (if this is the table where account_id is the primary key). If you get a result from the left join, the asset is linked to an account and the user is the same. This way you force that constraint.
Hope this helps,
Regards
ElChe