Can Fortran convert "time interval + reference date" into "date" conveniently? - fortran

In other languages, there usually occurs a function to calculate the date using the reference date and time interval. For example, in R, if the reference date is 2019/09/01, and the time interval is 2 days, then the calculated date is 2019/09/03. We can use the following date conversion function:
as.Date(2, origin = "2019-09-01")
# [1] "2019-09-03"
I was wondering if Fortran has the similar functions or packages?

The Fortran standard only provides the current date and time up to milliseconds.
call date_and_time ( [ date ] [ , time ] [ , zone ] [ , values ] )
returns the following (with default values blank or -huge(0), as appropriate, when there is no clock).
date is a scalar character variable of length 8 or more. Its first 8 characters are set to the century, year, month, and day in the form ccyymmdd.
time is a scalar character variable of length 10 or more. Its first 10 characters
are set to the time as hours, minutes, seconds, and milliseconds in the form hhmmss.sss.
zone is a scalar character variable of length 5 or more. Its first 5 characters are
set to the difference between local time and UTC (also known as Greenwich Mean Time) in the form Shhmm, corresponding to sign, hours, and minutes. For example, a processor in New York in winter would return the value -0500.
values is a rank-one default integer array of size at least 8 holding the sequence of
values: the year, the month of the year, the day of the month, the **time difference in minutes with respect to UTC, the hour of the day, the minutes of the hour, the seconds of the minute, and the milliseconds of the second.
If you need anything beyond this, you will have to currently write your own functions or, as mentioned in the comments, use one of the existing ones. Among the most prominent that I know of, there is the open-srouce library datetime-fortran here.

Related

Power BI by item Slice date calculate percent complete period

It is necessary to calculate the percentage of the completion of the period by the Slice of the date, i.e. 100% is from 01 to 31 days, 97% is from 01 to 30 days, etc. or 1 day is 3%.
The % period formula looks something like this ((current day - 1 day)*100)/period
Tried to describe it like this
Period = CALCULATE((TODAY()-1)*100)/sum(GKB[stat_date])
But the output is 0.11...
Since there are no separate columns Start date and End date, but only a slice element with a slider, I don’t understand how to implement this and why to start.
enter image description here

Power BI measurement between fixed Date and calculated Date

I'm interested in creating a report comparing a before and after of two equivalent time periods.
The after period is looking at the days from a fixed date (1/10/20) to the most recent case in the tbl_Data table (in this case it is 92 days).
The before period would subtract the calculated 92 days from the fixed date (1/10/20).
I was able to get the days between part fairly easily using the following:
Days_Between =
calculate(
countrows(date_table),
DATESBETWEEN(
date_table[Date_field].[Date],
date(2020,10,01),
MAX(tbl_Data[Date Received])
)
)
However I'm at odds on how to subtract this from the fixed date to get a date range I can filter on easily. Any pointers/ideas would be greatly appreciated.
Cheers
First, I would simplify your days calculation: Days_Between = DATEDIFF(date(2020,10,01), MAX(tbl_Data[Date Received]), DAY ). Then, I would simply subtract the result from the given date. Start date = Date(2020, 10, 1) - [Days_Between]

how can i use wso2 siddhiQL Cache data?

My question is like this, I define a data source access to real-time data per second (has), I will for this batch of data per hour for an average calculation, and then to have this group of data per hour average accumulative sum, finally put the cumulative value of an hour, to another data source.Such as the mean value is 10 1 hour, I will give 10 to a data source, the second hour average is 20, then I will add 1 hour on average 10 output 30, so on, to the end of the 24 hours a day, the second day in from the first hour is calculated.Problem now is how can I, cache the last time I calculate the cumulative values, how to solve the similar problem?
eg: enter image description here
Just like the picture above, in the column of the avg data is I through instream_ # window.externalTimeBatch (datetime, 1 hour) can get, at the back of the column is the result of the output per hour, I think.
like this:enter image description here
Every compute a result is output
You can use Event Table to cache the data in relation database like postgres/mysql/oracle.
Fist define table from database :
#From(eventtable='rdbms', datasource.name='db_event', table.name='_tag_time_value')
define table tEvent (tag string, datetime long , value double);
and if the stream time reach , you can insert overwrite 0.0 into the event table

how to get the next day date in informaitca

I have a date field coming form source paid_date and i want it to convert as
trunc(next_day(sysdate-1,'MON')).. I need to get the NEXT_DAY here and the filed data type is date-time.
Please share your inputs.
Unfortunately, as of now, there is no NEXT_DAY equivalent in Informatica. So you have to calculate it like this in expression.
TRUNC(
ADD_TO_DATE(
SYSDATE,
'DD',
(9 - TO_FLOAT(TO_CHAR(SYSDATE,'D')))%7
)
)
Explanation:
(9 - TO_FLOAT(TO_CHAR(SYSDATE,'D')))%7 - Calculates the number of days till next Monday.
ADD_TO_DATE(SYSDATE,'DD',...) - Adds the above no. of days to the input date
In this case you can use Add_To_Date function. Using this function you can get your exact date or month or year.
Formats of defining date,
Date – DD, DDD, DY and DAY
Month – MM, MON and MONTH
Year – YY, YYY and YYYY
Hour – HH, HH12 and HH24
Minute – MI
Seconds - SS
Syntax : ADD_TO_DATE (date_column, format, value)
Example: ADD_TO_DATE (Date, ‘DD’, 10)
Result:
10/01/2016 - 20/01/2016
As the format is provided as ‘DD’ and value as 10, the dates are displayed by increasing 10 days. This logics stands for date, month, year, minute, hour or seconds whatever defined in the syntax. To decrease the date value just add negative number (-10).
For you to get next day, just define
ADD_TO_DATE (Your column, ‘DD’, 1).
For more details on informatica just visit my blog,
http://etlinfromatica.wordpress.com/

Filter data to get only first day of the month rows

I have a dataset of daily data. I need to get only the data of the first day of each month in the data set (The data is from 1972 to 2013). So for example I would need Index 20, Date 2013-12-02 value of 0.1555 to be extracted.
The problem I have is that the first day for each month is different, so I cannot use a step such as relativedelta(months=1), how would I go about of extracting these values from my dataset?
Is there a similar command as I have found in another post for R?
R - XTS: Get the first dates and values for each month from a daily time series with missing rows
17 2013-12-05 0.1621
18 2013-12-04 0.1698
19 2013-12-03 0.1516
20 2013-12-02 0.1555
21 2013-11-29 0.1480
22 2013-11-27 0.1487
23 2013-11-26 0.1648
I would groupby the month and then get the zeroth (nth) row of each group.
First set as index (I think this is necessary):
In [11]: df1 = df.set_index('date')
In [12]: df1
Out[12]:
n val
date
2013-12-05 17 0.1621
2013-12-04 18 0.1698
2013-12-03 19 0.1516
2013-12-02 20 0.1555
2013-11-29 21 0.1480
2013-11-27 22 0.1487
2013-11-26 23 0.1648
Next sort, so that the first element is the first date of that month (Note: this doesn't appear to be necessary for nth, but I think that's actually a bug!):
In [13]: df1.sort_index(inplace=True)
In [14]: df1.groupby(pd.TimeGrouper('M')).nth(0)
Out[14]:
n val
date
2013-11-26 23 0.1648
2013-12-02 20 0.1555
another option is to resample and take the first entry:
In [15]: df1.resample('M', 'first')
Out[15]:
n val
date
2013-11-30 23 0.1648
2013-12-31 20 0.1555
Thinking about this, you can do this much simpler by extracting the month and then grouping by that:
In [21]: pd.DatetimeIndex(df.date).to_period('M')
Out[21]:
<class 'pandas.tseries.period.PeriodIndex'>
[2013-12, ..., 2013-11]
Length: 7, Freq: M
In [22]: df.groupby(pd.DatetimeIndex(df.date).to_period('M')).nth(0)
Out[22]:
n date val
0 17 2013-12-05 0.1621
4 21 2013-11-29 0.1480
This time the sortedness of df.date is (correctly) relevant, if you know it's in descending date order you can use nth(-1):
In [23]: df.groupby(pd.DatetimeIndex(df.date).to_period('M')).nth(-1)
Out[23]:
n date val
3 20 2013-12-02 0.1555
6 23 2013-11-26 0.1648
If this isn't guaranteed then sort by the date column first: df.sort('date').
One way is to add a column for the year, month and day:
df['year'] = df.SomeDatetimeColumn.map(lambda x: x.year)
df['month'] = df.SomeDatetimeColumn.map(lambda x: x.month)
df['day'] = df.SomeDatetimeColumn.map(lambda x: x.day)
Then group by the year and month, order by day, and take only the first entry (which will be the minimum day entry).
df.groupby(
['year', 'month']
).apply(lambda x: x.sort('day', ascending=True)).head(1)
The use of the lambda expressions makes this less than ideal for large data sets. You may not wish to grow the size of the data by keeping separately stored year, month, and day values. However, for these kinds of ad hoc date alignment problems, sooner or later having these values separated is very helpful.
Another approach is to group directly by a function of the datetime column:
dfrm.groupby(
by=dfrm.dt.map(lambda x: (x.year, x.month))
).apply(lambda x: x.sort('dt', ascending=True).head(1))
Normally these problems arise because of a dysfunctional database or data storage schema that exists one level prior to the Python/pandas layer.
For example, in this situation, it should be commonplace to rely on the existence of a calendar database table or a calendar data set which contains (or makes it easy to query for) the earliest active date in a month relative to the given data set (such as, the first trading day, the first week day, the first business day, the first holiday, or whatever).
If a companion database table exists with this data, it should be easy to combine it with the dataset you already have loaded (say, by joining on the date column you already have) and then it's just a matter of applying a logical filter on the calendar data columns.
This becomes especially important once you need to use date lags: for example, lining up a company's 1-month-ago market capitalization with the company's current-month stock return, to calculate a total return realized over that 1-month period.
This can be done by lagging the columns in pandas with shift, or trying to do a complicated self-join that is likely very bug prone and creates the problem of perpetuating the particular date convention to every place downstream that uses data from that code.
Much better to simply demand (or do it yourself) that the data must have properly normalized date features in its raw format (database, flat files, whatever) and to stop what you are doing, fix that date problem first, and only then get back to carrying out some analysis with the date data.
import pandas as pd
dates = pd.date_range('2014-02-05', '2014-03-15', freq='D')
df = pd.DataFrame({'vals': range(len(dates))}, index=dates)
g = df.groupby(lambda x: x.strftime('%Y-%m'), axis=0)
g.apply(lambda x: x.index.min())
#Or depending on whether you want the index or the vals
g.apply(lambda x: x.ix[x.index.min()])
The above didn't work for me because I needed more than one row per month where the number of rows every month could change. This is what I did:
dates_month = pd.bdate_range(df['date'].min(), df['date'].max(), freq='1M')
df_mth = df[df['date'].isin(dates_month)]