w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
what is the average time, that an average process, running on an average kernel, using an average scheduler, gets in one active cycle?
Linux uses 100 milliseconds as the scheduler quantum, if that's what you were asking, in your own, convoluted way :-) There's nothing saying a process has to use their entire quantum and, in fact, if they release early, I think their priority gets bumped up a bit as a reward.

Categories : C

How to get the average of a DATEDIFF()?
this sql could execute? SELECT AVG(t.a) from ( SELECT DATEDIFF(d, DateUsed, DateExpires) AS a FROM tbl ) as t this is my test: but good answer is: SELECT AVG(DATEDIFF(d, DateOne, DateTwo)*1.0) AS avgDate FROM Test

Categories : SQL

Is n operations of O(1) average time each considered O(n) in average?
Given that you are traversing all your array the second time, yes that is O(n) * O(1) (and not O(n)+O(1) as previously stated from me) (for hash lookup in average time), so you are talking about an algorithm of O(n) complexity .

Categories : Database

Why is Average Visit Duration different to Average Time on Page, when only one page is viewed?
Visit duration is affected by pageviews and events. Time on page is only affected by pageviews, and you need a second pageview in order to calculate the time on page for the first page. To put it another way...your events are skewing the avg visit duration metric. Technically that visit is a bounce too.

Categories : Google Analytics

How to get list of records from table where the time difference found using DATEDIFF function between 2 variables that are select queries themselves?
You can't use variables this way. Now it's hard to tell for sure not seeing your table schema and sample data but you should be able to do what you want using JOIN with a query like this SELECT l1.* FROM log.time l1 JOIN log.time l2 ON l1.sender = l2.sender AND l1.receiver = l2.receiver AND l1.code = 158 AND l2.code = 189 WHERE l1.sender = 'Japan' AND l1.receiver = 'USA' AND DATEDIFF(minute, l1.log_time, l2.log_time) >= 10 If you were to provide a table schema, sample data and desired output, then it'll be possible to test your query

Categories : Mysql

How to get time average
The problem there is that your strtotime call, not having a date component, is defaulting to the current date. So the $ts is a much much larger number than just the sum of the time parts; it includes the date parts as well. I would avoid using the time functions like that. It's simple enough to calculate the number of seconds based on the hours, minutes and seconds. Once you have that, you can use date() to echo the formatted time like you do there. Try something more like this: function getTimeAverage($hours, $minutes, $seconds, $division) { $seconds += ($hours * 3600) + ($minutes * 60); return $seconds / $division; } $average = getTimeAverage(6, 3, 5, 175); echo gmdate("H:i:s", $average);

Categories : PHP

time-weighted average in xts or zoo
I'm still not sure what you're asking, but the code below will calculate the time-weighted mean in each non-overlapping 10-minute interval. All rows (except the first) will be the same as a regular mean because your data occur once every minute, except for between the 7th and 8th observations. x <- structure(c(28.2, 28.2, 28.2, 28.2, 28.1, 28.1, 28.1, 28.1, 28.1, 28.2, 28.3, 28.2, 28.2, 28.1, 28.1, 28.1, 28.1, 28.1, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 27.9, 27.9, 27.9, 27.9, 27.9, 27.9, 27.8, 27.8, 27.8, 27.8, 27.8, 27.8, 27.8, 27.8, 27.8, 27.8, 27.8, 27.8, 27.8, 27.8, 27.8, 27.8, 27.8, 27.8, 27.8, 27.8, 27.7, 27.7, 27.7, 27.8), class = c("xts", "zoo"), .indexCLASS = c("POSIXct", "POSIXt"), tclass = c("POSIXct", "POSIXt"), .indexTZ = "", tzone = "", index = stru

Categories : R

Time average in hours
Try this, $total_time=0; foreach($time as $t){ $total_time+=strtotime($t)-1373241600; } So $total_time will be an integer number and you can divide it with 3600 and with count($time) to get average hour :) $average_time = ($total_time/count($time))/3600;

Categories : PHP

Average Time between Two Date Fields in MySQL?
Try this: SELECT AVG(TIMESTAMPDIFF(SECOND, contactdatetimeinitiate, contactdatetimecomplete) ) AS average This should give you the average contact duration in seconds. If you're really worrying about fractional-second time intervals, you could try using MICROSECOND in place of SECOND. In this case you'll need SELECT AVG( 0.000001 * TIMESTAMPDIFF(MICROSECOND, contactdatetimeinitiate, contactdatetimecomplete) ) AS average This answer is valid for MySQL.

Categories : Mysql

having issues with finding the average run time of a block
Your method is mostly ok so far, except you don't need to branch out i == 1 from i > 1 – { 1.times { yield } is functionally equivalent to just calling yield. yield doesn't return anything on its own. It is a keyword that indicates the block given to the method should be called, and can optionally be fed variables that would in turn get passed to the block, e.g: class String def each_character_in_reverse_order each_char.to_a.reverse_each do |char| yield char end end end "hello".each_character_in_reverse_order do |c| puts c.upcase end #=> # O # L # L # E # H In the case of the tests you've linked to, the return values of the blocks are complete inconsequential, as they are only interested in how long it takes to run the block. But as you can see in the exa

Categories : Ruby

Oracle SQL - Average Time Between Dates By Subject
The average is actually the difference between the min and max values, divided by one less than the count. For your data: select SubjectId, (case when count(*) > 1 then (max(date) - min(date))/(count(*) - 1) end) as AvgDifference from t group by SubjectId; To get the overall average, use a subquery: select avg(AvgDifference) from (select SubjectId, (case when count(*) > 1 then (max(date) - min(date))/(count(*) - 1) end) as AvgDifference from t group by SubjectId ) t

Categories : SQL

Calculate the average of several "time" commands in Linux
Like the commenter above mentioned, it sounds like you may want to use a loop to run your program multiple times, to get more data points. You can use the time command with the -o option to output the results of the time command to a text file, like so: time -o output.txt myprog

Categories : Linux

How to construct moving time average with different weights for different months?
A weighted average is defined as sum(x .* weights) / sum(weights). If you want to calculate this in a moving average kind of way, I guess you could do (untested): moving_sum = @(n, x) filter(ones(1,n), 1, x); moving_weighted_avg = moving_sum(12, temperature .* days_per_month) ... ./ moving_sum(12, days_per_month); If temperature is a vector of monthly temperatures and days_per_month contains the actual number of days of the corresponding months, this should even work in case of leap years. Edit to answer comment You can reconstruct days_per_month like so: start_year = 2003; start_month = 10; nmonth = 130; month_offset = 0:nmonth - 1; month = mod(start_month + month_offset - 1, 12) + 1; year = start_year + floor((start_month + month_offset - 1) / 12); days_in_month = eomday(year,

Categories : Matlab

Postgres: average user response time from interaction with a bot
If I understand correctly, then each time the outgoing is false, you want the created_at from preceding row with the same user_id and state_code. I'm not sure how you would use the windows functions for this. Here is an approach using correlated subqueries: Here is one way: select t.*, (select created_at from t t2 where t2.user_id = t.user_id and t2.state_code = t.state_code and t2.outgoing = 't' and t2.created_at < t.created_at order by t2.created_at desc limit 1 ) as prev_created_at from t You can then do your date arithmetic to get what you want (mostly that prev_created_at is not NULL). If you know that the previous row is the "one just before", you can do something similar with lag():

Categories : SQL

Average time from a list of start end times in linq to sql
long averageTime = listOfStartEndTimes .Select(se => se.End - se.Start) .Average(t => t.Ticks); Or alternatively, with a slightly lower resolution (unix epoch date instead): long averageTime = listOfStartEndTimes .Select(se => se.End - se.Start) .Average(t => (t.Ticks – 621355968000000000) / 10000000);

Categories : C#

Calculate average time difference between multiple unix timestamps
The most straight forward way it to do it like you described. $res =0; for($x = 1, $num = count($array); $x < $num; $x++){ $res =+ $array[$x] - $array[$x-1]; } echo $res/($num-1);

Categories : PHP

Calculating the average traverse time for a graph in millisecond gives an inconceivable output?
The number is simply written as a floating point number. 1.4765902999997995E-4 = 0.000147659... So because it's a very small number, the output is in float format to be easier to read. EDIT: To clarify about floating point number. It's just a way to write numbers that is usually referred to as "scientific notation". This is just a different and convenient way to write very large or very small numbers. In school you might've run into something like: 3,000,000 = 3 * 10^6 = 3E6 1,456,000,000,000 = 1.456 * 10^12 = 1.456E12 So the "E" simply means *10^. If the numbers are small, you use negative numbers after the E, like this: 0,04653 = 4.653 * 10^-2 = 4.653E-2 0,00000134 = 1.34 * 10^-6 = 1.34E-6 0.000000000000000018 = 1.8 * 10^-17 = 1.8E-17 If you want more exampl

Categories : Java

MySQL average number of hours between created datetimes for a specific time interval
The average is the difference between the first and last records divided by the count plus some number. SELECT (UNIX_TIMESTAMP(max(date(created)+1), min(date(created)))/1000)/(count(*)+2) AS timediffsecs FROM Sessions WHERE created BETWEEN DATE_SUB(NOW(), INTERVAL 4 DAYS) AND NOW() What is this doing? First, it is not adding additional records to the data. Instead, it is just rounding down the earlier date and rounding up the later date. UNIX_TIMETAMP produces values in milliseconds since some point in time. Take the difference between the biggest and smallest. Finally, divide by the number of rows encountered plus 2 (I think it should be the count plus 1, but your question says count plus 2).

Categories : Mysql

Trying to aggregate (and average) time series data (collected every five minutes) into day and night periods for each 24 hr period in R
You don't have a particularly good dataset to test code since you have only am cases for the first data and pm cases for the second, but this will do a two-way classification by date and am/pm indicator in the time column. I also removed all the non-numeric columns from consideration, since it makes no sense to ask for the mean of a factor. new2 <- aggregate(dat[unlist(lapply(dat, is.numeric))], by = list(date, gsub("^.+ ", "", dat$GMT_Time) ), mean) new2 Group.1 Group.2 CollarID ActivityX ActivityY ActivitySum Temp 1 2000-01-01 AM 2905 0.00000 0 0.00000 21.66667 2 2011-02-21 PM 2905 10.66667 12 22.66667 20.66667 The gsub call is removing any character between the beginning of the string and the last instance of a

Categories : R

SQL query to compare individual average with a group average
You don't need the first ; since it is a statement terminator. Change this : SELECT Person, Avg(Score) AS PersonAverage FROM TblScores GROUP BY Person HAVING (((Avg(Score))>(SELECT Avg(Score) AS AverageOfAllScores FROM TblScores;))); with this : SELECT Person, Avg(Score) AS PersonAverage FROM TblScores GROUP BY Person HAVING (((Avg(Score))>(SELECT Avg(Score) AS AverageOfAllScores FROM TblScores)));

Categories : Mysql

Relation between worst case and average case running time of an algorithm
If you're mentioning A(n) and W(n) are functions - then, yes, you can do such statement in common case - it is because big-o formal definition. Note, that in terms on big-o there's no sense to act such way - since it makes understanding of the real complexity worse. (In general, three cases - worst, average, best - are present exactly to show complexity more clear)

Categories : Algorithm

DateDiff in VBA for ranges
DateDiff can not be used on a range, only a single value. Perhaps you can point a separate cell at the range and create a single value from it, and then DateDiff that? Or use a variable that does it, like: UpDate = Sheets("Sheet1").Cells("H4") & Sheets("Sheet1").Cells("H5") That might need some tweaking since I'm not sure what's in each cell, but you get the idea.

Categories : Excel

SQLite select average from one table and update average field from another table using trigger
To compute the average value of a specific field dynamically, use this query: SELECT AVG(value) FROM table_1 WHERE field = 'field_a'; If you want instead a view that looks like your table_2, you can define it like this: CREATE VIEW view_2 AS SELECT field, AVG(value) AS average_value FROM table_1 GROUP BY field; If you really want table_2 to be an actual table, you could compute the average values like this: UPDATE table_2 SET average_value = (SELECT AVG(value) FROM table_1 WHERE table_1.field = table_2.field); If you want table_2 to be an actual table, and want to update only those values that have changed, use a trigger like this: CREATE TRIGGER update_average_value_after_insert AFTER INSERT ON table_1 FOR EACH ROW BEGIN UPDATE

Categories : SQL

How to use DATEDIFF function with Eloquent?
You can use DB::raw for this. Reservation::select(array( 'obj_id', 'name', 'surname', 'date_from', 'date_to', 'days', 'status', 'slug', 'payable', DB::raw("DATEDIFF(date_from,date_to)AS Days")) ))

Categories : PHP

using datediff with 1 decimal for years
Division like what you are doing should work well to get the result you're looking for. This should get you the right amount of decimal points: Select Books.title as Title , ROUND(DATEDIFF(CURDATE(),Books.release_date)/365.25,1) as Age From Books

Categories : Mysql

Need to exhance a DateDiff for further detail
This is what I use with $ptime being timestamp function ElapsedTime($ptime) { $etime = time() - $ptime; if ($etime < 1) { return '0 seconds'; } $a = array( 12 * 30 * 24 * 60 * 60 => 'year', 30 * 24 * 60 * 60 => 'month', 24 * 60 * 60 => 'day', 60 * 60 => 'hour', 60 => 'minute', 1 => 'second' ); foreach ($a as $secs => $str) { $d = $etime / $secs; if ($d >= 1) { $r = round($d); return $r . ' ' . $str . ($r > 1 ? 's' : '') . ' ago'; } } }

Categories : PHP

SQL Server 2008 - DateDiff
The challenge is getting the previous date. In SQL Server 2012, you can use lag(), but this is not supported in SQL Server 2008. Instead, I use a correlated subquery to get the previous date. The following returns the set you are looking for: with t as ( select 1 as id, CAST('2013-01-01' as DATE) as CurrentMailPromoDate union all select 2, '2013-03-01' union all select 3, '2013-06-09' union all select 4, '2013-06-10' union all select 5, '2013-09-18' union all select 6, '2013-12-27' union all select 7, '2013-12-27') select t.id, t.CurrentMailPromoDate from (select t.*, (select top 1 CurrentMailPromoDate from t t2 where t2.CurrentMailPromoDate < t.CurrentMailPromoDate order by CurrentMailP

Categories : SQL

Datediff & Group By not working?
[...execute query does not include the specified expression as part of aggregate function] That error message already indicates that using GROUP BY does not work with aggregate Functions. DATEDIFF() is an aggregate function and does not work with a GROUP BY. The reason for that is that GROUP BY reduces your dataresult and only displays one line per different entry of the column you are using. What is your aim for that query anyways? I am sure there is a different solumtion for that problem. GROUP BY DATE.ID sounds like you are making a GROUP BY on the primary key which has no effect, because primary keys are unique per definition.

Categories : Mysql

How to group rows by their DATEDIFF?
Here's an idea. You don't need ROW_NUMBER and previous and next records. You just need to queries unioned - one looking for everyone that have someone checked X minutes behind, and another looking for X minutes upfront. Each uses a correlated sub-query and COUNT(*) to find number of matching people. If number is greater then your @numOfPeople - that's it. EDIT: new version: Instead of doing two queries with 10 minutes upfront and behind, we'll only check for 10 minutes behind - selecting those that match in cteLastOnes. After that will go in another part of query to search for those that actually exist within those 10 minutes. Ultimately again making union of them and the 'last ones' WITH cteSource AS ( SELECT ID, STAFF_GUID, LAST_UPDATED FROM HH_SOLUTION_AUDIT WHERE LAST_UP

Categories : SQL

How to do a timediff or datediff query in CakePHP
You have to place the SQL fragment inside of the conditions array, currently it's placed outside and thus it's being ignored. $this->find('first', array ( 'conditions' => array ( 'username' => $v['User']['username'], // this is where it needs to go 'TIMESTAMPDIFF(MINUTE, request_time, NOW()) < ' => 15 ) // this is where it was before )); That will result in a query similar to this: SELECT `Model`.`username`, ... FROM `db`.`model` AS `Model` WHERE `username` = 'whatever' AND TIMESTAMPDIFF(MINUTE, request_time, NOW()) < 15 LIMIT 1 By default CakePHP will include all fields in the SELECT statement. Obviously if you want the query to use only the TIMESTAMPDIFF condition as in your example, then you have to dro

Categories : PHP

How to get a SUM of a DATEDIFF but provide cut-off at 24 hours IF a single day is specified
You'll want a conditional SUM, using CASE. Not sure of syntax for your db exactly, but something like: , SUM (CASE WHEN TIME_TO_SEC(TIMEDIFF(re.time_end, re.time_start))/3600 > 24 THEN 0 ELSE TIME_TO_SEC(TIMEDIFF(re.time_end, re.time_start))/3600 END)'Total Time in Hours'

Categories : SQL

datediff in mysql select new field only if of certain value
If I'm not mistaken, try SELECT datediff(date1, date2) AS new FROM table1 WHERE new > 30; The > operator can be used as a boolean and is comparing your datediff() and your 30. That's why you should place it in a WHERE statement, to prevent a boolean value in your select.

Categories : Mysql

SQL datediff function resulted in an overflow
Instead of using 0 as your default/fixed point in time, use some other constant date instead, that's closer to the values you're going to be processing - and thus less likely to produce an overflow. 0 gets implicitly converted to midnight on 01/01/1900. A better constant might be, for instance, 01/01/2000: SELECT EMPLOYEEID, sum(DateDiff(mi,isnull(In_Time,'20000101'),isnull(Out_Time,'20000101'))/60) + sum(round(DateDiff(mi,isnull(In_Time,'20000101'),isnull(Out_Time,'20000101'))%60,2))/100.0 + sum(round(DateDiff(ss,isnull(In_Time,'20000101'),isnull(Out_Time,'20000101')),2))/10000.0 as TotalHours from HR_EMPLOYEES Although the more I look at this, the more I'm unsure that defaulting the date to any value even makes sense.

Categories : SQL

SQL Server : Sum of DateDiff From Multiple Rows
EDIT Based on your updated question this will work. I've joined on your jump type table rather than assuming the id's (personally I think its a bad idea to assume id's eg assume 1 and 3 are the up type) Also I've used an inner join to get the corresponding down jump - I am assuming that if the jumper goes up he will come down ;) select r.RunID, r.PlayerID, TimeUp = uj.[Time], TimeDown = dj.[Time], TimeDifference = DATEDIFF(MILLISECOND, uj.Time, dj.Time) from @Run r inner join @Jump uj on uj.RunID = r.RunID inner join @JumpType ut on ut.TypeID = uj.[Type] inner join @Jump dj on dj.RunID = uj.RunID inner join @JumpType dt on dt.TypeID = dj.[Type] where ut.[Description] like '%Up%' and dt.[Description] like '%Down%' ORIGINAL - before you showed us your schema Heres

Categories : SQL

Selecting records younger then 2 minutes with DATEDIFF
I would replace DATEDIFF(MINUTE, @ScannedTime, updates.ScannedTime) < 2 Cause if the second argument is bigger than the third argument (the dates), you will have a negative result. And... a negative result is smaller than 2. by updates.ScannedTime > DATEADD(MINUTE, -2, @ScannedTime) or invert parameters DATEDIFF(MINUTE, updates.ScannedTime, @ScannedTime) < 2

Categories : SQL

How to use DATEDIFF SQL Server function and still benefit from the index?
Well, the following still uses a function, but does allow the use of an index on LastActivityTimestamp, which may be what you're asking for: LastActivityTimestamp < DATEADD(day,-90,getdate()) If that's not what you're asking for, you may have to add more information to your question about exactly what you're trying to do/seeking to avoid.

Categories : Sql Server

Datediff function adds startdate day also to the output
Execute this in Sql Server and you get 9 days: select DATEDIFF(day, '2013-07-01', '2013-07-10') Using this as a dataset: select CAST('2013-07-01' AS DateTime) AS StartDate, CAST('2013-07-10 23:59:59' AS DateTime) AS EndDate then using this expression in SSRS: =DateDiff(DateInterval.Day, Fields!StartDate.Value, Fields!EndDate.Value) still yields 9 days, even when using a time component. Try the following expression: =DateDiff(DateInterval.Day, DateTime.Today, Fields!EndDate.Value) Are you displaying the date fields to make sure what you think you should get is what you actually get? For instance, make sure you aren't being returned cached data.

Categories : Reporting Services

Converting irregularly time stamped Dateframe object, having price and volume information into equally spaced, volume weighted average price
I think I would create a new column for the total sold, and do two resamples: In [11]: df['total'] = df['price'] * df['amount'] In [12]: df.total.resample('30S', how='sum') / df.amount.resample('30S', how='sum') Out[12]: 2011-04-17 01:03:00 1.025700 2011-04-17 01:03:30 1.025700 2011-04-17 01:04:00 NaN 2011-04-17 01:04:30 1.025700 2011-04-17 01:05:00 1.025700 2011-04-17 01:05:30 1.025700 2011-04-17 01:06:00 1.025700 2011-04-17 01:06:30 1.025650 2011-04-17 01:07:00 1.025615 2011-04-17 01:07:30 1.025630 2011-04-17 01:08:00 1.025630 2011-04-17 01:08:30 NaN 2011-04-17 01:09:00 NaN 2011-04-17 01:09:30 1.025700 2011-04-17 01:10:00 NaN 2011-04-17 01:10:30 1.025700 2011-04-17 01:11:00 1.025700 Freq: 30S, dtype: float64 Assum

Categories : Python

Loosing the battle - Datediff working but I want to apply a condition
Try SELECT [faxdate],DAY(DATEDIFF(CAST(SUBSTRING(RPT.FaxDate, 1, 4) + '-' + SUBSTRING(RPT.FaxDate, 5, 2) + '-' + SUBSTRING(RPT.FaxDate, 7, 2) AS DATE), getdate())) AS vDiff instead of using where, use having like below HAVING vDiff > 60

Categories : Misc

Query Construction: Count, Case, Datediff, and Group By
You can do this with a self join (Assuming you have a primary key of KeyID): SELECT T.ID, T.Date, Lookback = COUNT(CASE WHEN t2.Date < T.Date THEN t2.ID END), Lookahead = COUNT(CASE WHEN t2.Date > T.Date THEN t2.ID END) FROM T INNER JOIN T t2 ON t2.ID = t.ID AND t2.Date >= DATEADD(MONTH, -6, T.Date) AND T2.Date < DATEADD(MONTH, 6, T.Date) GROUP BY T.ID, T.Date, T.KeyID; Example on SQL Fiddle The key is that it just joins all rows for the previous 6 months and the next 6 months, and counts the result. The COUNT(CASE WHEN... ensures that for the before column you are only counting the records before, and the after only the records after.

Categories : SQL



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.