neo4j 2.0 / cypher searching by date - date

I have looked at previous SO questions about using neo4j with dates and this blog post
http://blog.nigelsmall.com/2012/09/modelling-dates-in-neo4j.html
I'm not exactly sure how to get this to work however. Basically I need two things, to add a date to a node and then to query nodes by date.
As an example of something similar to what I like, imagine I have the movie The Matrix in my graph. Text examples for queries that should include then the movie The Matrix:
Movies released in Q1, 1999
Movies relased on March 31, 1999
Movies released in March 1999
Movies released before 2000
Movies released between 1998 and 20000
What I've tried for now as a start is building the date graph as described in the blog post. I tried with the following query, but I guess it's not constructed correctly
CREATE UNIQUE p = (CAL)-[:YEAR]->(1999 { number:1999 })-[:QUARTER]->(1 { number:1} )-[:MONTH]->(3 { number:3})-[:DAY]->(31 { number:31}) return p;
I guess then after I've made a node for a specific date, I would add a released_on->(that_date) to The Matrix.
So now I'm wondering if this is the way to go for the kind of queries I'd like to do, and how to actually make it work.

If those are the only queries you are planning to do, I would say that a property and an index query might be a better idea.
For each movie, you add a date property as a string in the following format : YYYYMMDD
You can then query for a specific date from a date_index, or have where conditions like : > 19990101 and <19990401 for the first quarter of 1999.
There are of course few shortcomings with this approach, one that comes to my mind being that you can't get movies by "seasonality", say for examples all summer movies for all the years ! In this, the in graph data index is a better idea.

I ended up putting the dates in the graph in a similar way to what is described in the blog post.
To add a date I use the following query:
MERGE (n0:Calendar) CREATE UNIQUE (n0)-[r0:YEAR]->(n1 {number: 2003})-[:QUARTER]->(q { number: 1} )-[r1:MONTH]->(n2 {number: 3})-[r2:DAY]->(n3 {number: 31}) RETURN n3;
Then I use queries similar to this to get nodes and their dates:
MATCH (r)-[:has_date]->(day)<-[:DAY]-(month)<-[:MONTH]-(quarter)<-[:QUARTER]-(year) return day,month,quarter,year;

Related

Can I get AuthorRetrieval data since a specific year?

I tried to use this format but it returns data from all the years:
AuthorRetrieval(author_id, refresh=True, kwds='PUBYEAR IS 2022 OR PUBYEAR IS 2021 OR PUBYEAR IS 2020 OR PUBYEAR IS 2019 OR PUBYEAR IS 2018')
To be more specific to my problem, I am trying to get the number of documents that have cited(cited by) excluding the self-cited documents of the past five years.
For the citations I used the parameters start, end(CitationOverview), but I cant find something for the number of cited-by.
That is unfortunately not possible. The Author Retrieval API returns only the current state - just as if you were looking at an Author profile on scopus.com.
The reason why your kwds parameter is ignored is because it's not a valid keyword. It's not made for a Scopus query string. See https://www.programiz.com/python-programming/args-and-kwargs for an overview of what the parameter does.
Your only option is to reconstruct author values from her publications. You can get them with the ScopusSearch() class.
I'd recommend to use a query like "AU-ID(123466)" and then extract the documents based on their publication year. This way it's much more likely that you can re-use the cached results.

Firestore creating a representation of a order form

I'm new at firebase/firestore. Appreciate your thoughts on this.
I'm trying to create an order form using Firestore.
I was wondering:
Do I need to create a YEAR, MONTH, DATE of collections and documents just to save all the order forms ?
This felt redundant to me, otherwise a lot of databases in Firestore will require a lot of collections and documents of dates!
E.g.:
(CAPS is Collection, bracketed are the documents)
YEAR (2018) -> MONTH (Jan, Feb, Mar, etc)
JAN -> 1 (order #1, order #2, order #3, etc)
JAN -> 2 (order #1, order #2, etc...)
Or just a simple time stamp on each document of order form - and then if I want to look up say for the month of January, is there a search query to look up all the documents in a specific month? or date?
And as order forms go, the user can enter as many items as possible. Is it correct to have each item stored as a new document? Therefore possibly creating 100+ documents per collection of order form.
E.g.:
order 1 collection - banana document, apple document, orange document
There is no single best data model. It all depends on the use-cases of your app. For a general introduction to this domain, I recommend reading NoSQL data modeling.
But in Firestore having a collection with many documents is not a concern. The database was made to scale to almost any number of documents.
You'll indeed want to store a timestamp in each order. The best way for this is like to use a server-side timestamp. You can then query for orders in a given date range with a query like this:
var now = new Date();
var yesterday = new Date(Date.now() - 24*60*60*1000);
ordersRef.where("timestamp", ">=", yesterday).where("timestamp", "<=", now)
Or
ordersRef.where("timestamp", ">=", "2017-01-01").where("timestamp", "<=", "2017-12-31")
For more examples, see the Firestore documentation on queries.

How to get only the first 6 months action of all my records

I'm pretty new in Tableau. I have looked at the forum already and the answered suggested. But I'm not quite sure it match my question.
I have a bunch of records. This is about registration for a sport lesson depending on time. All of them have a start date and and some of them a finish date. The other never finish (They continue until date T with T = now).
My goal is to compare only the first 6 months of all my records, I think there are 50 of them, like the evolution during this period of time. So, for some the start date would be in January 2009, for some other, it would be in May 2016, etc.
As field provided, I have the start date and the number of person that have subscribed those lesson through time.
So, do you if there is any to achieve this goal? Is there enough detail for you to understand what I am saying ?
Thx to you guys !!
EDIT
You can find enclosed a screenshot of the result that I already have.
number of registration for all lesson through time
I'm not sure to be clear, what I try to do is to compare the first 6 months only of each courses. So the evolution of the first 6 months of this course compare to the evolution of the first 6 months of this other course and so on :)
If I understand your question correctly you are wanting to show only the first six months of your data but you want this by each category.
I am assumuming that by definition this means 6 months from the first record in your data for each category.
In order to achieve this I would create a true/false flag using a level of detail expression. As you are new to tableau I would suggest you do some reading on this but basically you can force a calculation to be at a certain level of the data rather than at the row level. You use this to find the minimum date in the table and then use a date diff to return true if the actual date field is within 6 months of this.
Create a calculated field as follows:
[date] <= DATEADD('month', 6, { FIXED [category] :min([date])})
Then drag this onto your filters pane and select "TRUE". This should give you only the first six months of records for each category.
Let me know if you need anything else.

Storing dates as nodes in Neo4j

I'm new to Neo4j so maybe I'm just completely wrong on this, but I'll give it a try!
Our data is mostly composed by reservations, users and facilities stored as nodes.
I need both to count the total reservations that occurred in a specific time frame and the overall income (stored as reservation.income) in this timeframe.
I was thinking to overcome the problem by creating the date as a node, in this way I can assign a relationship [:PURCHASED_ON] to all the reservations that occurred on a specific date.
As far as I've understood, creating the date as a node could give me a few pros:
I could split the date from dd/mm/yyyy and store them as integer properties, in this way I could use mathematical operators such as > and <
I could create a label for the node representing each month as a word
It should be easier to sum() the income on a day or a month
Basicly, I was thinking about doing something like this
CREATE (d:Day {name:01/11/2016 day: TOINT(01), month: TOINT(11), year: TOINT(2016)}
I have seen that a possible solution could be to create a node for every year, every month (1-12) and every day (1-31), but I think that would just complicate terribly the architecture of my Graph since every reservation has an "insert_date" (the day it's created) and then the official "reservation_date" (the day it's due).
Am I onto something here or is it just a waste of time? Thanks!
You may want to look at the GraphAware TimeTree library, as date handling is a complex thing, and this seems to be the logical conclusion of the direction you're going. The TimeTree also has support for finding events attached to your time tree between date ranges, at which point you can perform further operations (counting, summing of income, etc).
There are many date/time functions in the APOC plugin that you should take a look at.
As an example, you can use apoc.date.fields (incorrectly called by the obsolete name apoc.date.fieldsFormatted in the APOC doc) to get the year, month, day to put in your node:
WITH '01/11/2016' AS d
WITH apoc.date.fields(d, 'MM/dd/yyyy') AS f
CREATE (d:Day {name: d, day: f.days, month: f.month, year: f.years});
NOTE: The properties in the returned map have names that are oddly plural. I have submitted an issue requesting that the names be made singluar.

MongoId perform day / month specific queries on the date

I am using MongoId 3,Rails 3.2 ,Ruby 1.9.3.
I wanted to query only part of a date, such as the day, week or month.
So for example, let's say we need to find all users that signed up on a Wednesday OR
get all users whose birthday is on 25 day Or get all users who born in April month(not specific to particular year here) etc..
In Mysql we have select * from users where extract(dow from created_at) = 3;
But how can we perform this using MongoId.
Here is a pretty handy cookbook on querying data ranges on Mongodb: http://cookbook.mongodb.org/patterns/date_range/ . and you can just create the query almost in the same way on Mongoid, using .where
I think the aggregation framework is a better fit for this. This question discusses the use of date operators in aggregation.
I've not had much experience with Mongoid, but it seems like it should support aggregation just fine, as long as you are using a recent version.