average

Average array of times as strings in Ruby

心不动则不痛 提交于 2019-12-08 07:52:34
问题 I have an array: array = ["0:00:31", "0:00:52", "0:01:05", "0:00:55", "0:01:33", "0:00:05", "0:00:01", "0:05:10", "0:02:40", "0:03:03", "0:01:33", "0:00:00"] and I need to average all of the times in the array that are not equal to "0:00:00" . "0:00:00" should just be thrown out. What's the best way to do this? I'm currently looping through the array, removing all of the 0:00:00 values, turning the strings into integers and doing an average - But it seems like a lot of code for what I'm

Awk average of n data in each column

落爺英雄遲暮 提交于 2019-12-08 07:45:19
问题 "Using awk to bin values in a list of numbers" provide a solution to average each set of 3 points in a column using awk. How is it possible to extend it to an indefinite number of columns mantaining the format? For example: 2457135.564106 13.249116 13.140903 0.003615 0.003440 2457135.564604 13.250833 13.139971 0.003619 0.003438 2457135.565067 13.247932 13.135975 0.003614 0.003432 2457135.565576 13.256441 13.146996 0.003628 0.003449 2457135.566039 13.266003 13.159108 0.003644 0.003469 2457135

Average aggregation temporal database 10-minute interval in PostgreSQL

浪尽此生 提交于 2019-12-08 05:54:00
问题 I have a time series data where I want to perform aggregation on it by average function. Aggregation should be performed in 10-minute intervals: (HH-1):50, HH:00, HH:10, HH:20, HH:30, HH:40 or alternatively in 10-minute intervals: (HH-1):51, HH:01, HH:11, HH:21, HH:31, HH:41. Note: hourly mean of 5 o'clock is average of (4):51, 5:01,5:11, 5:21, 5:31, 5:41 values. The problem is that a data-set includes the variables with odd and even frequencies in time. So, I cannot assign an aggregation for

php average of timestamp

孤街浪徒 提交于 2019-12-08 04:55:40
问题 I want to calculate average of time-in for a user for particular duration , i have timestamp values for each time-in . To calculate average i want to add all timestamps and divide by no of days . But sum of all timestamps gives wrong input so i want convert timestamps to seconds so i can add them and calculate average . I am using following code . $timeInTotalSec = 0; $timeInTotalSec += intval(date("H",$punchintime)) * 60 * 60; $timeInTotalSec += intval(date("i",$punchintime)) * 60;

Calculate AVERAGE from 2 columns for each row in SQL

我的梦境 提交于 2019-12-08 04:55:34
问题 As an example I will have this table from MySQL Id | Name | Grade 1 | Grade 2 | Average 1. | Jack | 9 | 10 | 2. | Jimmy | 9 | 8 | 2. | Emmy | 9 | 7 | So, in the Average field from this table, I need to calculate the AVERAGE from the Grade 1 and Grade 2 fields. I tried a lot of possiblities which I know they are wrong like: UPDATE table_name SET Average=AVG(Grade 1 + Grade 2) I there a way to do this? Can anyone help me? Thanks! 回答1: You need to add the fields together and divide by the number

MapReduce - how do I calculate relative values (average, top k and so)?

我的未来我决定 提交于 2019-12-08 04:30:32
问题 I'm looking for a way to calculate "global" or "relative" values during a MapReduce process - an average, sum, top etc. Say I have a list of workers, with their IDs associated with their salaries (and a bunch of other stuff). At some stage of the processing, I'd like to know who are the workers who earn the top 10% of salaries. For that I need some "global" view of the values, which I can't figure out. If I have all values sent into a single reducer, it has that global view, but then I loose

Is there a fast way to the average colors from several framebuffers in WebGL / Javascript?

空扰寡人 提交于 2019-12-08 03:18:44
问题 I am very new to the WebGL subject. What I want to do is to calculate the average color of 6 different framebuffers like the ones below in the picture. Now I am wondering what the best way to go about it would be? I tried to do gl.readPixels(0, 0, 256, 256, gl.RGBA, gl.UNSIGNED_BYTE, pixelValues); but that seems to be very slow... Is there a way that this can happen on the graphics card? this is how the FBO is set up - I have this from a tutorial: ... 回答1: You have two options Write a

Using exponential smoothing with NaN values

你离开我真会死。 提交于 2019-12-07 20:24:02
问题 I have a sample of some kind that can create somewhat noisy output. The sample is the result of some image processing from a camera, which indicates the heading of a blob of a certain color. It is an angle from around -45° to +45°, or a NaN , which means that the blob is not actually in view. In order to combat the noisy data, I felt that exponential smoothing would do the trick. However, I'm not sure how to handle the NaN values. On the one hand, involving them in the math would result in a

How to average a signal to remove noise with Python

南楼画角 提交于 2019-12-07 18:51:42
问题 I am working on a small project in the lab with an Arduino Mega 2560 board. I want to average the signal (voltage) of the positive-slope portion (rise) of a triangle wave to try to remove as much noise as possible. My frequency is 20Hz and I am working with a data rate of 115200 bits/second (fastest recommended by Arduino for data transfer to a computer). The raw signal looks like this: My data is stored in a text file, with each line corresponding to a data point. Since I do have thousands

Moving average - MySQL

◇◆丶佛笑我妖孽 提交于 2019-12-07 14:45:40
问题 I'm trying to implement system-wide login throttling and I need to calculate the daily average number of failed login attempts from the last 3 months. I'm currently inserting a record on every login fail, each with a timestamp. How can I do this in MySQL? Thanks in advance for your help 回答1: SELECT AVG(cnt) FROM (SELECT COUNT(*) AS cnt FROM mytable WHERE `date` BETWEEN DATE_SUB(NOW(), INTERVAL 3 MONTH) AND NOW() GROUP BY DATE(`date`)) x Assuming you have a table mytable with field date of