aggregate

Calculating average age in Django

蓝咒 提交于 2019-12-13 03:37:49
问题 I need to find out average age of items (groupped by various criteria, but it does not seem to be the issue). However I fail to find how to effectively create aggregation over DateTimeField using Django (on top of MySQL). Pure Item.objects.all.aggregate(Avg('created')) seems to produce absolutely bogus values (eg. 20081988007238.133) and using Item.objects.all.extra(...) I have not found a way how to aggregate. Of course I can manually create SQL query (something like SELECT AVG(UNIX

@Formula field is not recognized by client code

核能气质少年 提交于 2019-12-13 02:59:19
问题 Related to: How to countDistinct on multiple columns I have an entity class that contains many fields, three of which are longitude , latitude and update_time . I am trying to add a @Formula field that concatenates the three: @Formula("concat(longitude, latitude, update_time)") public String fix; I would then like to use that field as part of a countDistinct query: @SuppressWarnings( {"unchecked", "rawtypes"} ) public long getCountDistinctPositions() { Session session = sessionFactory

Table aggregation using linq (calculate Average value)

落爺英雄遲暮 提交于 2019-12-13 01:43:33
问题 How to Aggregate below table using linq query Date tagname value 06-06-2018 14:15:00 Poll.Registers Block 0.310-PT-304_(4) 54.73497 06-06-2018 14:15:00 Poll.Registers Block 0.310-PT-304_(5) 3.417564 06-06-2018 14:15:00 Poll.Registers Block 0.310-PT-304_(4) 94.82829 06-06-2018 14:15:00 Poll.Registers Block 0.310-PT-304_(4) 15.08091 06-06-2018 14:15:00 Poll.Registers Block 0.310-PT-304_(5) 3.6422 06-06-2018 14:15:00 Poll.Registers Block 0.310-PT-304_(4) 5.078211 06-06-2018 14:15:00 Poll

performing previous tick aggregation using lapply and split

老子叫甜甜 提交于 2019-12-12 22:23:00
问题 I am trying to solve this issue for past 3 months. Please help. I have tick data (Price and Volume) for many stocks belonging to a single exchange. Each stock has its own .rds file on the hard disk. I am interested in cleaning it up: merge multiple same time stamps by taking median subset data for exchange hours only aggregate it over 20 minutes by previous tick aggregation I know that the function aggregatets in highfrequency package can perform the previous tick aggregation operation.

pyspark substring and aggregation

一个人想着一个人 提交于 2019-12-12 22:08:49
问题 I am new to Spark and I've got a csv file with such data: date, accidents, injured 2015/20/03 18:00 15, 5 2015/20/03 18:30 25, 4 2015/20/03 21:10 14, 7 2015/20/02 21:00 15, 6 I would like to aggregate this data by a specific hour of when it has happened. My idea is to Substring date to 'year/month/day hh' with no minutes so I can make it a key. I wanted to give average of accidents and injured by each hour. Maybe there is a different, smarter way with pyspark? Thanks guys! 回答1: Well, it

R: How to group and aggregate list elements using regex?

非 Y 不嫁゛ 提交于 2019-12-12 18:34:00
问题 I want to aggregate (sum up) the following product list by groups (see below): prods <- list("101.2000"=data.frame(1,2,3), "102.2000"=data.frame(4,5,6), "103.2000"=data.frame(7,8,9), "104.2000"=data.frame(1,2,3), "105.2000"=data.frame(4,5,6), "106.2000"=data.frame(7,8,9), "101.2001"=data.frame(1,2,3), "102.2001"=data.frame(4,5,6), "103.2001"=data.frame(7,8,9), "104.2001"=data.frame(1,2,3), "105.2001"=data.frame(4,5,6), "106.2001"=data.frame(7,8,9)) test= list("100.2000"=data.frame(2,3,5),

Summarizing data in table by group for each variable in r

我的梦境 提交于 2019-12-12 18:13:14
问题 I have some data that I'd like to properly format with some summary values in R. I've played with aggregate and other things such as summaryBy , but none produced what I wanted to. Here's the data data <- data.frame(id = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48), x1 = c(0.2846,0.3741,0.4208,0.3756,0.3476,0.3664,0.2852,0.3537,0.3116,0.3124,0.364,0.3934,0.3456,0.3034,0.3139,0.2766,0.3034,0.3159,0

Aggregating based on “near” row values

僤鯓⒐⒋嵵緔 提交于 2019-12-12 17:13:10
问题 I have a very messy dataframe (webscraped) that unfortunately has many double and even triple entries in it. Most of the dataframe looks like this: > df1<-data.frame(var1=c("a","a","b","b","c","c","d","d"),var2=c("right.a",NA,"right.b",NA,"right.c",NA,"right.d",NA),var3=c("correct.a","correct.a","correct.b","correct.b","correct.c","correct.c","correct.d","correct.d")) > df1 var1 var2 var3 1 a right.a correct.a 2 a <NA> correct.a 3 b right.b correct.b 4 b <NA> correct.b 5 c right.c correct.c 6

In SQL, how to aggregate on a field inside the table

依然范特西╮ 提交于 2019-12-12 14:59:20
问题 I'm sorry the TITLE is not so specific. I'll try to explain: I'm new to SQL. I'm at work and wrote a query which has 9 columns that takes information out of many tables. on the 9th column are names of types of machines, on the 3rd are value representing the time a machine worked in a month. I need to add a 10th column which will have for each type of machine, the maximum of 3rd columns for this type. lets say there are 5 machines of type XR (5 rows in the table) with times (3rd column) of 1,2

Preserve the order of distinct inside string_agg

一世执手 提交于 2019-12-12 13:19:34
问题 My SQL function: with recursive locpais as ( select l.id, l.nome, l.tipo tid, lp.pai from loc l left join locpai lp on lp.loc = l.id where l.id = 12554 union select l.id, l.nome, l.tipo tid, lp.pai from loc l left join locpai lp on lp.loc = l.id join locpais p on (l.id = p.pai) ) select * from locpais gives me 12554 | PARNA Pico da Neblina | 9 | 1564 12554 | PARNA Pico da Neblina | 9 | 1547 1547 | São Gabriel da Cachoeira | 8 | 1400 1564 | Santa Isabel do Rio Negro | 8 | 1400 1400 | RIO NEGRO