|
@@ -66,7 +66,7 @@ def gen_ranking_sql(entity_type, data_table, indicator_table) {
|
|
|
ranking_num = iif(entity_type IN ['PL', 'CO'], create_mc_indicator_ranking_num(), create_entity_indicator_ranking_num());
|
|
|
|
|
|
if(entity_type IN ['PL', 'CO'])
|
|
|
- v_groupby = ['curve_type', 'category_id', 'end_date'];
|
|
|
+ v_groupby = ['curve_type', 'strategy', 'category_id', 'end_date'];
|
|
|
else
|
|
|
v_groupby = ['category_id', 'end_date'];
|
|
|
|
|
@@ -223,10 +223,13 @@ def prepare_data_for_ranking(ranking_by, entity_type, entity_info, end_date, isF
|
|
|
tb_data_indicator_stats = get_monthly_indicator_data(table_desc.table_name[0], end_date, isFromMySQL);
|
|
|
|
|
|
// 做个大宽表
|
|
|
- if(entity_type IN ['PL', 'CO'])
|
|
|
+ if(entity_type IN ['PL', 'CO']) {
|
|
|
matchingCols = [entity_id_name, 'curve_type', 'strategy', 'end_date'];
|
|
|
- else
|
|
|
+ matchingCols2 = [entity_id_name, 'curve_type', 'strategy', 'end_date', 'factor_id'];
|
|
|
+ } else {
|
|
|
matchingCols = [entity_id_name, 'end_date'];
|
|
|
+ matchingCols2 = [entity_id_name, 'end_date', 'factor_id'];
|
|
|
+ }
|
|
|
tb_data = lj(lj(lj(tb_data_return, tb_data_indicator_stats, matchingCols), tb_data_risk_stats, matchingCols), tb_data_riskadjret_stats, matchingCols);
|
|
|
|
|
|
if(ranking_by == 'bfi') {
|
|
@@ -247,7 +250,6 @@ def prepare_data_for_ranking(ranking_by, entity_type, entity_info, end_date, isF
|
|
|
table_desc = get_bfi_indicator_table_description(entity_type);
|
|
|
tb_data_bfi_indicator = get_monthly_indicator_data(table_desc.table_name[0], end_date, isFromMySQL);
|
|
|
|
|
|
- matchingCols2 = [entity_id_name, 'end_date', 'factor_id'];
|
|
|
tb_data = lj(ej(tb_data, tb_bfi, matchingCols), tb_data_bfi_indicator, matchingCols2);
|
|
|
|
|
|
v_indicator_id = [1, // 对应 fund_performance, 取消39(年化收益) 因为没有意义
|
|
@@ -459,28 +461,46 @@ def save_ranking_tables(entity_type, ranking_by, ranking_tables) {
|
|
|
if(ranking_tables.isVoid()) return;
|
|
|
|
|
|
des_strategy = get_indicator_ranking_table_description(entity_type)[0];
|
|
|
- des_bfi = get_indicator_ranking_table_description(entity_type)[0];
|
|
|
+ des_bfi = get_bfi_bm_indicator_ranking_table_description(entity_type)[0];
|
|
|
|
|
|
entity_id_col = des_strategy.sec_id_col;
|
|
|
-
|
|
|
+
|
|
|
+ t = ranking_tables[0];
|
|
|
if(ranking_by == 'bfi') {
|
|
|
|
|
|
source_table = des_bfi.table_name.strReplace('pfdb', 'raw_db');
|
|
|
target_table = des_bfi.table_name.strReplace('pfdb', 'raw_db');
|
|
|
category_id_col = 'factor_id';
|
|
|
+ t.rename!(['entity_id', 'category_id'], [entity_id_col, category_id_col]);
|
|
|
|
|
|
} else {
|
|
|
source_table = des_strategy.table_name.strReplace('pfdb', 'raw_db');
|
|
|
target_table = des_strategy.table_name.strReplace('pfdb', 'raw_db');
|
|
|
category_id_col = 'strategy';
|
|
|
+
|
|
|
+ // 基金经理和公司自带 strategy 字段,而 category_id 就是 strategy 的复制,所以要去掉
|
|
|
+ // 基金和组合则没有这个字段,将 category_id 改名改回 strategy
|
|
|
+ if(entity_type IN ['PL', 'CO'])
|
|
|
+ t.rename!('entity_id', entity_id_col).dropColumns!('category_id');
|
|
|
+ else
|
|
|
+ t.rename!(['entity_id', 'category_id'], [entity_id_col, category_id_col]);
|
|
|
}
|
|
|
|
|
|
- t = ranking_tables[0];
|
|
|
- save_and_sync(t.rename!(['entity_id', 'category_id'], [entity_id_col, category_id_col]), source_table, target_table);
|
|
|
+ save_and_sync(t, source_table, target_table);
|
|
|
|
|
|
t = ranking_tables[1];
|
|
|
- save_and_sync(t.rename!('category_id', category_id_col), source_table + '_num', target_table + '_num');
|
|
|
+ if(ranking_by == 'bfi') {
|
|
|
+ t.rename!('category_id', category_id_col);
|
|
|
+ } else {
|
|
|
+ if(entity_type IN ['PL', 'CO'])
|
|
|
+ t.dropColumns!('category_id');
|
|
|
+ else
|
|
|
+ t.rename!('category_id', category_id_col);
|
|
|
+ }
|
|
|
+
|
|
|
+ save_and_sync(t, source_table + '_num', target_table + '_num');
|
|
|
|
|
|
+ // 基金有二级策略排名
|
|
|
if(ranking_by == 'strategy' && entity_type IN ['HF', 'MF']) {
|
|
|
|
|
|
source_table = source_table.strReplace('_ranking', '_substrategy_ranking');
|