Skip to content

Instantly share code, notes, and snippets.

@pauldambra
Last active January 16, 2020 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pauldambra/f5da226d4e51bc95ef11 to your computer and use it in GitHub Desktop.
Save pauldambra/f5da226d4e51bc95ef11 to your computer and use it in GitHub Desktop.
For a Code Review exercise
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,
"locateriser@omniplex.io", "locationSupport@globodex.de");
}
/// <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