1. mattgrande
  2. HamOntFire

Commits

mgr...@redwavecommerce.com  committed 524e481

Geocoder updates.

  • Participants
  • Parent commits f1e86f4
  • Branches default

Comments (1)

Files changed (5)

File HamOntFire.Core/Domain/EventIndex.cs

View file
  • Ignore whitespace
         }
     }
 
+    public class Events_UnitsPerType : AbstractIndexCreationTask<Event, Events_UnitsPerType.ReduceResult>
+    {
+        public class ReduceResult
+        {
+            public string Name { get; set; }
+            public int Units { get; set; }
+            public decimal UnitsPerType { get; set; }
+        }
+
+        public Events_UnitsPerType()
+        {
+            Map = events => from doc in events
+                            select new { Name = doc.Type, doc.Units, UnitsPerType = 0};
+            Reduce = results => from eventCount in results
+                                group eventCount by eventCount.Name
+                                into g
+                                select new { Name = g.Key, Units = g.Sum(x => x.Units), UnitsPerType = g.Average(x => x.Units) };
+            Sort(result => result.UnitsPerType, SortOptions.Double);
+        }
+    }
+
     public class Events_ByTweetIdSortByTweetId : AbstractIndexCreationTask<Event>
     {
         public Events_ByTweetIdSortByTweetId()

File HamOntFire.Core/TweetManager.cs

View file
  • Ignore whitespace
             _session.SaveChanges();
         }
 
-        #endregion
-
         public long GetGreatestTweetId()
         {
             var @event = _session.Query<Event>("Events/ByTweetIdSortByTweetId").OrderByDescending(e => e.TweetId).FirstOrDefault();
             return tweetsSince;
         }
 
+        #endregion
+
         /// <summary>
         /// Downloads the most recent tweets from HFS_Incidents
         /// </summary>
                     intersection = intersection.Replace(" @ ", " & ");
                     e.Intersection = intersection.Trim();
                 }
+                else if (cn.StartsWith("RHVP"))
+                {
+                    // EG: RHVP @ KING ST. TO GREENHILL
+                    var intersection = cn.Replace("RHVP", "Red Hill Valley Parkway");
+                    if (intersection.Contains("@") && intersection.Contains(" TO ")) ;
+                    {
+                        // Remove the " TO GREENHILL" part
+                        int i = intersection.IndexOf(" TO ", StringComparison.Ordinal);
+                        intersection = intersection.Remove(i);
+                    }
+
+                    intersection = intersection.Replace(" TO ", " & ");
+                    intersection = intersection.Replace(" @ ", " & ");
+                    e.Intersection = intersection.Trim();
+                }
             }
 
             if (location.Contains(" /PRIVATE RD"))

File HamOntFire.Web/Controllers/HomeController.cs

View file
  • Ignore whitespace
         public JsonResult ReoCode()
         {
             var events = RavenSession.Query<Event>().Where(e => (e.Lat == 0m || e.Long == 0m) && e.Location != "Location Not Available").ToList();
+
+            var dict = new Dictionary<string, List<String>>
+                {
+                    {"Parsed", new List<string>()},
+                    {"Unparsed", new List<string>()}
+                };
+
             var g = new GeoCoder();
             foreach (Event @event in events)
             {
                 TweetManager.ParseLocation(@event, @event.Location);
                 g.GeoCode( @event );
+
+                if (@event.Lat == 0 || @event.Long == 0)
+                {
+                    dict["Unparsed"].Add(@event.Location);
+                }
+                else
+                {
+                    dict["Parsed"].Add(string.Format("{0}:{1},{2}", @event.Location, @event.Lat, @event.Long));
+                }
             }
 
-            return Json("OK:" + events.Count, JsonRequestBehavior.AllowGet);
+            return Json(dict, JsonRequestBehavior.AllowGet);
         }
 
         public ActionResult About()

File HamOntFire.Web/Controllers/StatisticsController.cs

View file
  • Ignore whitespace
         // GET: /Statistics/
         public ActionResult Index()
         {
-            var result = RavenSession.Query<Events_Count.ReduceResult, Events_Count>()
+            var vm = new StatisticsViewModel();
+
+            // Event Count by Event Type
+            vm.EventCountByType = RavenSession.Query<Events_Count.ReduceResult, Events_Count>()
                 .OrderByDescending(x => x.Count).ToList();
-            int total = result.Sum(r => r.Count);
+            int total = vm.EventCountByType.Sum(r => r.Count);
 
+            // Anything less than 1%, put into the 'Other' column
             var other = new Events_Count.ReduceResult {Name = "Other"};
-            for (int i = result.Count-1; i >= 0; i--)
+            for (int i = vm.EventCountByType.Count - 1; i >= 0; i--)
             {
-                var percent = ((double)result[i].Count/total)*100;
+                var percent = ((double)vm.EventCountByType[i].Count / total) * 100;
                 if (percent > 1)
                     break;
-                
-                other.Count += result[i].Count;
-                result.RemoveAt(i);
+
+                other.Count += vm.EventCountByType[i].Count;
+                vm.EventCountByType.RemoveAt(i);
             }
 
             if (other.Count > 0)
-                result.Add(other);
+                vm.EventCountByType.Add(other);
 
-            return View(result.ToArray());
+            // Average # of Units per Event Type
+            vm.AverageUnitsPerEventType = RavenSession.Query<Events_UnitsPerType.ReduceResult, Events_UnitsPerType>()
+                .OrderByDescending(x => x.UnitsPerType).ToList();
+            
+            return View( vm );
         }
 
         [OutputCache(NoStore = true, Location = OutputCacheLocation.None)]
         }
     }
 
+    public class StatisticsViewModel
+    {
+        public List<Events_Count.ReduceResult> EventCountByType { get; set; }
+        public List<Events_UnitsPerType.ReduceResult> AverageUnitsPerEventType { get; set; }
+    }
+
     public static class JsonExtension
     {
         public static string ToJson(this object o)

File HamOntFire.Web/Views/Statistics/Index.cshtml

View file
  • Ignore whitespace
 @using HamOntFire.Web.Controllers
-@model HamOntFire.Core.Domain.Events_Count.ReduceResult[]
+@model StatisticsViewModel
 
 <h2>Statistics</h2>
 
 <div>
     <div style="float: left;">
         <table>
-            @foreach (var result in Model)
+            @foreach (var result in Model.EventCountByType)
             {
                 <tr>
                     <td>@result.Name</td>
-                    <td>@result.Count</td>
+                    <td style="text-align:right">@result.Count</td>
                 </tr>
             }
         </table>
 
 <div style="clear: both"></div>
 
+<h3>Average Number of Units per Event Type</h3>
+
+<div>
+    <div id="container2"></div>
+</div>
+
 <h3>Heat Map</h3>
 <img src="@Url.Action("HeatMap")" alt="some image" />
 
-<script>
-//    $(function () {
-//        var chart;
-    //        $(document).ready(function () {
-            var model = @Html.Raw( Model.ToJson() );
-            var categories = [];
-            var data = [];
-            for (var i = 0; i < model.length; i++) {
-                data[i] = [model[i].Name, model[i].Count];
+<script type="text/javascript">
+var model = @Html.Raw( Model.EventCountByType.ToJson() );
+var categories = [];
+var data = [];
+for (var i = 0; i < model.length; i++) {
+    data[i] = [model[i].Name, model[i].Count];
+}
+chart = new Highcharts.Chart({
+    chart: {
+        renderTo: 'container'
+    },
+    title: {
+        text: ''
+    },
+    xAxis: {
+        categories: categories
+    },
+    yAxis: {
+        min: 0,
+        title: {
+            text: 'Number'
+        }
+    },
+    tooltip: {
+        pointFormat: '{series.name}: <b>{point.percentage}%</b>', percentageDecimals: 1
+    },
+    plotOptions: {
+    pie: {
+        allowPointSelect: true,
+        cursor: 'pointer',
+        dataLabels: {
+            enabled: true,
+            color: '#000000',
+            connectorColor: '#000000',
+            formatter: function() {
+                return '<b>'+ this.point.name +'</b>: '+ this.percentage.toFixed(1) +' %';
             }
-            chart = new Highcharts.Chart({
-                chart: {
-                    renderTo: 'container'
-                },
-                title: {
-                    text: ''
-                },
-                xAxis: {
-                    categories: categories
-                },
-                yAxis: {
-                    min: 0,
-                    title: {
-                        text: 'Number'
-                    }
-                },
-                tooltip: {
-                    pointFormat: '{series.name}: <b>{point.percentage}%</b>', percentageDecimals: 1
-                },
-                plotOptions: {
-                pie: {
-                    allowPointSelect: true,
-                    cursor: 'pointer',
-                    dataLabels: {
-                        enabled: true,
-                        color: '#000000',
-                        connectorColor: '#000000',
-                        formatter: function() {
-                            return '<b>'+ this.point.name +'</b>: '+ this.percentage.toFixed(1) +' %';
-                        }
-                    }
-                }
-            },
-            series: [{
-                type: 'pie',
-                name: 'Browser share',
-                data: data
-                }]
-            });
-//        });
-
-//    });
+        }
+    }
+},
+series: [{
+    type: 'pie',
+    name: 'Browser share',
+    data: data
+    }]
+});
 </script>