Пример #1
0
def import_done_trades_data(uid: long):
    DoneTrade.objects(user_id=uid).delete()
    dt = DoneTrade()
    dt.drop_collection()

    dt.user_id = uid
    dt.calculation_start_date = datetime.now()
    dt.timely_trades_count_of_last_3_months = 1
    dt.timely_trades_count_between_last_3_to_12_months = 0
    dt.past_due_trades_count_of_last_3_months = 0
    dt.past_due_trades_count_between_last_3_to_12_months = 0
    dt.arrear_trades_count_of_last_3_months = 0
    dt.arrear_trades_count_between_last_3_to_12_months = 0
    dt.trades_total_balance = 45000000
    dt.total_delay_days = 0
    dt.save()
Пример #2
0
def get_document_by_user_id(doc: object, user_id: bson.ObjectId):
    if doc == DoneTrade.__name__:
        return DoneTrade.objects(user_id=user_id).first()
Пример #3
0
def get_done_trades_for_user(user_id: bson.ObjectId) -> DoneTrade:
    done_trade = DoneTrade.objects(user_id=user_id).first()
    # done_trade = db.doneTrades.find_one({'user_id': 23})
    return done_trade
 def test_get_bulk_data(self):
     done_trades: DoneTrade = DoneTrade.objects(user_id=1).all()
     # print(user.to_json())
     print("all doneTrades are loaded.")
     for dt in done_trades:
         print(dt.to_json())
Пример #5
0
    def calculate_user_undone_trades_score_2(
            self,
            user_id: long,
            reset_cache=False,
            undone_trade_object: UndoneTrade = None,
            done_trade_object: DoneTrade = None):
        if undone_trade_object is not None:
            undone_trade = undone_trade_object
        else:
            undone_trade: UndoneTrade = UndoneTrade.objects(
                user_id=user_id).first()

        if done_trade_object is not None:
            done_trade = done_trade_object
        else:
            done_trade: DoneTrade = DoneTrade.objects(user_id=user_id).first()
        rds: RedisCachingRulesUndoneTrades = self.rds.get_redis_caching_rules_undone_trades_service(
            reset_cache)
        undone_trades_score = 0
        normalized_undone_trades_score = 0

        score = rds.get_score_of_rules_undone_undue_trades_counts_h10(
            undone_trade.undue_trades_count)
        # normalized_score = calculate_normalized_score(H10_RULES_UNDONE_UNDUE_TRADES_COUNTS, score)
        # normalized_undone_trades_score += normalized_score
        undone_trades_score += score
        self.scores_dict[HISTORIES_SCORE] = self.scores_dict.get(
            HISTORIES_SCORE) + score
        print('score= {}, undoneTrades:[undue_trades_count-h10]= {}'.format(
            score, undone_trade.undue_trades_count))

        # calculate undue_total_balance_ratio
        undue_total_balance_ratio = float(
            undone_trade.undue_trades_total_balance_of_last_year /
            done_trade.trades_total_balance)
        score = rds.get_score_of_rules_undone_undue_trades_total_balance_of_last_year_ratios_v15(
            undue_total_balance_ratio)
        # normalized_score = calculate_normalized_score(V15_RULES_UNDONE_UNDUE_TRADES_TOTAL_BALANCE_OF_LAST_YEAR_RATIOS, score)
        # normalized_undone_trades_score += normalized_score
        undone_trades_score += score
        self.scores_dict[VOLUMES_SCORE] = self.scores_dict.get(
            VOLUMES_SCORE) + score
        print('score= {}, undoneTrades:[undue_total_balance_ratio-v15]= {}'.
              format(score, undue_total_balance_ratio))

        score = rds.get_score_of_rules_undone_past_due_trades_counts_t26(
            undone_trade.past_due_trades_count)
        # normalized_score = calculate_normalized_score(T26_RULES_UNDONE_PAST_DUE_TRADES_COUNTS, score)
        # normalized_undone_trades_score += normalized_score
        undone_trades_score += score
        self.scores_dict[TIMELINESS_SCORE] = self.scores_dict.get(
            TIMELINESS_SCORE) + score
        print('score= {}, undoneTrades:[past_due_trades_count-t26]= {}'.format(
            score, undone_trade.past_due_trades_count))

        timely_done_trades_of_last_year = (
            done_trade.timely_trades_count_of_last_3_months +
            done_trade.timely_trades_count_between_last_3_to_12_months)
        # calculate past_due_total_balance_ratio
        past_due_total_balance_ratio = float(
            undone_trade.past_due_trades_total_balance_of_last_year /
            done_trade.trades_total_balance)
        score = rds.get_score_of_rules_undone_past_due_trades_total_balance_of_last_year_ratios_v13(
            past_due_total_balance_ratio)
        score_code = rds.get_code_of_rules_undone_past_due_trades_total_balance_of_last_year_ratios_v13(
            past_due_total_balance_ratio)
        if timely_done_trades_of_last_year == 1 and score_code == SCORE_CODE_RULES_UNDONE_PAST_DUE_TRADES_TOTAL_BALANCE_OF_LAST_YEAR_RATIOS:
            score *= 2

        # normalized_score = calculate_normalized_score(V13_RULES_UNDONE_PAST_DUE_TRADES_TOTAL_BALANCE_OF_LAST_YEAR_RATIOS, score)
        # normalized_undone_trades_score += normalized_score
        undone_trades_score += score
        self.scores_dict[VOLUMES_SCORE] = self.scores_dict.get(
            VOLUMES_SCORE) + score
        print('score= {}, undoneTrades:[past_due_total_balance_ratio-v13]= {}'.
              format(score, past_due_total_balance_ratio))

        score = rds.get_score_of_rules_undone_arrear_trades_counts_t27(
            undone_trade.arrear_trades_count)
        # normalized_score = calculate_normalized_score(T27_RULES_UNDONE_ARREAR_TRADES_COUNTS, score)
        # normalized_undone_trades_score += normalized_score
        undone_trades_score += score
        self.scores_dict[TIMELINESS_SCORE] = self.scores_dict.get(
            TIMELINESS_SCORE) + score
        print('score= {}, undoneTrades:[arrear_trades_count-t27]= {}'.format(
            score, undone_trade.arrear_trades_count))

        # calculate arrear_total_balance_ratio
        arrear_total_balance_ratio = float(
            undone_trade.arrear_trades_total_balance_of_last_year /
            done_trade.trades_total_balance)
        score = rds.get_score_of_rules_undone_arrear_trades_total_balance_of_last_year_ratios_v14(
            arrear_total_balance_ratio)
        score_code = rds.get_code_of_rules_undone_arrear_trades_total_balance_of_last_year_ratios_v14(
            arrear_total_balance_ratio)
        if timely_done_trades_of_last_year == 1 and score_code == SCORE_CODE_RULES_UNDONE_ARREAR_TRADES_TOTAL_BALANCE_OF_LAST_YEAR_RATIOS:
            score *= 2
        # normalized_score = calculate_normalized_score(V14_RULES_UNDONE_ARREAR_TRADES_TOTAL_BALANCE_OF_LAST_YEAR_RATIOS, score)
        # normalized_undone_trades_score += normalized_score
        undone_trades_score += score
        self.scores_dict[VOLUMES_SCORE] = self.scores_dict.get(
            VOLUMES_SCORE) + score
        print('score= {}, undoneTrades:[arrear_total_balance_ratio-v14]= {}'.
              format(score, arrear_total_balance_ratio))

        # print('............. undoneTrades_score = {} , normalized_score = {} ................\n'.format(undone_trades_score,
        # normalized_undone_trades_score))

        print('............. undoneTrades_score = {} ................'.format(
            undone_trades_score))
        print(
            '... IDENTITIES_SCORE= {} , HISTORIES_SCORE= {}, VOLUMES_SCORE= {}, TIMELINESS_SCORE= {} \n'
            .format(self.scores_dict.get(IDENTITIES_SCORE),
                    self.scores_dict.get(HISTORIES_SCORE),
                    self.scores_dict.get(VOLUMES_SCORE),
                    self.scores_dict.get(TIMELINESS_SCORE)))
        return undone_trades_score