Last active
February 17, 2023 07:08
-
-
Save Axik/9db82d9771703b937cdb80377131f3df to your computer and use it in GitHub Desktop.
Код для визначення переможця в зборі ps4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import uuid | |
import math | |
import quantumrandom | |
statement = pd.read_csv('Виписка_по_Банці_N92_30_0019107280_на_2023_02_16.csv') | |
statement_list = statement.to_dict(orient='records') | |
def round_down(n, decimals=0): | |
multiplier = 10 ** decimals | |
return math.floor(n * multiplier) / multiplier | |
def produce_tickets(input_statement_list): | |
lottery_tickets = {} | |
for item in input_statement_list: | |
number_of_tickets = int(round_down(item['Сума'] / 100.0)) | |
for _ in range(number_of_tickets): | |
lottery_tickets[str(uuid.uuid4())] = {'RRN': item['RRN'], 'Опис': item['Опис']} | |
return lottery_tickets | |
def test_produce_tickets(): | |
fixture_record = {'Дата та час': '16.02.2023 18:21:35', | |
'Опис': 'Від: Мото Кроссовіч', | |
'Сума': 200.0, | |
'RRN': 67188942381} | |
fixture_record2 = {'Дата та час': '16.02.2023 18:21:36', | |
'Опис': 'Від: Голуб Голубовіч', | |
'Сума': 350.0, | |
'RRN': 67188942382} | |
fixture_record3 = {'Дата та час': '16.02.2023 18:21:37', | |
'Опис': 'Від: Тест Тестовіч', | |
'Сума': 110.0, | |
'RRN': 67188942383} | |
fixture_record4 = {'Дата та час': '16.02.2023 18:21:38', | |
'Опис': 'Від: Тест Тестовіч', | |
'Сума': 190.0, | |
'RRN': 67188942384} | |
# WHEN I PASS THOSE 4 RECORDS AS A LIST | |
result = produce_tickets([fixture_record, fixture_record2, fixture_record3, fixture_record4]) | |
# SHOULD GET 6 TOTAL NUMBER OF TICKETS | |
assert len(result.keys()) == 7, len(result.keys()) | |
# SHOULD GET 1 TICKET FOR ТЕСТ ТЕСТВІЧ | |
assert len(list(filter(lambda x: x['Опис'] == 'Від: Тест Тестовіч', result.values()))) == 2 | |
# SHOULD GET 2 TICKETS FOR МОТО КРОСОВІЧ | |
assert len(list(filter(lambda x: x['Опис'] == 'Від: Мото Кроссовіч', result.values()))) == 2 | |
# SHOULD GET 3 TICKETS FOR Голуб Голубовіч | |
assert len(list(filter(lambda x: x['Опис'] == 'Від: Голуб Голубовіч', result.values()))) == 3 | |
test_produce_tickets() | |
def random_choice(input_lottery_tickets): | |
tickets = list(input_lottery_tickets.keys()) | |
lucky_number = int(quantumrandom.randint(0, len(tickets))) # py3 compatibility. quantumrandom returns float >.< | |
lucky_ticket_id = tickets[lucky_number] | |
lucky_ticket = input_lottery_tickets[lucky_ticket_id] | |
return lucky_ticket | |
def test_random_choice(): | |
fixture_record = {'Дата та час': '16.02.2023 18:21:35', | |
'Опис': 'Від: Мото Кроссовіч', | |
'Сума': 200.0, | |
'RRN': 67188942381} | |
fixture_record2 = {'Дата та час': '16.02.2023 18:21:36', | |
'Опис': 'Від: Голуб Голубовіч', | |
'Сума': 350.0, | |
'RRN': 67188942382} | |
fixture_record3 = {'Дата та час': '16.02.2023 18:21:37', | |
'Опис': 'Від: Тест Тестовіч', | |
'Сума': 110.0, | |
'RRN': 67188942383} | |
fixture_record4 = {'Дата та час': '16.02.2023 18:21:38', | |
'Опис': 'Від: Тест Тестовіч', | |
'Сума': 190.0, | |
'RRN': 67188942384} | |
# WHEN I PASS THOSE 4 RECORDS AS A LIST | |
fixture_lottery_tickets = produce_tickets([fixture_record, fixture_record2, fixture_record3, fixture_record4]) | |
lucky_ticket = random_choice(fixture_lottery_tickets) | |
assert isinstance(lucky_ticket, dict) | |
assert 'RRN' in lucky_ticket | |
assert 'Опис' in lucky_ticket | |
test_random_choice() | |
tickets = produce_tickets(statement_list) | |
lucky_ticket = random_choice(tickets) | |
print(lucky_ticket) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment