public void processKodeFile(KoduGame g, String file) { StreamReader sr = new StreamReader(file); String line; g.file = sr.ReadLine(); //header g.title = sr.ReadLine(); // header g.author = sr.ReadLine(); // header g.date = sr.ReadLine(); //header while ((line = sr.ReadLine()) != null) { processKodeLine(g, line); } sr.Close(); //create summary information for the game g.totalTiles = (from a in g.actordata.actors.Values where a.allrules.Count() > 0 select a.tileCount).Sum(); }
private void getTabbedData(KoduGame g) { foreach (Actor a in g.actordata.actors.Values) { foreach (Rule r in a.allrules) { if (r.Condition.Contains("tab")) { g.tabbedRules++; //check for the type of 'and' //if condition = always and action != null, we have action //if condition != always, and action != null, we have cond. if (r.Condition.Contains("sensor.always")) { if (r.actionTiles.Count() > 0) { g.logicalAndAction++; } else { Console.WriteLine("Check me Action: " + g.upid); } } else { if (r.actionTiles.Count() > 0) { g.logicalAndCondition++; } else { Console.WriteLine("Check me Condition: " + g.upid); } } } } } }
private void getLogicalAndActionProxy(KoduGame g) { foreach (Actor a in g.actordata.actors.Values) { foreach (Page p in a.allpages) { for (int i = 0; i < p.rules.Count(); i++) { Rule current = p.rules[i]; if (current.conditionTiles.Contains("sensor.always")) { current.conditionIsAlways = true; } for (int j = i + 1; j < p.rules.Count(); j++) { Rule test = p.rules[j]; if (isSameSetOfStrings(current.conditionTiles, test.conditionTiles)) { current.conditionDuplicatedInPage = true; test.conditionDuplicatedInPage = true; } } } } //check for the rules that are duplicates int allDuplicates = (from rules in a.allrules where rules.conditionDuplicatedInPage == true select rules).Count(); g.logicalAndConditionProxies += allDuplicates; int allDuplicatesNotAlways = (from rules in a.allrules where rules.conditionDuplicatedInPage == true & rules.conditionIsAlways == false select rules).Count(); g.logicalAndConditionProxiesNoAlways += allDuplicatesNotAlways; } }
private void printStateMachine(KoduGame g, Actor a) { string directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\analytics\Machines\"; Directory.CreateDirectory(directory); directory += g.upid + "_" + a.id + ".dot"; using (StreamWriter sw = File.CreateText(directory)) { sw.WriteLine("digraph state {"); // sw.WriteLine("rankdir=LR;"); // sw.WriteLine("node [shape = doublecircle]; stop;"); sw.WriteLine("node [shape = circle];"); foreach (Transition t in a.stateMachine.transitions) { sw.WriteLine(t.src.name + " -> " + t.dest.name + "[ label = \"" + "\" ];"); } sw.WriteLine("}"); sw.Flush(); sw.Close(); } }
private void getNotData(KoduGame g) { foreach (Actor a in g.actordata.actors.Values) { foreach (Rule r in a.allrules) { Boolean contains = false; if (r.Action.Contains(" filter.not ")) { g.notAction++; contains = true; } else if (r.Condition.Contains(" filter.not ")) { g.notCondition++; contains = true; } if (contains) { g.notRule++; } } } }
private void getRandomVariableInformation(KoduGame g) { foreach (Actor a in g.actordata.actors.Values) { foreach (Rule r in a.allrules) { Boolean contains = false; if (r.Action.Contains("random")) { g.randomAction++; contains = true; } else if (r.Condition.Contains("random")) { g.randomCondition++; contains = true; } if (contains) { g.randomRule++; } } } }
/* * Looks at the rule interactions with each scorebucket, as a proxy for * global variables. We care here about the number of rules that read * versus the number of rules that write. Some rules may do both. */ private void getScoreBucketInformation(KoduGame g) { List <KeyValuePair <string, int> > sb = (from t in g.tiledata.tiles where t.Key.Contains("scorebucket") select t).ToList(); List <string> buckets = new List <string>(); for (int i = 0; i < sb.Count(); i++) { String bucket = sb[i].Key; bucket = bucket.Substring(bucket.IndexOf('.') + 1); if (!g.bucketreads.ContainsKey(bucket)) { g.bucketreads.Add(bucket, 0); g.bucketwrites.Add(bucket, 0); buckets.Add(bucket); } } String color; foreach (Actor a in g.actordata.actors.Values) { foreach (Rule r in a.allrules) { if (r.Condition.Contains("sensor.scored")) { if ((color = extractcolor(r.Condition)) != "") { String bucket = getScoreBucketName(color); if (!g.bucketreads.ContainsKey(bucket)) { g.bucketreads.Add(bucket, 0); g.bucketwrites.Add(bucket, 0); buckets.Add(bucket); } } } } } g.distinctbuckets = buckets.Count(); Boolean contains = false; foreach (Actor a in g.actordata.actors.Values) { foreach (Rule r in a.allrules) { contains = false; foreach (string bucket in buckets) { if (r.Action.Contains(bucket)) { contains = true; g.bucketwrites[bucket]++; } if (r.Condition.Contains(bucket)) { contains = true; g.bucketreads[bucket]++; } else if (r.Condition.Contains("sensor.scored")) { if ((color = extractcolor(r.Condition)) != "") { String b = getScoreBucketName(color); if (b == bucket) { g.bucketreads[b]++; contains = true; } } } } if (contains) { g.bucketreadorwriterulecount++; } } } }
public void processUnreachable() { //process unreachavble file String file = filepath + "unreachablePages.txt"; using (StreamReader sr = new StreamReader(file)) { sr.ReadLine(); //eat first line String line; while ((line = sr.ReadLine()) != null) { String[] parts = line.Split(' '); String id = parts[2]; String page = parts[parts.Length - 1]; String actor = parts[parts.Length - 5] + " " + parts[parts.Length - 4]; actor = actor.Substring(0, actor.Length - 1); actor.Trim(); var game = (from g in games where g.upid == id select g); if (game != null) { KoduGame kg = (KoduGame)(game.ToList()[0]); kg.unreachablePages.Add(new KeyValuePair <string, int>(actor, Convert.ToInt32(page.Trim()))); } } sr.Close(); } //process blankjumps file file = filepath + "blankjumps.txt"; using (StreamReader sr = new StreamReader(file)) { sr.ReadLine();//eat the first line String line; while ((line = sr.ReadLine()) != null) { String[] parts = line.Split(' '); String id = parts[2]; String page = parts[parts.Length - 1]; String actor = parts[parts.Length - 8] + " " + parts[parts.Length - 7]; actor = actor.Substring(0, actor.Length - 1); actor.Trim(); var game = (from g in games where g.upid == id select g); if (game != null) { KoduGame kg = (KoduGame)(game.ToList()[0]); kg.blankJumps.Add(new KeyValuePair <string, int>(actor, Convert.ToInt32(page.Trim()))); } } sr.Close(); } //summarize the frequency and object percentages int unreachable = (from g in games where g.unreachablePages.Count() > 0 select g).Count(); int total = games.Count(); double unreachper = (double)unreachable / (double)total; Console.WriteLine("Unreach {0} / {1} = {2}", unreachable, total, unreachper); double unreachablecount = (from g in games where g.unreachablePages.Count() > 0 select g.unreachablePages.Count()).Average(); Console.WriteLine("Unreach pages per Game = {0}", unreachablecount); int blank = (from g in games where g.blankJumps.Count() > 0 select g).Count(); double blankper = (double)blank / (double)total; Console.WriteLine("Blank {0} / {1} = {2}", blank, total, blankper); double blankcount = (from g in games where g.blankJumps.Count() > 0 select g.blankJumps.Count()).Average(); Console.WriteLine("Blank pages per Game = {0}", blankcount); }