示例#1
0
    public void get_avg()
    {
        CSVManager.CreateReport1();
        //var dataset = Resources.Load<TextAsset>("W:\\csv test\\CSharpToCSV\\Assets\\Report\report.csv");
        var dataset   = File.ReadAllText(@"W:\\csv test\\CSharpToCSV\\Assets\\Report\report.csv");
        var dataLines = dataset.Split(','); // Split also works with simple arguments, no need to pass char[]

        using (StreamWriter sw = File.AppendText(@"W:\\csv test\\CSharpToCSV\\Assets\\Report\report2.csv"))
        {
            for (int i = 0; i < dataLines.Length; i++)
            {
                var data = dataLines[i].Split(',');
                //string data1 = data;

                for (int d = 0; d < data.Length; d++)
                {
                    print(data[d]); // what you get is split sequential data that is column-first, then row
                                    //CSVManager.AppendToReport2(new string[]{
                                    //   data[i]

                    //data[d] += reportSeparator;

                    sw.WriteLine(data[d]);


                    //for(int k = 0; k < data.Length; k++)
                    //{
                    //  sw.WriteLine("," + data[d]);
                    //}
                    //sw.WriteLine(data[1]);
                    //sw.WriteLine(data[2]);
                    //sw.WriteLine(data[3]);
                }
            }
        }


        Avg_hips_x = "=AVERAGE(A2:A" + count + ")";
        Avg_hips_y = "=AVERAGE(B2:B" + count + ")";
        Avg_hips_z = "=AVERAGE(C2:C" + count + ")";

        Avg_Spine_x = "=AVERAGE(D2:D" + count + ")";
        Avg_Spine_y = "=AVERAGE(E2:E" + count + ")";
        Avg_Spine_z = "=AVERAGE(F2:F" + count + ")";

        Avg_Neck_x = "=AVERAGE(G2:G" + count + ")";
        Avg_Neck_y = "=AVERAGE(H2:H" + count + ")";
        Avg_Neck_z = "=AVERAGE(I2:I" + count + ")";

        Avg_Head_x = "=AVERAGE(J2:J" + count + ")";
        Avg_Head_y = "=AVERAGE(K2:K" + count + ")";
        Avg_Head_z = "=AVERAGE(L2:L" + count + ")";

        Avg_leftShoulder_x = "=AVERAGE(M2:M" + count + ")";
        Avg_leftShoulder_y = "=AVERAGE(N2:N" + count + ")";
        Avg_leftShoulder_z = "=AVERAGE(O2:O" + count + ")";

        Avg_RightShoulder_x = "=AVERAGE(P2:P" + count + ")";
        Avg_RightShoulder_y = "=AVERAGE(Q2:Q" + count + ")";
        Avg_RightShoulder_z = "=AVERAGE(R2:R" + count + ")";

        Avg_leftArm_x = "=AVERAGE(S2:S" + count + ")";
        Avg_leftArm_y = "=AVERAGE(T2:T" + count + ")";
        Avg_leftArm_z = "=AVERAGE(U2:U" + count + ")";

        Avg_leftForeArm_x = "=AVERAGE(V2:V" + count + ")";
        Avg_leftForeArm_y = "=AVERAGE(W2:W" + count + ")";
        Avg_leftForeArm_z = "=AVERAGE(X2:X" + count + ")";

        Avg_leftHand_x = "=AVERAGE(Y2:Y" + count + ")";
        Avg_leftHand_y = "=AVERAGE(Z2:Z" + count + ")";
        Avg_leftHand_z = "=AVERAGE(AA2:AA" + count + ")";

        Avg_RightArm_x = "=AVERAGE(AB2:AB" + count + ")";
        Avg_RightArm_y = "=AVERAGE(AC2:AC" + count + ")";
        Avg_RightArm_z = "=AVERAGE(AD2:AD" + count + ")";

        Avg_RightForeArm_x = "=AVERAGE(AE2:AE" + count + ")";
        Avg_RightForeArm_y = "=AVERAGE(AF2:AF" + count + ")";
        Avg_RightForeArm_z = "=AVERAGE(AG2:AG" + count + ")";

        Avg_RightHand_x = "=AVERAGE(AH2:AH" + count + ")";
        Avg_RightHand_y = "=AVERAGE(AI2:AI" + count + ")";
        Avg_RightHand_z = "=AVERAGE(AJ2:AJ" + count + ")";

        Avg_leftUpLeg_x = "=AVERAGE(AK2:AK" + count + ")";
        Avg_leftUpLeg_y = "=AVERAGE(AL2:AL" + count + ")";
        Avg_leftUpLeg_z = "=AVERAGE(AM2:AM" + count + ")";

        Avg_leftLeg_x = "=AVERAGE(AN2:AN" + count + ")";
        Avg_leftLeg_y = "=AVERAGE(AO2:AO" + count + ")";
        Avg_leftLeg_z = "=AVERAGE(AP2:AP" + count + ")";

        Avg_leftFoot_x = "=AVERAGE(AQ2:AQ" + count + ")";
        Avg_leftFoot_y = "=AVERAGE(AR2:AR" + count + ")";
        Avg_leftFoot_z = "=AVERAGE(AS2:AS" + count + ")";

        Avg_rightUpLeg_x = "=AVERAGE(AT2:AT" + count + ")";
        Avg_rightUpLeg_y = "=AVERAGE(AU2:AU" + count + ")";
        Avg_rightUpLeg_z = "=AVERAGE(AV2:AV" + count + ")";

        Avg_rightLeg_x = "=AVERAGE(AW2:AW" + count + ")";
        Avg_rightLeg_y = "=AVERAGE(AX2:AX" + count + ")";
        Avg_rightLeg_z = "=AVERAGE(AY2:AY" + count + ")";

        Avg_rightFoot_x = "=AVERAGE(AZ2:AZ" + count + ")";
        Avg_rightFoot_y = "=AVERAGE(BA2:BA" + count + ")";
        Avg_rightFoot_z = "=AVERAGE(BB2:BB" + count + ")";
        CSVManager.AppendToReport(
            new string[54] {
            Avg_hips_x,
            Avg_hips_y,
            Avg_hips_z,

            Avg_Spine_x,
            Avg_Spine_y,
            Avg_Spine_z,

            Avg_Neck_x,
            Avg_Neck_y,
            Avg_Neck_z,

            Avg_Head_x,
            Avg_Head_y,
            Avg_Head_z,

            Avg_leftShoulder_x,
            Avg_leftShoulder_y,
            Avg_leftShoulder_z,

            Avg_RightShoulder_x,
            Avg_RightShoulder_y,
            Avg_RightShoulder_z,

            Avg_leftArm_x,
            Avg_leftArm_y,
            Avg_leftArm_z,

            Avg_leftForeArm_x,
            Avg_leftForeArm_y,
            Avg_leftForeArm_z,

            Avg_leftHand_x,
            Avg_leftHand_y,
            Avg_leftHand_z,

            Avg_RightArm_x,
            Avg_RightArm_y,
            Avg_RightArm_z,

            Avg_RightForeArm_x,
            Avg_RightForeArm_y,
            Avg_RightForeArm_z,

            Avg_RightHand_x,
            Avg_RightHand_y,
            Avg_RightHand_z,

            Avg_leftUpLeg_x,
            Avg_leftUpLeg_y,
            Avg_leftUpLeg_z,

            Avg_leftLeg_x,
            Avg_leftLeg_y,
            Avg_leftLeg_z,

            Avg_leftFoot_x,
            Avg_leftFoot_y,
            Avg_leftFoot_z,

            Avg_rightUpLeg_x,
            Avg_rightUpLeg_y,
            Avg_rightUpLeg_z,

            Avg_rightLeg_x,
            Avg_rightLeg_y,
            Avg_rightLeg_z,

            Avg_rightFoot_x,
            Avg_rightFoot_y,
            Avg_rightFoot_z,
        }
            );
        //Debug.Log("<color=green>Average updated successfully!</color>");
        //var textReader = new StreamReader("W:\\csv test\\CSharpToCSV\\Assets\\Report\report.csv");
        //var csv = new CsvReader(textReader, System.Globalization.CultureInfo.CreateSpecificCulture("enUS"));
        //var records = csv.GetRecords<report>();
        // var average = records.Average(_ => _.hips_x);
        // print("avs is: " + average);

        /* var reader = new StreamReader(File.OpenRead(@"W:\\csv test\\CSharpToCSV\\Assets\\Report\report.csv"));
         * List<string> listA = new List<string>();
         * List<string> listB = new List<string>();
         * while (!reader.EndOfStream)
         * {
         * var line = reader.ReadLine();
         * var values = line.Split(';');
         *
         *   listA.Add(values[0]);
         *   //listB.Add(values[1]);
         *
         * }
         * int headerRow = 1;
         * foreach (var values in listA.Skip(headerRow))
         * {
         *   Debug.Log(values);
         * }*/

        /*var contents = File.ReadAllText(@"W:\\csv test\\CSharpToCSV\\Assets\\Report\report.csv").Split('\n');
         * var csv = from line in contents
         *        select line.Split(',').ToArray();
         *
         * int headerRows = 1;
         * foreach (var row in csv.Skip(headerRows)
         *  .TakeWhile(r => r.Length > 1 && r.Last().Trim().Length > 0))
         * {
         *  string zerothColumnValue = row[0]; // leftmost column
         *  var firstColumnValue = row[1];
         * }*/



        //}
    }