Skip to content
Jop Molenaar edited this page Jun 19, 2024 · 5 revisions

Person

File: Meesterproef-SNSimulation/js/Person.js

Description

The Person class represents a person node in the network. It extends the Node class and includes additional properties and methods specific to a person, such as managing friends, items, info links, and social interactions.

Variables

The function of these variables is to change the behavior of the persons (nodes).

    acceptanceDisctance = 300; //The distance in px to decide if the person likes or dislikes a post. The bigger it is, the more post get liked
    stepDistance = 5; // The factor decide the distance that a node travels in a step 
    addInfoLinkThreshold = 3; // The score that is required for an friendLink to become an infoLink
    removeFriendLinkThreshold = -2; // The score that is required to break the friendship between friends
    removeInfoLinkThreshold = -5; // The score that is required to break the infoLink between friends
    defaultRelationshipScore = 1; // Default score between friends

Methods

  • readSocialMediaPost(nodes, links): Chooses a random social media post to read, calculates a score for it, and adds it to the person's items.

    • Parameters:
      • nodes (Map): The map of nodes in the network.
      • links (Map): The map of links in the network.
    • View Code
  • forwardSocialMediaPost(links): Forwards a social media post to the person's friends if the score of the post is positive.

    • Parameters:
      • links (Map): The map of links in the network.
    • View Code
  • receiveSocialMediaPost(sender, post, relationshipScore, links): Receives a forwarded social media post from a friend or info link and calculates a score for it.

    • Parameters:
      • sender (Person): The person who sent the post.
      • post (Post): The social media post being received.
      • relationshipScore (number): The relationship score between the sender and the receiver.
      • links (Map): The map of links in the network.
    • View Code
  • calculateScore(myScore, post): Calculates the score of a post for the person based on the distance to the post.

    • Parameters:
      • myScore (number): The initial score of the post.
      • post (Post): The social media post.
    • Returns: number - The calculated score.
    • View Code
  • manageRelationships(links): Manages relationships with friends and info links, adding or removing links based on scores.

    • Parameters:
      • links (Map): The map of links in the network.
    • View Code
  • addFriendThroughContent(links): Adds friends through shared content.

    • Parameters:
      • links (Map): The map of links in the network.
    • View Code
  • moveNode(links): Moves the node to a new position based on the average position of friends, info links, and items.

    • Parameters:
      • links (Map): The map of links in the network.
    • View Code
  • moveLinks(links): Moves the links connected to this node.

    • Parameters:
      • links (Map): The map of links in the network.
    • View Code
  • findLink(node, links): Finds the link between this node and another node.

    • Parameters:
      • node (Node): The other node to find the link to.
      • links (Map): The map of links in the network.
    • View Code
  • step(nodes, links): Performs all behaviors of the agent in one step.

    • Parameters:
      • nodes (Map): The map of nodes in the network.
      • links (Map): The map of links in the network.
    • View Code
  • spawnForwardButtons(links, filteredEdges): Spawns 'forward' buttons under each read social media post by the currently selected person node.

    • Parameters:
      • links (Map): The map of links in the network.
      • filteredEdges (Array): The list of filtered edges.
    • View Code
  • removeForwardButtons(): Removes all forward buttons from the canvas.

  • addFriend(node, links, score = this.defaultRelationshipScore): Adds a friend link between the currently selected node and the node with the given id.

    • Parameters:
      • node (Node): The node to add as a friend.
      • links (Map): The map of links in the network.
      • score (number): The initial score of the friendship.
    • View Code
  • removeFriend(node, links): Removes a friend link between the currently selected node and the node with the given id.

    • Parameters:
      • node (Node): The node to remove as a friend.
      • links (Map): The map of links in the network.
    • View Code
  • addItemLink(item, from, links, score = 1): Adds an item link between the currently selected node and the node with the given id.

    • Parameters:
      • item (Node): The item to add.
      • from (Node): The node to add the item link from.
      • links (Map): The map of links in the network.
      • score (number): The initial score of the item.
    • View Code
  • removeItemLink(item, links): Removes an item link between the currently selected node and the node with the given id.

    • Parameters:
      • item (Node): The item to remove.
      • links (Map): The map of links in the network.
    • View Code
  • addInfoLink(from, to, links, score = 0): Adds an info link between the currently selected node and the node with the given id.

    • Parameters:
      • from (Node): The node to add the info link from.
      • to (Node): The node to add the info link to.
      • links (Map): The map of links in the network.
      • score (number): The initial score of the info link.
    • View Code
  • removeInfoLink(from, to, links): Removes an info link between the currently selected node and the node with the given id.

    • Parameters:
      • from (Node): The node to remove the info link from.
      • to (Node): The node to remove the info link to.
      • links (Map): The map of links in the network.
    • View Code

Design rational

Clone this wiki locally