private void UpdateErgList() { ErgList = new List <Erg>(); foreach (Activity a in Data) { if (a.WorkPerformed > 0) { Erg m = new Erg(a); if (m.ParsedErg) { ErgList.Add(m); a.Erg = true; } } } }
private void ErgSerialization(List <Erg> ergdata, bool show) { string ergListFile = Path.Combine(Environment.CurrentDirectory, "erg.csv"); StreamWriter sw = new StreamWriter(ergListFile, false); Erg E = new Erg(); sw.WriteLine(E.GetDesc()); foreach (Erg e in ergdata) { sw.WriteLine(e.Serialize()); } sw.Close(); if (show) { Process.Start(ergListFile); } }
private List <Activity> ParseFile(string file) { List <Activity> workouts = new List <Activity>(); //Get First Line StreamReader streamReader = new StreamReader(file); string firstLine = streamReader.ReadLine(); streamReader.Close(); TextReader sr = File.OpenText(file); var parser = new CsvParser(sr); string[] row = parser.Read(); List <string[]> newLines = new List <string[]>(); while (true) { row = parser.Read(); newLines.Add(row); if (row == null) { break; } } sr.Close(); File.Delete(file); StreamWriter sw = new StreamWriter(file, false); sw.WriteLine(firstLine); sw.Flush(); using (var csv = new CsvWriter(sw)) { foreach (string[] line in newLines) { if (line != null) { string Workout = line[1]; string Description = line[9]; if ((Workout.Contains("Echo Bike Calories") || Description.Contains("Echo Bike Calories")) && line[5].Equals("0")) { string Result = line[2]; string WorkPerformed = line[5]; if (Workout.Contains("AMReps") || Workout.Contains("Tabata")) { WorkPerformed = (int.Parse(Result) * 639).ToString(); } else if (Workout.Contains("RFT")) { string[] split = Description.Split('\n'); Regex regex = new Regex("[0-9]+"); int rnds = 0; int cals = 0; foreach (string s in split) { if (s.Contains("Echo")) { Match m = regex.Match(s); if (m.Success) { cals = int.Parse(m.Value); } } if (s.Contains("rounds")) { Match m = regex.Match(s); if (m.Success) { rnds = int.Parse(m.Value); } } } if (cals > 0 && rnds > 0) { WorkPerformed = (rnds * cals * 639).ToString(); } } else if (Workout.Contains("FT")) { string[] split = Description.Split(' '); int cals = int.Parse(split[0]); WorkPerformed = (cals * 639).ToString(); } line[5] = WorkPerformed; } for (int i = 0; i < 10; i++) { string s = line[i]; csv.WriteField(s); } Activity act = new Activity(line); Erg erg = new Erg(act); csv.WriteField(erg.ParsedErg.ToString()); csv.NextRecord(); } } } sw.Close(); sr = File.OpenText(file); parser = new CsvParser(sr); row = parser.Read(); while (true) { row = parser.Read(); if (row == null) { break; } Activity wo = new Activity(row); workouts.Add(wo); } sr.Close(); return(workouts); }