public static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("You must provide the source directory and at least " + "one gaze file to run this program."); return; } string source_directory = args[0]; List <string> gaze_files = new List <string>(); for (int i = 1; i < args.Length; ++i) { gaze_files.Add(args[i]); } Config config = new Config(); SourceCodeEntitiesFileCollection source_info = SrcMLCodeReader.run( config.src2srcml_path, source_directory); List <GazeResults> gaze_results = GazeReader.run(gaze_files); for (int i = 0; i < gaze_results.Count; ++i) { GazeResults cur_gaze_results = gaze_results[i]; string cur_filename = gaze_files[i]; GazeSourceRelationship gsr = GazeToSource.run(cur_gaze_results, source_info); gsr.writeSqlite(cur_filename + ".sql"); } }
public static void Main(string[] args) { GazeResults gaze_results = GazeReader.run( new List <string> { "data/gazedata1.xml" })[0]; foreach (GazeData gaze_data in gaze_results.gazes) { foreach (PropertyDescriptor descriptor in TypeDescriptor. GetProperties(gaze_data)) { Console.Write("{0}={1}; ", descriptor.Name, descriptor.GetValue(gaze_data)); } Console.WriteLine(""); } Config config = new Config(); SourceCodeEntitiesFileCollection collection = SrcMLCodeReader.run( config.src2srcml_path, "data/java/"); foreach (SourceCodeEntitiesFile file in collection) { Console.WriteLine(file.FileName + ":"); foreach (SourceCodeEntity entity in file) { Console.Write(" - "); foreach (PropertyDescriptor descriptor in TypeDescriptor. GetProperties(entity)) { Console.Write("{0}={1}; ", descriptor.Name, descriptor.GetValue(entity)); } Console.WriteLine(""); } } }
// 2013-11-08 TRS: First commit with basic functionality. Uses GraphViz // for rendering graphs to human-viewable form. Only minimal // processing is implemented, i.e. scale timestamp-based weights // into [0.0, 1.0] and remove links lighter than 1%. // 2013-11-13 TRS: Adjusted processing so that new links are initialized // to t^2 and repeat links get t added. Postprocessing now scales and // applies a highpass filter at 90%. Also, filenames are now inlcuded // in the nodes; thanks Braden. // TODO: // - Make the DOT files prettier, e.g. different node styles for // different types. // - Improve/tune postprocessing. // - Add functional-style utilities (I love lisps). // Including classes tends to blow everyone else // away since classes contain everything but get // parsed in the same way; including comments and, // to a lesser extent, attributes makes the // graph noisy. // private static SourceCodeEntityType[] EXCLUDED_TYPES = { // SourceCodeEntityType.COMMENT, // SourceCodeEntityType.CLASS, // //SourceCodeEntityType.ATTRIBUTE, // //SourceCodeEntityType.METHOD, // }; public static Dictionary <EntityLink, double> gen_graph( GazeResults gaze_results, SourceCodeEntitiesFileCollection collection) { Dictionary <EntityLink, double> src2src_links = new Dictionary <EntityLink, double> (); HashSet <SourceCodeEntity> previous = null; HashSet <SourceCodeEntity> current = new HashSet <SourceCodeEntity>(); foreach (GazeData gaze_data in gaze_results.gazes) { // find out which SourceCodeEntity the subject // was looking at for this GazeData foreach (SourceCodeEntitiesFile file in collection) { if (gaze_data.filename != file.FileName) { continue; } foreach (SourceCodeEntity entity in file) { // if this GazeData looks at an ignored type, skip // if (((IList<SourceCodeEntityType>) EXCLUDED_TYPES).Contains( // entity.Type)) { // continue; // } // Sorry about the ugliness, but I hate code // duplication more than this; i"1.0" encoding=t should be // write-only, anyway. if (((gaze_data.line > entity.LineStart) && (gaze_data.line < entity.LineEnd)) || ((gaze_data.line == entity.LineStart) && (gaze_data.col >= entity.ColumnStart)) || ((gaze_data.line == entity.LineEnd) && (gaze_data.col <= entity.ColumnEnd))) { current.Add(entity); //break; } } } // if there was a change of entity, make a note of it if ((current != previous) && (previous != null) && (previous.Count > 0) && (current.Count > 0)) { EntityLink link = new EntityLink(); link.left = new HashSet <SourceCodeEntity> (previous); link.right = new HashSet <SourceCodeEntity> (current); if (src2src_links.ContainsKey(link)) { //src2src_links [link] += Math.Pow (gaze_data.timestamp, 2.0); src2src_links [link] += Math.Pow(100, gaze_data.timestamp); } else { //src2src_links [link] = Math.Pow (gaze_data.timestamp, 2.0); src2src_links [link] = Math.Pow(100, gaze_data.timestamp); } } previous = current; current = new HashSet <SourceCodeEntity> (); } return(src2src_links); }
public static int Main(string[] args) { // I don't recommend making a composite of several sessions. // The differing timestamps would throw off the weights such // that earlier sessions count less. If composites are a // design goal, a preprocessing step wouldn't be hard to add // to the src2srcml reader. // Split files from the same session should be OK, though. if (args.Length < 3) { Console.WriteLine("USAGE: SimpleGraph.exe {edge-digraph|importance} " + "out-file source-directory edge-filter-highpass sce-filter-highpass composite-sce-filter-highpass gaze-result(s)"); Console.WriteLine("\tIf <out-file> is - print to stdout."); Console.WriteLine("\t<source-directory> is recursively " + "searched for .java source files."); Console.WriteLine("\t<edge-filter-highpass>, <sce-filter-highpass> and <composite-sce-filter-highpass>" + "should be numbers between 0 and 1."); Console.WriteLine("\t<gaze-result(s)> is/are XML eye tracking " + "data over the source\n\t files in <source-directory>."); return(1); } Config config = new Config(); SourceCodeEntitiesFileCollection collection = SrcMLCodeReader.run( config.src2srcml_path, args [2]); List <string> gaze_files = new List <string> (); for (int i = 0; i < args.Length - 6; i++) { gaze_files.Add(args [i + 6]); } List <GazeResults> gaze_results = GazeReader.run(gaze_files); var src2src_links = new List <Dictionary <EntityLink, double> >(); var entity_scores = new List <Dictionary <SourceCodeEntity, double> >(); foreach (var gaze_result in gaze_results) { var cur_src2src_links = gen_graph(gaze_result, collection); normalize_graph(cur_src2src_links); edge_filter_highpass(cur_src2src_links, Convert.ToDouble(args[3])); src2src_links.Add(cur_src2src_links); if (args[0] == "importance") { var entity_score = entity_score_from_edge_score(cur_src2src_links); sce_filter_highpass(entity_score, Convert.ToDouble(args[4])); entity_scores.Add(entity_score); } } // Write DOT file for GraphViz or write importance set. Use standard out if // specified. TextWriter output_writer = System.Console.Out; if (args[1] != "-") { output_writer = new StreamWriter(args[1]); } if (args[0] == "edge-digraph") { dump_DOT(output_writer, src2src_links[0]); } else if (args[0] == "importance") { var composite = composite_entity_scores(entity_scores); sce_filter_highpass(composite, Convert.ToDouble(args[5])); dump_links(output_writer, composite); } else { Console.WriteLine("Incorrect first parameter"); } return(0); }
// 2013-11-08 TRS: First commit with basic functionality. Uses GraphViz // for rendering graphs to human-viewable form. Only minimal // processing is implemented, i.e. scale timestamp-based weights // into [0.0, 1.0] and remove links lighter than 1%. // 2013-11-13 TRS: Adjusted processing so that new links are initialized // to t^2 and repeat links get t added. Postprocessing now scales and // applies a highpass filter at 90%. Also, filenames are now inlcuded // in the nodes; thanks Braden. // TODO: // - Make the DOT files prettier, e.g. different node styles for // different types. // - Improve/tune postprocessing. // - Add functional-style utilities (I love lisps). // Including classes tends to blow everyone else // away since classes contain everything but get // parsed in the same way; including comments and, // to a lesser extent, attributes makes the // graph noisy. // private static SourceCodeEntityType[] EXCLUDED_TYPES = { // SourceCodeEntityType.COMMENT, // SourceCodeEntityType.CLASS, // //SourceCodeEntityType.ATTRIBUTE, // //SourceCodeEntityType.METHOD, // }; public static Dictionary<EntityLink, double> gen_graph( GazeResults gaze_results, SourceCodeEntitiesFileCollection collection) { Dictionary<EntityLink,double> src2src_links = new Dictionary<EntityLink,double> (); HashSet <SourceCodeEntity> previous = null; HashSet <SourceCodeEntity> current = new HashSet <SourceCodeEntity>(); foreach (GazeData gaze_data in gaze_results.gazes) { // find out which SourceCodeEntity the subject // was looking at for this GazeData foreach (SourceCodeEntitiesFile file in collection) { if (gaze_data.filename != file.FileName) { continue; } foreach (SourceCodeEntity entity in file) { // if this GazeData looks at an ignored type, skip // if (((IList<SourceCodeEntityType>) EXCLUDED_TYPES).Contains( // entity.Type)) { // continue; // } // Sorry about the ugliness, but I hate code // duplication more than this; i"1.0" encoding=t should be // write-only, anyway. if (((gaze_data.line > entity.LineStart) && (gaze_data.line < entity.LineEnd)) || ((gaze_data.line == entity.LineStart) && (gaze_data.col >= entity.ColumnStart)) || ((gaze_data.line == entity.LineEnd) && (gaze_data.col <= entity.ColumnEnd))) { current.Add(entity); //break; } } } // if there was a change of entity, make a note of it if ((current != previous) && (previous != null) && (previous.Count > 0) && (current.Count > 0)) { EntityLink link = new EntityLink (); link.left = new HashSet <SourceCodeEntity> (previous); link.right = new HashSet <SourceCodeEntity> (current); if (src2src_links.ContainsKey (link)) { //src2src_links [link] += Math.Pow (gaze_data.timestamp, 2.0); src2src_links [link] += Math.Pow (100, gaze_data.timestamp); } else { //src2src_links [link] = Math.Pow (gaze_data.timestamp, 2.0); src2src_links [link] = Math.Pow (100, gaze_data.timestamp); } } previous = current; current = new HashSet <SourceCodeEntity> (); } return src2src_links; }