Would really appreciate help in determining how I can calculate the time passed of a Tandem (Nonstop) process since its creation.
For example:
- I can get the Process creation time when I do a STATUS $proc, DETAIL and I get the textual time in "Process Creation Time"
- I want to accurately calculate how much time since the process was create
My initial thought is to get the current time by #TIMESTAMP (or #JULIANTIMESTAMP), then converting the textual Process Creation time to one of the above three- or four-word format, then subctract to find the difference. Afterward, I will then convert that difference back to textual to get the actual time.
I'm having a challenge in getting this to accurately compute ...
Appreciate any guidance!
Thanks!
I think that you have the right idea, there doesn't seems to be a neat way (in TACL) to get the process creation time, so you have to process the status command output. That doesn't take a variable as an OUTV parameter, so you can use a file, and do some processing in there, rather than in TACL.
I converted both timestamps to the space-separated list that #CONTIME gives, then converted those to Julian timestamps (see below).
This is probably much easier to do in (say) C, where you can call PROCESS_GETINFOLIST_ to get the creation timestamp directly. It may even be easier to do in an OSS shell, given teh better handling for timestamps in there.
?TACL ROUTINE
#FRAME
#PUSH tempfile
#SET tempfile XXTEMPXX
[#DEF MakeTimeList ROUTINE |BODY|
#FRAME
#PUSH month day year time hour min sec centi milli
SINK [#ARGUMENT/VALUE month/WORD]
SINK [#ARGUMENT/VALUE day/WORD]
SINK [#ARGUMENT COMMA]
SINK [#ARGUMENT/VALUE year/NUMBER]
SINK [#ARGUMENT/VALUE hour/NUMBER]
SINK [#ARGUMENT/VALUE min/NUMBER]
SINK [#ARGUMENT/VALUE sec/NUMBER]
SINK [#ARGUMENT/VALUE centi/NUMBER]
[#CASE [month]
|January| #SET month 1
|February| #SET month 2
|March| #SET month 3
|April| #SET month 4
|May| #SET month 5
|June| #SET month 6
|July| #SET month 7
|August| #SET month 8
|September| #SET month 9
|October| #SET month 10
|November| #SET month 11
|December| #SET month 12
]
#SET milli [#CHARGET centi 4 TO 6]
#SET centi [#CHARGET centi 1 TO 3]
#RESULT [year] [month] [day] [hour] [min] [sec] [centi] [milli]
#UNFRAME
]
#PUSH start now lines line pos process
SINK [#ARGUMENT/VALUE process/ PROCESSNAME]
[#IF NOT [#PROCESSEXISTS [process]] |THEN|
#OUTPUT [process] does not exist
]
status/out [tempfile]/[process],detail
edit [tempfile];cqab/:/ /a;cqab/./ /a;exit
filetovar [tempfile] lines
SINK [#PURGE [tempfile]]
#SET pos [#LINEFIND lines 1 Process Creation Time]
[#IF pos > 1 |THEN|
#SET line [#LINEGET lines [pos]]
#SET start [#CHARGET line 23 TO [#CHARCOUNT line]]
#SET start [MakeTimeList [start]]
#SETMANY start, [#COMPUTETIMESTAMP [start] ]
#SETMANY now, [#COMPUTETIMESTAMP [#CONTIME [#TIMESTAMP]] 0]
#OUTPUT [#COMPUTE ([now] - [start])/1000000] seconds have elapsed
]
#UNFRAME
TACL has really good process time builtin functions, try this:
?tacl routine
#frame
[#push
inProcess processCreateTime timeRightNow
timeDifference aMicroSecond aMilliSecond
pctY pctM pctD pctH pctMI pctS pctMIL pctMIC
trnY trnM trnD trnH trnMI trnS trnMIL trnMIC
]
#setmany aMicroSecond aMilliSecond , 1000000 1000
#if [#argument/value inProcess/processid]
#set processCreateTime [#processinfo/processcreationtime/[inProcess]]
[#setmany _ pctY pctM pctD pctH pctMI pctS pctMIL pctMIC , [#interprettimestamp [processCreateTime]]]
#set timeRightNow [#juliantimestamp]
[#setmany _ trnY trnM trnD trnH trnMI trnS trnMIL trnMIC , [#interprettimestamp [timeRightNow]]]
#output Process [#shiftstring [inProcess]] create vs now times
#set timeDifference [#compute [timeRightNow] - [processCreateTime]]
#output Created: [pctY]-[pctM]-[pctD] [pctH]:[pctMI]:[pctS]
#output Time Now: [trnY]-[trnM]-[trnD] [trnH]:[trnMI]:[trnS]
#output Differences:
#output in micros: [timeDifference]
#output in mills: [#compute [timeDifference] / [aMilliSecond]]
#output in seconds: [#compute [timeDifference] / [aMicroSecond]]
#unframe
Related
"[it just needs to be done using numpy and pandas.]"
Your task:
You are asked to write a function that applies ”slack time remaining” (STR) sequencing rule to a given collection of jobs. Although this rule has not been covered in class, application is very similar to critical ratio. You need to calculate STR value for all jobs and schedule the one with the lowest STR. Continue this until all jobs are scheduled. The STR values are calculated as follows:
STR = [Time Until Due Date] − [Processing Time]
If you have more than 1 job with the lowest STR, break ties with Earliest Due Date
(EDD) rule. If due dates are also the same, schedule the one arrived earlier (that means the one in the upper rows of the table.)
Your function will accept a single parameter as pandas dataframe:
Function Parameter:
df jobs: A pandas dataframe whose indexes are the names of the jobs. Jobs
are assumed to be arrived in the same day in the same order given in the dataframe. There
will be two data columns in the dataframe:
ˆ ”Processing Time”: Processing time required for the job
ˆ ”Due Date”: Time between arrival of the job and the due date of the job.
Output: Your function should return a list containing the correct sequence according to STR rule.
Example inputs and expected outputs:
Example Input Data:
Job Processing Time Due Date
A 2 7
B 8 16
C 4 4
D 10 17
E 5 15
F 12 18
Expected Output: [’C’, ’A’, ’F’, ’D’, ’B’, ’E’]
Assuming your input is a DataFrame - your function would be:
def str_list(df):
df = df.set_index('Job')
return (df['Due Date'] - df['Processing Time']).sort_values().index.tolist()
I have a pandas dataframe with an unusual DatetimeIndex. The frame contains daily data (end of each day) from 1985 to 1990 but some "random" days are missing:
DatetimeIndex(['1985-01-02', '1985-01-03', '1985-01-04', '1985-01-07',
'1985-01-08', '1985-01-09', '1985-01-10', '1985-01-11',
'1985-01-14', '1985-01-15',
...
'1990-12-17', '1990-12-18', '1990-12-19', '1990-12-20',
'1990-12-21', '1990-12-24', '1990-12-26', '1990-12-27',
'1990-12-28', '1990-12-31'],
dtype='datetime64[ns]', name='date', length=1516, freq=None)
I often need operations like shifting an entire column such that a value that is at the last day of a month (which could e.g. in my DatetimeIndex be '1985-05-30') is shifted to the last day of the next (which could e.g. my DatetimeIndex be '1985-06-27').
While looking for a smart way to perform such shifts, I stumbled over Offset Aliases provided by pandas.tseries.offsets. It can be observed that there are the aliases custom business day frequency (C) and custom business month end frequency (CBM). When looking at an example, it seems like that this could provide exactly what I need:
mth_us = pd.offsets.CustomBusinessMonthEnd(calendar=USFederalHolidayCalendar())
day_us = pd.offsets.CustomBusinessDay(calendar=USFederalHolidayCalendar())
df['Col1_shifted'] = df['Col1'].shift(periods=1, freq = mth_us) # shifted by 1 month
df['Col2_shifted'] = df['Col2'].shift(periods=1, freq = day_us) # shifted by 1 day
The problem is that my DatetimeIndex is not equal to USFederalHolidayCalendar(). Can someone please tell me how I can use pd.offsets.CustomBusinessMonthEnd (and also pd.offsets.CustomBusinessDay) with my own custom DatetimeIndex?
If not, has any of you an idea how to tackle this issue in a different way?
Thanks a lot for your help!
I need to write a function below that can compute the moving average of time series using a sliding window over an array. This function should take an array of date strings (say arr_date), an array of numbers (say arr_record), and a sliding window (default value 50). It should:
Return a list of dictionaries for all windows.
Each dictionary should include the date, average value, min, max, standard deviation at each window.
Able to handle missing data in time series by replacing missing data with the most recent available data.
(b) Download SPY daily data (Dec. 31, 2017 to Dec. 31, 2018) from Yahoo! as your test data in a .csv file. Read reading .csv file example and write a test programming for calling your function.
Does anyone have any thoughts? Extremely new to python and struggling.
So something following this logic should probably be a good starting point. Hope this is a helpful start, and welcome to the cs community.
def sliding_window( dates, numbers, sliding_window_value):
# list of dictionaries
return_dicts =[{}]
# if window size is greater than length of dates, there's only one window
if sliding_window_value >= len(dates):
return_dicts += [create_window(dates, numbers)]
return return_dicts
# gather all our windows into one list
for i in range (0, len(dates) - sliding_window_value ):
# get our window subsets
dates_subset = dates[i:(sliding_window_value+1)]
numbers_subset = numbers[i:(sliding_window_value+1)]
# get our window stats dictionary
window_stats = create_window(dates_subset,numbers_subset)
# add these stats to our return list
return_dicts += [window_stats]
return return_dicts
def create_window(dates_subset, numbers_subset):
window_min = 1000000 # some high minimum to start
window_max = -1000000 # some low maximuim to start
window_total = 0
for i in range ( 0, len(dates_subset)):
# calculate total
window_total += numbers_subset[i]
# calculate max
if numbers_subset[i] > window_max:
window_max = numbers_subset[i]
# calculate min
if numbers_subset[i] < window_min:
window_min = numbers_subset[i]
# other calculations....
return_dict = {
"min" : window_min,
"max" : window_max,
"average" : window_total / len(dates_subset),
# other calculations....
}
return return_dict
Good luck bud, the work is worth it.
I have the start and end times of trips made by a bus, with the times in an Excel sheet. I want to make the graph as below :
I tried with Matlab nodes and graphs but did not got the exact figure, below is the Matlab code which I tried as an example:
A = [1 4]
B = [2 3]
weights = [5 5];
G = digraph(A,B,weights,4)
plot(G)
And the figure it generates:
I have got many more than 4 points in the Excel sheet, and I want them to all be displayed as in the first image.
Overview
You don't need any sort of complicated graph package for this, just use normal line plots! Here are methods in Excel and Matlab.
Excel
Give each bus stop a number, and list the bus stop number by the time it arrives/leaves there. I'll use stops number 0 and 1 for this example.
0 04:41
1 05:35
1 05:40
0 06:34
0 06:51
1 07:45
1 15:21
0 16:15
Then simply highlight the data and insert a "scatter with straight lines"
The rest is formatting. You can format the y-axis and tick "values in reverse order" to get the time increasing as in your desired plot. You can change the x-axis tick marks to just show integer stop numbers, get rid of the legend etc.
Final output:
Matlab
Here is the Matlab documentation for converting Excel formatted dates into Matlab datetime arrays: Convert Excel Date Number to Datetime.
Once you have the datetime objects, you can do this easily with the standard plot function.
% Set times up as a datetime array, could do this any number of ways
times = datetime(strcat({'1/1/2000 '}, {'04:41', '05:35', '05:40', '06:34', '06:51', '07:45', '15:21', '16:15'}, ':00'), 'format', 'dd/MM/yyyy HH:mm:ss');
% Set up the location of the bus at each of the above times
station = [0,1,1,0,0,1,1,0];
% Plot
plot(station, times) % Create plot
set(gca, 'xtick', [0,1]) % Limit to just ticks at the 2 stops
set(gca, 'ydir', 'reverse') % Reverse y axis to have earlier at top
set(gca,'XTickLabel',{'R', 'L'}) % Name the stops
Output:
Currently I am getting time with the keyword Get time epoch , which is returning time in seconds. But I need time in milliseconds , So that I can get time span for a particular event.
or is there any other way to get the time span for a particular event or a testsceanrio?
Check the new test library DateTime, which contains keyword Get Current Date, which also returns milliseconds. It also has keyword Subtract Dates to calculate difference between two timestamps.
One of the more powerful features of robot is that you can directly call python code from a test script using the Evaluate keyword. For example, you can call the time.time() function, and do a little math:
*** Test cases
| Example getting the time in milliseconds
| | ${ms}= | Evaluate | int(round(time.time() * 1000)) | time
| | log | time in ms: ${ms}
Note that even though time.time returns a floating point value, not all systems will return a value more precise than one second.
Using the DateTime library, as suggested by janne:
*** Settings ***
Library DateTime
*** Test Cases ***
Performance Test
${timeAvgMs} = Test wall clock time 100 MyKeywordToPerformanceTest and optional arguments
Should be true ${timeAvgMs} < 50
*** Keywords ***
MyKeywordToPerformanceTest
# Do something here
Test wall clock time
[Arguments] ${iterations} #{commandAndArgs}
${timeBefore} = Get Current Date
:FOR ${it} IN RANGE ${iterations}
\ #{commandAndArgs}
${timeAfter} = Get Current Date
${timeTotalMs} = Subtract Date From Date ${timeAfter} ${timeBefore} result_format=number
${timeAvgMs} = Evaluate int(${timeTotalMs} / ${iterations} * 1000)
Return from keyword ${timeAvgMs}
In the report, for each suite, test and keyword, you have the information about start, end and length with millisecond details. Something like:
Start / End / Elapsed: 20140602 10:57:15.948 / 20140602 10:57:16.985 / 00:00:01.037
I don't see a way to do it using Builtin, look:
def get_time(format='timestamp', time_=None):
"""Return the given or current time in requested format.
If time is not given, current time is used. How time is returned is
is deternined based on the given 'format' string as follows. Note that all
checks are case insensitive.
- If 'format' contains word 'epoch' the time is returned in seconds after
the unix epoch.
- If 'format' contains any of the words 'year', 'month', 'day', 'hour',
'min' or 'sec' only selected parts are returned. The order of the returned
parts is always the one in previous sentence and order of words in
'format' is not significant. Parts are returned as zero padded strings
(e.g. May -> '05').
- Otherwise (and by default) the time is returned as a timestamp string in
format '2006-02-24 15:08:31'
"""
time_ = int(time_ or time.time())
format = format.lower()
# 1) Return time in seconds since epoc
if 'epoch' in format:
return time_
timetuple = time.localtime(time_)
parts = []
for i, match in enumerate('year month day hour min sec'.split()):
if match in format:
parts.append('%.2d' % timetuple[i])
# 2) Return time as timestamp
if not parts:
return format_time(timetuple, daysep='-')
# Return requested parts of the time
elif len(parts) == 1:
return parts[0]
else:
return parts
You have to write your own module, you need something like:
import time
def get_time_in_millies():
time_millies = lambda: int(round(time.time() * 1000))
return time_millies
Then import this library in Ride for the suite and you can use the method name like keyword, in my case it would be Get Time In Millies. More info here.