Changeset 6 for trunk/Car.pas


Ignore:
Timestamp:
Sep 30, 2025, 1:13:00 PM (7 days ago)
Author:
chronos
Message:
  • Modified: Present estimated CO2 emissions in separate table.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Car.pas

    r5 r6  
    9797    constructor Create;
    9898    destructor Destroy; override;
     99    procedure Clean;
    99100    procedure LoadFromFile(FileName: string);
    100101    procedure LoadFromStrings(Lines: TStrings);
     
    132133    'g', 'g');
    133134  DistanceUnits: array[TEngineType] of Integer = (1, 100, 100, 1, 100, 100);
     135  // https://fdrive.cz/clanky/kolik-oxidu-uhliciteho-vypousti-vozidlo-do-ovzdusi-velke-srovnani-podle-pohonu-6874
     136  EmissionPerUnit: array[TEngineType] of Double = (0, 3366, 3616, 0.411, 2.640, 1.660);
    134137
    135138function Explode(Separator: string; Data: string): TStringArray;
     
    279282function TRent.GetEmission: Double;
    280283begin
    281   // https://www.autolexicon.net/cs/articles/vypocet-emisi-co2/
    282   case Car.EngineType of
    283     etPetrol: Result := GetFuel * 2390;
    284     etDiesel: Result := GetFuel * 2640;
    285     etLpg: Result := GetFuel * 1660;
    286     etCng: Result := GetFuel * 2666;
    287     etElectric: Result := GetFuel * 1-17;
    288   end;
     284  Result := GetFuel * EmissionPerUnit[Car.EngineType];
    289285end;
    290286
     
    385381  FreeAndNil(Cars);
    386382  inherited;
     383end;
     384
     385procedure TSummary.Clean;
     386begin
     387  Rents.Count := 0;
     388  Cars.Count := 0;
     389  Companies.Count := 0;
    387390end;
    388391
     
    439442  TableLineCellSeparator = '||';
    440443begin
     444  Clean;
    441445  for I := 0 to Lines.Count - 1 do begin
    442446    Line := Lines[I];
     
    561565  TotalPriceWithFuel: Double;
    562566  TotalEmission: Double;
    563   TotalFuel: array[TEngineType] of Double;
     567  TotalEmissionByEngine: array[TEngineType] of Double;
     568  TotalFuelByEngine: array[TEngineType] of Double;
    564569  CarName: string;
    565570  CompanyName: string;
     
    583588  TotalPriceWithFuel := 0;
    584589  TotalEmission := 0;
    585   for E := Low(TEngineType) to High(TEngineType) do
    586     TotalFuel[E] := 0;
     590  for E := Low(TEngineType) to High(TEngineType) do begin
     591    TotalFuelByEngine[E] := 0;
     592    TotalEmissionByEngine[E] := 0;
     593  end;
    587594  for I := 0 to Rents.Count - 1 do
    588595  with TRent(Rents[I]) do begin
     
    591598    TotalPriceWithFuel := TotalPriceWithFuel + PriceWithFuel;
    592599    TotalEmission := TotalEmission + GetEmission;
    593     TotalFuel[Car.EngineType] := TotalFuel[Car.EngineType] + GetFuel;
     600    TotalFuelByEngine[Car.EngineType] := TotalFuelByEngine[Car.EngineType] + GetFuel;
     601    TotalEmissionByEngine[Car.EngineType] := TotalEmissionByEngine[Car.EngineType] + GetEmission;
    594602
    595603    Year := YearOf(Time);
     
    612620  AddLine('* Cena půjčení včetně paliva: ' + FloatToStr(TotalPriceWithFuel) + ' Kč');
    613621  AddLine('* Vzdálenost: ' + FloatToStr(TotalDistance) + ' km');
    614   for E := Succ(Low(TEngineType)) to High(TEngineType) do
    615     AddLine('* Palivo ' + EngineTypeText[E] + ': ' + PrefixMultiplier.Add(TotalFuel[E], BasePrefixMultipliers, EngineTypeUnit[E]));
    616   AddLine('* Emise CO2: ' + FloatToStr(TotalEmission / 1000) + ' Kg');
     622  AddLine('* Emise CO2: ' + FloatToStr(Round(TotalEmission / 1000)) + ' Kg');
     623  AddLine('* Modelů aut: ' + IntToStr(Cars.Count));
     624  AddLine('* Půjčoven: ' + IntToStr(Companies.Count));
    617625
    618626  AddLine;
     
    628636      IntToStr(Companies.Count));
    629637    if I < SummaryYears.Count - 1 then AddLine('|-');
     638  end;
     639  AddLine('|}');
     640
     641  AddLine;
     642  AddLine('==Energie==');
     643  AddLine('{| class="wikitable sortable"');
     644  AddLine('! Druh !! Množství !! Emise koeficient [g/l] !! Emise CO2 [Kg]');
     645  AddLine('|-');
     646  for E := Succ(Low(TEngineType)) to High(TEngineType) do begin
     647    AddLine('| ' + EngineTypeText[E] + ' || ' + PrefixMultiplier.Add(TotalFuelByEngine[E],
     648      BasePrefixMultipliers, EngineTypeUnit[E]) + ' || ' + FloatToStr(EmissionPerUnit[E]) +
     649      ' || ' + FloatToStr(Round(TotalEmissionByEngine[E] / 1000)));
     650    if E < High(TEngineType) then AddLine('|-');
    630651  end;
    631652  AddLine('|}');
Note: See TracChangeset for help on using the changeset viewer.