public static RoomKey Create(Constants.AttributeType attribute) { RoomKey newKey = Instantiate <GameObject>(Resources.Load <GameObject>("Prefabs/UI/RoomKey")).GetComponent <RoomKey>(); newKey.Attribute = attribute; newKey.transform.SetParent(null); return(newKey); }
public double getDistanceByAttribute(Constants.AttributeType type) { for (int i = 0; i < Distances.Count; i++) { if (Distances[i].Item1.Equals(type)) { return(Distances[i].Item2); } } return(Constants.INVALID_DISTANCE); }
public double getDistance(Constants.AttributeType type = Constants.AttributeType.Net) { try { var targetTuple = Distances.First(a => a.Item1 == type); return(targetTuple.Item2); } catch (System.InvalidOperationException e) { return(Constants.INVALID_DISTANCE); } }
public List <JobAttribute> getAttributesByType(Constants.AttributeType type) { switch (type) { case Constants.AttributeType.Ability: return(Abilities); case Constants.AttributeType.Knowledge: return(Knowledge); case Constants.AttributeType.Skill: return(Skills); default: return(new List <JobAttribute>()); } }
public OccupationAttributeEdge(Constants.AttributeType type, string occupationA, string occupationB, string attribute, double distance) { this.Type = type; this.OccupationA = occupationA; this.OccupationB = occupationB; this.Attribute = attribute; this.Distance = distance; if (occupationA.Length < 1 || occupationB.Length < 1) { isShared = false; } else { isShared = true; } }
public List <OccupationAttributeEdge> getAttributeSimilarityMatrix(Occupation other, Constants.AttributeType type) { var retList = new List <OccupationAttributeEdge>(); List <JobAttribute> listA = getAttributesByType(type); List <JobAttribute> listB = other.getAttributesByType(type); List <JobAttribute> inA_notB = listA.Where(w => !listB.Contains(w)).ToList(); List <JobAttribute> inB_notA = listB.Where(w => !listA.Contains(w)).ToList(); //add attributes shared by both occupations foreach (JobAttribute a in listA) { if (listB.Contains(a)) { JobAttribute b = listB.Single(s => s.Equals(a)); double dist = a.calculateSimilarity(b); retList.Add(new OccupationAttributeEdge(type, this.Name, other.Name, a.Name, dist)); } } //add attributes shared by only one of the occupations foreach (JobAttribute a in inA_notB) { retList.Add(new OccupationAttributeEdge(type, this.Name, "", a.Name, a.getDistance())); } foreach (JobAttribute b in inB_notA) { retList.Add(new OccupationAttributeEdge(type, "", other.Name, b.Name, b.getDistance())); } return(retList); }
public void SetRoom(Constants.AttributeType attribute) { this.SelectedAttribute = attribute; VisitorManager.Instance.OnRoomSelected(); }
public static void writeGraphHTML(ONETReport forkReport, int numberOfOccupations, Constants.AttributeType type, string FileName, string FileType = ".html") { string a = ""; //Random random = new Random(); string fileName = Helper.Publics.FILEPATHS.PATH_FORK_HTML + FileName + FileType; double maxDist = 0; foreach (OccupationEdge edge in forkReport.OccupationEdges) { if (edge.getDistanceByAttribute(type) > maxDist) { maxDist = edge.getDistanceByAttribute(type); } } FileStream fcreate = File.Open(fileName, FileMode.Create); using (StreamWriter writer = new StreamWriter(fcreate)) { writer.WriteLine("<!DOCTYPE html>"); writer.WriteLine("<meta charset = " + quote + "utf-8" + quote + ">"); writer.WriteLine("<svg width = " + quote + "100%" + quote + " height = " + quote + "100%" + quote + "></svg>"); writer.WriteLine("<script src = " + quote + "https://d3js.org/d3.v4.min.js" + quote + "></script>"); writer.WriteLine("<script>"); writer.WriteLine("var baseNodes = ["); int occLevel; for (int i = 0; i < numberOfOccupations - 1; i++) { if ((int)forkReport.MasterOccupationList[i].Zone >= 4) { occLevel = 1; } else { occLevel = 2; } writer.WriteLine("{id: " + quote + forkReport.MasterOccupationList[i].Name.Replace(" ", "") + quote + ", group: " + (int)forkReport.MasterOccupationList[i].Zone + ", label: " + quote + forkReport.MasterOccupationList[i].Name + quote + ", level: " + occLevel + "},"); } int j = numberOfOccupations - 1; if ((int)forkReport.MasterOccupationList[j].Zone >= 4) { occLevel = 1; } else { occLevel = 2; } writer.WriteLine("{id: " + quote + forkReport.MasterOccupationList[j].Name.Replace(" ", "") + quote + ", group: " + (int)forkReport.MasterOccupationList[j].Zone + ", label: " + quote + forkReport.MasterOccupationList[j].Name + quote + ", level: " + occLevel + "}"); /* * writer.WriteLine("{id: " + quote + "mammal" + quote + ", group: 0, label: " + quote + "Mammals" + quote + ", level: 1},"); * writer.WriteLine("{id: " + quote + "dog" + quote + " , group: 0, label: " + quote + "Dogs" + quote + " , level: 2},"); * writer.WriteLine("{id: " + quote + "fish" + quote + " , group: 2, label: " + quote + "Fish" + quote + " , level: 1},"); * writer.WriteLine("{id: " + quote + "carp" + quote + " , group: 2, label: " + quote + "Carp" + quote + " , level: 2},"); * writer.WriteLine("{id: " + quote + "pike" + quote + " , group: 2, label: " + quote + "Pikes" + quote + " , level: 2}"); */ writer.WriteLine("]"); writer.WriteLine("var baseLinks = ["); for (int i = 0; i < forkReport.OccupationEdges.Count - 1; i++) { writer.WriteLine("{target: " + quote + forkReport.OccupationEdges[i].OccupationAName.Replace(" ", "") + quote + ", source: " + quote + forkReport.OccupationEdges[i].OccupationBName.Replace(" ", "") + quote + " , strength: " + Math.Round(forkReport.OccupationEdges[i].getDistanceByAttribute(type) / maxDist, 3) + "},"); } j = forkReport.OccupationEdges.Count - 1; writer.WriteLine("{target: " + quote + forkReport.OccupationEdges[j].OccupationAName.Replace(" ", "") + quote + ", source: " + quote + forkReport.OccupationEdges[j].OccupationBName.Replace(" ", "") + quote + " , strength: " + Math.Round(forkReport.OccupationEdges[j].getDistanceByAttribute(type) / maxDist, 3) + "}"); /* * writer.WriteLine("{target: " + quote + "mammal" + quote + ", source: " + quote + "dog" + quote + " , strength: 0.7},"); * writer.WriteLine(" {target: " + quote + "mammal" + quote + ", source: " + quote + "cat" + quote + " , strength: 0.7},"); * writer.WriteLine("{target: " + quote + "fox" + quote + " , source: " + quote + "ant" + quote + " , strength: 0.1},"); * writer.WriteLine(" {target: " + quote + "pike" + quote + " , source: " + quote + "cat" + quote + " , strength: 0.1}"); */ writer.WriteLine("]"); writer.WriteLine("var nodes = [...baseNodes]"); writer.WriteLine("var links = [...baseLinks]"); writer.WriteLine("function getNeighbors(node)"); writer.WriteLine("{"); writer.WriteLine("return baseLinks.reduce(function(neighbors, link) {"); writer.WriteLine("if (link.target.id === node.id)"); writer.WriteLine("{"); writer.WriteLine("neighbors.push(link.source.id)"); writer.WriteLine("}"); writer.WriteLine("else if (link.source.id === node.id)"); writer.WriteLine("{"); writer.WriteLine("neighbors.push(link.target.id)"); writer.WriteLine("}"); writer.WriteLine("return neighbors"); writer.WriteLine("},"); writer.WriteLine("[node.id]"); writer.WriteLine(")"); writer.WriteLine("}"); writer.WriteLine("function isNeighborLink(node, link)"); writer.WriteLine("{"); writer.WriteLine("return link.target.id === node.id || link.source.id === node.id"); writer.WriteLine("}"); writer.WriteLine("function getNodeColor(node, neighbors)"); writer.WriteLine("{"); writer.WriteLine("if (Array.isArray(neighbors) && neighbors.indexOf(node.id)> -1)"); writer.WriteLine("{"); writer.WriteLine("return node.level === 1 ? " + quote_single + "blue" + quote_single + " : " + quote_single + "green" + quote_single + ""); writer.WriteLine("}"); writer.WriteLine("return node.level === 1 ? " + quote_single + "red" + quote_single + " : " + quote_single + "gray" + quote_single + ""); writer.WriteLine("}"); writer.WriteLine("function getLinkColor(node, link)"); writer.WriteLine("{"); writer.WriteLine("return isNeighborLink(node, link) ? " + quote_single + "green" + quote_single + " : " + quote_single + "#E5E5E5" + quote_single + ""); writer.WriteLine("}"); writer.WriteLine("function getTextColor(node, neighbors)"); writer.WriteLine("{"); writer.WriteLine("return Array.isArray(neighbors) && neighbors.indexOf(node.id)> -1 ? " + quote_single + "green" + quote_single + " : " + quote_single + "black" + quote_single + ""); writer.WriteLine("}"); writer.WriteLine("var width = window.innerWidth"); writer.WriteLine("var height = window.innerHeight"); writer.WriteLine("var svg = d3.select(" + quote_single + "svg" + quote_single + ")"); writer.WriteLine("svg.attr(" + quote_single + "width" + quote_single + ", width).attr(" + quote_single + "height" + quote_single + ", height)"); writer.WriteLine("var linkElements,"); writer.WriteLine("nodeElements,"); writer.WriteLine("textElements"); writer.WriteLine("var linkGroup = svg.append(" + quote_single + "g" + quote_single + ").attr(" + quote_single + "class" + quote_single + ", " + quote_single + "links" + quote_single + ")"); writer.WriteLine("var nodeGroup = svg.append(" + quote_single + "g" + quote_single + ").attr(" + quote_single + "class" + quote_single + ", " + quote_single + "nodes" + quote_single + ")"); writer.WriteLine("var textGroup = svg.append(" + quote_single + "g" + quote_single + ").attr(" + quote_single + "class" + quote_single + ", " + quote_single + "texts" + quote_single + ")"); writer.WriteLine("var selectedId"); writer.WriteLine("var linkForce = d3"); writer.WriteLine(".forceLink()"); writer.WriteLine(".id(function(link) {return link.id})"); writer.WriteLine(".strength(function (link) {return link.strength})"); writer.WriteLine("var simulation = d3"); writer.WriteLine(".forceSimulation()"); writer.WriteLine(".force(" + quote_single + "link" + quote_single + ", linkForce)"); writer.WriteLine(".force(" + quote_single + "charge" + quote_single + ", d3.forceManyBody().strength(-120))"); writer.WriteLine(".force(" + quote_single + "center" + quote_single + ", d3.forceCenter(width / 2, height / 2))"); writer.WriteLine("var dragDrop = d3.drag().on(" + quote_single + "start" + quote_single + ", function(node) {"); writer.WriteLine("node.fx = node.x"); writer.WriteLine("node.fy = node.y"); writer.WriteLine("}).on(" + quote_single + "drag" + quote_single + ", function (node) {"); writer.WriteLine("simulation.alphaTarget(0.7).restart()"); writer.WriteLine("node.fx = d3.event.x"); writer.WriteLine("node.fy = d3.event.y"); writer.WriteLine("}).on(" + quote_single + "end" + quote_single + ", function (node) {"); writer.WriteLine("if (!d3.event.active) {"); writer.WriteLine("simulation.alphaTarget(0)"); writer.WriteLine("}"); writer.WriteLine("node.fx = null"); writer.WriteLine("node.fy = null"); writer.WriteLine("})"); writer.WriteLine("function selectNode(selectedNode)"); writer.WriteLine("{"); writer.WriteLine("if (selectedId === selectedNode.id)"); writer.WriteLine("{"); writer.WriteLine("selectedId = undefined"); writer.WriteLine("resetData()"); writer.WriteLine("updateSimulation()"); writer.WriteLine("}"); writer.WriteLine("else"); writer.WriteLine("{"); writer.WriteLine("selectedId = selectedNode.id"); writer.WriteLine("updateData(selectedNode)"); writer.WriteLine("updateSimulation()"); writer.WriteLine("}"); writer.WriteLine("var neighbors = getNeighbors(selectedNode)"); writer.WriteLine("nodeElements.attr(" + quote_single + "fill" + quote_single + ", function(node) {return getNodeColor(node, neighbors)})"); writer.WriteLine("textElements.attr(" + quote_single + "fill" + quote_single + ", function(node) {return getTextColor(node, neighbors)})"); writer.WriteLine("linkElements.attr(" + quote_single + "stroke" + quote_single + ", function(link) {return getLinkColor(selectedNode, link)})"); writer.WriteLine("}"); writer.WriteLine("function resetData()"); writer.WriteLine("{"); writer.WriteLine("var nodeIds = nodes.map(function(node) {return node.id})"); writer.WriteLine("baseNodes.forEach(function(node) {"); writer.WriteLine("if (nodeIds.indexOf(node.id) === -1)"); writer.WriteLine("{"); writer.WriteLine("nodes.push(node)"); writer.WriteLine("}"); writer.WriteLine("})"); writer.WriteLine("links = baseLinks"); writer.WriteLine("}"); writer.WriteLine("function updateData(selectedNode)"); writer.WriteLine("{"); writer.WriteLine("var neighbors = getNeighbors(selectedNode)"); writer.WriteLine("var newNodes = baseNodes.filter(function(node) {"); writer.WriteLine("return neighbors.indexOf(node.id)> -1 || node.level === 1"); writer.WriteLine("})"); writer.WriteLine("var diff = {"); writer.WriteLine("removed: nodes.filter(function(node) {return newNodes.indexOf(node) === -1}),"); writer.WriteLine("added: newNodes.filter(function(node) {return nodes.indexOf(node) === -1})"); writer.WriteLine("}"); writer.WriteLine("diff.removed.forEach(function (node) {nodes.splice(nodes.indexOf(node), 1)})"); writer.WriteLine("diff.added.forEach(function (node) {nodes.push(node)})"); writer.WriteLine("links = baseLinks.filter(function (link) {"); writer.WriteLine("return link.target.id === selectedNode.id || link.source.id === selectedNode.id"); writer.WriteLine("})"); writer.WriteLine("}"); writer.WriteLine("function updateGraph()"); writer.WriteLine("{"); writer.WriteLine("linkElements = linkGroup.selectAll(" + quote_single + "line" + quote_single + ")"); writer.WriteLine(".data(links, function(link) {"); writer.WriteLine("return link.target.id + link.source.id"); writer.WriteLine("})"); writer.WriteLine("linkElements.exit().remove()"); writer.WriteLine("var linkEnter = linkElements"); writer.WriteLine(".enter().append(" + quote_single + "line" + quote_single + ")"); writer.WriteLine(".attr(" + quote_single + "stroke-width" + quote_single + ", 1)"); writer.WriteLine(".attr(" + quote_single + "stroke" + quote_single + ", " + quote_single + "rgba(50, 50, 50, 0.2)" + quote_single + ")"); writer.WriteLine("linkElements = linkEnter.merge(linkElements)"); writer.WriteLine("nodeElements = nodeGroup.selectAll(" + quote_single + "circle" + quote_single + ")"); writer.WriteLine(".data(nodes, function(node) {return node.id})"); writer.WriteLine("nodeElements.exit().remove()"); writer.WriteLine("var nodeEnter = nodeElements"); writer.WriteLine(".enter()"); writer.WriteLine(".append(" + quote_single + "circle" + quote_single + ")"); writer.WriteLine(".attr(" + quote_single + "r" + quote_single + ", 10)"); writer.WriteLine(".attr(" + quote_single + "fill" + quote_single + ", function(node) {return node.level === 1 ? " + quote_single + "red" + quote_single + " : " + quote_single + "gray" + quote_single + "})"); writer.WriteLine(".call(dragDrop)"); writer.WriteLine(".on(" + quote_single + "click" + quote_single + ", selectNode)"); writer.WriteLine("nodeElements = nodeEnter.merge(nodeElements)"); writer.WriteLine("textElements = textGroup.selectAll(" + quote_single + "text" + quote_single + ")"); writer.WriteLine(".data(nodes, function(node) {return node.id})"); writer.WriteLine("textElements.exit().remove()"); writer.WriteLine("var textEnter = textElements"); writer.WriteLine(".enter()"); writer.WriteLine(".append(" + quote_single + "text" + quote_single + ")"); writer.WriteLine(".text(function(node) {return node.label})"); writer.WriteLine(".attr(" + quote_single + "font-size" + quote_single + ", 15)"); writer.WriteLine(".attr(" + quote_single + "dx" + quote_single + ", 15)"); writer.WriteLine(".attr(" + quote_single + "dy" + quote_single + ", 4)"); writer.WriteLine("textElements = textEnter.merge(textElements)"); writer.WriteLine("}"); writer.WriteLine("function updateSimulation()"); writer.WriteLine("{"); writer.WriteLine("updateGraph()"); writer.WriteLine("simulation.nodes(nodes).on(" + quote_single + "tick" + quote_single + ", () => {"); writer.WriteLine("nodeElements"); writer.WriteLine(".attr(" + quote_single + "cx" + quote_single + ", function(node) {return node.x})"); writer.WriteLine(".attr(" + quote_single + "cy" + quote_single + ", function(node) {return node.y})"); writer.WriteLine("textElements"); writer.WriteLine(".attr(" + quote_single + "x" + quote_single + ", function(node) {return node.x})"); writer.WriteLine(".attr(" + quote_single + "y" + quote_single + ", function(node) {return node.y})"); writer.WriteLine("linkElements"); writer.WriteLine(".attr(" + quote_single + "x1" + quote_single + ", function(link) {return link.source.x})"); writer.WriteLine(".attr(" + quote_single + "y1" + quote_single + ", function(link) {return link.source.y})"); writer.WriteLine(".attr(" + quote_single + "x2" + quote_single + ", function(link) {return link.target.x})"); writer.WriteLine(".attr(" + quote_single + "y2" + quote_single + ", function(link) {return link.target.y})"); writer.WriteLine("})"); writer.WriteLine("simulation.force(" + quote_single + "link" + quote_single + ").links(links)"); writer.WriteLine("simulation.alphaTarget(0.7).restart()"); writer.WriteLine("}"); writer.WriteLine("updateSimulation()"); writer.WriteLine("</script>"); writer.Close(); } }