コード例 #1
0
    /// <summary>
    /// 更新本地版本信息
    /// </summary>
    /// <param name="ab">Ab.</param>
    public static void SyncVersion(List <string> abs)
    {
        // 遍历需要更新的ab信息
        foreach (string ab in abs)
        {
            // 新版树中没有该版本信息
            CsvRow data = mNewVersionCsv.FindByKey(ab);
            if (data == null)
            {
                return;
            }

            // 修正本地版本信息
            CsvRow oldData = mVersionCsv.FindByKey(ab);

            // 如果是新增资源
            if (oldData == null)
            {
                // 构建一列数据
                CsvRow row = new CsvRow(mNewVersionCsv);
                row.Add("bundle", data.Query <LPCValue>("bundle"));
                row.Add("md5", data.Query <LPCValue>("md5"));
                row.Add("patch", data.Query <LPCValue>("patch"));
                row.Add("unzip_size", data.Query <LPCValue>("unzip_size"));
                row.Add("zip_size", data.Query <LPCValue>("zip_size"));

                // 添加新数据
                mVersionCsv.AddNewRow(row);
            }
            else
            {
                oldData.Add("md5", data.Query <LPCValue>("md5"));
                oldData.Add("patch", data.Query <LPCValue>("patch"));
                oldData.Add("unzip_size", data.Query <LPCValue>("unzip_size"));
                oldData.Add("zip_size", data.Query <LPCValue>("zip_size"));
            }
        }

        // 序列化
        MemoryStream ms = new MemoryStream();

        CsvFileMgr.Serialize(ms, mVersionCsv);

        // 版本文件存放路径
        string     versionFilePath = string.Format("{0}/{1}.bytes", ConfigMgr.ASSETBUNDLES_PATH, VERSION_NAME);
        FileStream fs = new FileStream(versionFilePath, FileMode.Create, FileAccess.Write);

        fs.Write(ms.GetBuffer(), 0, (int)ms.Length);
        fs.Close();
    }
コード例 #2
0
        public string PrintToCsv()
        {
            //Get all attribute names
            List <string> AttributeNames = new List <string>();

            foreach (DataRecord dr in Records)
            {
                foreach (DataAttribute da in dr.Attributes)
                {
                    if (AttributeNames.Contains(da.Name) == false)
                    {
                        AttributeNames.Add(da.Name);
                    }
                }
            }

            //Make the csv file
            CsvFile csv = new CsvFile();


            //Write the headers
            DataRow header_row = csv.AddNewRow();

            foreach (string s in AttributeNames)
            {
                header_row.Values.Add(s);
            }

            //Write the records
            foreach (DataRecord dr in Records)
            {
                DataRow csv_row = csv.AddNewRow();
                foreach (string s in AttributeNames)
                {
                    try
                    {
                        DataAttribute da = dr.GetDataAttribute(s);
                        csv_row.Values.Add(da.Value);
                    }
                    catch
                    {
                        csv_row.Values.Add("");
                    }
                }
            }

            return(csv.GenerateAsCsvFileContent());
        }
        public string PrintFinancialStatements(FinancialStatement[] statements)
        {
            CsvFile csv = new CsvFile();

            //Write title
            List <string>       PropertiesToWrite = new List <string>();
            List <PropertyInfo> ToWriteProperties = new List <PropertyInfo>();
            DataRow             header            = csv.AddNewRow();

            PropertyInfo[] info = statements[0].GetType().GetProperties();
            foreach (PropertyInfo pi in info)
            {
                if (pi.PropertyType.IsClass == false)
                {
                    header.Values.Add(pi.Name);
                    PropertiesToWrite.Add(pi.Name);
                    ToWriteProperties.Add(pi);
                }
            }

            //Write all of the properties
            foreach (FinancialStatement fs in statements)
            {
                DataRow dr = csv.AddNewRow();
                foreach (PropertyInfo pi in ToWriteProperties)
                {
                    try
                    {
                        dr.Values.Add(pi.GetValue(fs).ToString());
                    }
                    catch
                    {
                        dr.Values.Add("-");
                    }
                }
            }

            return(csv.GenerateAsCsvFileContent());
        }
コード例 #4
0
        public static void CountAllTransactions()
        {
            Console.Write("Folder with transactions: ");
            string folder = Console.ReadLine().Replace("\"", "");

            Console.Write("Output CSV to what folder?");
            string outputto = Console.ReadLine().Replace("\"", "");

            CsvFile         csv = new CsvFile();
            ResearchToolkit rt  = new ResearchToolkit();


            string[] files = System.IO.Directory.GetFiles(folder);
            foreach (string s in files)
            {
                NonDerivativeTransaction[] transactions = JsonConvert.DeserializeObject <NonDerivativeTransaction[]>(System.IO.File.ReadAllText(s));

                //Count those between 2010 and 2019
                int count = 0;
                NonDerivativeTransaction[] filt = rt.FilterToTransactionsOfInterest(transactions);
                count = filt.Length;

                DataRow dr = csv.AddNewRow();
                dr.Values.Add(System.IO.Path.GetFileName(s));
                dr.Values.Add(count.ToString());
                Console.WriteLine(System.IO.Path.GetFileName(s) + "-" + count.ToString());
            }

            Stream       ss = System.IO.File.Create(outputto + "\\output.csv");
            StreamWriter sw = new StreamWriter(ss);

            sw.Write(csv.GenerateAsCsvFileContent());
            sw.Close();
            ss.Close();
            Console.WriteLine("Written!");
        }
コード例 #5
0
        public string PrintTelemetryToCsvContent(byte driver_index)
        {
            CsvFile csv = new CsvFile();


            #region "Write headers"

            //Write headers
            DataRow dr_header = csv.AddNewRow();

            //Time
            dr_header.Values.Add("Session Time");

            //Motion packet
            dr_header.Values.Add("Position X");
            dr_header.Values.Add("Position Y");
            dr_header.Values.Add("Position Z");
            dr_header.Values.Add("Velocity X");
            dr_header.Values.Add("Velocity Y");
            dr_header.Values.Add("Velocity Z");
            dr_header.Values.Add("Forward Direction X");
            dr_header.Values.Add("Forward Direction Y");
            dr_header.Values.Add("Forward Direction Z");
            dr_header.Values.Add("Right Direction X");
            dr_header.Values.Add("Right Direction Y");
            dr_header.Values.Add("Right Direction Z");
            dr_header.Values.Add("Lateral G Force");
            dr_header.Values.Add("Longitudinal G Force");
            dr_header.Values.Add("Vertical G Force");
            dr_header.Values.Add("Yaw");
            dr_header.Values.Add("Pitch");
            dr_header.Values.Add("Roll");

            //Motion packet (only for player data, not for other drivers. Will be blank if requesting for other players)
            dr_header.Values.Add("Suspension Position - Rear Left");
            dr_header.Values.Add("Suspension Position - Rear Right");
            dr_header.Values.Add("Suspennsion Position - Front Left");
            dr_header.Values.Add("Suspension Position - Front Right");
            dr_header.Values.Add("Suspension Velocity - Rear Left");
            dr_header.Values.Add("Suspension Velocity - Rear Right");
            dr_header.Values.Add("Suspension Velocity - Front Left");
            dr_header.Values.Add("Suspension Velocity - Front Right");
            dr_header.Values.Add("Suspension Acceleration - Rear Left");
            dr_header.Values.Add("Suspension Acceleration - Rear Right");
            dr_header.Values.Add("Suspension Acceleration - Front Left");
            dr_header.Values.Add("Suspension Acceleration - Front Right");
            dr_header.Values.Add("Wheel Speed - Rear Left");
            dr_header.Values.Add("Wheel Speed - Rear Right");
            dr_header.Values.Add("Wheel Speed - Front Left");
            dr_header.Values.Add("Wheel Speed - Front Right");
            dr_header.Values.Add("Wheel Slip - Rear Left");
            dr_header.Values.Add("Wheel Slip - Rear Right");
            dr_header.Values.Add("Wheel Slip - Front Left");
            dr_header.Values.Add("Wheel Slip - Front Right");
            dr_header.Values.Add("Local Velocity X");
            dr_header.Values.Add("Local Velocity Y");
            dr_header.Values.Add("Local Velocity Z");
            dr_header.Values.Add("Angular Velocity X");
            dr_header.Values.Add("Angular Velocity Y");
            dr_header.Values.Add("Angular Velocity Z");
            dr_header.Values.Add("Angular Acceleration X");
            dr_header.Values.Add("Angular Acceleration Y");
            dr_header.Values.Add("Angular Acceleration Z");
            dr_header.Values.Add("Front Wheels Angle");

            //Lap Packet
            dr_header.Values.Add("Lap Distance");
            dr_header.Values.Add("Total Distance");
            dr_header.Values.Add("Safety Car Delta");
            dr_header.Values.Add("Car Race Position");
            dr_header.Values.Add("Current Lap Number");
            dr_header.Values.Add("Pit Status");
            dr_header.Values.Add("Sector");
            dr_header.Values.Add("Current Lap Invalid");
            dr_header.Values.Add("Driver Status");



            //Telemetry Packet
            dr_header.Values.Add("Speed KPH");
            dr_header.Values.Add("Speed MPH");
            dr_header.Values.Add("Throttle");
            dr_header.Values.Add("Steer");
            dr_header.Values.Add("Brake");
            dr_header.Values.Add("Clutch");
            dr_header.Values.Add("Gear");
            dr_header.Values.Add("Engine RPM");
            dr_header.Values.Add("DRS Active");
            dr_header.Values.Add("Rev Lights Percentage");
            dr_header.Values.Add("Brake Temperature - Rear Left");
            dr_header.Values.Add("Brake Temperature - Rear Right");
            dr_header.Values.Add("Brake Temperature - Front Left");
            dr_header.Values.Add("Brake Temperature - Front Right");
            dr_header.Values.Add("Tyre Surface Temperature - Rear Left");
            dr_header.Values.Add("Tyre Surface Temperature - Rear Right");
            dr_header.Values.Add("Tyre Surface Temperature - Front Left");
            dr_header.Values.Add("Tyre Surface Temperature - Front Right");
            dr_header.Values.Add("Tyre Inner Temperature - Rear Left");
            dr_header.Values.Add("Tyre Inner Temperature - Rear Right");
            dr_header.Values.Add("Tyre Inner Temperature - Front Left");
            dr_header.Values.Add("Tyre Inner Temperature - Front Right");
            dr_header.Values.Add("Engine Temperature Celsius");
            dr_header.Values.Add("Tyre Pressure - Rear Left");
            dr_header.Values.Add("Tyre Pressure - Rear Right");
            dr_header.Values.Add("Tyre Pressure - Front Left");
            dr_header.Values.Add("Tyre Pressure - Front Right");
            dr_header.Values.Add("Surface Type - Rear Left");
            dr_header.Values.Add("Surface Type - Rear Right");
            dr_header.Values.Add("Surface Type - Front Left");
            dr_header.Values.Add("Surface Type - Front Right");

            //Car Status
            dr_header.Values.Add("Traction Control Level");
            dr_header.Values.Add("Anti Lock Brakes Active");
            dr_header.Values.Add("Fuel Mix");
            dr_header.Values.Add("Front Brake Bias Percentage");
            dr_header.Values.Add("Pit Limiter Active");
            dr_header.Values.Add("Fuel In Tank");
            dr_header.Values.Add("Max Fuel Capacity");
            dr_header.Values.Add("Fuel Remaining in Laps");
            dr_header.Values.Add("Max RPM");
            dr_header.Values.Add("Idle RPM");
            dr_header.Values.Add("Max Gears");
            dr_header.Values.Add("DRS Allowed");
            dr_header.Values.Add("DRS Activation Distance");
            dr_header.Values.Add("Tyre Wear - Rear Left");
            dr_header.Values.Add("Tyre Wear - Rear Right");
            dr_header.Values.Add("Tyre Wear - Front Left");
            dr_header.Values.Add("Tyre Wear - Front Right");
            dr_header.Values.Add("Actual Tyre Compound");
            dr_header.Values.Add("Visual Tyre Compound");
            dr_header.Values.Add("Tyre Age in Laps");
            dr_header.Values.Add("Tyre Damage Percentage - Rear Left");
            dr_header.Values.Add("Tyre Damage Percentage - Rear Right");
            dr_header.Values.Add("Tyre Damage Percentage - Front Left");
            dr_header.Values.Add("Tyre Damage Percentage - Front Right");
            dr_header.Values.Add("Front Left Wing Damage Percentage");
            dr_header.Values.Add("Front Right Wing Damage Percentage");
            dr_header.Values.Add("Rear Wing Damage Percentage");
            dr_header.Values.Add("DRS Failure");
            dr_header.Values.Add("Engine Damage Percentage");
            dr_header.Values.Add("Gear Box Damage Percentage");
            dr_header.Values.Add("FIA Flag");
            dr_header.Values.Add("ERS Stored Energy Joules");
            dr_header.Values.Add("ERS Deploy Mode");
            dr_header.Values.Add("ERS Harvested This Lap by MGUK");
            dr_header.Values.Add("ERS Harvested This Lap by MGUH");
            dr_header.Values.Add("ERS Deployed This Lap");
            #endregion

            //Write the data
            foreach (PacketFrame frame in Frames)
            {
                //Create the new row
                DataRow row = csv.AddNewRow();

                //Write the session time
                row.Values.Add(frame.Telemetry.SessionTime.ToString());

                //Write Write motion data
                MotionPacket.CarMotionData cmd = frame.Motion.FieldMotionData[driver_index];
                row.Values.Add(cmd.PositionX.ToString());
                row.Values.Add(cmd.PositionY.ToString());
                row.Values.Add(cmd.PositionZ.ToString());
                row.Values.Add(cmd.VelocityX.ToString());
                row.Values.Add(cmd.VelocityY.ToString());
                row.Values.Add(cmd.VelocityZ.ToString());
                row.Values.Add(cmd.ForwardDirectionX.ToString());
                row.Values.Add(cmd.ForwardDirectionY.ToString());
                row.Values.Add(cmd.ForwardDirectionZ.ToString());
                row.Values.Add(cmd.RightDirectionX.ToString());
                row.Values.Add(cmd.RightDirectionY.ToString());
                row.Values.Add(cmd.RightDirectionZ.ToString());
                row.Values.Add(cmd.gForceLateral.ToString());
                row.Values.Add(cmd.gForceLongitudinal.ToString());
                row.Values.Add(cmd.gForceVertical.ToString());
                row.Values.Add(cmd.Yaw.ToString());
                row.Values.Add(cmd.Pitch.ToString());
                row.Values.Add(cmd.Roll.ToString());

                //Write motion data player-specific (if they are requesting for the player, return the data. Otherwise, return 0's!)
                if (driver_index == frame.Motion.PlayerCarIndex)
                {
                    row.Values.Add(frame.Motion.SuspensionPosition.RearLeft.ToString());
                    row.Values.Add(frame.Motion.SuspensionPosition.RearRight.ToString());
                    row.Values.Add(frame.Motion.SuspensionPosition.FrontLeft.ToString());
                    row.Values.Add(frame.Motion.SuspensionPosition.FrontRight.ToString());
                    row.Values.Add(frame.Motion.SuspensionVelocity.RearLeft.ToString());
                    row.Values.Add(frame.Motion.SuspensionVelocity.RearRight.ToString());
                    row.Values.Add(frame.Motion.SuspensionVelocity.FrontLeft.ToString());
                    row.Values.Add(frame.Motion.SuspensionVelocity.FrontRight.ToString());
                    row.Values.Add(frame.Motion.SuspensionAcceleration.RearLeft.ToString());
                    row.Values.Add(frame.Motion.SuspensionAcceleration.RearRight.ToString());
                    row.Values.Add(frame.Motion.SuspensionAcceleration.FrontLeft.ToString());
                    row.Values.Add(frame.Motion.SuspensionAcceleration.FrontRight.ToString());
                    row.Values.Add(frame.Motion.WheelSpeed.RearLeft.ToString());
                    row.Values.Add(frame.Motion.WheelSpeed.RearRight.ToString());
                    row.Values.Add(frame.Motion.WheelSpeed.FrontLeft.ToString());
                    row.Values.Add(frame.Motion.WheelSpeed.FrontRight.ToString());
                    row.Values.Add(frame.Motion.WheelSlip.RearLeft.ToString());
                    row.Values.Add(frame.Motion.WheelSlip.RearRight.ToString());
                    row.Values.Add(frame.Motion.WheelSlip.FrontLeft.ToString());
                    row.Values.Add(frame.Motion.WheelSlip.FrontRight.ToString());
                    row.Values.Add(frame.Motion.VelocityX.ToString());
                    row.Values.Add(frame.Motion.VelocityY.ToString());
                    row.Values.Add(frame.Motion.VelocityZ.ToString());
                    row.Values.Add(frame.Motion.AngularVelocityX.ToString());
                    row.Values.Add(frame.Motion.AngularVelocityY.ToString());
                    row.Values.Add(frame.Motion.AngularVelocityZ.ToString());
                    row.Values.Add(frame.Motion.AngularAccelerationX.ToString());
                    row.Values.Add(frame.Motion.AngularAccelerationY.ToString());
                    row.Values.Add(frame.Motion.AngularAccelerationZ.ToString());
                    row.Values.Add(frame.Motion.FrontWheelAngle.ToString());
                }
                else
                {
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                    row.Values.Add("-");
                }


                //Lap Packet
                LapPacket.LapData ld = frame.Lap.FieldLapData[driver_index];
                row.Values.Add(ld.LapDistance.ToString());
                row.Values.Add(ld.TotalDistance.ToString());
                row.Values.Add(ld.SafetyCarDelta.ToString());
                row.Values.Add(ld.CarPosition.ToString());
                row.Values.Add(ld.CurrentLapNumber.ToString());
                row.Values.Add(ld.CurrentPitStatus.ToString());
                row.Values.Add(ld.Sector.ToString());
                row.Values.Add(ld.CurrentLapInvalid.ToString());
                row.Values.Add(ld.CurrentDriverStatus.ToString());

                //Telemetry packet
                TelemetryPacket.CarTelemetryData ctd = frame.Telemetry.FieldTelemetryData[driver_index];
                row.Values.Add(ctd.SpeedKph.ToString());
                row.Values.Add(ctd.SpeedMph.ToString());
                row.Values.Add(ctd.Throttle.ToString());
                row.Values.Add(ctd.Steer.ToString());
                row.Values.Add(ctd.Brake.ToString());
                row.Values.Add(ctd.Clutch.ToString());
                row.Values.Add(ctd.Gear.ToString());
                row.Values.Add(ctd.EngineRpm.ToString());
                row.Values.Add(ctd.DrsActive.ToString());
                row.Values.Add(ctd.RevLightsPercentage.ToString());
                row.Values.Add(ctd.BrakeTemperature.RearLeft.ToString());
                row.Values.Add(ctd.BrakeTemperature.RearRight.ToString());
                row.Values.Add(ctd.BrakeTemperature.FrontLeft.ToString());
                row.Values.Add(ctd.BrakeTemperature.FrontRight.ToString());
                row.Values.Add(ctd.TyreSurfaceTemperature.RearLeft.ToString());
                row.Values.Add(ctd.TyreSurfaceTemperature.RearRight.ToString());
                row.Values.Add(ctd.TyreSurfaceTemperature.FrontLeft.ToString());
                row.Values.Add(ctd.TyreSurfaceTemperature.FrontRight.ToString());
                row.Values.Add(ctd.TyreInnerTemperature.RearLeft.ToString());
                row.Values.Add(ctd.TyreInnerTemperature.RearRight.ToString());
                row.Values.Add(ctd.TyreInnerTemperature.FrontLeft.ToString());
                row.Values.Add(ctd.TyreInnerTemperature.FrontRight.ToString());
                row.Values.Add(ctd.EngineTemperature.ToString());
                row.Values.Add(ctd.TyrePressure.RearLeft.ToString());
                row.Values.Add(ctd.TyrePressure.RearRight.ToString());
                row.Values.Add(ctd.TyrePressure.FrontLeft.ToString());
                row.Values.Add(ctd.TyrePressure.FrontRight.ToString());
                row.Values.Add(ctd.SurfaceType_RearLeft.ToString());
                row.Values.Add(ctd.SurfaceType_RearRight.ToString());
                row.Values.Add(ctd.SurfaceType_FrontLeft.ToString());
                row.Values.Add(ctd.SurfaceType_FrontRight.ToString());

                //Car status
                CarStatusPacket.CarStatusData csd = frame.CarStatus.FieldCarStatusData[driver_index];
                row.Values.Add(csd.TractionControlStatus.ToString());
                row.Values.Add(csd.AntiLockBrakesOn.ToString());
                row.Values.Add(csd.SelectedFuelMix.ToString());
                row.Values.Add(csd.FrontBrakeBiasPercentage.ToString());
                row.Values.Add(csd.PitLimiterOn.ToString());
                row.Values.Add(csd.FuelLevel.ToString());
                row.Values.Add(csd.FuelCapacity.ToString());
                row.Values.Add(csd.FuelRemainingLaps.ToString());
                row.Values.Add(csd.MaxRpm.ToString());
                row.Values.Add(csd.IdleRpm.ToString());
                row.Values.Add(csd.MaxGears.ToString());
                row.Values.Add(csd.DrsAllowed.ToString());
                row.Values.Add(csd.DrsActivationDistance.ToString());
                row.Values.Add(csd.TyreWearPercentage.RearLeft.ToString());
                row.Values.Add(csd.TyreWearPercentage.RearRight.ToString());
                row.Values.Add(csd.TyreWearPercentage.FrontLeft.ToString());
                row.Values.Add(csd.TyreWearPercentage.FrontRight.ToString());
                row.Values.Add(csd.EquippedTyreCompound.ToString());
                row.Values.Add(csd.EquippedVisualTyreCompoundId.ToString());
                row.Values.Add(csd.TyreAgeLaps.ToString());
                row.Values.Add(csd.TyreDamagePercentage.RearLeft.ToString());
                row.Values.Add(csd.TyreDamagePercentage.RearRight.ToString());
                row.Values.Add(csd.TyreDamagePercentage.FrontLeft.ToString());
                row.Values.Add(csd.TyreDamagePercentage.FrontRight.ToString());
                row.Values.Add(csd.FrontLeftWingDamagePercent.ToString());
                row.Values.Add(csd.FrontRightWingDamagePercent.ToString());
                row.Values.Add(csd.RearWingDamagePercent.ToString());
                row.Values.Add(csd.DrsFailure.ToString());
                row.Values.Add(csd.EngineDamagePercent.ToString());
                row.Values.Add(csd.GearBoxDamagePercent.ToString());
                row.Values.Add(csd.VehicleFiaFlag.ToString());
                row.Values.Add(csd.ErsStoredEnergyJoules.ToString());
                row.Values.Add(csd.SelectedErsDeployMode.ToString());
                row.Values.Add(csd.ErsHarvestedThisLapByMGUK.ToString());
                row.Values.Add(csd.ErsHarvestedThisLapByMGUH.ToString());
                row.Values.Add(csd.ErsDeployedThisLap.ToString());
            }

            return(csv.GenerateAsCsvFileContent());
        }
コード例 #6
0
        public static string PrintFinancialStatements(FinancialStatement[] statements)
        {
            #region  "Error checking"

            if (statements == null)
            {
                throw new Exception("Unable to print financial statements - the supplied array of statements was null.");
            }

            #endregion

            //Arrange the statements from oldest to newest
            List <FinancialStatement> ToPullFrom         = new List <FinancialStatement>();
            List <FinancialStatement> StatementsArranged = new List <FinancialStatement>();
            ToPullFrom.AddRange(statements);
            while (ToPullFrom.Count > 0)
            {
                FinancialStatement Winner = ToPullFrom[0];
                foreach (FinancialStatement fs in ToPullFrom)
                {
                    if (fs.PeriodEnd < Winner.PeriodEnd)
                    {
                        Winner = fs;
                    }
                }
                StatementsArranged.Add(Winner);
                ToPullFrom.Remove(Winner);
            }


            CsvFile csv = new CsvFile();

            //Headers
            DataRow dr_header = csv.AddNewRow();
            dr_header.Values.Add("Period Start");
            dr_header.Values.Add("Period End");
            dr_header.Values.Add("Revenue");
            dr_header.Values.Add("SGA Expenses");
            dr_header.Values.Add("R&D Expenses");
            dr_header.Values.Add("Operating Income");
            dr_header.Values.Add("Net Income");
            dr_header.Values.Add("Assets");
            dr_header.Values.Add("Liabilities");
            dr_header.Values.Add("Equity");
            dr_header.Values.Add("Cash");
            dr_header.Values.Add("Current Assets");
            dr_header.Values.Add("Current Liabilities");
            dr_header.Values.Add("Retained Earnings");
            dr_header.Values.Add("Common Stock Shares Outstanding");
            dr_header.Values.Add("Operating Cash Flows");
            dr_header.Values.Add("Investing Cash Flows");
            dr_header.Values.Add("Financing Cash Flows");
            dr_header.Values.Add("Proceeds from Issuance of Debt");
            dr_header.Values.Add("Payments of Debt");
            dr_header.Values.Add("Dividends Paid");

            //Add each value
            foreach (FinancialStatement fs in StatementsArranged)
            {
                DataRow dr = csv.AddNewRow();

                //Start date
                if (fs.PeriodStart.HasValue)
                {
                    dr.Values.Add(fs.PeriodStart.Value.ToShortDateString());
                }
                else
                {
                    dr.Values.Add("-");
                }

                //End date
                if (fs.PeriodEnd.HasValue)
                {
                    dr.Values.Add(fs.PeriodEnd.Value.ToShortDateString());
                }
                else
                {
                    dr.Values.Add("-");
                }

                //Revenue
                if (fs.Revenue.HasValue)
                {
                    dr.Values.Add(fs.Revenue.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }

                //SGA expenses
                if (fs.SellingGeneralAndAdministrativeExpense.HasValue)
                {
                    dr.Values.Add(fs.SellingGeneralAndAdministrativeExpense.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }

                //Research and Development costs
                if (fs.ResearchAndDevelopmentExpense.HasValue)
                {
                    dr.Values.Add(fs.ResearchAndDevelopmentExpense.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }

                //Operating income
                if (fs.OperatingIncome.HasValue)
                {
                    dr.Values.Add(fs.OperatingIncome.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }

                //Net Income
                if (fs.NetIncome.HasValue)
                {
                    dr.Values.Add(fs.NetIncome.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }


                //Assets
                if (fs.Assets.HasValue)
                {
                    dr.Values.Add(fs.Assets.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }

                //Liabilities
                if (fs.Liabilities.HasValue)
                {
                    dr.Values.Add(fs.Liabilities.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }

                //Euity
                if (fs.Equity.HasValue)
                {
                    dr.Values.Add(fs.Equity.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }

                //Casg
                if (fs.Cash.HasValue)
                {
                    dr.Values.Add(fs.Cash.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }

                //Current Assets
                if (fs.CurrentAssets.HasValue)
                {
                    dr.Values.Add(fs.CurrentAssets.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }

                //Current Liabilities
                if (fs.CurrentLiabilities.HasValue)
                {
                    dr.Values.Add(fs.CurrentLiabilities.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }

                //Retained Earnings
                if (fs.RetainedEarnings.HasValue)
                {
                    dr.Values.Add(fs.RetainedEarnings.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }

                //Common stock shares outstanding
                if (fs.CommonStockSharesOutstanding.HasValue)
                {
                    dr.Values.Add(fs.CommonStockSharesOutstanding.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }

                //Operating cash flows
                if (fs.OperatingCashFlows.HasValue)
                {
                    dr.Values.Add(fs.OperatingCashFlows.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }

                //Investing cash flows
                if (fs.InvestingCashFlows.HasValue)
                {
                    dr.Values.Add(fs.InvestingCashFlows.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }

                //Financing Cash flows
                if (fs.FinancingCashFlows.HasValue)
                {
                    dr.Values.Add(fs.FinancingCashFlows.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }

                //Proceeds from issuance of debt
                if (fs.ProceedsFromIssuanceOfDebt.HasValue)
                {
                    dr.Values.Add(fs.ProceedsFromIssuanceOfDebt.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }

                //Payments of debt
                if (fs.PaymentsOfDebt.HasValue)
                {
                    dr.Values.Add(fs.PaymentsOfDebt.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }

                //Dividends Paid
                if (fs.DividendsPaid.HasValue)
                {
                    dr.Values.Add(fs.DividendsPaid.Value.ToString("#,##0"));
                }
                else
                {
                    dr.Values.Add("-");
                }
            }

            return(csv.GenerateAsCsvFileContent());
        }
コード例 #7
0
        //Step 3: Assemble results into a CSV file
        public static void AssembleResultsCsv()
        {
            Console.Write("Folder with the full analyses >");
            string analysis_folder = Console.ReadLine().Replace("\"", "");

            Console.Write("Output CSV file to folder:");
            string output_folder = Console.ReadLine().Replace("\"", "");

            string[] files = System.IO.Directory.GetFiles(analysis_folder);
            AdminPrint(files.Length.ToString() + " files found");

            CsvFile csv = new CsvFile();

            //Label the averages
            DataRow drl = csv.AddNewRow();

            drl.Values.Add("");
            drl.Values.Add("");
            drl.Values.Add("Averages");
            drl.Values.Add("");
            drl.Values.Add("");
            drl.Values.Add("");
            drl.Values.Add("");
            drl.Values.Add("Following buys");


            DataRow headerrow = csv.AddNewRow();

            headerrow.Values.Add("Symbol");

            headerrow.Values.Add("Insider Buys");

            //Average
            headerrow.Values.Add("14 Days");
            headerrow.Values.Add("30 Days");
            headerrow.Values.Add("90 Days");
            headerrow.Values.Add("180 Days");
            headerrow.Values.Add("360 Days");

            //Following buys
            headerrow.Values.Add("14 Days");
            headerrow.Values.Add("30 Days");
            headerrow.Values.Add("90 Days");
            headerrow.Values.Add("180 Days");
            headerrow.Values.Add("360 Days");

            foreach (string s in files)
            {
                DataRow dr = csv.AddNewRow();

                AdminPrint("Opening " + System.IO.Path.GetFileName(s) + "...");
                FullResearchSet frs = JsonConvert.DeserializeObject <FullResearchSet>(System.IO.File.ReadAllText(s));
                AdminPrint("Writing " + System.IO.Path.GetFileName(s) + "...");

                dr.Values.Add(frs.Symbol.ToUpper().Trim());
                dr.Values.Add(frs.PerformancesFollowingInsiderBuys.Length.ToString());

                //Write the average over that period
                string ar14  = frs.AveragePerformance.Return14.ToString();
                string ar30  = frs.AveragePerformance.Return30.ToString();
                string ar90  = frs.AveragePerformance.Return90.ToString();
                string ar180 = frs.AveragePerformance.Return180.ToString();
                string ar360 = frs.AveragePerformance.Return360.ToString();
                dr.Values.Add(ar14);
                dr.Values.Add(ar30);
                dr.Values.Add(ar90);
                dr.Values.Add(ar180);
                dr.Values.Add(ar360);

                //Get the averages
                StockPerformanceSet avg = StockPerformanceSet.Average(frs.PerformancesFollowingInsiderBuys);
                dr.Values.Add(avg.Return14.ToString());
                dr.Values.Add(avg.Return30.ToString());
                dr.Values.Add(avg.Return90.ToString());
                dr.Values.Add(avg.Return180.ToString());
                dr.Values.Add(avg.Return360.ToString());
            }

            //Write to the file
            AdminPrint("Writing to file...");
            string       path = output_folder + "\\InsiderBuyPerformance.csv";
            FileStream   fs   = System.IO.File.Create(path);
            StreamWriter sw   = new StreamWriter(fs);

            sw.Write(csv.GenerateAsCsvFileContent());
            sw.Close();
            fs.Close();
            AdminPrint("Successfully wrote to " + path, ConsoleColor.Green);
        }
コード例 #8
0
        public static string PrintToCsvContent(this Equity[] equities)
        {
            if (equities.Length == 0)
            {
                throw new Exception("This equity array is empty.");
            }

            //Get the properties of each
            PropertyInfo[]      props          = equities[0].GetType().GetProperties();
            List <PropertyInfo> CoreProperties = new List <PropertyInfo>();

            foreach (PropertyInfo pi in props)
            {
                object thiso = pi.GetValue(equities[0]);
                if (thiso.GetType().IsClass == false || thiso.GetType() == typeof(string))
                {
                    CoreProperties.Add(pi);
                }
            }

            //Get the properties of summary
            List <PropertyInfo> SummaryProperties = new List <PropertyInfo>();

            if (equities[0].Summary != null)
            {
                PropertyInfo[] props_summary = equities[0].Summary.GetType().GetProperties();

                //Summary
                foreach (PropertyInfo pi in props_summary)
                {
                    object thiso = pi.GetValue(equities[0].Summary);
                    if (thiso.GetType().IsClass == false || thiso.GetType() == typeof(string))
                    {
                        SummaryProperties.Add(pi);
                    }
                }
            }


            //Get the properties of statistics
            List <PropertyInfo> StatisticsProperties = new List <PropertyInfo>();

            if (equities[0].Statistics != null)
            {
                PropertyInfo[] props_statistics = equities[0].Statistics.GetType().GetProperties();

                foreach (PropertyInfo pi in props_statistics)
                {
                    object thiso = pi.GetValue(equities[0].Statistics);
                    if (thiso.GetType().IsClass == false || thiso.GetType() == typeof(string))
                    {
                        StatisticsProperties.Add(pi);
                    }
                }
            }



            CsvFile csv = new CsvFile();

            //Set up header
            DataRow dr_header = csv.AddNewRow();

            //Write headers
            foreach (PropertyInfo pi in CoreProperties)
            {
                dr_header.Values.Add(pi.Name);
            }
            foreach (PropertyInfo pi in SummaryProperties)
            {
                dr_header.Values.Add(pi.Name);
            }
            foreach (PropertyInfo pi in StatisticsProperties)
            {
                dr_header.Values.Add(pi.Name);
            }


            //Write data
            foreach (Equity e in equities)
            {
                DataRow dr = csv.AddNewRow();

                //Core
                foreach (PropertyInfo pi in CoreProperties)
                {
                    try
                    {
                        dr.Values.Add(pi.GetValue(e).ToString());
                    }
                    catch
                    {
                        dr.Values.Add("-");
                    }
                }

                //Summary
                foreach (PropertyInfo pi in SummaryProperties)
                {
                    try
                    {
                        dr.Values.Add(pi.GetValue(e.Summary).ToString());
                    }
                    catch
                    {
                        dr.Values.Add("-");
                    }
                }

                //Statistics
                foreach (PropertyInfo pi in StatisticsProperties)
                {
                    try
                    {
                        dr.Values.Add(pi.GetValue(e.Statistics).ToString());
                    }
                    catch
                    {
                        dr.Values.Add("-");
                    }
                }
            }

            return(csv.GenerateAsCsvFileContent());
        }