owl datetime restriction creater than - datetime

I have a class and i make it equivelent to this restriction
Rates and createdOn value "2016-01-01T09:00:00+00:00"^^dateTime
where Rates is a class and createdOn is a data type property has domain as a date time
what i did is not what i want to do because i want to say something like:
all the dates that are greater than 2016 january first
i though that could be done by two ways but i don't know if owl support any of them
first i thought :
Rates and createdOn value > "2016-01-01T09:00:00+00:00"^^dateTime
but protege told me that we can't put >
then i though that if there is a way to just check the year of the date, but also i don't know how to do that
could you help please ?

You need to use a DatatypeRestriction:
Declaration(Class(example:Rates))
Declaration(DataProperty(example:createdOn))
Declaration(Datatype(xsd:dateTime))
DataPropertyRange(example:createdOn DatatypeRestriction(xsd:dateTime xsd:minInclusive "2016-01-01T00:00:00"^^xsd:dateTime))
SubClassOf(DataSomeValuesFrom(example:createdOn rdfs:Literal) example:Rates)
Edit: In Manchester syntax, these facets are written like this:
Class: <http://example.org#Rates>
SubClassOf:
<http://example.org#createdOn> some xsd:dateTime[>= "2016-01-01T00:00:00"^^xsd:dateTime]

Related

USQL reading last n days when file name pattern does not have day part

In data lake I have file names with pattern yyyyMM_data.csv. Now I want to read previous 3 days data. I am using below code -
DECLARE #ReportDate DateTime= DateTime.Parse("05/08/2017");
DECLARE #FeatureSummaryInput string=#"/FolderPath/{InputFileDate:yyyy}{InputFileDate:MM}_data.csv";
#FeaturedUsed =
EXTRACT Id string,InputFileDate DateTime
FROM #FeatureSummaryInput
USING Extractors.Csv(silent : true, skipFirstNRows : 1);
#FeaturedUsed=
SELECT *
FROM #FeaturedUsed
WHERE InputFileDate BETWEEN #ReportDate.AddDays(-3) AND #ReportDate;
If I run above code it runs with empty input. Please let me know if I am missing something. Why it is not reading correct file?
It seems like we need to must have "day" in file name pattern to work this.
Possibly I am missing something but, as you cast InputFileDate to DateTime it defaults to the first of the month, as no day is specified. For your test ReportDate set to 05/08/2017, your WHERE clause basically evaluates to Between 2017-08-02 And 2017-08-05, which will never be true.
Where do you expect the day element to come in with your files structured as yyyyMM?

MDX Compare DateTime attribute

I´m new to MDX and I have a simple question. I work with the TFS Cube it is named as Team System. My problem:
I have an IIF expression where I want to check additional my expression with an AND operator. There I want to compare two DateTime objects. The report should only show me the data from the actual date. Here my code:
IIF(ISEMPTY(SUM(YTD(
[Work Item].[PlannedWeek__HierarchyByWeek].CurrentMember),
[Measures].[EffectivelyValue]))
AND[Work Item].[PlannedWeek__HierarchyByWeek].CurrentMember < Now()
, [Measures].[EffectivelyValue]
, SUM(YTD(
[Work Item].[PlannedWeek__HierarchyByWeek].CurrentMember),
[Measures].[EffectivelyValue]) )
Planned Week is a self created field which has the DateTime datatype. The Now() function has also a DateTime datatype so the comparision should be right but it happens nothing.
Thanking you in anticipation
Eugen
Hierarchy members in MDX have a data type of 'member', and do not have a 'primitive' data type like datetime, string, or integer. Only member properties have 'primitive' data types. You could either define a property like datetime of your week attribute. Assuming you are SQL Server Analysis Services, this would be done via relationships.
Or you could use string operations to extract the date information from the UniqueName property which avoids having to change the cube. The UniqueName contains the data that you defined as the key in your cube design. Assuming your week hierarchy members have a key from which you can extract something like 20130820 for August 20, 3013 via string functions (I just will use Mid(, 30, 8) as an example below), you could do something like
CLng(Mid([Work Item].[PlannedWeek__HierarchyByWeek].CurrentMember.UniqueName, 30, 8))
<
CLng(Format(Now(), "yyyymmdd"))
You will have to check what exactly the CurrentMember.UniqueName shows in your cube to adapt the above code.
And finally, you could of course also use string methods to extract the relevant parts from the UniqueName and then the CDate function on that to compare to an unchanged Now(), i. e. do all operations on the left side of the <.
Hello thank you very much for you answer. I tried:
Mid([Work Item].[xxxx_PlannedWeek__HierarchyByWeek].CurrentMember.UniqueName,58,10)
shows e.g. 2013-07-21, 2013-07-28 (it shows the week endings)
so I tried this:
AND CLng(Mid([Work Item].[xxxx_PlannedWeek__HierarchyByWeek].CurrentMember.UniqueName,58,10))
<CLng(Format(Now(), "yyyy-mm-dd"))
But it happens nothing. If I execute it in a single way it shows everywhere "true". But I have datasets with dates which are e.g. > 2013-08-23. So there should be false values too.
EDIT: OK I solved the problem. The
Format(Now(), "yyyy-mm-dd")
must be
Format(Now(), "yyyy-MM-dd")

SELECT clause with a DATETIME column in Sybase 15

I'm trying to do a query like this on a table with a DATETIME column.
SELECT * FROM table WHERE the_date =
2011-03-06T15:53:34.890-05:00
I have the following as an string input from an external source:
2011-03-06T15:53:34.890-05:00
I need to perform a query on my database table and extract the row which contains this same date. In my database it gets stored as a DATETIME and looks like the following:
2011-03-06 15:53:34.89
I can probably manipulate the outside input slightly ( like strip off the -5:00 ). But I can't figure out how to do a simple select with the datetime column.
I found the convert function, and style 123 seems to match my needs but I can't get it to work. Here is the link to reference about style 123
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.blocks/html/blocks/blocks125.htm
I think that convert's slightly wrongly documented in that version of the docs.
Because this format always has century I think you only need use 23. Normally the 100 range for convert adds the century to the year format.
That format only goes down to seconds what's more.
If you want more you'll need to past together 2 x converts. That is, past a ymd part onto a convert(varchar, datetime-column, 14) and compare with your trimmed string. milliseconds comparison is likely to be a problem depending on where you got your big time string though because the Sybase binary stored form has a granularity of 300ms I think, so if your source string is from somewhere else it's not likely to compare. In other words - strip the milliseconds and compare as strings.
So maybe:
SELECT * FROM table WHERE convert(varchar,the_date,23) =
'2011-03-06T15:53:34'
But the convert on the column would prevent the use of an index, if that's a problem.
If you compare as datetimes then the convert is on the rhs - but you have to know what your milliseconds are in the_date. Then an index can be used.

Dynamically create categories for SQLite pivot/crosstab

I realise it is possible to create a crosstab within sqlite, but is it possible to dynamically determine the relevant categories/columns at runtime rather than hardcoding them?
Given the following example, it can get rather tedious ...
SELECT
shop_id,
sum(CASE WHEN product = 'Fiesta' THEN units END) as Fiesta,
sum(CASE WHEN product = 'Focus' THEN units END) as Focus,
sum(CASE WHEN product = 'Puma' THEN units END) as Puma,
sum(units) AS total
FROM sales
GROUP BY shop_id
I managed to do this in SQLServer in a stored proceedure before and wondered if there was anything equivalent.
No, you can't do that in SQLite, since analytic means in SQLite lack many usefull features available in heavier RDBMSes. Here is the corresponding ticket, but it is in the pending status.
Old question, but anyway: I faked something like this in Ruby on Rails. For my purposes it works well.
def self.yearstats(attr)
# Determine number of columns
minyear = self.select("strftime('%Y', min(recorded_at)) AS minyear").first.minyear.to_i
maxyear = self.select("strftime('%Y', max(recorded_at)) AS maxyear").first.maxyear.to_i
# Stitch SQL query. Use explicit same column name to not confuse Rails' typecasting.
select_str = ["strftime('#{minyear}/%m/%d %H:%m', recorded_at) AS recorded_at"]
(minyear..maxyear).to_a.each do |y|
# avg because the table might have multiple rows per day
select_str += ["avg(case when strftime('%Y', recorded_at)='#{y}' then #{attr} end) AS value#{y}"]
end
self.select(select_str.join(",")).group("strftime('%m/%d', recorded_at)").all.collect {|row|
[row.recorded_at.utc.to_i*1000] + (minyear..maxyear).to_a.collect { |y| row.send("value#{y}") }
}
end
Note that for the first column I used a (fake) date using a fixed first year so that my graphing routines get a "real" date, not just day/month display. This is a little dirty but it works for my purposes. (Improvements still welcome...)
Instead of getting minyear and maxyear, you might want to do a SELECT DISTINCT.. to get the unique list of categories and modify the code appropriately.

Comparing dates in Lingo

How do I compare two dates in Lingo? To be specific, I want to know if today's date is after some fixed date. I know I can create the fixed date by using:
date("20090101")
and I can get the current date using:
_system.date()
but I can't seem to directly compare the two. Do I have to parse the _system.date() to determine if it's after my fixed date? I tried:
if(_system.date() > date("20090101") then
--do something
end if
but that doesn't seem to work. Any ideas?
Instead of _system.date(), try _movie.systemDate(), it will return a date object that you can safely compare with another one.
if _movie.systemDate() > date("20090101") then
--do something
end if
regards
I ended up doing the following. Inelegant, but it works:
if (_system.date().char[1..2] >= 01 and _system.date().char[4..5] >= 01 and _system.date().char[7..10] >= 2010) then
alert("Your license has expired. Please contact the Company to renew your license.")
_player.quit()
end if
It does the trick, but I would still be interested in alternative methods of doing this.

Resources