Problems with temporal types like duration in of the wShortest aggregate function - memgraphdb

I have v2.0 of Memgraph, seems like temporal types like duration can't be part of the wShortest aggregate function.
Here is my code:
MATCH (n) DETACH DELETE n;
CREATE
(storage {name: "storage", current_time: localtime("T11:00")}),
(tape {name: "tape"}),
(lto {name: "lto"}),
(archive1 {name: "archive1", opens: localtime("T10:00"), closes: localtime("T11:00")}),
(archive2 {name: "archive2", opens: localtime("T08:00"), closes: localtime("T10:00")}),
(archive3 {name: "archive3", opens: localtime("T13:00"), closes: localtime("T16:00")}),
(archive4 {name: "archive4", opens: localtime("T15:00"), closes: localtime("T19:00")}),
(storage)-[:Fetch {duration: duration("3H")}]->(tape),
(storage)-[:Fetch {duration: duration("1H")}]->(lto),
(tape)-[:Drive {duration: duration("2H")}]->(archive1),
(tape)-[:Drive {duration: duration("4H")}]->(archive2),
(lto)-[:Ride {duration: duration("5H")}]->(archive3),
(lto)-[:Ride {duration: duration("4H")}]->(archive)
;
Here is wShortest query:
MATCH (a {name: "storage"})-[edge_list *wShortest 10 (e, n | e.duration) fetch_time]->(b)
RETURN *;
The error that I get is Error: Query failed: Calculated weight must be numeric, got duration.

This was a bug that was fixed with Memgraph 2.1.0 release. In the changelog it says: Allow duration values to be used as weights in the Weighted Shortest Path query.

Related

Sankey amcharts nodes are not being aligned well

So I'm working with amcharts v4 and Sankey diagram.
I'm trying a dataset that is quite simple but I have the node 500 and 652 on same level and causing some visual issues as in the picture below.
I've tryied to arrange differently the dataset but having same issue.
Anyone can help?
Is even possibile to reduce the links width in order to make it fit better? (tryied everything from SankeyLink but with no results)
[{from: '100', to: '200', value: 1},
{from: '200', to: '450', value: 1},
{from: '450', to: '652', value: 1},
{from: '450', to: '652', value: 1},
{from: '652', to: '500', value: 1},
{from: '652', to: '500', value: 1},
{from: '500', to: '650', value: 1},
{from: '500', to: '650', value: 1}]
enter image description here
So it seems to be a bug becouse all nodes have names that are all numbers.
Below the reply from amcharts responsable.
It seems to be a bug caused by all-number names. If I change the name of the last node to something that starts with a letter, the chart displays fine.

ionic 2 time wise sorting

how to short my list time wise ascending/ descending order
i have array like this:
this.array= [
{name: A, time: 10:00am},
{name: b, time: 10:05am},
{name: c, time: 10:02am},
{name: e, time: 09:00am}
]
i want to show this array time wise acceding order like:
this.array= [
{name: e, time: 09:00am},
{name: A, time: 10:00am},
{name: c, time: 10:02am},
{name: b, time: 10:05am},
]
The best way would be to use MomentJS:
array= [
{'name': 'A', 'time': '10:00am'},
{'name': 'b', 'time': '10:05am'},
{'name': 'c', 'time': '10:02am'},
{'name': 'e', 'time': '09:00am'}
]
sorted = array.sort(function(a, b) {
aT = new moment(a.time, 'HH:mm:ss a');
bT = new moment(b.time, 'HH:mm:ss a');
return aT.isBefore(bT) ? -1 : bT.isBefore(aT) ? 1 : 0;
});
To get MomentJS do:
npm install --save moment
then use it:
import * as moment from 'moment';
See https://momentjs.com/docs/#/use-it/typescript/.

How to use a SplayTreeMap on Firebase snapshot dictionary in dart/Flutter?

I'm successfully getting data back through StreamBuilder and need to sort it. How can I sort a Map of my snapshot data by keys? Also, If you give an example of doing this my value that would help also. I think I want to do a SplayTreeMap, but if there is a better way please provide. Here is my dictionary...
{Vid2: {imageString: https://i.ytimg.com/vi/Amq-qlqbjYA/mqdefault.jpg, title: BLACKPINK - '마지막처럼 (AS IF IT'S YOUR LAST)' M/V, rank: 2, videoID: Amq-qlqbjYA}, Vid10: {imageString: https://i.ytimg.com/vi/KSH-FVVtTf0/mqdefault.jpg, title: EXO 엑소 'Monster' MV, rank: 10, videoID: KSH-FVVtTf0}, Vid6: {imageString: https://i.ytimg.com/vi/BVwAVbKYYeM/mqdefault.jpg, title: [MV] BTS(방탄소년단) _ DOPE(쩔어), rank: 6, videoID: BVwAVbKYYeM}, Vid3: {imageString: https://i.ytimg.com/vi/m8MfJg68oCs/mqdefault.jpg, title: [MV] BTS(방탄소년단) _ Boy In Luv(상남자), rank: 3, videoID: m8MfJg68oCs}, Vid4: {imageString: https://i.ytimg.com/vi/9pdj4iJD08s/mqdefault.jpg, title: BLACKPINK - '불장난 (PLAYING WITH FIRE)' M/V, rank: 4, videoID: 9pdj4iJD08s}, Vid1: {imageString: https://i.ytimg.com/vi/3s1jaFDrp5M/mqdefault.jpg, title: EPIK HIGH - 'BORN HATER' M/V, rank: 1, videoID: 3s1jaFDrp5M}, Vid8: {imageString: https://i.ytimg.com/vi/3QAcvc4Ysl0/mqdefault.jpg, title: LONNI - LA KPOP 2, rank: 8, videoID: 3QAcvc4Ysl0}, Vid5: {imageString: https://i.ytimg.com/vi/2ips2mM7Zqw/default.jpg, title: BIGBANG - 뱅뱅뱅 (BANG BANG BANG) M/V, rank: 5, videoID: 2ips2mM7Zqw}}
I would like to display it either by keys...
Vid1, Vid2, Vid3...
or by values like rank ie...
Vid1:rank "1", Vid2: rank "2", Vid3: rank "3"...
If the source is a map, this should do what you want:
final sorted = new SplayTreeMap<String,dynamic>.from(map, (a, b) => a.compareTo(b));
DartPad example

ActiveRecord: Unique by attribute

I am trying to filter ActiveRecord_AssociationRelations to be unique by parent id.
So, I'd like a list like this:
[#<Message id: 25, posted_by_id: 3, posted_at: "2014-10-30 06:02:47", parent_id: 20, content: "This is a comment", created_at: "2014-10-30 06:02:47", updated_at: "2014-10-30 06:02:47">,
#<Message id: 23, posted_by_id: 3, posted_at: "2014-10-28 16:11:02", parent_id: 20, content: "This is another comment", created_at: "2014-10-28 16:11:02", updated_at: "2014-10-28 16:11:02">]}
to return this:
[#<Message id: 25, posted_by_id: 3, posted_at: "2014-10-30 06:02:47", parent_id: 20, content: "This is a comment", created_at: "2014-10-30 06:02:47", updated_at: "2014-10-30 06:02:47">]
I've tried various techniques including:
#messages.uniq(&:parent_id) # returns the same list (with duplicate parent_ids)
#messages.select(:parent_id).distinct # returns [#<Message id: nil, parent_id: 20>]
and uniq_by has been removed from Rails 4.1.
Have you tried
group(:parent_id)
It sounds to me like that is what you are after. This does return the first entry with the given parent_id. If you want the last entry you will have to reorder the result in a subquery and then use the group.
For me in Rails 3.2 & Postgresql, Foo.group(:bar) works on simple queries but gives me an error if I have any where clauses on there, for instance
irb> Message.where(receiver_id: 434).group(:sender_id)
=> PG::GroupingError: ERROR: column "messages.id" must appear in the
GROUP BY clause or be used in an aggregate function
I ended up specifying an SQL 'DISTINCT ON' clause to select. In a Message class I have the following scope:
scope :latest_from_each_sender, -> { order("sender_id ASC, created_at DESC").select('DISTINCT ON ("sender_id") *') }
Usage:
irb> Message.where(receiver_id: 434).latest_from_each_sender

Get Unique contents from Ruby Hash

I have a Hash #estate:
[#<Estate id: 1, Name: "Thane ", Address: "Thane St.", created_at: "2013-06-21 16:40:50", updated_at: "2013-06-21 16:40:50", user_id: 2, asset_file_name: "DSC02358.JPG", asset_content_type: "image/jpeg", asset_file_size: 5520613, asset_updated_at: "2013-06-21 16:40:49", Mgmt: "abc">,
#<Estate id: 2, Name: "Mumbai", Address: "Mumbai St.", created_at: "2013-06-21 19:13:59", updated_at: "2013-06-21 19:14:28", user_id: 2, asset_file_name: "DSC02359.JPG", asset_content_type: "image/jpeg", asset_file_size: 5085580, asset_updated_at: "2013-06-21 19:13:57", Mgmt: "abc">]
Is it possible to make new Hash with unique values according to the user_id: 2, because currently 2 elements have the user_id same i.e 2, I just want it once in the hash, what should I do ?
It seems to be something like a has_many relation between User model and Estate model, right? If I understood you correctly, than you need in fact to group your Estate by user_id:
PostgreSQL:
Estate.select('DISTINCT ON (user_id) *').all
MySQL:
Estate.group(:user_id).all
P.S. I'd not recommend to select all records from a database and then process them with Ruby as databases handle operations with data in much more efficient way.
Here is an sample example to get you a good start:
h = [ { a: 2, b: 3}, { a: 2, c: 3 } ]
h.uniq { |i| i[:a] }
# => [{:a=>2, :b=>3}]

Resources