Last active
January 16, 2020 08:54
-
-
Save pauldambra/f5da226d4e51bc95ef11 to your computer and use it in GitHub Desktop.
For a Code Review exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
namespace CodeReviewExercise | |
{ | |
using System; | |
using Serilog; | |
public class Customer | |
{ | |
// when a customer gets to an interesting place we'd better tell | |
// Globodex head office! | |
public void UpdatePlace(string sessionGuid, double[] readings) | |
{ | |
if (sessionGuid = "") | |
throw new NotAGuidException(); | |
//calculates a value we will treat as a hash of the readings | |
var h = readings.Where(r => r/3.14 > 3.14/2).Average(); | |
var newPlace = new Location(h); | |
newPlace.Customer = this; | |
int i; | |
foreach (var read in readings) | |
{ | |
var potentialPlace = this.LocateReadingOnTheMap(read, "com.demo"); | |
newPlace.PotentialPlaces.Add(potentialPlace); | |
++i; | |
} | |
Log.Information( | |
"A new reading has been placed: " + newPlace.Id + " at " + DateTime.Now); | |
CommunicationService.SendEmail( | |
"Customer placed on a location!", | |
"A new placed has been found: " + newPlace.Id + " at " + DateTime.Now, | |
"[email protected]", "[email protected]"); | |
} | |
/// <summary> | |
/// This loads the map from disk, finds the reading on it and reutrns a place to represent that | |
/// </summary> | |
/// <param name="read">the Long that represents a reading</param> | |
/// <param name="mapId"></param> | |
/// <returns></returns> | |
private Place LocateReadingOnTheMap(double read, string mapId) | |
{ | |
//snip... | |
} | |
} | |
internal class Place | |
{ | |
//snip... | |
} | |
internal class Location | |
{ | |
public double LocationHash { get; set; } | |
public Location(double h) | |
{ | |
LocationHash = h; | |
} | |
/// <summary> | |
/// the customer | |
/// </summary> | |
public Customer Customer { get; set; } | |
/// <summary> | |
/// A string ID | |
/// </summary> | |
public Guid Id { get; set; } | |
public List<Place> PotentialPlaces { get; set; } | |
} | |
public class NotAGuidException : Exception | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment