milestones investigate methods for ai development(week 2) revise initial design (week 3) develop...

Post on 19-Jan-2018

217 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

UtilitiesClass public void parseCSV(string path, ref string[] str1, ref string[] str2, ref string[] str3) { // List parsedData = new List (); try { using (StreamReader readFile = new StreamReader(path)) { string line; string[] row; int i = 0, k = 0, l = 0; while ((line = readFile.ReadLine()) != null) { row = line.Split(','); if (i < 5000) { Array.Resize(ref str1, str1.Length + 1); str1[i] = row[0]; i++; if (row[1].Length > 3) { Array.Resize(ref str2, str2.Length + 1); str2[k] = row[1]; k++; } if (row[2].Length > 1) { Array.Resize(ref str3, str3.Length + 1); str3[l] = row[2]; l++; } Array.Resize(ref str1, str1.Length - 1); Array.Resize(ref str2, str2.Length - 1); Array.Resize(ref str3, str3.Length - 1); } catch (Exception e) { MessageBox.Show(e.Message); }

TRANSCRIPT

Milestones Investigate Methods for AI development(week 2) Revise initial design (week 3) Develop functions to generate specific types of data: (week 4)

Date, currency, timestamp, names, imbalanced types (like gender)

Make DBMS specific protocols (week 6) Include connection, retrieval, and insertion

Implement Website specific web crawler (week 7) Design AI protocols (week 9)

Must correlate desired types with minimal errors Design User Interface (week 9)

Incorporate standard interface functions with symmetrical design layout considerations

Complete final documentation and fine-tuning (week 10)

UtilitiesClass public void parseCSV(string path, ref string[] str1, ref string[] str2, ref string[] str3) { // List<string[]> parsedData = new List<string[]>();

try { using (StreamReader readFile = new StreamReader(path)) { string line; string[] row; int i = 0, k = 0, l = 0; while ((line = readFile.ReadLine()) != null) { row = line.Split(','); if (i < 5000) { Array.Resize(ref str1, str1.Length + 1); str1[i] = row[0]; i++; if (row[1].Length > 3) { Array.Resize(ref str2, str2.Length + 1); str2[k] = row[1]; k++; } if (row[2].Length > 1) { Array.Resize(ref str3, str3.Length + 1); str3[l] = row[2]; l++; } } } Array.Resize(ref str1, str1.Length - 1); Array.Resize(ref str2, str2.Length - 1); Array.Resize(ref str3, str3.Length - 1); } } catch (Exception e) { MessageBox.Show(e.Message); } }

UtilitiesClasspublic void parseTxt(string path, ref string[] str1) { try {

using (StreamReader readFile = new StreamReader(path)) {

string line; int i = 0; while ((line = readFile.ReadLine()) != null) { Array.Resize(ref str1, str1.Length + 1); str1[i] = line; i++; }

} } catch (Exception e) { MessageBox.Show(e.Message); } }

UtilitiesClasspublic void getColumn(ref string[] str1, ref string[] str2, int column) { try { string line; string[] row; int k = 0, l = 0; for (int i = 0; i < str2.Count(); i++) { line = str2[i]; row = line.Split(',', '(', ')');

Array.Resize(ref str1, str1.Length + 1); str1[i] = row[column];

} Array.Resize(ref str1, str1.Length - 1);

} catch (Exception e) { MessageBox.Show(e.Message); } }

UtilitiesClass public void parallelWrite(string[] str, string file, int start, int end) { TextWriter tw = TextWriter.Synchronized(File.AppendText(file)); Parallel.For(start, end, i => { //tw.WriteLine(str[i]); if (str[i] != null) { tw.WriteLine(str[i]); }

} ); tw.Close(); }

UtilitiesClasspublic void writeLine(string sqlstr, string filename) { TextWriter tw = TextWriter.Synchronized(File.AppendText(filename));

// write a line of text to the file tw.WriteLine(sqlstr);

// close the stream tw.Close(); }

UtilitiesClass public string formatText(string str, int end = 0) { string tmp; tmp = "'" + str + "'"; if (end == 0) tmp += ", "; return tmp; }

UtilitiesClasspublic string formatNum(string str, int end = 0) { string tmp; tmp = str; if (end == 0) tmp += ", "; return tmp; }

UtilitiesClasspublic string formatDate(string tmp, string format = "mm/dd/yyyy") { string date = "(to_date(\'"+ tmp + "\'" + ",\'" + format + "\'))"; return date; }

generatorClass public void createFile(string[] array, int size, int filecount = 0) { bool atend = false; int count = array.Count(); int start = 0, end = count; double loop = (double)count / 1000 * size; string filename; if (array.Count() >= 1000 / size) { end = start + 1000 / size; } //for(int i = 0; i < Math.Ceiling(loop); i++) while (atend == false) { if (end == array.Count()) { atend = true; } filename = "insert" + Convert.ToString(filecount) + ".sql"; uC.writeLine("@" + filename + ";", "insertall.sql"); uC.writeLine("INSERT ALL", filename); uC.parallelWrite(array, filename, start, end); uC.writeLine("SELECT * FROM dual;", filename); filecount++; start = end + 1; if (end + 1000 / size - 1 >= array.Count() - 1) end = array.Count(); else end = end + (1000 / size);

}

}

//builds an array of numbers for use with unique number sets public int[] initIds(int size) { int[] nums = new int[size]; nums[0] = 0; for (int i = 1; i < size; i++) nums[i] = nums[i - 1] + 1; return nums; }

//generates a random number based on the upper and lower boundaries int getRand(int ub, int lb = 0) { int num = 0; num = ThreadSafeRandom.Next(lb, ub); return num; }

//returns a value which is based on an uneven displacement //takes an array of integers to represent percentile for the value string of the same index //and the string array of values public string getImbalanced(int[] percentile, string[] values) { int num = 0, num2, count = 0, sum = 0;

for (int i = 0; i < percentile.Count(); i++){sum += percentile[i];} num2 = getRand(sum + 1); bool found = false; while (found == false) { num += percentile[count]; if (num2 <= num){found = true;} else count++; } return values[count]; }

//generates a string of numbers buffered by zeros public string getZeroBufferString(int[] ids, int length) { string id, formatString = null; long num = -1; while (num == -1) { num = ids[getRand(ids.Count())]; } ids[num] = -1; for (int i = 0; i < length; i++) { formatString += '0'; } id = num.ToString(formatString);

return id; }

//gets a randomly chosen name from the array passed to it public string getName(string[] name, int offset = 1) { string ChosenName = "blank";

int num = getRand(name.Count(), offset); ChosenName = name[num]; return ChosenName; }

//combines calls to the getDate function to generate a date within a specified range public string textDate(string format = "mm/dd/yyyy", int yearStart = 0, int yearEnd = 0) { if(yearStart == 0) yearStart = DateTime.Now.Year - 100; if(yearEnd == 0) yearEnd = DateTime.Now.Year; string date; if (format == "mm/dd/yyyy") { date = getDate(12, 1) + "/" + getDate(28, 1) + "/" + getDate(yearEnd, yearStart); } else { date = getDate(28, 1) + "/" + getDate(12, 1) + "/" + getDate(yearEnd, yearStart); } return date; }

//generates date within a given range public string getDate(int max, int min = 0) { max++; string date = null; int num = getRand(max, min); if (num < 10) { date += Convert.ToString(0); } date += Convert.ToString(num); return date; }

//generates a standard login name : first initial, with last name public string getlogin(string FirstName, string LastName) { if (FirstName == null || LastName == null) return null;

string email = FirstName.Substring(0, 1).ToLower() + LastName.ToLower();

return email; }

//uses a login and domain to generate a business email address public string getEmail(string login, string domain = "contoso.com") { return login + "@" + domain; }

ThreadSafeRandom [ThreadStatic]

private static Random _random; public ThreadSafeRandom() { _random = SafeRandom(); }

private static Random SafeRandom() {

return _random ?? (_random = new Random(Environment.TickCount));

} public static int Next(int lb, int ub) { try { int? x = _random.Next(lb, ub); if (x!=null) { return Convert.ToInt32(x); } else return Convert.ToInt32( Next(lb, ub)); } catch { _random = SafeRandom(); return Next(lb, ub); } }

top related