comp10001-project01/old/part4.py

48 lines
2.1 KiB
Python
Raw Normal View History

# Title: Project 1 - Network Coverage
# Author: Rory Healy
# Date created - 18th April 2019
def besties_coverage(individuals, bestie_dict, relationship_list):
'''Takes a list of people "individuals", stored as strings in a list, a
dictionary of sets of friends "bestie_dict", and a list of functions that
define relationships in the social network, selected from friend_besties
and friend_second_besties. Returns a float that corresponds to the
proportion of individuals who are either a member of individuals or are
connected via a relationship stated in relationship_list.'''
# Calculate the total number of people in the network to calculate the
# proportion.
list_of_people = []
for item in list(bestie_dict.items()):
if item[0] not in list_of_people:
list_of_people.append(item[0])
number_of_people = len(list_of_people)
# Calculates number of people in 'individuals' to calculate the proportion.
number_of_individuals = len(individuals)
# Calculates number of relationships the individual has to calculate the
# proportion.
for i in range(len(individuals)):
number_of_besties = len(friend_besties(individuals[i],
bestie_dict))
number_of_second_besties = len(friend_second_besties(individuals[i],
bestie_dict))
number_of_relationships = 0
if len(relationship_list) == 0:
number_of_relationships = 0
else:
for relationship_type in relationship_list:
if str(relationship_type) == str(friend_besties):
number_of_relationships += number_of_besties
elif str(relationship_type) == str(friend_second_besties):
number_of_relationships += number_of_second_besties
# Returns the proportion as defined in the docstring.
number_of_connections = number_of_relationships + number_of_individuals
coverage_proportion = number_of_connections / number_of_people
return coverage_proportion