Some datetime filters on Wonderware Historian queries returns no data - wonderware

I'm querying to Wonderware Historian Database from SQL Server Management Studio and found that sometimes I don't get values, depending on the datetime filters I've set, even using Full retrieval mode.
I can get the values for the first ten days of October with this statement:
SELECT *
FROM Runtime.dbo.History
WHERE TagName = 'SFRL_JP\QInst'
AND wwRetrievalMode = 'Full'
AND wwQualityRule = 'Extended'
AND wwVersion = 'Latest'
AND DateTime >= '20191001 00:00:00'
AND DateTime <= '20191101 00:00:00';
But if I change de start date to October 2 (or any day after) the query only returns a tupla with value 0:
SELECT *
FROM Runtime.dbo.History
WHERE TagName = 'SFRL_JP\QInst'
AND wwRetrievalMode = 'Full'
AND wwQualityRule = 'Extended'
AND wwVersion = 'Latest'
AND DateTime >= '20191002 00:00:00'
AND DateTime <= '20191101 00:00:00';
Get same results using Historian Query and Historian Trends.
All returned data with the first statement seems to be good (QualityDetail = 192 and OPCQuality = 192).
I can't see what's wrong in the second query.

It looks like the latest.dat files get corrupted over a period of time, so I've tried to export the existing data for those dates in .csv file, and then upload this new set of CSV files specifying "Original Values" instead of "Update Values" and process them via FastLoad for that specific tag and check the values. Queries seems to be ok, but after a couple of days same error appears again.
Finally, solution comes from installing a patch on Historian: Wonderware Historian 11.6 SP1 P02 .

Related

Mule 4 - Set Start Date & End Date as QueryParams

I'm having trouble defining both start and end dates as a query parameters. When the data gets pulled, it needs to return as a range of dates based on the query parameters. The GET URL would look like http://localhost:8081/test?FileType=Sales&StartDate=2022-10-01&EndDate=2022-10-26. This should return a date range of data from 10/1/2022-10/26/2022.
In my query, my where clause is set to:
where dp.Nid = 405 and fs.DDate=:DDate
**dp and fs are used in my joins and 405 is an ID that i'll need to unique identify a product.
My input Parameters:
{ DDate : attributes.queryParams.StartDate, DDate : attributes.queryParams.EndDate }
What do i need to set to make a range of dates? Do i need to set startdate to > and enddate to < ? Also, is it possible to define query parameters when using a stored procedure instead of select database method in anypoint studio?
Operations in Mule 4 (ie the boxes inside a flow) can have several inputs (payload, variables, attributes) and 1 output, but they are expected to be independent from each other. The Database query operation doesn't care if its inputs come the query params or from somewhere else. You need to map inputs explicitly to parameters in the query.
Once you have the arguments you need to use them in the SQL query. Usually that means adding a greater than and a lesser than comparison, to ensure that the value is in range. Or the same including also equals, if the business logic requires it.
Depending on the data types and the SQL dialect you may need to convert the inputs to a date format that is compatible with the database type of the column. The inputs here are strings, because that's what query params always are parsed to. The column type is something that you will need to understand and see how to transform, in DataWeave or in the SQL query.
As an example:
<db:select config-ref="dbConfig">
<db:sql>SELECT ... WHERE dp.Nid = 405 AND fs.DDate >= :StartDate AND fs.DDate <= :StartDate</db:sql>
<db:input-parameters>
#[{
StartDate : attributes.queryParams.StartDate,
EndDate : attributes.queryParams.EndDate
}]
</db:input-parameters>
</db:select>

Using JIRA Query Language from Klipfolio To Query JIRA API For Number of Rejected Issues

I am trying to query the JIRA API from Klipfolio, to return all issues whos status = "rejected" in a given month, and the number of times each issue's status = "rejected".
Example queries I have run:
Give me the issue history for a given issue which contains rejected issues. But I don't know how to return the number of times the issue's status = "rejected" from this query:
https://upvate.atlassian.net/rest/api/2/project/UC?expand=changelog.
Give me the the number of issues whos status = "rejected" for a given project and sprint:
https://upvate.atlassian.net/rest/api/2/search?jql=project="UC" and sprint="21" and status="rejected"
But I need all issues whos status = "rejected" in a given month, and the number of times each issue's status = "rejected".
To determine which issues have been rejected, you will need to construct a JQL statement and insert that into the query. If you want to see the changelog for any issue that has been rejected, the query will look like this:
https://upvate.atlassian.net/rest/api/2/search?jql=project='UC' and status = 'rejected'&expand=changelog&maxResults=100
The expand=changelog will add a JSON array to each issue object with a revision history of each change made to that issue. In case you have more than the default 50 issues per call, you can use the maxResults parameter (maxResults=100) which will bring the number of issues up to the max per call set by JIRA of 100. If you have more than that you will need to use the startAt parameter to paginate through the pages of issues.
Like the above, you will need to create a JQL statement and insert it into the query url.
https://upvate.atlassian.net/rest/api/2/search?jql=project = 'UC' and sprint = '21' and status = 'rejected' and createdDate >= 2017-12-01 AND createdDate <= 2017-12-31&maxResults=100
This will successfully return data from project UC for sprint 21 that has been rejected and created within the month of December 2017. If you want to filter the data by a relative date range; for example, the previous month, you can utilize Klipfolio's date parameters. To have the above query always return data for the previous month's with the same conditions, the query will look like so:
https://upvate.atlassian.net/rest/api/2/search?jql=project = 'UC' and sprint = '21' and status = 'rejected' and createdDate >= {date.addMonths(-1).startOfMonth.format()} AND createdDate <= {date.addMonths(-1).endOfMonth.format()}&maxResults=100

ActiveRecord: milliseconds aren't taken into account when using a where clause

I'm working on a project with a rails api and an iOS client, using the updated_at field as the reference to detect modifications on the server that happened after the last pull from the client.
The updated_at datetime has a precision in milliseconds, meaning that
Model.updated_at.to_f
returns something like "1368977381.063427".
This is sent to the client formatted as "2013-05-19T15:29:41.063427000Z".
The trouble is, when I get that datetime back from the client, parse it and query with it, the milliseconds are lost.
last_update = DateTime.strptime("2013-05-19T15:29:41.063427000Z", "%Y-%m-%dT%H:%M:%S.%N%z")
Model.where("updated_at > ?", last_update)
is as good as doing
last_update = DateTime.strptime("2013-05-19T15:29:41Z", "%Y-%m-%dT%H:%M:%S%z")
Model.where("updated_at > ?", last_update)
As a result, I always get at least one result when I should get none, because the milliseconds are truncated.
How can I take those into account in my query ?
Try
Model.where("updated_at > ?", last_update.strftime("%Y-%m-%dT%H:%M:%S.%N%z"))
You can also set this format as the standard format for DateTime in databases by setting (i.e. in an initiallizer):
Time::DATE_FORMATS[:db]= '%Y-%m-%dT%H:%M:%S.%N%z'
then your original query works again:
Model.where("updated_at > ?", last_update)
See the Rails API for DateTime.to_s (aka .to_formated_s)
If you're using the ISO8601 standard you can use .iso8601(10). Don't know why but it rounds to seconds by default.

DateTime insertion and then selection: sequence contains no elements

My table structure in sql server is :
TableId int (Pk) identity
Data string
DateNTime DateTime
My method is::
public int insertData(string data){
Date= DateTime.Now;
Table table= new Table();
table.Data= data;
table.DateNTime=Date;
this.DataContext.Set<Table>().Add(table);
this.DataContext.SaveChanges();
return this.DataContext.Tables.Single(b => b.DateNTime == Date).TableId
}
The data insertion happens without any problems but in 9 out of 10 times while returning TableId I get the exception "sequence contains no elements"
Could it be that before the table row is saved the select command is fired and I get this error, if so what do I do?
Thanks
Arnab
SaveChanges() is a synchronous "blocking" operation, it doesn't return before the transaction that saves the date is committed. So, when you call the query the date is definitely saved in the database.
I think, it is a precision/rounding problem. If you look at the precision of a DateTime in .NET you'll see (for example in the TimeOfDay property):
TimeOfDay of .NET DateTime type: 10:32:51.0312500
So, the precision is 10E-7 seconds. A datetime in SQL Server has only 10E-3 seconds precision and the .NET DateTime is saved like this in the database:
Column value of SQL Server datetime type: 10:32:51.030
So, it is rounded to three digits. When you run the query the .NET DateTime is transmitted with high precision (as type datetime2(7) in SQL Server) ...
WHERE [Extent1].[MyDateTimeColumn] = #p__linq__0',
N'#p__linq__0 datetime2(7)', #p__linq__0='2012-05-18 10:32:51.0312500'
... and the equality comparison fails because
2012-05-18 10:32:51.0312500 != 2012-05-18 10:32:51.030
If you want a higher precision use a datetime2(7) as type in SQL Server that matches the .NET DateTime type. Or avoid such queries for equality and instead query for an interval of +/- 1 second or something around your DateTime value, like so:
var date1 = Date.AddSeconds(-1);
var date2 = Date.AddSeconds( 1);
return this.DataContext.Tables
.Single(b => b.DateNTime >= date1 && b.DateNTime <= date2)
.TableId;
(Not a good solution of course if you save faster than every 2nd second, Single might fail with "Sequence contains more than one element" exception.)

TFS Team Query: get all changed work items since a given time

Apparently it is impossible to provide the Changed Date field with a timestamp (format '2009-12-14 10:00:00') when defining a new Team Query. I get the error: "The query failed. You cannot supply a time with the date when running a query using date precision.".
Is there a workaround for this? I just want a list of work items which are changed since the last 'x' minutes.
The solution is to write your own WIQL query: http://teamfoundation.blogspot.com/2008/01/specifying-date-and-time-in-wiql.html.
You to enter the date in the same format as it is displayed by VSTS: dd-MMM-YY (01-Jan-16).
In order to filter your items in TFS by a specific date, stick to this format:
try adding query parameter timePrecision:true. This worked for me
I ran into the same problem while trying to query for the latest updates and worked around it by doing the following
// defined elsewhere
private DateTime lastUpdated;
string consult = "select * from WorkItem where [Created Date] > ' " + lastUpdated.ToString("MM/dd/yy") +
"' AND [Work Item Type] = 'Test Case'";
IEnumerable<ITestCase> tcc = testManagementTeamProject.TestCases.Query(consult).Where(tp => tp.DateCreated > lastUpdated);
I did something very similar for retrieving test results
The last parameter of this query constructor lets you define the precision:
dayPrecision
When TRUE, indicates that a DateTime should resolve to an entire day. Often, it is TRUE to avoid being more precise about a specific time.

Resources