Changeset 6 for trunk/Car.pas
- Timestamp:
- Sep 30, 2025, 1:13:00 PM (7 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Car.pas
r5 r6 97 97 constructor Create; 98 98 destructor Destroy; override; 99 procedure Clean; 99 100 procedure LoadFromFile(FileName: string); 100 101 procedure LoadFromStrings(Lines: TStrings); … … 132 133 'g', 'g'); 133 134 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); 134 137 135 138 function Explode(Separator: string; Data: string): TStringArray; … … 279 282 function TRent.GetEmission: Double; 280 283 begin 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]; 289 285 end; 290 286 … … 385 381 FreeAndNil(Cars); 386 382 inherited; 383 end; 384 385 procedure TSummary.Clean; 386 begin 387 Rents.Count := 0; 388 Cars.Count := 0; 389 Companies.Count := 0; 387 390 end; 388 391 … … 439 442 TableLineCellSeparator = '||'; 440 443 begin 444 Clean; 441 445 for I := 0 to Lines.Count - 1 do begin 442 446 Line := Lines[I]; … … 561 565 TotalPriceWithFuel: Double; 562 566 TotalEmission: Double; 563 TotalFuel: array[TEngineType] of Double; 567 TotalEmissionByEngine: array[TEngineType] of Double; 568 TotalFuelByEngine: array[TEngineType] of Double; 564 569 CarName: string; 565 570 CompanyName: string; … … 583 588 TotalPriceWithFuel := 0; 584 589 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; 587 594 for I := 0 to Rents.Count - 1 do 588 595 with TRent(Rents[I]) do begin … … 591 598 TotalPriceWithFuel := TotalPriceWithFuel + PriceWithFuel; 592 599 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; 594 602 595 603 Year := YearOf(Time); … … 612 620 AddLine('* Cena půjčení včetně paliva: ' + FloatToStr(TotalPriceWithFuel) + ' Kč'); 613 621 AddLine('* Vzdálenost: ' + FloatToStr(TotalDistance) + ' km'); 614 for E := Succ(Low(TEngineType)) to High(TEngineType) do615 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)); 617 625 618 626 AddLine; … … 628 636 IntToStr(Companies.Count)); 629 637 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('|-'); 630 651 end; 631 652 AddLine('|}');
Note:
See TracChangeset
for help on using the changeset viewer.