From 9fb8a0aafb2e21151424e86eb44791f0eb8365eb Mon Sep 17 00:00:00 2001 From: Peter Hoppe Date: Tue, 6 Dec 2022 21:12:35 +0100 Subject: [PATCH] SeasonTable dazu --- src/App.tsx | 2 +- src/classes/CFlight.ts | 2 +- src/classes/CSeason.ts | 49 ++++++++++++++++++++++++--------- src/components/FlightsTable.tsx | 15 ++++++++-- src/components/SeasonTable.tsx | 22 ++++++++++++--- src/interfaces/IKey.ts | 2 +- 6 files changed, 69 insertions(+), 23 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 51701ea..1e37044 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -27,7 +27,7 @@ export default function App() { return(
- {/* */} +
); diff --git a/src/classes/CFlight.ts b/src/classes/CFlight.ts index eb83c85..da2c586 100644 --- a/src/classes/CFlight.ts +++ b/src/classes/CFlight.ts @@ -30,6 +30,6 @@ export class CFlight implements IKey public get key() { - return +this.IDFlight; + return this.IDFlight; } } diff --git a/src/classes/CSeason.ts b/src/classes/CSeason.ts index 56434c1..331a29b 100644 --- a/src/classes/CSeason.ts +++ b/src/classes/CSeason.ts @@ -1,31 +1,54 @@ import {CFlight} from '../classes/CFlight'; import {CHour} from '../classes/CHour'; +import { IKey } from '../interfaces/IKey'; -export class CSeason +export class CSeason implements IKey { - id: string; - flighttime: CHour; - flights: CFlight[]; + public readonly id: string; + public readonly distance: number; + public readonly points: number; + public readonly flightCount: number; + public readonly flighttime: CHour; + public readonly flighttimeDisp: string; + public readonly flights: CFlight[]; constructor(id: string, flights: CFlight[]) { this.id = id; this.flights = flights; this.flighttime = new CHour(0) - this.calcFlighttime(); + + var Vals = this.calcValues(); + + this.distance = Vals.Dist; + this.points = Vals.Points; + this.flightCount = Vals.Count; + this.flighttimeDisp = this.flighttime.Print(); } - calcFlighttime() + public get key() { + return this.id; + } + + private calcValues() + { + var sumDist: number = 0; + var sumPoints: number = 0; for (let f of this.flights) { - const ftime: number = +f.FlightDuration; - this.flighttime.Add(new CHour(ftime)); - } - } + this.flighttime.Add(f.FlightDuration); - get flightCount() : number - { - return this.flights.length; + sumDist += +f.BestTaskDistance; + sumPoints += +f.BestTaskPoints; + } + var count: number = this.flights.length; + + return ( + { + 'Dist': sumDist, + 'Points': sumPoints, + 'Count': count, + }); } } \ No newline at end of file diff --git a/src/components/FlightsTable.tsx b/src/components/FlightsTable.tsx index b6832ea..6b20e42 100644 --- a/src/components/FlightsTable.tsx +++ b/src/components/FlightsTable.tsx @@ -12,11 +12,20 @@ function Link2Flight(u_key: string, key: string, row: any, data: string | null) return val; } -function Meter2Km(u_key: string, key: string, row: any, data: string | null) +export function Meter2Km(u_key: string, key: string, row: any, data: string | null) { var val: JSX.Element = <>; const numdata: number = +data! / 1000; - val = {numdata}; + val = {numdata.toFixed(2)}; + + return val; +} + +export function FixNachKomma00(u_key: string, key: string, row: any, data: string | null) +{ + var val: JSX.Element = <>; + const numdata: number = +data!; + val = {numdata.toFixed(2)}; return val; } @@ -30,7 +39,7 @@ export default function FlightsTable({flightdata}: {flightdata: CFlight[]}) { key: "Glider", label: "Gleitschirm" }, { key: "BestTaskDistance", label: "Strecke", callback: Meter2Km }, { key: "BestTaskType", label: "Streckentyp" }, - { key: "BestTaskPoints", label: "Punkte" }, + { key: "BestTaskPoints", label: "Punkte", callback: FixNachKomma00 }, { key: "FlightDurationDispl", label: "Dauer" } ]; diff --git a/src/components/SeasonTable.tsx b/src/components/SeasonTable.tsx index 437eaf4..9b87fcd 100644 --- a/src/components/SeasonTable.tsx +++ b/src/components/SeasonTable.tsx @@ -1,9 +1,23 @@ import React from "react"; +import SortableTable from "./SortableTable"; import {CSeason} from '../classes/CSeason'; +import {THeader} from "./SortableTable"; +import {Meter2Km, FixNachKomma00} from "./FlightsTable"; -//export default function SeasonTable(seasondata: CSeason[]) -export default function SeasonTable(seasondata: CSeason[]) +export default function SeasonTable({seasondata}:{seasondata: CSeason[]}) { - return (<>); -} + const headers: THeader[] = [ + { key: "id", label: "Saison" }, + { key: "flightCount", label: "Anzahl" }, + { key: "flighttimeDisp", label: "Dauer" }, + { key: "distance", label: "Strecke", callback: Meter2Km }, + { key: "points", label: "Punkte", callback: FixNachKomma00 } + ]; + + return( +
+ headers={headers} dataTbl={seasondata} > +
+ ); + } \ No newline at end of file diff --git a/src/interfaces/IKey.ts b/src/interfaces/IKey.ts index 95418d1..7d9223c 100644 --- a/src/interfaces/IKey.ts +++ b/src/interfaces/IKey.ts @@ -1,4 +1,4 @@ export interface IKey { - key: number; + key: string; } \ No newline at end of file