Changeset 6


Ignore:
Timestamp:
Sep 30, 2025, 1:13:00 PM (7 days ago)
Author:
chronos
Message:
  • Modified: Present estimated CO2 emissions in separate table.
Location:
trunk
Files:
3 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('|}');
  • trunk/FormMain.lfm

    r5 r6  
    11object FormMain: TFormMain
    2   Left = 456
    3   Height = 869
    4   Top = 228
    5   Width = 1128
     2  Left = 433
     3  Height = 812
     4  Top = 288
     5  Width = 1370
    66  Caption = 'Car rental summary'
    7   ClientHeight = 869
    8   ClientWidth = 1128
     7  ClientHeight = 812
     8  ClientWidth = 1370
    99  DesignTimePPI = 144
     10  LCLVersion = '4.2.0.0'
     11  WindowState = wsMaximized
    1012  OnClose = FormClose
    1113  OnCreate = FormCreate
    1214  OnDestroy = FormDestroy
    1315  OnShow = FormShow
    14   LCLVersion = '3.4.0.0'
    15   WindowState = wsMaximized
    1616  object LabelSummary: TLabel
    1717    Left = 16
     
    3434    Height = 43
    3535    Top = 12
    36     Width = 968
     36    Width = 1210
    3737    Anchors = [akTop, akLeft, akRight]
    3838    TabOrder = 0
     
    4141  object PageControlSummary: TPageControl
    4242    Left = 21
    43     Height = 764
     43    Height = 707
    4444    Top = 104
    45     Width = 1099
     45    Width = 1341
    4646    ActivePage = TabSheetSource
    4747    Anchors = [akTop, akLeft, akRight, akBottom]
     
    5050    object TabSheetSource: TTabSheet
    5151      Caption = 'Source'
    52       ClientHeight = 724
    53       ClientWidth = 1089
     52      ClientHeight = 667
     53      ClientWidth = 1331
    5454      object MemoSource: TMemo
    5555        Left = 8
    56         Height = 708
     56        Height = 651
    5757        Top = 8
    58         Width = 1073
     58        Width = 1315
    5959        Align = alClient
    6060        BorderSpacing.Around = 8
    6161        ScrollBars = ssAutoBoth
    6262        TabOrder = 0
     63        OnChange = MemoSourceChange
    6364      end
    6465    end
    6566    object TabSheetSummary: TTabSheet
    6667      Caption = 'Summary'
    67       ClientHeight = 724
    68       ClientWidth = 1089
     68      ClientHeight = 667
     69      ClientWidth = 1331
    6970      object MemoSummary: TMemo
    7071        Left = 8
    71         Height = 708
     72        Height = 651
    7273        Top = 8
    73         Width = 1073
     74        Width = 1315
    7475        Align = alClient
    7576        BorderSpacing.Around = 8
     
    8081    object TabSheetLog: TTabSheet
    8182      Caption = 'Log'
    82       ClientHeight = 724
    83       ClientWidth = 1089
     83      ClientHeight = 667
     84      ClientWidth = 1331
    8485      object MemoLog: TMemo
    8586        Left = 8
    86         Height = 708
     87        Height = 651
    8788        Top = 8
    88         Width = 1073
     89        Width = 1315
    8990        Align = alClient
    9091        BorderSpacing.Around = 8
  • trunk/FormMain.pas

    r5 r6  
    2626    procedure FormDestroy(Sender: TObject);
    2727    procedure FormShow(Sender: TObject);
     28    procedure MemoSourceChange(Sender: TObject);
    2829  private
    2930    procedure Log(Text: string);
     31    procedure UpdateSummary;
    3032  public
    3133    Summary: TSummary;
     
    3436var
    3537  FormMain: TFormMain;
     38
    3639
    3740implementation
     
    4548  if FileExists(EditSource.Text) then
    4649    MemoSource.Lines.LoadFromFile(EditSource.Text);
    47   Summary.OnLog := Log;
    48   Summary.LoadFromStrings(MemoSource.Lines);
    49   MemoSummary.Text := Summary.Print;
     50  UpdateSummary;
    5051  //PageControlSummary.TabIndex := 1;
     52end;
     53
     54procedure TFormMain.MemoSourceChange(Sender: TObject);
     55begin
     56  UpdateSummary;
    5157end;
    5258
     
    5662end;
    5763
     64procedure TFormMain.UpdateSummary;
     65begin
     66  Summary.LoadFromStrings(MemoSource.Lines);
     67  MemoSummary.Text := Summary.Print;
     68end;
     69
    5870procedure TFormMain.FormCreate(Sender: TObject);
    5971begin
    6072  Summary := TSummary.Create;
     73  Summary.OnLog := Log;
    6174end;
    6275
Note: See TracChangeset for help on using the changeset viewer.