Omron PLC elpsed time - time

I'm wokring on project with Omron PLC, I need to show on HMI elapsed time after I started my system but problem is that, I can see my time just in seconds but I need in hour and min type. How to display elapsed time in hour and minute type from Omron Nx1 PLC to HMI?

One solution is to calculate the total hours and minutes from the total secconds and display on the HMI. You could concatenate the values into a string, but since I don't know what your purpose is, it's easier to use the values directly in integers with two different variables.
As you didn't define the language, here's an example in Structured-text. The Time given in Seconds in TotalSeconds will be separated into Hours and Minutes (and also Seconds as a bonus!).
Note: I'm putting the variable declaration as text, but I know that in Sysmac it is possible to declare it as a table...
Declaration
VAR
TotalSeconds : DINT;
Seconds : DINT;
Minutes : DINT;
Hours : DINT;
rest : DINT;
END_VAR
Program
rest := TotalSeconds MOD 3600;
Seconds := rest MOD 60;
Minutes := (rest - seconds) / 60;
Hours := (TotalSeconds - rest) / 3600;
Example
242 s >>> 0 h / 4 min / 2 s
33868 s >>> 9 h / 24 min / 28 s

Related

How calculate working time in Oracle PLSQL

How calculate working time eg.
7.5 = 7h and 30 min (working hours)
0.75 = 45 min (pause)
8 = 8h (Planing hours)
How get result eg. (-15 min) below query return 00:15 is it possible get in minus or use have better example?
Select
to_char(time'0:0:0'+numtodsinterval((7.5 + 0.75 - 8 ),'hour'),'hh24:mi')
from dual
You have the arithmetic backwards and to get a negative number you want 8 - (7.5 + 0.75).
Don't use a time and just use the interval (and extract the sign, hour and minute components using string functions if you want a different format):
SELECT numtodsinterval(8 - (7.5 + 0.75),'hour') AS interval,
REGEXP_REPLACE(
numtodsinterval(8 - (7.5 + 0.75),'hour'),
'([+-]?)(\d+) (\d+):(\d+):(\d+\.?\d*)',
'\1\3:\4'
) AS hhmm
FROM DUAL;
Outputs:
INTERVAL
HHMM
-000000000 00:15:00.000000000
-00:15
fiddle

Calculate CPU usage from process.cpu.time

https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/hostmetricsreceiver/internal/scraper/processscraper/documentation.md
I have been using this library which gives me 3 values for a single process :
user time, system time & wait time
One example value is : 0.05, 0.01, 0.00
How can I calculate CPU percent of the particular process ?
To calculate the total CPU load/utilization percent of the system, we need to calculate "total system cpu time (during the period)" + "total user cpu time (during the period)" / "period"
In your case, suppose you take sample every 2 seconds, then for every sample, you need to calculate:
= ( (process.cpu.time.sys - previous_process.cpu.time.sys) + (process.cpu.time.user - previous_process.cpu.time.user) ) / 2

How to calculate which second of song will be playing after x minutes of repeating?

I am not doing pretty well with algorithms, so I need your help :)
Case: I play a song that lasts 3 minutes 40 seconds at 1st August 00:00 (for example). How could I be able to calculate which second of the song will be playing after (again, for expample) 3 days, 7 hours, 3 minutes and 54 seconds or any other time interval?
Sorry if it sounds lame :(
That's a use case for the modulo operator, that gives the remainder of a division.
10 / 3 is 3 * 3 + 1. The +1 is the remainder
It's as simple as :
SecondOfTheSongCurrentlyPlaying = TotalSecondsElapsed % LengthOfTheSongInSeconds
In example, if the song lasts 3 minutes 40 seconds, this is 220 seconds.
3 days, 7 hours, 3 minutes and 54 seconds are 284 634 seconds.
284634 % 220 == 174 seconds

Scheduling: advance deadline for implicit-deadline rate monotonic algorithm

Given a set of tasks:
T1(20,100) T2(30,250) T3(100,400) (execution time, deadline=peroid)
Now I want to constrict the deadlines as Di = f * Pi where Di is new deadline for ith task, Pi is the original period for ith task and f is the factor I want to figure out. What is the smallest value of f that the tasks will continue to meet their deadlines using rate monotonic scheduler?
This schema will repeat (synchronize) every 2000 time units. During this period
T1 must run 20 times, requiring 400 time units.
T2 must run 8 times, requiring 240 time units.
T3 must run 5 times, requiring 500 time units.
Total is 1140 time units per 2000 time unit interval.
f = 1140 / 2000 = 0.57
This assumes long-running tasks can be interrupted and resumed, to allow shorter-running tasks to run in between. Otherwise there will be no way for T1 to meet it's deadline once T3 has started.
The updated deadlines are:
T1(20,57)
T2(30,142.5)
T3(100,228)
These will repeat every 1851930 time units, and require the same time to complete.
A small simplification: When calculating factor, the period-time cancels out. This means you don't really need to calculate the period to get the factor:
Period = 2000
Required time = (Period / 100) * 20 + (Period / 250) * 30 + (Period / 400) * 100
f = Required time / Period = 20 / 100 + 30 / 250 + 100 / 400 = 0.57
f = Sum(Duration[i] / Period[i])
To calculate the period, you could do this:
Period(T1,T2) = lcm(100, 250) = 500
Period(T1,T2,T3) = lcm(500, 400) = 2000
where lcm(x,y) is the Least Common Multiple.

Basic Velocity Algorithm?

Given the following dataset for a single article on my site:
Article 1
2/1/2010 100
2/2/2010 80
2/3/2010 60
Article 2
2/1/2010 20000
2/2/2010 25000
2/3/2010 23000
where column 1 is the date and column 2 is the number of pageviews for an article. What is a basic velocity calculation that can be done to determine if this article is trending upwards or downwards for the most recent 3 days?
Caveats, the articles will not know the total number of pageviews only their own totals. Ideally with a number between 0 and 1. Any pointers to what this class of algorithms is called?
thanks!
update: Your data actually already is a list of velocities (pageviews/day). The following answer simply shows how to find the average velocity over the past three days. See my other answer for how to calculate pageview acceleration, which is the real statistic you are probably looking for.
Velocity is simply the change in a value (delta pageviews) over time:
For article 1 on 2/3/2010:
delta pageviews = 100 + 80 + 60
= 240 pageviews
delta time = 3 days
pageview velocity (over last three days) = [delta pageviews] / [delta time]
= 240 / 3
= 80 pageviews/day
For article 2 on 2/3/2010:
delta pageviews = 20000 + 25000 + 23000
= 68000 pageviews
delta time = 3 days
pageview velocity (over last three days) = [delta pageviews] / [delta time]
= 68,000 / 3
= 22,666 + 2/3 pageviews/day
Now that we know the maximum velocity, we can scale all the velocities to get relative velocities between 0 and 1 (or between 0% and 100%):
relative pageview velocity of article 1 = velocity / MAX_VELOCITY
= 240 / (22,666 + 2/3)
~ 0.0105882353
~ 1.05882353%
relative pageview velocity of article 2 = velocity / MAX_VELOCITY
= (22,666 + 2/3)/(22,666 + 2/3)
= 1
= 100%
"Pageview trend" likely refers to pageview acceleration, not velocity. Your dataset actually already is a list of velocities (pageviews/day). Pageviews are non-decreasing values, so pageview velocity can never be negative. The following describes how to calculate pageview acceleration, which may be negative.
PV_acceleration(t1,t2) = (PV_velocity{t2} - PV_velocity{t1}) / (t2 - t1)
("PV" == "Pageview")
Explanation:
Acceleration is simply change in velocity divided by change in time. Since your dataset is a list of page view velocities, you can plug them directly into the formula:
PV_acceleration("2/1/2010", "2/3/2010") = (60 - 100) / ("2/3/2010" - "2/1/2010")
= -40 / 2
= -20 pageviews per day per day
Note the data for "2/2/2010" was not used. An alternate method is to calculate three PV_accelerations (using a date range that goes back only a single day) and averaging them. There is not enough data in your example to do this for three days, but here is how to do it for the last two days:
PV_acceleration("2/3/2010", "2/2/2010") = (60 - 80) / ("2/3/2010" - "2/2/2010")
= -20 / 1
= -20 pageviews per day per day
PV_acceleration("2/2/2010", "2/1/2010") = (80 - 100) / ("2/2/2010" - "2/1/2010")
= -20 / 1
= -20 pageviews per day per day
PV_acceleration_average("2/3/2010", "2/2/2010") = -20 + -20 / 2
= -20 pageviews per day per day
This alternate method did not make a difference for the article 1 data because the page view acceleration did not change between the two days, but it will make a difference for article 2.
Just a link to an article about the 'trending' algorithm reddit, SUs and HN use among others.
http://www.seomoz.org/blog/reddit-stumbleupon-delicious-and-hacker-news-algorithms-exposed

Resources