public void TestDetermineCrimeRatingForPenrith2015()
        {
            CrimeDataService dataService = new CrimeDataService();
            // Test using Ashfield data
            var result = dataService.DetermineCrimeRatingIndex(527.4);

            Assert.AreEqual(3, result);
        }
        public void TestThatDetermineCrimeRatingIsNotFalse()
        {
            CrimeDataService dataService = new CrimeDataService();
            // Test using Ashfield data
            var result = dataService.DetermineCrimeRatingIndex(265.7);

            Assert.AreEqual(2, result);
        }
Beispiel #3
0
        public CrimeDataViewModel Get(double latitude, double longitude)
        {
            var service     = new CrimeDataService();
            var lgaAndScore = service.DetermineLga(latitude, longitude);
            var lga         = lgaAndScore.First().Key;
            var index       = service.DetermineCrimeRatingIndex(lgaAndScore[lga]);

            return(new CrimeDataViewModel()
            {
                Lat = latitude,
                Long = longitude,
                LGAName = lga,
                CrimeRatingIndex = index,
                Rate = lgaAndScore[lga]
            });
        }
Beispiel #4
0
        public async Task <HttpResponseMessage> Post()
        {
            var crimeService = new CrimeDataService();

            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            string root     = HttpContext.Current.Server.MapPath("~/App_Data");
            var    provider = new MultipartFormDataStreamProvider(root);

            try
            {
                // Read the form data.
                await Request.Content.ReadAsMultipartAsync(provider);

                string line = null;
                // This illustrates how to get the file names.
                foreach (MultipartFileData file in provider.FileData)
                {
                    Trace.WriteLine(file.Headers.ContentDisposition.FileName);
                    Trace.WriteLine("Server file path: " + file.LocalFileName);
                    TextReader reader = File.OpenText(file.LocalFileName);
                    Dictionary <string, double> records = new Dictionary <string, double>();
                    while ((line = reader.ReadLine()) != null)
                    {
                        string[] tokens = line.Split(',');
                        var      lga    = tokens[0];
                        var      stat   = double.Parse(tokens[1]);
                        records[lga] = stat;
                    }
                    line = crimeService.InitialiseCrimeStatistics(records).ToString();
                }
                return(Request.CreateResponse(HttpStatusCode.OK, line != null ? line : ""));
            }
            catch (System.Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }
        }