Skip to content

Instantly share code, notes, and snippets.

@David-Mimnagh
Last active December 20, 2016 08:59
Show Gist options
  • Save David-Mimnagh/81fd9415ae7df73a04f954b1b249115c to your computer and use it in GitHub Desktop.
Save David-Mimnagh/81fd9415ae7df73a04f954b1b249115c to your computer and use it in GitHub Desktop.
Character comparng weighting system
class Program
{
const int MAXWEIGHT = 100;
const int F_NAME_WEIGHT = 10;
const int S_NAME_WEIGHT = 30;
const int WP_REF_WEIGHT = 50;
const int FEE_REF_WEIGHT = 70;
const int NINO_WEIGHT = 100;
const int DOB_WEIGHT = 20;
const int PC_WEIGHT = 50;
const int ADDR_WEIGHT = 50;
const double CERTAIN_PERC = 0.90;
const double PROB_PERC = 0.658;
public class Client
{
public string FirstName { get; set; }
public string SecondName { get; set; }
public string WPRef { get; set; }
public string FeeRef { get; set; }
public int ClientID { get; set; }
public int MasterID { get; set; }
public string NINum { get; set; }
public DateTime? DoB { get; set; }
public string PostCode { get; set; }
public string Address { get; set; }
public int MaxScore { get; set; }
public int MatchIndex { get; set; }
public Client BestMatch { get; set; }
}
static List<string> StringSetup(string input, List<string> list)
{
string[] items = input.Split('\n');
for (int i = 0; i < items.Length; i++)
{
items[i] = items[i].Replace("\r", String.Empty);
list.Add(items[i]);
}
return list;
}
static List<Client> CreateFakeClients(List<Client> clientList)
{
String input = File.ReadAllText("../../firstnames.txt");
List<string> FakeFirstNames = new List<string>();
FakeFirstNames = StringSetup(input, FakeFirstNames);
input = File.ReadAllText("../../secondnames.txt");
List<string> FakeSecondNames = new List<string>();
FakeSecondNames = StringSetup(input, FakeSecondNames);
input = File.ReadAllText("../../wprefs.txt");
List<string> FakeWPRefs = new List<string>();
FakeWPRefs = StringSetup(input, FakeWPRefs);
input = File.ReadAllText("../../feerefs.txt");
List<string> FakeFeeRefs = new List<string>();
FakeFeeRefs = StringSetup(input, FakeFeeRefs);
input = File.ReadAllText("../../ninums.txt");
List<string> FakeNINums = new List<string>();
FakeNINums = StringSetup(input, FakeNINums);
List<DateTime> FakeDoBs = new List<DateTime>();
input = File.ReadAllText("../../postcodes.txt");
List<string> FakePostCodes = new List<string>();
FakePostCodes = StringSetup(input, FakePostCodes);
input = File.ReadAllText("../../address.txt");
List<string> FakeAddress = new List<string>();
FakeAddress = StringSetup(input, FakeAddress);
Random rnd = new Random();
for (int i = 0; i < 500; i++)
{
Client currClient = new Client();
int fnameID = rnd.Next(0, FakeFirstNames.Count());
int snameID = rnd.Next(0, FakeSecondNames.Count());
int wpRefID = rnd.Next(0, FakeWPRefs.Count());
int feeRefID = rnd.Next(0, FakeFeeRefs.Count());
int niNumID = rnd.Next(0, FakeNINums.Count());
int pcID = rnd.Next(0, FakePostCodes.Count());
int addID = rnd.Next(0, FakeAddress.Count());
currClient.FirstName = FakeFirstNames[fnameID];
if( currClient.FirstName == null)
currClient.FirstName = "david";
currClient.SecondName = FakeSecondNames[snameID];
if (currClient.SecondName == null)
currClient.SecondName = "sully";
currClient.WPRef = FakeWPRefs[wpRefID];
if (currClient.WPRef == null)
currClient.WPRef = "AD4MO";
currClient.FeeRef = FakeFeeRefs[feeRefID];
if (currClient.FeeRef == null)
currClient.FeeRef = "cx543901239";
currClient.NINum = FakeNINums[niNumID];
if (currClient.NINum == null)
currClient.NINum = "FG834639S";
currClient.PostCode = FakePostCodes[pcID];
if (currClient.PostCode == null)
currClient.PostCode = "PA56JE";
currClient.Address = FakeAddress[addID];
if (currClient.Address == null)
currClient.Address = "42 Wallaby way sydney";
clientList.Add(currClient);
}
Client currClientManual = new Client();
currClientManual.FirstName = "david";
currClientManual.SecondName = "sully";
currClientManual.WPRef = "AD4MO";
currClientManual.FeeRef = "cx543901239";
currClientManual.NINum = "FG834639S";
currClientManual.PostCode = "PA56JE";
currClientManual.Address = "42 Wallaby way sydney";
clientList.Add(currClientManual);
Client currClientManual2 = new Client();
currClientManual2.FirstName = "david";
currClientManual2.SecondName = "george";
currClientManual2.WPRef = "AD4NO";
currClientManual2.FeeRef = "cx543901239";
currClientManual2.NINum = "FG834639S";
currClientManual2.PostCode = "PA56HE";
currClientManual2.Address = "42 Wallaby way sydney";
clientList.Add(currClientManual2);
return clientList;
}
static Client LookForClient()
{
Client lookingFor = new Client();
Console.Write("\nAlright. Let's look for a client...");
Console.Write("\n\n\nDo you happen to know their first name? (y-yes, n-no)");
string reply = Console.ReadLine();
if (reply == "y")
{
Console.Write("\nWhat is his or her firstname?");
reply = Console.ReadLine();
lookingFor.FirstName = reply;
Console.Write("\nThank you.");
Console.Write("\nWhat is his or her surname?");
reply = Console.ReadLine();
lookingFor.SecondName = reply;
Console.Write("\nGreat.");
}
else
{
lookingFor.FirstName = null;
lookingFor.SecondName = null;
}
Console.Write("\n\n\nDo you happen to know their WP Ref? (y-yes, n-no)");
reply = Console.ReadLine();
if (reply == "y")
{
Console.Write("\nWhat is the WP Ref?");
reply = Console.ReadLine();
lookingFor.WPRef = reply;
Console.Write("\nThank you.");
}
else
{
lookingFor.WPRef = null;
}
Console.Write("\n\n\nDo you happen to know their Account Fee Ref? (y-yes, n-no)");
reply = Console.ReadLine();
if (reply == "y")
{
Console.Write("\nWhat is the Fee Ref?");
reply = Console.ReadLine();
lookingFor.FeeRef = reply;
Console.Write("\nThank you.");
}
else
{
lookingFor.FeeRef = null;
}
Console.Write("\n\n\nDo you happen to know their National Insurance Number? (y-yes, n-no)");
reply = Console.ReadLine();
if (reply == "y")
{
Console.Write("\nWhat is the NI Number?");
reply = Console.ReadLine();
lookingFor.NINum = reply;
Console.Write("\nThank you.");
}
else
{
lookingFor.NINum = null;
}
Console.Write("\n\n\nDo you happen to know their Postcode? (y-yes, n-no)");
reply = Console.ReadLine();
if (reply == "y")
{
Console.Write("\nWhat is the Postcode?");
reply = Console.ReadLine();
lookingFor.PostCode = reply;
Console.Write("\nThank you.");
}
else
{
lookingFor.PostCode = null;
}
Console.Write("\n\n\nDo you happen to know their Address? (y-yes, n-no)");
reply = Console.ReadLine();
if (reply == "y")
{
Console.Write("\nWhat is the Address?");
reply = Console.ReadLine();
lookingFor.Address = reply;
Console.Write("\nThank you.");
}
else
{
lookingFor.Address = null;
}
return lookingFor;
}
//static bool CheckSimilarity(string original, string lookingFor)
//{
// char[] origChars = original.ToCharArray();
// if (original.Length >1)
// {
// if (lookingFor != null)
// {
// char[] lfChars = lookingFor.ToCharArray();
// int similarCount = 0;
// string similars = null;
// for (int i = 0; i < origChars.Count(); i++)
// {
// for (int j = 0; j < lookingFor.Count(); j++)
// {
// if (origChars[i] == lfChars[j])
// {
// similarCount += 1;
// similars += lfChars[j];
// break;
// //TO DO - CHECK ORDER OF CHARS
// }
// }
// }
// if (similarCount > origChars.Count() - 2)
// return true;
// else
// return false;
// }
// else
// return false;
// }
// else
// return false;
//}
//static void RunCheck(List<Client> clientList, List<Client> certClients, List<Client> probClients, Client clientToLookFor)
//{
// for (int i = 0; i < clientList.Count; i++)
// {
// int informationAvailable = 0;
// int itemsToCheckOn = 0;
// int currentScoreMatch = 0;
// if (clientToLookFor.FirstName != null)
// {
// informationAvailable += 1;
// if (CheckSimilarity(clientList[i].FirstName, clientToLookFor.FirstName))
// {
// currentScoreMatch += F_NAME_WEIGHT;
// itemsToCheckOn += 1;
// }
// }
// if (clientToLookFor.SecondName != null)
// {
// informationAvailable += 1;
// if (CheckSimilarity(clientList[i].SecondName, clientToLookFor.SecondName))
// {
// currentScoreMatch += S_NAME_WEIGHT;
// itemsToCheckOn += 1;
// }
// }
// if (clientToLookFor.WPRef != null)
// {
// informationAvailable += 1;
// if (CheckSimilarity(clientList[i].WPRef, clientToLookFor.WPRef))
// {
// itemsToCheckOn += 1;
// currentScoreMatch += WP_REF_WEIGHT;
// }
// }
// if (clientToLookFor.FeeRef != null)
// {
// informationAvailable += 1;
// if (CheckSimilarity(clientList[i].FeeRef, clientToLookFor.FeeRef))
// {
// itemsToCheckOn += 1;
// currentScoreMatch += FEE_REF_WEIGHT;
// }
// }
// if (clientToLookFor.NINum != null)
// {
// informationAvailable += 1;
// if (CheckSimilarity(clientList[i].NINum, clientToLookFor.NINum))
// {
// itemsToCheckOn += 1;
// currentScoreMatch += NINO_WEIGHT;
// }
// }
// if (clientToLookFor.PostCode != null)
// {
// informationAvailable += 1;
// if (CheckSimilarity(clientList[i].PostCode, clientToLookFor.PostCode))
// {
// itemsToCheckOn += 1;
// currentScoreMatch += PC_WEIGHT;
// }
// }
// if (clientToLookFor.Address != null)
// {
// informationAvailable += 1;
// if (CheckSimilarity(clientList[i].Address, clientToLookFor.Address))
// {
// itemsToCheckOn += 1;
// currentScoreMatch += ADDR_WEIGHT;
// }
// }
// if (itemsToCheckOn >= 6)
// {
// if (currentScoreMatch >= (CERTAIN_PERC * MAXWEIGHT))
// certClients.Add(clientList[i]);
// else if (currentScoreMatch >= (PROB_PERC * MAXWEIGHT))
// probClients.Add(clientList[i]);
// }
// else
// {
// if (itemsToCheckOn > 0)
// {
// if(informationAvailable == itemsToCheckOn)
// certClients.Add(clientList[i]);
// if (itemsToCheckOn >= 4)
// {
// double quickCERT = itemsToCheckOn / 10;
// if (currentScoreMatch >= (quickCERT * MAXWEIGHT))
// certClients.Add(clientList[i]);
// }
// if (itemsToCheckOn < 4)
// {
// if (itemsToCheckOn > 2)
// {
// probClients.Add(clientList[i]);
// }
// }
// }
// }
// }
// if(certClients.Count >0)
// {
// for(int i =0;i<certClients.Count;i++)
// {
// Console.Write("\n----\nCertain client ID: " + (i + 1).ToString());
// Console.Write("\n First Name: " + certClients[i].FirstName);
// Console.Write( "\n Second Name: " + certClients[i].SecondName);
// Console.Write("\n WP Ref: " + certClients[i].WPRef);
// Console.Write("\n Fee Ref: " + certClients[i].FeeRef);
// Console.Write("\n NI Num: " + certClients[i].NINum);
// Console.Write("\n Address: " + certClients[i].Address);
// Console.Write("\n Postcode: " + certClients[i].PostCode);
// }
// }
// else
// Console.Write("\n\n------\tNo certain matching clients found.\n-----\tTry supplying more information.");
// if(probClients.Count >0)
// {
// for (int i = 0; i < probClients.Count; i++)
// {
// Console.Write("\n----\nPossible client ID: " + (i + 1).ToString());
// Console.Write("\n First Name: " + probClients[i].FirstName);
// Console.Write("\n Second Name: " + probClients[i].SecondName);
// Console.Write("\n WP Ref: " + probClients[i].WPRef);
// Console.Write("\n Fee Ref: " + probClients[i].FeeRef);
// Console.Write("\n NI Num: " + probClients[i].NINum);
// Console.Write("\n Address: " + probClients[i].Address);
// Console.Write("\n Postcode: "+ probClients[i].PostCode);
// }
// }
// else
// Console.Write("\n\n------\tNo possible matching clients found.\n-----\tTry supplying more information.");
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment