average

How long should functions/methods should be in average?

Hi there... We've all read excessively long methods or functions, where your eyes end up bleeding when you reach the return statement. We've also seen those one-liner functions that seem pointless... I just wanted to ask: which do you think is the best average length for a function/method? Having into account that every language has it...

How to select an unlike number in an array in C++?

I'm using C++ to write a ROOT script for some task. At some point I have an array of doubles in which many are quite similar and one or two are different. I want to average all the number except those sore thumbs. How should I approach it? For an example, lets consider: x = [2.3, 2.4, 2.11, 10.5, 1.9, 2.2, 11.2, 2.1] I want to somehow...

MS Access 2003 - Calculating an average based on qty sold/per site with supply %

Here is another question I have about being able to calculate this scenario in Access, or even at all for that matter: I have a query that find the TOP 5 items sold in a given timeframe, and it groups by site. I use this to create a comparative chart between the site for ppt presentations. I do a lot of these but I have a problem with t...

Linux max server processes

Hello all, I have a GNU/Linux Debian server running: apache, jboss, proftpd and postgresql (RAM: 16GB, 4 core Xeon). Max Apache process is 1200, same thing for the Jboss DB Pool. And I can have up to 400 simultaneous FTP download. Load average can raise 5 (1 most of time). What do you think about that? Is this server considered as "to...

How to calculate a monthly average when the month is not finished

Hello! Let's say I have a 12 cells on column A with the sales for each month last year. To calculate a monthly I can do a simple formula like this in A13 =sum(A1:A12)/12. But in column B I have the sales for this year, not a complete year, and August is not finished, but I have the running amount of sales for this month, so far. What kin...

How to average 3 values in Sql Server?

Hi folks, I have three variables :- @ScoreA DECIMAL(10,7) @ScoreB DECIMAL(10,7) @ScoreC DECIMAL(10,7) @FinalScore DECIMAL(10, 7) I wish to get the average of the three scores. BUT 1, 2 or all 3 values might be zero. Eg. scenarios: A = 1.4, B=3.5, C=5.0; FinalScore = 3.3 A = 0.0, B=0.0, C=0.0; FinalScore = 0.0 A = 1.1, B=0.0, C=0.0...

Averaging a set of points on a Google Map into a smaller set

I'm displaying a small Google map on a web page using the Google Maps Static API. I have a set of 15 co-ordinates, which I'd like to represent as points on the map. Due to the map being fairly small (184 x 90 pixels) and the upper limit of 2000 characters on a Google Maps URL, I can't represent every point on the map. So instead I'd l...

SQL aggregate functions using MIN and AVG...

How can I omit Zeros in my data? For example using the MIN function? I would like the Minimum value except a 0... How can I get the next largest? MIN(availables.price) Also is there a generally way to skip over 0s in the same way if I'm using the AVG function? The problem is the table I've inherited doesn't use NULL values but has...

Generic awk script to calculate average on any field through command line argument

Hi, I want to write a generic awk script that can take as input a file and a field number (in that file) and give me the average value of that field in that file. I would use it something like this: bash$ avg.awk 3 input.file 22 bash$ avg.awk 4 input.file 2001 Of course, I can write the script if I know which field (e.g., $3) I am go...

Use SELECT AVG with parameters "SELECT AVG(@parameter)" SQL!!

I'm working with a table of float values, but I enter the column by parameter SELECT AVG(@var) AS Aver FROM ListVal When I enter the column name (the parameter) I recieve an error: That the datatype nvarchar is not valid for the avg operator. But all the columns are float. Help!!! please ...

Avg of a Sum in one query

I would like to know if I can get the average of a sum in one single SQL SERVER request, Have tried to do it with the following request but it doesn't work: SELECT t.client, AVG(SUM(t.asset)) AS Expr1 FROM TABLE t GROUP BY t.client ...

Table of averages by date for multiple IDs

I have a table full of items that each have a unique ItemID. There is another table with information on tests that are done on these items around once a month (some may have multiple tests per month and some may have none some months) and each test entry has a full date mm/dd/yyyy. I would like to display the average of one of the fiel...

Calculating average in interchangable range?

I know it's because of n, but n is supposed to be any variable, and left as n, this is what I have: def average(n): if n >= 0: avg = sum((range(1:int(n)))/float(len(range(1:int(n))))) print avg how do I fix it? ...

Select average from MySQL table with LIMIT

I am trying to get the average of the lowest 5 priced items, grouped by the username attached to them. However, the below query gives the average price for each user (which of course is the price), but I just want one answer returned. SELECT AVG(price) FROM table WHERE price > '0' && item_id = '$id' GROUP BY username ORDER BY pr...

How to reduce calculation of average to sub-sets in a general way?

Edit: Since it appears nobody is reading the original question this links to, let me bring in a synopsis of it here. The original problem, as asked by someone else, was that, given a large number of values, where the sum would exceed what a data type of Double would hold, how can one calculate the average of those values. There was sev...

Query to calculate average time between successive events

My question is about how to write an SQL query to calculate the average time between successive events. I have a small table: event Name | Time stage 1 | 10:01 stage 2 | 10:03 stage 3 | 10:06 stage 1 | 10:10 stage 2 | 10:15 stage 3 | 10:21 stage 1 | 10:22 stage 2 ...

Math average with php

Time to test your math skills... I'm using php to find the average of $num1, $num2, $num3 and so on; upto an unset amount of numbers. It then saves that average to a database. Next time the php script is called a new number is added to the mix. Is there a math (most likely algebra) equation that I can use to find the average of the o...

Speeding up database access

I have a database containing records collected every 0.1 seconds, and I need to time-average the data from a given day to once every 20 minutes. So I need to return a day's worth of data averaged to every 20 minutes which is 24*3 values. Currently I do a separate AVG call to the database for each 20-minute period within the day, which i...

How to average certain sized subsections of a list in python?

I would like to take bites out of a list (or array) of a certain size, return the average for that bite, and then move on to the next bite and do that all over again. Is there some way to do this without writing a for loop? In [1]: import numpy as np In [2]: x = range(10) In [3]: np.average(x[:4]) Out[3]: 1.5 In [4]: np.average(x[4:8]) ...

Get average value from double[] between two indices

I have a double[] array holding many numbers. I have an algorithm that selects sections from within this array that fall under certain conditions (value greater than x, at least y values, etc.) Now I want to calculate the average value of all these values in my section. So, say my section is from index 20 to 40. Now I have 20 values. ...