示例#1
0
    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);
    }
示例#2
0
    public (bool, string) GetElevdataFromQresFinder(QresFinder qrf)
    {
        if (!qrf.Exists())
        {
            return(false, "Qrf could not find data");
        }
        var text   = qrf.GetText();
        var textar = text.Split('\n');
        var df     = new SimpleDf();

        df.ReadCsv(textar);
        var rv = ProcessDf(df);

        return(rv);
    }
示例#3
0
    public (bool, string) GetElevdataFromCsvFile(string fname)
    {
        bool ok     = false;
        var  errmsg = "no error";

        if (!File.Exists(fname))
        {
            heights = new List <float>();;
            errmsg  = $"File {fname} does not exist";
            return(ok, errmsg);
        }
        var df = new SimpleDf();

        df.ReadCsv(fname);
        return(ProcessDf(df));
    }
示例#4
0
        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
        }
示例#5
0
    void testsdf(SimpleDf sdf, string startFilterDate, string endFilterDate)
    {
        sdf.OutputDebugInfoStatStr();
        var tdf = SimpleDf.Copy(sdf, "tdf");

        Debug.Log($"Copying completed");
        Debug.Log($"Copied {tdf.InfoStr()}");
        Debug.Log($"Cols: {tdf.InfoClassStr()}");
        Debug.Log($"Cols: {tdf.InfoInversionsStr()}");
        tdf.KeepColumns(new string[] { "Id", "Timestamp", "x", "y" });
        //tdf = SimpleDf.SortOnColumn(tdf, "Timestamp", descend:true, quiet: false);
        tdf.preferedFormat["Timestamp"] = "yyyy-MM-dd HH:mm:ss.fff";
        var tblst = tdf.GetBoolFilter("Timestamp", startFilterDate, endFilterDate);

        tdf = SimpleDf.Subset(tdf, "tdf", tblst);
        tdf.MakeNewFloatCol("testcol", 0.0f, 3.14f);
        tdf.FloatTimeFromDateString("Timestamp", "Elaptime");
        tdf.preferedFormat["Elaptime"] = "f2";
        tdf.WriteCsv("testcsvname.csv");
    }
示例#6
0
 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());
     }
 }
示例#7
0
    public void Init(VehicleTrack vehicleTrack, SimpleDf sdf, GameObject vehicleParent, string avatartype, float startime, float avaSecpersecInput)
    {
        this.vehicleTrack = vehicleTrack;
        this.vtm          = vehicleTrack.vtm;
        this.sdf          = sdf;
        this.avaSecpersec = avaSecpersecInput;
        var cnt = Count(avatartype);

        totcnt++;

        avaGo = new GameObject(avatartype + "_" + cnt);
        avaGo.transform.parent = vehicleParent.transform;
        GameObject prefabgo = null;
        var        shift    = Vector3.zero;
        var        angle    = 0;
        var        scale    = 1;

        switch (avatartype)
        {
        case "DumpTruck":
            scale    = 1;
            angle    = 180;
            prefabgo = Resources.Load <GameObject>("obj/DumpTruck_TS1");
            break;

        case "Dozer1":
            scale    = 1;
            angle    = 0;
            shift    = new Vector3(-28.80f, 0, 0);
            prefabgo = Resources.Load <GameObject>("obj/Dozer1");
            break;

        case "Dozer2":
            scale    = 1;
            angle    = 0;
            shift    = new Vector3(-20, 0, 0);
            prefabgo = Resources.Load <GameObject>("obj/Dozer2");
            break;

        case "Minehaul1":
            scale    = 1;
            angle    = 0;
            shift    = new Vector3(0, 0, 0);
            prefabgo = Resources.Load <GameObject>("obj/Minehaul1");
            break;

        case "Shovel1":
            scale    = 1;
            angle    = 0;
            shift    = new Vector3(-10, 0, 0);
            prefabgo = Resources.Load <GameObject>("obj/Shovel1");
            break;

        case "Rover":
            scale    = 1;
            angle    = 0;
            shift    = new Vector3(0, 0, 0);
            prefabgo = Resources.Load <GameObject>("obj/Rover2");
            break;

        case "Sailboat1":
            scale    = 1;
            angle    = 90;
            shift    = new Vector3(0, 0, 0);
            prefabgo = Resources.Load <GameObject>("obj/Sailboat1");
            break;

        case "Sailboat100":
            scale             = 100;
            angle             = 90;
            this.avaSecpersec = avaSecpersec * 100;
            shift             = new Vector3(0, 0, 0);
            prefabgo          = Resources.Load <GameObject>("obj/Sailboat1");
            break;
        }
        switch (vtm.vehicleInitialPlacement)
        {
        case VehicleInitialPlacement.zero:
            this.starttime = avaSecpersec * vehicleTrack.vtm.GetSimulationTime();
            break;

        case VehicleInitialPlacement.random:
            this.starttime = vehicleTrack.GetRandomTrackTime();
            break;
        }
        if (prefabgo == null)
        {
            Debug.LogWarning($"Prefab not loaded for {avatartype}");
            return;
        }
        var       skav3 = prefabgo.transform.localScale * scale;
        Transform t     = UnityEngine.Object.Instantiate <Transform>(prefabgo.transform);

        t.localScale    = skav3;
        t.localRotation = Quaternion.Euler(0, angle, 0);
        t.position      = shift;
        t.SetParent(avaGo.transform, worldPositionStays: false);
        MoveToTracktime();
    }