def test_import_score_time_series_bulk_data(self):
     db = get_db()
     db.scoreTimeSeries.delete_many({})
     score = 330
     for i in range(365):
         d = jdatetime.timedelta(days=365 - i)
         score_date = datetime.today().__sub__(d)
         # score_date = dateutil.parser.parse(score_date.isoformat())
         if i <= 30:
             score += 1
         elif i <= 50:
             score -= 1
         elif i <= 80:
             score += 1
         elif i <= 99:
             score = score
         elif i <= 115:
             score = score
         elif i <= 140:
             score += 1
         elif i <= 160:
             score -= 1
         elif i <= 190:
             score = score
         elif i <= 260:
             score += 1
         elif i <= 285:
             score = score
         elif i <= 325:
             score -= 1
         elif i <= 365:
             score += 1
         db.scoreTimeSeries.insert_one(
             dict(
                 ScoreTimeSeries(user_id=1,
                                 score_date=score_date,
                                 score=score)))
         print(
             'ScoreTimeSeries(user_id:{}, score_date:{}, score:{}) is inserted.'
             .format(1, score_date, score))
import random
from datetime import date

from app.core.database import get_db
from app.core.models.profile import Profile
from app.core.models.scoring_enums import ProfileMilitaryServiceStatusEnum
from app.core.services.data_service import DataService

if __name__ == '__main__':
    ds = DataService(get_db())
    ds.delete_profiles({})
    for i in range(2):
        p = Profile(user_id=int(100 + i))
        p.has_kyc = 1
        p.military_service_status = ProfileMilitaryServiceStatusEnum.FINISHED
        p.sim_card_ownership = 1
        p.address_verification = 1
        p.membership_date = date.today()
        p.recommended_to_others_count = 23
        p.star_count_average = 1

        p.identities_score = random.randint(0, 100)  # 10%
        p.histories_score = random.randint(0, 300)  # 30%
        p.volumes_score = random.randint(0, 250)  # 25%
        p.timeliness_score = random.randint(0, 350)  # 35%
        p.score = p.identities_score + p.histories_score + p.volumes_score + p.timeliness_score
        ds.insert_profile(p)

        # Test aggregation pipeline run performance
        # pipeline = generate_scores_distributions_pipeline(0, 1000, 20)
        # ref: CommandCursor = ds.db.profiles.aggregate(pipeline)
from app.core.data.import_history_rules_data import import_rules_histories
from app.core.data.import_identity_rules_data import import_rules_identities
from app.core.data.import_score_gauges_data import import_score_gauges
from app.core.data.import_timeliness_rules_data import import_rules_timeliness
from app.core.data.import_volume_rules_data import import_rules_volumes
from app.core.database import get_db
from app.core.services.data_service import DataService


def import_rules(ds: DataService):
    import_score_gauges(ds)
    import_rules_identities(ds)
    import_rules_histories(ds)
    import_rules_volumes(ds)
    import_rules_timeliness(ds)


if __name__ == '__main__':
    import_rules(DataService(get_db()))
Example #4
0
    ds.insert_rule(rule)
    rule_codes: List[str] = [rule.code]

    # AddressVerification = No	00	I0402P0 0%	عدم احراز اصالت نشانی محل سکونت کاربر
    rule = create_new_rule(
        3, 'I4', 'I0402P0',
        'تطابق هویت واقعی کاربر با مشخصات مالک خط تلفن همراه در سامانه شاهکار',
        0, 0, 0)
    ds.insert_rule(rule)
    rule_codes.append(rule.code)
    print('Identities(I) address_verifications_i4 rules are created.')
    ds.delete_score_reasons(
        {RULE_MASTER_CODE: I4_RULES_PROFILE_ADDRESS_VERIFICATIONS})
    change_reason = create_new_score_reason(
        I4_RULES_PROFILE_ADDRESS_VERIFICATIONS, rule_codes,
        'تایید نشانی محل سکونت', 'عدم تایید نشانی محل سکونت')
    ds.insert_score_reason(change_reason)
    print('Identities(I) address_verifications_i4 change reasons are created.')


def import_rules_identities(ds: DataService):
    import_rule_identity_master(ds)
    import_rules_identity_has_kycs_i1(ds)
    import_rules_identity_military_service_status_i2(ds)
    import_rules_identity_sim_card_ownerships_i3(ds)
    import_rules_identity_address_verifications_i4(ds)


if __name__ == '__main__':
    import_rules_identities(DataService(get_db()))

if __name__ == '__main__':
    dates = [
        jdatetime.date(1399, 11, 13, locale=PERSIAN_LOCALE).togregorian(),
        jdatetime.date(1399, 11, 19, locale=PERSIAN_LOCALE).togregorian(),
        jdatetime.date(1399, 11, 24, locale=PERSIAN_LOCALE).togregorian(),
        # jdatetime.date(1398, 11, 29, locale=PERSIAN_LOCALE).togregorian(),
        # jdatetime.date(1398, 12, 4, locale=PERSIAN_LOCALE).togregorian(),
        # jdatetime.date(1398, 12, 9, locale=PERSIAN_LOCALE).togregorian(),
    ]
    # dt_time = datetime.now()
    dt_time = datetime(year=2021,
                       month=2,
                       day=2,
                       hour=13,
                       minute=23,
                       second=59)
    print('now={}'.format(dt_time))
    # to_int_1 = int(round(dt_time.timestamp() * 1000))
    to_int_1 = convert_date_to_milliseconds_since_epoch(dt_time)
    print('to_int_1:{}'.format(to_int_1))
    f = 10000 * dt_time.year + 100 * dt_time.month + dt_time.day
    print('to_int_2:{}'.format(f))
    pipeline = generate_score_changes_max_in_month_interval_pipeline(dates)
    r: CommandCursor = get_db().get_collection('scoreChanges').aggregate(
        pipeline)
    r_dict: {} = r.next()
    for k in r_dict.keys():
        print('{}:{}'.format(k, r_dict[k]))
Example #6
0
    rule_codes.append(rule.code)

    # Loans = 5	-30	H1106N30	کاربر ۵ تسهیلات در جریان دارد
    rule = create_new_rule(3, 'H11', 'H1106N30', 'کاربر ۵ تسهیلات در جریان دارد', 3.33, -30, 5, 5)
    ds.insert_rule(rule)
    rule_codes.append(rule.code)

    # Loans >= 6	-50	H1107N50	کاربر بیش از ۵ تسهیلات در جریان دارد
    rule = create_new_rule(3, 'H11', 'H1107N50', 'کاربر بیش از ۵ تسهیلات در جریان دارد', 5.56, -50, 6, rules_max_val)
    ds.insert_rule(rule)
    rule_codes.append(rule.code)
    print('Histories(H) loans_total_count_h11 rules are created.')
    change_reason = create_new_score_reason(H11_RULES_LOAN_TOTAL_COUNTS, rule_codes, 'کاهش تعداد تسهیلات بانکی در جریان', 'افزایش تعداد تسهیلات بانکی در جریان')
    ds.insert_score_reason(change_reason)
    print('Histories(H) loans_total_count_h11 part-2 change reasons are created.')


def import_rules_histories(ds: DataService):
    import_rule_history_master(ds)
    import_rules_history_membership_days_counts_h5(ds)
    import_rules_history_done_timely_trades_of_last_3_months_h6(ds)
    import_rules_history_done_timely_trades_between_last_3_to_12_months_h7(ds)
    import_rules_history_recommended_to_others_counts_h8(ds)
    import_rules_history_star_counts_avgs_h9(ds)
    import_rules_history_undone_undue_trades_counts_h10(ds)
    import_rules_history_loans_total_count_h11(ds)


if __name__ == '__main__':
    import_rules_histories(DataService(get_db()))
    sg.risk_status = 'بالا'
    ds.insert_score_gauge(sg)

    sg = ScoreGauge()
    sg.start = 590
    sg.end = 669
    sg.title = 'متوسط'
    sg.color = 'ffbb5e'
    sg.risk_status = 'متوسط'
    ds.insert_score_gauge(sg)

    sg = ScoreGauge()
    sg.start = 670
    sg.end = 749
    sg.title = 'خوب'
    sg.color = 'a6d94c'
    sg.risk_status = 'پایین'
    ds.insert_score_gauge(sg)

    sg = ScoreGauge()
    sg.start = 750
    sg.end = 1000
    sg.title = 'عالی'
    sg.color = '00d184'
    sg.risk_status = 'بسیار پایین'
    ds.insert_score_gauge(sg)


if __name__ == '__main__':
    import_score_gauges(DataService(get_db()))
Example #8
0
 def __init__(self, db: Database = None) -> None:
     super().__init__()
     self.db = get_db() if db is None else db
Example #9
0
    rule = create_new_rule(3, 'T35', 'T3505N50', 'کاربر بیش از ۳ تسهیلات مشکوک الوصول دارد', 6.48, -50, 4, rules_max_val)
    ds.insert_rule(rule)
    rule_codes.append(rule.code)
    print('Timeliness(T) suspicious_loans_total_count_t35 rules are created.')
    ds.delete_score_reasons({RULE_MASTER_CODE: T35_RULES_LOAN_SUSPICIOUS_TOTAL_COUNTS})
    change_reason = create_new_score_reason(T35_RULES_LOAN_SUSPICIOUS_TOTAL_COUNTS, rule_codes, 'کاهش تعداد تسهیلات مشکوک الوصول در جریان', 'افزایش تعداد تسهیلات مشکوک الوصول در جریان')
    ds.insert_score_reason(change_reason)
    print('Timeliness(T) suspicious_loans_total_count_t35 change reasons are created.')


def import_rules_timeliness(ds: DataService):
    import_rule_timeliness_master(ds)
    import_rules_timeliness_arrear_loans_total_count_t34(ds)
    import_rules_timeliness_done_arrear_trades_between_last_3_to_12_months_t25(ds)
    import_rules_timeliness_done_arrear_trades_of_last_3_months_t24(ds)
    import_rules_timeliness_done_past_due_trades_between_last_3_to_12_months_t23(ds)
    import_rules_timeliness_done_past_due_trades_of_last_3_months_t22(ds)
    import_rules_timeliness_done_trades_average_delay_days_ratios_t28(ds)
    import_rules_timeliness_past_due_loans_total_count_t33(ds)
    import_rules_timeliness_suspicious_loans_total_count_t35(ds)
    import_rules_timeliness_undone_arrear_trades_counts_t27(ds)
    import_rules_timeliness_undone_past_due_trades_counts_t26(ds)
    import_rules_timeliness_unfixed_returned_cheques_count_between_last_3_to_12_months_t30(ds)
    import_rules_timeliness_unfixed_returned_cheques_count_of_last_3_months_t29(ds)
    import_rules_timeliness_unfixed_returned_cheques_count_of_last_5_years_t32(ds)
    import_rules_timeliness_unfixed_returned_cheques_count_of_more_12_months_t31(ds)


if __name__ == '__main__':
    import_rules_timeliness(DataService(get_db()))