private static string[] BuildOutput(InputPayload line, DateTime[] dates) { // 1) "Pen" // 2) "TRT" // 3) "Rep" // 4) "Ration" // 5) "ID" // 6) "IWT" // 7) "FWT" // 8) "ADG" string[] results = new string[8]; results[0] = line.Pen; results[1] = line.TRT; results[2] = line.Rep; results[3] = line.Ration; results[4] = line.ID; decimal?iwt = null; decimal?fwt = null; decimal?adg = null; if (dates.Length > 1) { // calculate IWT // check if the first two dates are contiguous if (AreDatesContiguous(dates[0], dates[1])) { iwt = line.Weights.Take(2).Average(); } else { iwt = line.Weights[0]; } // calculate FWT // check if the last two dates are contiguous if (AreDatesContiguous(dates[dates.Length - 2], dates[dates.Length - 1])) { fwt = line.Weights.Skip(line.Weights.Length - 2).Average(); } else { fwt = line.Weights.Last(); } // calculate ADG int daysInStudy = (dates[dates.Length - 1].Date - dates[0].Date).Days; decimal gain = line.Weights[line.Weights.Length - 1] - line.Weights[0]; if (daysInStudy > 0) { adg = gain / daysInStudy; } } results[5] = iwt.HasValue ? iwt.Value.ToString() : "0"; results[6] = fwt.HasValue ? fwt.Value.ToString() : "0"; results[7] = adg.HasValue ? adg.Value.ToString() : "0"; return(results); }
private static string[] BuildOutput(InputPayload line, DateTime[] dates) { // 1) "Pen" // 2) "TRT" // 3) "Rep" // 4) "Ration" // 5) "ID" // 6) "IWT" // 7) "FWT" // 8) "ADG" string[] results = new string[8]; results[0] = line.Pen; results[1] = line.TRT; results[2] = line.Rep; results[3] = line.Ration; results[4] = line.ID; decimal? iwt = null; decimal? fwt = null; decimal? adg = null; if (dates.Length > 1) { // calculate IWT // check if the first two dates are contiguous if (AreDatesContiguous(dates[0], dates[1])) { iwt = line.Weights.Take(2).Average(); } else { iwt = line.Weights[0]; } // calculate FWT // check if the last two dates are contiguous if (AreDatesContiguous(dates[dates.Length - 2], dates[dates.Length - 1])) { fwt = line.Weights.Skip(line.Weights.Length - 2).Average(); } else { fwt = line.Weights.Last(); } // calculate ADG int daysInStudy = (dates[dates.Length - 1].Date - dates[0].Date).Days; decimal gain = line.Weights[line.Weights.Length - 1] - line.Weights[0]; if (daysInStudy > 0) adg = gain / daysInStudy; } results[5] = iwt.HasValue ? iwt.Value.ToString() : "0"; results[6] = fwt.HasValue ? fwt.Value.ToString() : "0"; results[7] = adg.HasValue ? adg.Value.ToString() : "0"; return results; }
private static InputPayload GetPayloadFromLine(string line) { var fields = GetFields(line); var payload = new InputPayload() { Pen = fields[0], TRT = fields[1], Rep = fields[2], Ration = fields[3], ID = fields[4], Weights = fields.Skip(5).Select(s => !String.IsNullOrWhiteSpace(s) ? Decimal.Parse(s) : 0).ToArray() }; return(payload); }
private static InputPayload GetPayloadFromLine(string line) { var fields = GetFields(line); var payload = new InputPayload() { Pen = fields[0], TRT = fields[1], Rep = fields[2], Ration = fields[3], ID = fields[4], Weights = fields.Skip(5).Select(s => !String.IsNullOrWhiteSpace(s) ? Decimal.Parse(s) : 0).ToArray() }; return payload; }