public (bool, string) ProcessDf(SimpleDf df) { var ok = true; var errmsg = ""; var rheights = new List <float>(); var vsum = 0f; var icnt = 0; var nc = df.Ncol(); var nr = df.Nrow(); var icolstart = df.ColIdx("V0"); for (int irow = 0; irow < nr; irow++) { for (int icol = icolstart; icol < nc; icol++) { var v = df.GetFltColRow(icol, irow); rheights.Add(v); vsum += v; icnt++; } } ok = true; var vavg = vsum / icnt; Debug.Log($"Got {icnt} values average:{vavg}"); heights = rheights; return(ok, errmsg); }
public void SimpleTest() { var sdf = new SimpleDf("sdf"); sdf.preferedType["id"] = SdfColType.dfint; sdf.preferedType["dt"] = SdfColType.dfdatetime; sdf.preferedFormat["dt"] = "yyyy-MM-dd HH:mm:ss"; sdf.preferedSubstitute["dt"] = ("+00", ""); sdf.ReadCsv(sdflines); Assert.True(sdf.Nrow() == 3); Assert.True(sdf.Ncol() == 5); Assert.True(sdf.InfoClassStr() == "Classes:id:dfint,x:dfdouble,y:dfdouble,dt:dfdatetime,n:dfstring"); Assert.True(sdf.GetIntCol("id").Sum() == 6); Assert.True(sdf.GetDoubleCol("x").Sum() == 6); Assert.True(sdf.GetDoubleCol("y").Sum() == 9); Assert.True(sdf.DataErrors() == 0); // Use the Assert class to test conditions }
public void Load(string startFilterDate, string endFilterDate) { try { ResolveFullCsvName(); Debug.Log("Load " + fullcsvname); sdf = new SimpleDf(); sdf.comment = clr; sdf.CheckConsistency("Before Load"); sdf.preferedType["Id"] = SdfColType.dflong; sdf.preferedType["Timestamp"] = SdfColType.dfdatetime; sdf.preferedFormat["Timestamp"] = "yyyy-MM-dd HH:mm:ss.fff"; sdf.preferedType["time"] = SdfColType.dfdatetime; sdf.preferedFormat["time"] = "yyyy/MM/dd HH:mm:ss.fff"; sdf.preferedSubstitute["time"] = ("+00", ""); sdf.ReadCsv(fullcsvname, quiet: false); Debug.Log($"Read {sdf.InfoStr()}"); Debug.Log($"Cols: {sdf.InfoClassStr()}"); Debug.Log($"Copying {sdf.InfoStr()}"); var test = false; if (test) { testsdf(sdf, startFilterDate, endFilterDate); } var tcolname = "Timestamp"; isdozertrack = true; if (sdf.ColumnExists("time")) { tcolname = "time"; isdozertrack = false; } sdf.KeepColumns(new string[] { "Id", "Timestamp", "x", "y", "time", "X", "Y" }); sdf = SimpleDf.SortOnColumn(sdf, tcolname); if (isdozertrack) { var blst = sdf.GetBoolFilter("Timestamp", startFilterDate, endFilterDate); sdf = SimpleDf.Subset(sdf, "df", blst); } else { sdf.RenameColumn("X", "x"); sdf.RenameColumn("Y", "y"); } sdf.FloatTimeFromDateString(tcolname, "Elaptime"); sdf.preferedFormat["Elaptime"] = "f2"; test = true; if (test) { sdf.WriteCsv("transformed_df.csv"); } var nrow = sdf.Nrow(); if (nrow == 0) { Debug.LogWarning("No rows in df " + fullcsvname); sdf = null; } } catch (Exception ex) { Debug.LogError("Exception in DozerTracks.Load:" + ex.ToString()); } }