Exemplo n.º 1
0
 /// <summary>
 /// Reads in a CSV file to process it into a GML
 /// </summary>
 /// <param name="includeTeachers"> parameter for whether or not to include teachers </param>
 public void readCSV(Boolean includeTeachers) {
     String outline = "#000000";
     String outline_width = "2.0";
     String fill = "";
     double xVal = 0;
     double yVal = 0;
     using (StreamReader sr = new StreamReader(filename)) {
         if (!sr.EndOfStream) {
             String[] line = sr.ReadLine().Split(',');
             //assume last two columns are reserved for sums and not IDs
             int count = 0;
             for (int i = 0; i < line.Length; i++) {
                 if (includeTeachers)
                 {
                     if (!line[i].Contains("SUM") && !line[i].Equals("")) {
                         count++;
                     }
                 }
                 else {
                     if (!line[i].Contains("T") && !line[i].Contains("Lab") && !line[i].Contains("SUM") && !line[i].Equals(""))
                     {
                         count++;
                     }
                 }
             }
             ids = new String[count];
             for (int i = 0; i < ids.Count(); i++) {
                 ids[i] = line[i + 1];
             }
         }
         int rowCount = 1;
         while (!sr.EndOfStream) {
             String[] line = sr.ReadLine().Split(',');
             for (int i = rowCount + 1; i <= ids.Count(); i++) {
                 if (Convert.ToDouble(line[i]) >= average) {
                     if (!includeTeachers) {
                         if (rowCount <= ids.Count()) {
                             String e = GMLWriter.writeEdge(-rowCount, -i, (Convert.ToDouble(line[i]) * 200));
                             edges.Add(e);
                         }
                     }
                     else {
                         String e = GMLWriter.writeEdge(-rowCount, -i, (Convert.ToDouble(line[i]) * 200));
                         edges.Add(e);
                     }
                 }
             }
             if (rowCount <= ids.Length) {
                 double nodeSize = 0.0;
                 nodeSize = includeTeachers ? Convert.ToDouble(line[line.Length - 2]) : Convert.ToDouble(line[line.Length - 1]);
                 nodeSize *= 300;
                 fill = colorMap[ids[rowCount - 1]];
                 String n = GMLWriter.writeNode(-rowCount, -rowCount, xVal, yVal, nodeSize, nodeSize, fill, outline, 
                                                outline_width, ids[rowCount - 1]);
                 nodes.Add(n);
             }
             rowCount++;
         }
     }
 }
Exemplo n.º 2
0
 static void Main(string[] args) {
     String path = "C://Users/leibo/Documents/UM_REU/Data Vis/GMLWriter/GMLWriter/data/";
     String mappingfile = "MAPPINGNEW.CSV";
     String file3_3_normalized = "3_3_interactionsv2_normalized.CSV";
     String file3_10_normalized = "3_10_interactionsv2_normalized.CSV";
     String file3_17_normalized = "3_17_interactionsv2_normalized.CSV";
     String file3_31_normalized = "3_31_interactionsv3_normalized.CSV";
     String file4_7_normalized = "4_7_interactionsv3_normalized.CSV";
     String file4_21_normalized = "4_21_interactionsv3_normalized.CSV";
     String file4_28_normalized = "4_28_interactionsv2_normalized.CSV";
     List<String> files = new List<String> { file3_3_normalized,
         file3_10_normalized, file3_17_normalized, file3_31_normalized,
         file4_7_normalized, file4_21_normalized, file4_28_normalized };
     
     foreach (String file in files) {
         GMLWriter gml = new GMLWriter(path + file);
         GMLWriter.readMapping(path + mappingfile);
         gml.findAverage(false);
         gml.readCSV(false);
         gml.writeGML();
     }
     
     //replace with files to use
     String gml3_3 = "cotalk/3_3_cotalk.gml";
     String gml3_10 = "cotalk/3_10_cotalk.gml";
     String gml3_17 = "cotalk/3_17_cotalk.gml";
     String gml3_31 = "cotalk/3_31_cotalk.gml";
     String gml4_7 = "cotalk/4_7_cotalk.gml";
     String gml4_21 = "cotalk/4_21_cotalk.gml";
     String gml4_28 = "cotalk/4_28_cotalk.gml";
     List<String> gmls = new List<String>() { path + gml3_3, path + gml3_10, path + gml3_17, path + gml3_31, path + gml4_7, path + gml4_21, path + gml4_28 };
     GMLWriter.sumGML("cotalk/cotalk_pruned_aggregate.gml", gmls, false, true);
     
     //use the below to manually create edge and node lists
     //takes in 10 doubles in order representing the sizes of B1 to B10 and returns a list of those nodes.
     List<Tuple<int, double>> makeNodeList(List<double> nodewidths) {
         List<Tuple<int, double>> nodelist = new List<Tuple<int, double>>();
         for (int i = -1; i >= -nodewidths.Count; i--) {
             if (!nodewidths[-i - 1].Equals(0)) {
                 nodelist.Add(new Tuple<int, double>(i, nodewidths[-i - 1]));
             }
         }
         return nodelist;
     }
     Tuple<int, int, double> edge(int source, int target, double width) {
         return new Tuple<int, int, double>(source, target, width);
     }
     
     GMLWriter.summaryCSV2GML(path + "sortedsync/summary3_3.CSV");
     BidirectionalGraph g = new BidirectionalGraph();
     g.readGML(path + "cotalk/3_3_cotalk.gml");
 }
Exemplo n.º 3
0
 /// <summary>
 /// takes in a List of files and produces one GML with aggregate values of node and edge size
 /// </summary>
 public static void sumGML(String outputname, List<String> files, Boolean penalizeAbsent, Boolean pruneEdges) {
     Dictionary<String, Node> nodeDict = new Dictionary<string, Node>();
     double edgesum = 0.0;
     int edgecount = 0;
     foreach (String file in files) {
         List<String> rawNodes = new List<String>();
         List<String> rawEdges = new List<String>();
         using (StreamReader sr = new StreamReader(file)) {
             string[] splitNode = new string[] { "node" };
             string[] splitEdge = new string[] { "edge" };
             String[] line = sr.ReadToEnd().Split(splitNode, StringSplitOptions.RemoveEmptyEntries);
             for (int i = 1; i < line.Length - 1; i++) {
                 rawNodes.Add(line[i]);
             }
             String rest = line[line.Length - 1];
             String[] line2 = rest.Split(splitEdge, StringSplitOptions.RemoveEmptyEntries);
             Console.WriteLine(line2[0]);
             rawNodes.Add(line2[0]);
             for(int i = 1; i< line2.Length; i++) {
                 rawEdges.Add(line2[i]);
             }
         }
         foreach (String nodeString in rawNodes) {
             int id_index_start = nodeString.IndexOf("id");
             int id_index_end = nodeString.IndexOf("graphics");
             int size_index_start = nodeString.IndexOf("w");
             int fill_index_start = nodeString.IndexOf("fill");
             int fill_index_end = nodeString.IndexOf("type");
             int label_index_start = nodeString.IndexOf("label");
             String id = nodeString.Substring(id_index_start + 2, id_index_end - id_index_start - 2).Trim();
             String size = nodeString.Substring(size_index_start + 1, fill_index_start - size_index_start - 1).Trim();
             if(nodeDict.ContainsKey(id)) {
                 nodeDict[id].addSize(Convert.ToDouble(size));
             }
             else {
                 String fill = nodeString.Substring(fill_index_start + 4, fill_index_end - fill_index_start - 4).Trim();
                 fill = fill.Substring(1, fill.Length - 2);
                 String label = nodeString.Substring(label_index_start + 5).Trim();
                 label = label.Substring(0, label.Length - 1).Trim();
                 label = label.Substring(1, label.Length - 2);
                 Node node = new Node(id, label, Convert.ToDouble(size), fill);
                 nodeDict.Add(id, node);
             }
         }
         foreach(String edgeString in rawEdges) {
             int source_index_start = edgeString.IndexOf("source");
             int target_index_start = edgeString.IndexOf("target");
             int target_index_end = edgeString.IndexOf("label");
             int width_index_start = edgeString.IndexOf("width");
             String source = edgeString.Substring(source_index_start + 6, target_index_start - source_index_start - 7).Trim();
             String target = edgeString.Substring(target_index_start + 6, target_index_end - target_index_start - 6).Trim();
             String width = edgeString.Substring(width_index_start + 5).Trim();
             width = width.Split(']')[0];
             width = width.Split(']')[0];
             nodeDict[source].addEdge(target, Convert.ToDouble(width));
         }
     }
     using (TextWriter sw = new StreamWriter(outputname)) {
         String header = "Creator \"Y\"\nVersion 1.0\ngraph\n[";
         sw.WriteLine(header);
         foreach (String key in nodeDict.Keys) {
             if (penalizeAbsent) {
                 nodeDict[key].average(files.Count);
             }
             else {
                 nodeDict[key].average();
             }
             int id = int.Parse(nodeDict[key].getID());
             String label = nodeDict[key].getLabel();
             String fill = nodeDict[key].getFill();
             double size = nodeDict[key].getSize();
             String nodeprint = GMLWriter.writeNode(id, id, 0, 0, size, size, fill, "#000000", "2.0", label);
             sw.WriteLine("\t" + nodeprint);
         }
         foreach(String key in nodeDict.Keys) {
             Dictionary<string, double> edgeDict = nodeDict[key].getEdges();
             foreach (String s in nodeDict.Keys) {
                 foreach (String edge in nodeDict[s].getEdges().Keys) {
                     edgesum += nodeDict[s].getEdges()[edge];
                     edgecount++;
                 }
             }
             double averagewidth = edgesum / edgecount;
             foreach (String s in edgeDict.Keys {
                 if (pruneEdges) {
                     if (edgeDict[s] >= averagewidth) {
                         String edgeprint = GMLWriter.writeEdge(int.Parse(key), int.Parse(s), edgeDict[s]);
                         sw.WriteLine("\t" + edgeprint);
                     }
                 }
                 else {
                     String edgeprint = GMLWriter.writeEdge(int.Parse(key), int.Parse(s), edgeDict[s]);
                     sw.WriteLine("\t" + edgeprint);
                 }
             }
         }
         sw.WriteLine("]");
     }
 }