group = [
    {"id": 1024, "fullname": "Тимченко Дмитрий",    "email": "dmt.tym@gmail.com", "github": "https://github.com/TymDmitriy", "rank": 0},
    {"id": 1025, "fullname": "Юношев Павел",        "email": "p.n.yunoshev@gmail.com", "github": "", "rank": 0},
    {"id": 1026, "fullname": "Лукшин Евгений",      "email": "otis01990@gmail.com", "github": "https://github.com/EugeneSchweiger", "rank": 0},
    {"id": 1027, "fullname": "Сеченова Анна",       "email": "sechenovaanna@gmail.com", "github": "https://github.com/AnnaSechenova", "rank": 0},
    {"id": 1028, "fullname": "Квято Сергей",        "email": "skvantos@gmail.com", "github": "https://github.com/kvantos/", "rank": 0},
    {"id": 1029, "fullname": "Кань Евгений",        "email": "suckrat.us1337@gmail.com", "github": "https://github.com/suckratus", "rank": 0},
    {"id": 1030, "fullname": "Лавренко Евгений",    "email": "superlavrik@gmail.com", "github": "https://github.com/SuperLavrik", "rank": 0},
    {"id": 1031, "fullname": "Кирсанов Илья",       "email": "ilya.kirsanov@gmail.com", "github": "https://github.com/IlyaKirsanov", "rank": 0},
    {"id": 1032, "fullname": "Жолондковский Вадим", "email": "vadymzholondkovskiy@gmail.com", "github": "", "rank": 0},
    {"id": 1033, "fullname": "Марченко Вадим",      "email": "wardomir@gmail.com", "github": "", "rank": 0},
    {"id": 1034, "fullname": "Митев Алексей",       "email": "oleksii.mitiev@gmail.com", "github": "https://github.com/omitiev", "rank": 0},
    {"id": 1035, "fullname": "Якутко Анастасия",    "email": "anastasiia.yakutko@gmail.com", "github": "https://github.com/ayakutko/HW_1_6", "rank": 0},
    {"id": 1036, "fullname": "Каменцев Никита",     "email": "niqkamentsev@gmail.com", "github": "https://github.com/TheNiq", "rank": 0},
    {"id": 1037, "fullname": "Белоус Екатерина",    "email": "katherinebilous@gmail.com", "github": "https://github.com/KateBilous/", "rank": 0},
    {"id": 1038, "fullname": "Друмов Вадим",        "email": "vkdrumov@gmail.com", "github": "https://github.com/Vkdrumov", "rank": 0},
]

hw_results = [
    {"id":1024, "task_completion": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0]},
    {"id":1025, "task_completion": [1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},
    {"id":1026, "task_completion": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0]},
    {"id":1027, "task_completion": [1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},
    {"id":1028, "task_completion": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0]},
    {"id":1029, "task_completion": [1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},
    {"id":1030, "task_completion": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0]},
    {"id":1031, "task_completion": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0]},
    {"id":1032, "task_completion": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},
    {"id":1033, "task_completion": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0]},
    {"id":1034, "task_completion": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0]},
    {"id":1035, "task_completion": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},
    {"id":1036, "task_completion": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0]},
    {"id":1037, "task_completion": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},
    {"id":1038, "task_completion": [1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},
]


test1_results = [
    {"id": 1024, "task_completion": [1,1,1,1,1,1,1,1,1,1,0,0] },
    {"id": 1025, "task_completion": [0,0,0,0,0,0,0,0,0,0,0,0] },
    {"id": 1026, "task_completion": [1,1,1,1,1,1,1,1,1,1,1,1] },
    {"id": 1027, "task_completion": [0,0,0,0,0,0,0,0,0,0,0,0] },
    {"id": 1028, "task_completion": [1,1,1,1,1,1,1,1,1,1,1,1] },
    {"id": 1029, "task_completion": [0,0,0,0,0,0,0,0,0,0,0,0] },
    {"id": 1030, "task_completion": [0,0,0,0,0,0,0,0,0,0,0,1] },
    {"id": 1031, "task_completion": [1,1,1,1,1,1,0,0,0,0,0,0] },
    {"id": 1032, "task_completion": [0,0,0,0,0,0,0,0,0,0,0,0] },
    {"id": 1033, "task_completion": [1,1,1,1,1,1,1,1,1,1,1,0] },
    {"id": 1034, "task_completion": [0,0,0,0,0,0,0,0,0,0,0,0] },
    {"id": 1035, "task_completion": [0,0,0,0,0,0,0,0,0,0,0,0] },
    {"id": 1036, "task_completion": [0,0,0,0,0,0,0,0,0,0,0,0] },
    {"id": 1037, "task_completion": [0,0,0,0,0,0,0,0,0,0,0,0] },
    {"id": 1038, "task_completion": [0,0,0,0,0,0,0,0,0,0,0,0] },
]


test1_weights = {
    1 : 1,
    2 : 1,
    3 : 1,
    4 : 2,
    5 : 2,
    6 : 2,
    7 : 4,
    8 : 4,
    9 : 4,
    10 : 8,
    11 : 8,
    12 : 15
}


def update_students_results(group):
    for student in group:
        for tests_st_result in test1_results:
            if tests_st_result["id"] == student["id"]:
                st_tests_sum = 0
                for idx, elem in enumerate(tests_st_result["task_completion"]):
                    st_tests_sum += elem * test1_weights.get(idx+1)

        for hw_st_result in hw_results:
            if hw_st_result["id"] == student["id"]:
                st_hw_sum = 0
                for elem in hw_st_result["task_completion"]:
                    st_hw_sum += elem

        student["rank"] = st_hw_sum + st_tests_sum




update_students_results(group)
# for student in group:
#     print(student)
#     print("----")



planets = {'moon' : 131354, 'earth': 345778 , 'mars' : 47789, 'venus' : 4679339}
planets_2 = {'moon' : (10, 1), 'earth': (6, 2) , 'mars' : (8, 3), 'venus' : (7, 4)}

# def get_value_by_keyue_by_key_2(key):
#     return planets_2[key][1]
#
# l = []
#
# for key in sorted(planets_2.keys(), key=get_value_by_keyue_by_key_2, reverse=True):
#     print(key, '->', planets_2[key])

# planets_3 = [{'name' : 8, 'distance' : 4},
#              {'name': 6, 'distance' : 21},
#              {'name' :9, 'distance' : 3},
#              {'name' : 10, 'distance' : 4}]
#
# def get_value_by_key_3(key='distance'):
#     for planet in planets_3:
#         return(planet[key])

# planets_sorted = sorted(planets_3, key=lambda x: x['name'])
# print(planets_sorted)
# print(planets_3.sort(key=get_value_by_key_3()))

# lod = [{'k': 1, 'v': 2}, {'k': 4, 'v': 5}, {'k': 3, 'v': 4}, {'k': 2, 'v': 3}]
# print sorted(lod, key=lambda x: x['k'])

# for key in sorted(planets_3.key(), key=get_value_by_key_3, reverse=True):
#     print(key, '->', planets_2[key])
# print(planets_3)

def print_students_info(group, key1="fullname"):
    group_sorted = sorted(group, key=lambda x: x[key1])
    for student in group_sorted:
        st_github_short = student["github"][int(student["github"].rfind('/'))+1:]
        print ("----------------------------")
        print ("ID                      %d " % student['id'])
        print ("............................")
        print("Full name: %s" % student['fullname'])
        print("Email: %s" % student['email'])
        print("Github: %s" % st_github_short)
        print("Rank:                     %s" % student["rank"])
        print("----------------------------")
        print()




x = print_students_info(group)
print(x)


    # '''
    # Prints students info sorted according to the passed key in dictionary). By default, sort by students names.
    # Student info should be presented as a card that includes the following information:
    #     - id,
    #     - name,
    #     - email,
    #     - github account (only name, not URL path)
    #     - rank
    # Example (format is not strictly required):
    #     -----------------------------------------
    #     : ID:                               1025:
    #     :.......................................:
    #     : Full name:                Юношев Павел:
    #     : Email:          p.n.yunoshev@gmail.com:
    #     : Github:                               :
    #     : Rank:                               42:
    #     -----------------------------------------
    # :return: None
    # '''
    # pass
#
# if __name__ == "__main__":
#     update_students_results(group)
#     print_students_info(group, "rank")