コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
7634 ビュー

Hello,

I'm trying to create a graph bar view : My problem is that when I use a fields.function to calculate datas, the values are not right and it seems that the fields.function is not called! But when I use a simple fields.integer, it works fine.

To be sure that my fields.function is correctly defined and the calculation is good, I added it to the form view and it works fine.

Lastly, if I add store=True to the fields.function, it works, but I don't want to store the calculated data in the DataBase.

Thanks for your help.

 

 

 

 

アバター
破棄
最善の回答

Well, you had the right idea by storing the value.  Unfortunately, right now, it is the only solution.

 

The way the graph view gets its data is by calling the read_group method in the ORM.  That method will collect the data from the database.  This means that the aggregation (sum) is done by postgres (and is very fast) instead of being done by the python code (not so fast).

 

So, right now, the design of the graph view makes it impossible to aggregate functional fields if they are not stored.  A possible solution is to add a controller to the graph view.  That controller could call read_group itself, then, perform additional requests to the database to aggregate manually on all non stored functional fields.  It would probably be much slower, but the additional functionality might be worth it.

 

 

アバター
破棄

@GED: can you explain how to create controller for graph view? If possible give one example. Thank you.

i could, but this would be quite involved. It is a non trivial task, and of course, I don't have so much time. Doing this would require adding a controller which will acts as a specialized read_group, calling read_group when possible, and aggregating the data when a functional field is not stored, then the graph view could in theory call that controller instead of readgroup. However, (1) that controller would be difficult to program, because the groupbys could be any combinaison of functional fields and normal fields, and you want to use the native read_group as much as possible, (2) I am not sure that this is a good idea performance wise. It will probably be too slow (and too cpu/memory hungry) when aggregating millions of rows.

関連投稿 返信 ビュー 活動
1
3月 15
3723
0
7月 16
4749
1
3月 15
4847
3
8月 19
7335
2
5月 18
27266