PHEMlightdll.CEPHandler.ReadFleetShares C# (CSharp) Метод

ReadFleetShares() публичный Метод

public ReadFleetShares ( string DataPath, System.Helpers Helper ) : bool
DataPath string
Helper System.Helpers
Результат bool
        public bool ReadFleetShares(string DataPath, Helpers Helper)
        {
            //Declaration
            string line;
            string path = DataPath + @"\FleetShares.csv";
            if (!File.Exists(@path))
            {
                Helper.ErrMsg = "FleetShares file does not exist! (" + path + ")";
                return false;
            }
            StreamReader shareReader = File.OpenText(@path);

            _fleetShares = new Dictionary<string, Dictionary<string, double>>();

            while ((line = ReadLine(shareReader)) != null)
            {
                if (line.Substring(0, 1) == Helper.CommentPrefix)
                    continue;

                List<string> splitLine = split(line, ',');
                string aggregateClass = splitLine[0];

                if (!FleetShares.ContainsKey(aggregateClass))
                    FleetShares.Add(aggregateClass, new Dictionary<string, double>());

                string subClass = splitLine[1];

                if (!FleetShares[aggregateClass].ContainsKey(subClass))
                    FleetShares[aggregateClass].Add(subClass, todouble(splitLine[2]));
            }
            return true;
        }
        #endregion

Usage Example

Пример #1
0
        //******************* Parameters of Array or Single calculation *******************
        //********************************* INPUT ******************************************
        //***  DATATYP            |  UNIT   |  VARIBLE                  |     Description  ***
        //List<string>            |  [-]    |   DataFiles (VEH, FC, EMI)| Name of file (e.g. "PC_D_EU4" path neede if not in "Default Vehicles") or aggregated name (PC, HDV, BUS, TW) by FleetMix calculation
        //List<double> / double   |  [s]    |   Time                    | Time signal
        //List<double> / double   |  [m/s]  |   Velocity                | Velocity signal
        //double                  |  [m/s^2]|   acc                     | Acceleration (ONLY NEDDED BY SINGLE CALCULATION)
        //List<double> / double   |  [%]    |   Gradient                | Gradient of the route
        //out List<VehicleResult> |  [-]    |   VehicleResultsOrg       | Returned result list
        //bool                    |  [-]    |   fleetMix = false        | Optional parameter if fleetMix should be calculate
        //string                  |  [-]    |   CommentPref = "c"       | Optional parameter for comment prefix

        //********************************* OUPUT: VehicleResultsOrg **********************
        //***  DATATYP            |  UNIT   |  VARIBLE     |      Description  ***
        //double                  |  [s]    |   time       | Time
        //double                  |  [m/s]  |   speed      | Velocity
        //double                  |  [kW]   |   power      | Calculated power at the engine (ICE for conventional and HEV vehicles, electric engine for BEVs) including engine inertia and auxiliaries; not limited for engine fullload and braking limitations
        //double                  |  [kW]   |   P_pos      | Positive engine power limited with engine rated power
        //double                  |  [-]    |   pNormRated | Engine power normalised with rated engine power and limited with the power range (fullload and drag) as specified in the characteristic curve for fuel consumption
        //double                  |  [-]    |   pNormDrive | Engine power normalised with "P_drive" and limited with the power range (fullload and drag) as specified in the characteristic curve for emissions
        //double                  |  [m/s^2]|   acc        | Caclulated/given acceleration
        //double                  |  [g/h]  |   fc         | Calculated fuel consumption (Different unit for BEV vehicles)
        //                        |  [kWh/h]|              |
        //double                  |  [g/h]  |   cO2        | Calculated CO2 emissions
        //double                  |  [g/h]  |   NOx        | Calculated NOx emissions
        //double                  |  [g/h]  |   HC         | Calculated HC emissions
        //double                  |  [g/h]  |   PM         | Calculated PM emissions
        //double                  |  [g/h]  |   CO         | Calculated CO emissions

        #region calculate
        //Calculate data from array
        public bool CALC_Array(List <string> DataFiles,
                               List <double> Time,
                               List <double> Velocity,
                               List <double> Gradient,
                               out List <VehicleResult> VehicleResultsOrg,
                               bool fleetMix      = false,
                               string CommentPref = "c")
        {
            //Declaration
            int    i;
            double acc;
            List <VehicleResult> _VehicleResult = new List <VehicleResult>();

            //Initialisation
            Helper.ErrMsg = null;

            //Borrow
            Helper.CommentPrefix = CommentPref;
            _DataPath            = new List <string>();
            //Set path by normal calculation (on given) and set path by fleetmix (on Default Vehicles) calculation
            for (i = 0; i < DataFiles.Count; i++)
            {
                if ((DataFiles[i].LastIndexOf(@"\")) >= 0)
                {
                    _DataPath.Add(DataFiles[i]);
                }
                else
                {
                    //_DataPath.Add(Assembly.GetExecutingAssembly().Location.Substring(0, Assembly.GetExecutingAssembly().Location.LastIndexOf(@"\")) + @"\Default Vehicles\" + Helper.PHEMDataV);
                    _DataPath.Add(DataFiles[i + 1].Substring(0, DataFiles[i + 1].LastIndexOf(@"\")));
                    _DataPath.Add(DataFiles[i + 1].Substring(0, DataFiles[i + 1].LastIndexOf(@"\")));
                    _DataPath.Add(DataFiles[i + 1].Substring(0, DataFiles[i + 1].LastIndexOf(@"\")));
                    i += 1;
                }
            }

            //Read the vehicle and emission data
            #if FLEET
            if (fleetMix)
            {
                //Set the vehicle class
                Helper.gClass = _DataPath[0];

                //Generate the class
                DataInput = new CEPHandler();

                //Read the FleetShares
                if (!DataInput.ReadFleetShares(DataFiles[1], Helper))
                {
                    VehicleResultsOrg = null;
                    return(false);
                }
                //Read the vehicle and emission data
                if (!DataInput.GetFleetCEP(_DataPath, DataFiles[0], Helper))
                {
                    VehicleResultsOrg = null;
                    return(false);
                }
            }
            else
            #endif
            {
                //Get vehicle string
                if (!Helper.setclass(DataFiles[0]))
                {
                    VehicleResultsOrg = null;
                    return(false);
                }

                //Generate the class
                DataInput = new CEPHandler();

                //Read the vehicle and emission data
                if (!DataInput.GetCEP(_DataPath, Helper))
                {
                    VehicleResultsOrg = null;
                    return(false);
                }
            }

            //Calculate emissions per second
            for (i = 1; i <= Time.Count - 1; i++)
            {
                //Calculate the acceleration
                acc = (Velocity[i] - Velocity[i - 1]) / (Time[i] - Time[i - 1]);

                //Calculate and save the data in the List
                _VehicleResult.Add(PHEMLight.CreateVehicleStateData(Helper,
                                                                    DataInput.CEPS[Helper.gClass],
                                                                    Time[i - 1],
                                                                    Velocity[i - 1],
                                                                    acc,
                                                                    Gradient[i - 1]));
                if (Helper.ErrMsg != null)
                {
                    VehicleResultsOrg = null;
                    return(false);
                }
            }
            VehicleResultsOrg = _VehicleResult;
            return(true);
        }
All Usage Examples Of PHEMlightdll.CEPHandler::ReadFleetShares