From 62e6dc5adae02c8047f75817dcd6e1e636011570 Mon Sep 17 00:00:00 2001
From: Simon Rieger <simon@rieger.app>
Date: Mon, 10 Mar 2025 10:31:45 +0100
Subject: [PATCH] =?UTF-8?q?Es=20werden=20nun=20den=20Zugtyp=20und=20die=20?=
 =?UTF-8?q?Fahrtart=20(privat,=20gesch=C3=A4ftlich,=20Pendelverkehr)=20als?=
 =?UTF-8?q?=20Prometheus-Metriken=20bereitgestellt?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 go/main.go | 43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/go/main.go b/go/main.go
index e44fc9f..73e44ce 100644
--- a/go/main.go
+++ b/go/main.go
@@ -36,6 +36,7 @@ type StatusResponse struct {
 				ArrivalPlanned string `json:"arrivalPlanned"`
 				ArrivalReal    string `json:"arrivalReal"`
 			} `json:"destination"`
+			TripType int `json:"tripType"` // 0: personal, 1: business, 2: commute
 		} `json:"train"`
 	} `json:"data"`
 }
@@ -58,6 +59,20 @@ var (
 		},
 		[]string{"username", "line_name", "origin", "destination"},
 	)
+	currentTrainTypes = promauto.NewGaugeVec(
+		prometheus.GaugeOpts{
+			Name: "traewelling_current_train_types",
+			Help: "Typ des aktuellen Zuges",
+		},
+		[]string{"username", "line_name", "origin", "destination", "train_type"},
+	)
+	currentTripTypes = promauto.NewGaugeVec(
+		prometheus.GaugeOpts{
+			Name: "traewelling_current_trip_types",
+			Help: "Art der Fahrt (0 = privat, 1 = geschäftlich, 2 = Pendelverkehr)",
+		},
+		[]string{"username", "line_name", "origin", "destination", "trip_type"},
+	)
 	totalTrainDistance = promauto.NewGaugeVec(
 		prometheus.GaugeOpts{
 			Name: "traewelling_total_train_distance_km",
@@ -150,7 +165,7 @@ func fetchUserDetails(username string) (*UserDetailsResponse, error) {
 }
 
 func isTrainActive(departureTimeStr, arrivalTimeStr string) bool {
-	if departureTimeStr == "" || arrivalTimeStr == "" { // Überprüfe auf leere Zeitstrings
+	if departureTimeStr == "" || arrivalTimeStr == "" {
 	    return false
     }
 
@@ -192,6 +207,32 @@ func updateMetricsForUser(username string) {
             trip.Train.Origin.Name,
             trip.Train.Destination.Name,
         ).Set(func() float64 { if active { return 1 } else { return 0 } }())
+
+        currentTrainTypes.WithLabelValues(
+            username,
+            trip.Train.LineName,
+            trip.Train.Origin.Name,
+            trip.Train.Destination.Name,
+            trip.Train.Category,
+        ).Set(1) // Typ des aktuellen Zuges
+
+        tripType := "unknown"
+        switch trip.Train.TripType {
+        case 0:
+            tripType = "personal"
+        case 1:
+            tripType = "business"
+        case 2:
+            tripType = "commute"
+        }
+
+        currentTripTypes.WithLabelValues(
+            username,
+            trip.Train.LineName,
+            trip.Train.Origin.Name,
+            trip.Train.Destination.Name,
+            tripType,
+        ).Set(1) // Art der Fahrt
     }
 
 	totalTrainDistance.WithLabelValues(username).Set(float64(userDetails.Data.TrainDistance) / 1000)