lets undo that?????

This commit is contained in:
pigwin
2025-01-04 20:14:51 +00:00
parent 7b96214476
commit c99f22b131

View File

@@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"log" "log"
"strings" "strings"
"sync"
"ti1/config" "ti1/config"
"ti1/data" "ti1/data"
"ti1/database" "ti1/database"
@@ -31,357 +30,362 @@ func DBData(data *data.Data) {
// counters // counters
var insertCount, updateCount, totalCount, estimatedCallInsertCount, estimatedCallUpdateCount, recordedCallInsertCount, recordedCallUpdateCount int var insertCount, updateCount, totalCount, estimatedCallInsertCount, estimatedCallUpdateCount, recordedCallInsertCount, recordedCallUpdateCount int
var wg sync.WaitGroup
var mu sync.Mutex
for _, journey := range data.ServiceDelivery.EstimatedTimetableDelivery[0].EstimatedJourneyVersionFrame.EstimatedVehicleJourney { for _, journey := range data.ServiceDelivery.EstimatedTimetableDelivery[0].EstimatedJourneyVersionFrame.EstimatedVehicleJourney {
wg.Add(1) var values []interface{}
go func(journey data.EstimatedVehicleJourney) { var datedVehicleJourneyRef, otherJson string
defer wg.Done()
var values []interface{} values = append(values, sid)
var datedVehicleJourneyRef, otherJson string values = append(values, journey.RecordedAtTime)
values = append(values, journey.LineRef)
//had to add to lowercase cus some values vary in case and it was causing duplicates
values = append(values, strings.ToLower(journey.DirectionRef))
values = append(values, journey.DataSource)
values = append(values, sid) if journey.FramedVehicleJourneyRef.DatedVehicleJourneyRef != "" {
values = append(values, journey.RecordedAtTime) datedVehicleJourneyRef = journey.FramedVehicleJourneyRef.DatedVehicleJourneyRef
values = append(values, journey.LineRef) } else if journey.DatedVehicleJourneyRef != "" {
values = append(values, strings.ToLower(journey.DirectionRef)) datedVehicleJourneyRef = journey.DatedVehicleJourneyRef
values = append(values, journey.DataSource) } else {
datedVehicleJourneyRef = "evj." + journey.EstimatedVehicleJourneyCode
}
values = append(values, datedVehicleJourneyRef)
if journey.FramedVehicleJourneyRef.DatedVehicleJourneyRef != "" { values = append(values, journey.VehicleMode)
datedVehicleJourneyRef = journey.FramedVehicleJourneyRef.DatedVehicleJourneyRef values = append(values, journey.FramedVehicleJourneyRef.DataFrameRef)
} else if journey.DatedVehicleJourneyRef != "" { values = append(values, journey.OriginRef)
datedVehicleJourneyRef = journey.DatedVehicleJourneyRef values = append(values, journey.DestinationRef)
} else { values = append(values, journey.OperatorRef)
datedVehicleJourneyRef = "evj." + journey.EstimatedVehicleJourneyCode values = append(values, journey.VehicleRef)
} values = append(values, journey.Cancellation)
values = append(values, datedVehicleJourneyRef)
values = append(values, journey.VehicleMode) // Create a map to hold the JSON object for the current journey
values = append(values, journey.FramedVehicleJourneyRef.DataFrameRef) jsonObject := make(map[string]interface{})
values = append(values, journey.OriginRef)
values = append(values, journey.DestinationRef)
values = append(values, journey.OperatorRef)
values = append(values, journey.VehicleRef)
values = append(values, journey.Cancellation)
// Create a map to hold the JSON object for the current journey // Add relevant fields to the JSON object
jsonObject := make(map[string]interface{}) if journey.OriginName != "" {
jsonObject["OriginName"] = journey.OriginName
}
if journey.DestinationName != "" {
jsonObject["DestinationName"] = journey.DestinationName
}
if journey.ProductCategoryRef != "" {
jsonObject["ProductCategoryRef"] = journey.ProductCategoryRef
}
if journey.ServiceFeatureRef != "" {
jsonObject["ServiceFeatureRef"] = journey.ServiceFeatureRef
}
if journey.Monitored != "" {
jsonObject["Monitored"] = journey.Monitored
}
if journey.JourneyPatternRef != "" {
jsonObject["JourneyPatternRef"] = journey.JourneyPatternRef
}
if journey.JourneyPatternName != "" {
jsonObject["JourneyPatternName"] = journey.JourneyPatternName
}
if journey.PublishedLineName != "" {
jsonObject["PublishedLineName"] = journey.PublishedLineName
}
if journey.DirectionName != "" {
jsonObject["DirectionName"] = journey.DirectionName
}
if journey.OriginAimedDepartureTime != "" {
jsonObject["OriginAimedDepartureTime"] = journey.OriginAimedDepartureTime
}
if journey.DestinationAimedArrivalTime != "" {
jsonObject["DestinationAimedArrivalTime"] = journey.DestinationAimedArrivalTime
}
if journey.BlockRef != "" {
jsonObject["BlockRef"] = journey.BlockRef
}
if journey.VehicleJourneyRef != "" {
jsonObject["VehicleJourneyRef"] = journey.VehicleJourneyRef
}
if journey.Occupancy != "" {
jsonObject["Occupancy"] = journey.Occupancy
}
if journey.DestinationDisplayAtOrigin != "" {
jsonObject["DestinationDisplayAtOrigin"] = journey.DestinationDisplayAtOrigin
}
if journey.ExtraJourney != "" {
jsonObject["ExtraJourney"] = journey.ExtraJourney
}
if journey.RouteRef != "" {
jsonObject["RouteRef"] = journey.RouteRef
}
if journey.GroupOfLinesRef != "" {
jsonObject["GroupOfLinesRef"] = journey.GroupOfLinesRef
}
if journey.ExternalLineRef != "" {
jsonObject["ExternalLineRef"] = journey.ExternalLineRef
}
if journey.InCongestion != "" {
jsonObject["InCongestion"] = journey.InCongestion
}
if journey.PredictionInaccurate != "" {
jsonObject["PredictionInaccurate"] = journey.PredictionInaccurate
}
if journey.JourneyNote != "" {
jsonObject["JourneyNote"] = journey.JourneyNote
}
if journey.Via.PlaceName != "" {
jsonObject["Via"] = journey.Via.PlaceName
}
// Add relevant fields to the JSON object // Convert the JSON object to a JSON string
if journey.OriginName != "" { jsonString, err := json.Marshal(jsonObject)
jsonObject["OriginName"] = journey.OriginName if err != nil {
} log.Fatal(err)
if journey.DestinationName != "" { }
jsonObject["DestinationName"] = journey.DestinationName otherJson = string(jsonString)
} values = append(values, otherJson)
if journey.ProductCategoryRef != "" {
jsonObject["ProductCategoryRef"] = journey.ProductCategoryRef // Insert or update the record
} id, action, err := database.InsertOrUpdateEstimatedVehicleJourney(db, values)
if journey.ServiceFeatureRef != "" { if err != nil {
jsonObject["ServiceFeatureRef"] = journey.ServiceFeatureRef fmt.Printf("Error inserting/updating estimated vehicle journey: %v\n", err)
} } else {
if journey.Monitored != "" { if 1 == 0 {
jsonObject["Monitored"] = journey.Monitored fmt.Printf("Action: %s, ID: %d\n", action, id)
}
if journey.JourneyPatternRef != "" {
jsonObject["JourneyPatternRef"] = journey.JourneyPatternRef
}
if journey.JourneyPatternName != "" {
jsonObject["JourneyPatternName"] = journey.JourneyPatternName
}
if journey.PublishedLineName != "" {
jsonObject["PublishedLineName"] = journey.PublishedLineName
}
if journey.DirectionName != "" {
jsonObject["DirectionName"] = journey.DirectionName
}
if journey.OriginAimedDepartureTime != "" {
jsonObject["OriginAimedDepartureTime"] = journey.OriginAimedDepartureTime
}
if journey.DestinationAimedArrivalTime != "" {
jsonObject["DestinationAimedArrivalTime"] = journey.DestinationAimedArrivalTime
}
if journey.BlockRef != "" {
jsonObject["BlockRef"] = journey.BlockRef
}
if journey.VehicleJourneyRef != "" {
jsonObject["VehicleJourneyRef"] = journey.VehicleJourneyRef
}
if journey.Occupancy != "" {
jsonObject["Occupancy"] = journey.Occupancy
}
if journey.DestinationDisplayAtOrigin != "" {
jsonObject["DestinationDisplayAtOrigin"] = journey.DestinationDisplayAtOrigin
}
if journey.ExtraJourney != "" {
jsonObject["ExtraJourney"] = journey.ExtraJourney
}
if journey.RouteRef != "" {
jsonObject["RouteRef"] = journey.RouteRef
}
if journey.GroupOfLinesRef != "" {
jsonObject["GroupOfLinesRef"] = journey.GroupOfLinesRef
}
if journey.ExternalLineRef != "" {
jsonObject["ExternalLineRef"] = journey.ExternalLineRef
}
if journey.InCongestion != "" {
jsonObject["InCongestion"] = journey.InCongestion
}
if journey.PredictionInaccurate != "" {
jsonObject["PredictionInaccurate"] = journey.PredictionInaccurate
}
if journey.JourneyNote != "" {
jsonObject["JourneyNote"] = journey.JourneyNote
}
if journey.Via.PlaceName != "" {
jsonObject["Via"] = journey.Via.PlaceName
} }
// Convert the JSON object to a JSON string if action == "insert" {
jsonString, err := json.Marshal(jsonObject) insertCount++
if err != nil { } else if action == "update" {
log.Fatal(err) updateCount++
} }
otherJson = string(jsonString) totalCount = insertCount + updateCount
values = append(values, otherJson)
// Insert or update the record //fmt.Printf("Inserts: %d, Updates: %d, Total: %d\n", insertCount, updateCount, totalCount)
id, action, err := database.InsertOrUpdateEstimatedVehicleJourney(db, values) if totalCount%1000 == 0 {
if err != nil { fmt.Printf(
fmt.Printf("Error inserting/updating estimated vehicle journey: %v\n", err) "Inserts: %d, Updates: %d, Total: %d; estimatedCalls = I: %d U: %d; recordedCalls = I: %d U: %d\n",
} else { insertCount,
mu.Lock() updateCount,
if action == "insert" { totalCount,
insertCount++ estimatedCallInsertCount,
} else if action == "update" { estimatedCallUpdateCount,
updateCount++ recordedCallInsertCount,
recordedCallUpdateCount,
)
}
}
for _, estimatedCall := range journey.EstimatedCalls {
for _, call := range estimatedCall.EstimatedCall {
var estimatedValues []interface{}
//1 estimatedvehiclejourney
estimatedValues = append(estimatedValues, id)
//2 order
estimatedValues = append(estimatedValues, call.Order)
//3 stoppointref
estimatedValues = append(estimatedValues, call.StopPointRef)
//4 aimeddeparturetime
estimatedValues = append(estimatedValues, call.AimedDepartureTime)
//5 expecteddeparturetime
estimatedValues = append(estimatedValues, call.ExpectedDepartureTime)
//6 aimedarrivaltime
estimatedValues = append(estimatedValues, call.AimedArrivalTime)
//7 expectedarrivaltime
estimatedValues = append(estimatedValues, call.ExpectedArrivalTime)
//8 cancellation
estimatedValues = append(estimatedValues, call.Cancellation)
//9 estimated_data (JSON)
estimatedJsonObject := make(map[string]interface{})
// data allrady loged
if call.ExpectedDepartureTime != "" {
estimatedJsonObject["ExpectedDepartureTime"] = call.ExpectedDepartureTime
}
if call.ExpectedArrivalTime != "" {
estimatedJsonObject["ExpectedArrivalTime"] = call.ExpectedArrivalTime
}
if call.Cancellation != "" {
estimatedJsonObject["Cancellation"] = call.Cancellation
}
// The rest
if call.StopPointName != "" {
estimatedJsonObject["StopPointName"] = call.StopPointName
}
if call.RequestStop != "" {
estimatedJsonObject["RequestStop"] = call.RequestStop
}
if call.DepartureStatus != "" {
estimatedJsonObject["DepartureStatus"] = call.DepartureStatus
}
if call.DeparturePlatformName != "" {
estimatedJsonObject["DeparturePlatformName"] = call.DeparturePlatformName
}
if call.DepartureBoardingActivity != "" {
estimatedJsonObject["DepartureBoardingActivity"] = call.DepartureBoardingActivity
}
if call.DepartureStopAssignment.AimedQuayRef != "" {
estimatedJsonObject["DepartureStopAssignment.AimedQuayRef"] = call.DepartureStopAssignment.AimedQuayRef
}
if call.DepartureStopAssignment.ExpectedQuayRef != "" {
estimatedJsonObject["DepartureStopAssignment.ExpectedQuayRef"] = call.DepartureStopAssignment.ExpectedQuayRef
}
if call.DepartureStopAssignment.ActualQuayRef != "" {
estimatedJsonObject["DepartureStopAssignment.ActualQuayRef"] = call.DepartureStopAssignment.ActualQuayRef
}
if call.Extensions.StopsAtAirport != "" {
estimatedJsonObject["Extensions.StopsAtAirport"] = call.Extensions.StopsAtAirport
}
if call.ArrivalStatus != "" {
estimatedJsonObject["ArrivalStatus"] = call.ArrivalStatus
}
if call.ArrivalPlatformName != "" {
estimatedJsonObject["ArrivalPlatformName"] = call.ArrivalPlatformName
}
if call.ArrivalBoardingActivity != "" {
estimatedJsonObject["ArrivalBoardingActivity"] = call.ArrivalBoardingActivity
}
if call.ArrivalStopAssignment.AimedQuayRef != "" {
estimatedJsonObject["ArrivalStopAssignment.AimedQuayRef"] = call.ArrivalStopAssignment.AimedQuayRef
}
if call.ArrivalStopAssignment.ExpectedQuayRef != "" {
estimatedJsonObject["ArrivalStopAssignment.ExpectedQuayRef"] = call.ArrivalStopAssignment.ExpectedQuayRef
}
if call.ArrivalStopAssignment.ActualQuayRef != "" {
estimatedJsonObject["ArrivalStopAssignment.ActualQuayRef"] = call.ArrivalStopAssignment.ActualQuayRef
}
if call.CallNote != "" {
estimatedJsonObject["CallNote"] = call.CallNote
}
if call.DestinationDisplay != "" {
estimatedJsonObject["DestinationDisplay"] = call.DestinationDisplay
}
if call.ExpectedDeparturePredictionQuality.PredictionLevel != "" {
estimatedJsonObject["ExpectedDeparturePredictionQuality.PredictionLevel"] = call.ExpectedDeparturePredictionQuality.PredictionLevel
}
if call.ExpectedArrivalPredictionQuality.PredictionLevel != "" {
estimatedJsonObject["ExpectedArrivalPredictionQuality.PredictionLevel"] = call.ExpectedArrivalPredictionQuality.PredictionLevel
}
if call.TimingPoint != "" {
estimatedJsonObject["TimingPoint"] = call.TimingPoint
}
if call.SituationRef != "" {
estimatedJsonObject["SituationRef"] = call.SituationRef
}
if call.PredictionInaccurate != "" {
estimatedJsonObject["PredictionInaccurate"] = call.PredictionInaccurate
}
if call.Occupancy != "" {
estimatedJsonObject["Occupancy"] = call.Occupancy
} }
totalCount = insertCount + updateCount
mu.Unlock()
if totalCount%1000 == 0 { // Convert the JSON object to a JSON string
fmt.Printf( jsonString, err := json.Marshal(estimatedJsonObject)
"Inserts: %d, Updates: %d, Total: %d; estimatedCalls = I: %d U: %d; recordedCalls = I: %d U: %d\n", if err != nil {
insertCount, log.Fatal(err)
updateCount, }
totalCount, estimatedValues = append(estimatedValues, string(jsonString))
estimatedCallInsertCount,
estimatedCallUpdateCount, // Insert or update the record
recordedCallInsertCount, stringValues := make([]string, len(estimatedValues))
recordedCallUpdateCount, for i, v := range estimatedValues {
) stringValues[i] = fmt.Sprintf("%v", v)
}
interfaceValues := make([]interface{}, len(stringValues))
for i, v := range stringValues {
interfaceValues[i] = v
}
id, action, err := database.InsertOrUpdateEstimatedCall(db, interfaceValues)
if err != nil {
fmt.Printf("Error inserting/updating estimated call: %v\n", err)
} else {
if 1 == 0 {
fmt.Printf("Action: %s, ID: %d\n", action, id)
}
if action == "insert" {
estimatedCallInsertCount++
} else if action == "update" {
estimatedCallUpdateCount++
}
} }
} }
}
for _, recordedCall := range journey.RecordedCalls {
for _, call := range recordedCall.RecordedCall {
var recordedValues []interface{}
for _, estimatedCall := range journey.EstimatedCalls { //1 estimatedvehiclejourney
for _, call := range estimatedCall.EstimatedCall { recordedValues = append(recordedValues, id)
wg.Add(1) //2 order
go func(call data.EstimatedCall) { recordedValues = append(recordedValues, call.Order)
defer wg.Done() //3 stoppointref
recordedValues = append(recordedValues, call.StopPointRef)
//4 aimeddeparturetime
recordedValues = append(recordedValues, call.AimedDepartureTime)
//5 expecteddeparturetime
recordedValues = append(recordedValues, call.ExpectedDepartureTime)
//6 aimedarrivaltime
recordedValues = append(recordedValues, call.AimedArrivalTime)
//7 expectedarrivaltime
recordedValues = append(recordedValues, call.ExpectedArrivalTime)
//8 cancellation
recordedValues = append(recordedValues, call.Cancellation)
//9 actualdeparturetime
recordedValues = append(recordedValues, call.ActualDepartureTime)
//10 actualarrivaltime
recordedValues = append(recordedValues, call.ActualArrivalTime)
var estimatedValues []interface{} //11 recorded_data (JSON)
recordedJsonObject := make(map[string]interface{})
if call.StopPointName != "" {
recordedJsonObject["StopPointName"] = call.StopPointName
}
if call.ArrivalPlatformName != "" {
recordedJsonObject["ArrivalPlatformName"] = call.ArrivalPlatformName
}
if call.DeparturePlatformName != "" {
recordedJsonObject["DeparturePlatformName"] = call.DeparturePlatformName
}
if call.PredictionInaccurate != "" {
recordedJsonObject["PredictionInaccurate"] = call.PredictionInaccurate
}
if call.Occupancy != "" {
recordedJsonObject["Occupancy"] = call.Occupancy
}
//1 estimatedvehiclejourney // Convert the JSON object to a JSON string
estimatedValues = append(estimatedValues, id) jsonString, err := json.Marshal(recordedJsonObject)
//2 order if err != nil {
estimatedValues = append(estimatedValues, call.Order) log.Fatal(err)
//3 stoppointref }
estimatedValues = append(estimatedValues, call.StopPointRef) recordedValues = append(recordedValues, string(jsonString))
//4 aimeddeparturetime
estimatedValues = append(estimatedValues, call.AimedDepartureTime)
//5 expecteddeparturetime
estimatedValues = append(estimatedValues, call.ExpectedDepartureTime)
//6 aimedarrivaltime
estimatedValues = append(estimatedValues, call.AimedArrivalTime)
//7 expectedarrivaltime
estimatedValues = append(estimatedValues, call.ExpectedArrivalTime)
//8 cancellation
estimatedValues = append(estimatedValues, call.Cancellation)
//9 estimated_data (JSON) // Insert or update the record
estimatedJsonObject := make(map[string]interface{}) stringValues := make([]string, len(recordedValues))
// data already logged for i, v := range recordedValues {
if call.ExpectedDepartureTime != "" { stringValues[i] = fmt.Sprintf("%v", v)
estimatedJsonObject["ExpectedDepartureTime"] = call.ExpectedDepartureTime }
} interfaceValues := make([]interface{}, len(stringValues))
if call.ExpectedArrivalTime != "" { for i, v := range stringValues {
estimatedJsonObject["ExpectedArrivalTime"] = call.ExpectedArrivalTime interfaceValues[i] = v
} }
if call.Cancellation != "" {
estimatedJsonObject["Cancellation"] = call.Cancellation
}
// The rest
if call.StopPointName != "" {
estimatedJsonObject["StopPointName"] = call.StopPointName
}
if call.RequestStop != "" {
estimatedJsonObject["RequestStop"] = call.RequestStop
}
if call.DepartureStatus != "" {
estimatedJsonObject["DepartureStatus"] = call.DepartureStatus
}
if call.DeparturePlatformName != "" {
estimatedJsonObject["DeparturePlatformName"] = call.DeparturePlatformName
}
if call.DepartureBoardingActivity != "" {
estimatedJsonObject["DepartureBoardingActivity"] = call.DepartureBoardingActivity
}
if call.DepartureStopAssignment.AimedQuayRef != "" {
estimatedJsonObject["DepartureStopAssignment.AimedQuayRef"] = call.DepartureStopAssignment.AimedQuayRef
}
if call.DepartureStopAssignment.ExpectedQuayRef != "" {
estimatedJsonObject["DepartureStopAssignment.ExpectedQuayRef"] = call.DepartureStopAssignment.ExpectedQuayRef
}
if call.DepartureStopAssignment.ActualQuayRef != "" {
estimatedJsonObject["DepartureStopAssignment.ActualQuayRef"] = call.DepartureStopAssignment.ActualQuayRef
}
if call.Extensions.StopsAtAirport != "" {
estimatedJsonObject["Extensions.StopsAtAirport"] = call.Extensions.StopsAtAirport
}
if call.ArrivalStatus != "" {
estimatedJsonObject["ArrivalStatus"] = call.ArrivalStatus
}
if call.ArrivalPlatformName != "" {
estimatedJsonObject["ArrivalPlatformName"] = call.ArrivalPlatformName
}
if call.ArrivalBoardingActivity != "" {
estimatedJsonObject["ArrivalBoardingActivity"] = call.ArrivalBoardingActivity
}
if call.ArrivalStopAssignment.AimedQuayRef != "" {
estimatedJsonObject["ArrivalStopAssignment.AimedQuayRef"] = call.ArrivalStopAssignment.AimedQuayRef
}
if call.ArrivalStopAssignment.ExpectedQuayRef != "" {
estimatedJsonObject["ArrivalStopAssignment.ExpectedQuayRef"] = call.ArrivalStopAssignment.ExpectedQuayRef
}
if call.ArrivalStopAssignment.ActualQuayRef != "" {
estimatedJsonObject["ArrivalStopAssignment.ActualQuayRef"] = call.ArrivalStopAssignment.ActualQuayRef
}
if call.CallNote != "" {
estimatedJsonObject["CallNote"] = call.CallNote
}
if call.DestinationDisplay != "" {
estimatedJsonObject["DestinationDisplay"] = call.DestinationDisplay
}
if call.ExpectedDeparturePredictionQuality.PredictionLevel != "" {
estimatedJsonObject["ExpectedDeparturePredictionQuality.PredictionLevel"] = call.ExpectedDeparturePredictionQuality.PredictionLevel
}
if call.ExpectedArrivalPredictionQuality.PredictionLevel != "" {
estimatedJsonObject["ExpectedArrivalPredictionQuality.PredictionLevel"] = call.ExpectedArrivalPredictionQuality.PredictionLevel
}
if call.TimingPoint != "" {
estimatedJsonObject["TimingPoint"] = call.TimingPoint
}
if call.SituationRef != "" {
estimatedJsonObject["SituationRef"] = call.SituationRef
}
if call.PredictionInaccurate != "" {
estimatedJsonObject["PredictionInaccurate"] = call.PredictionInaccurate
}
if call.Occupancy != "" {
estimatedJsonObject["Occupancy"] = call.Occupancy
}
// Convert the JSON object to a JSON string id, action, err := database.InsertOrUpdateRecordedCall(db, interfaceValues)
jsonString, err := json.Marshal(estimatedJsonObject) if err != nil {
if err != nil { fmt.Printf("Error inserting/updating recorded call: %v\n", err)
log.Fatal(err) } else {
} if 1 == 0 {
estimatedValues = append(estimatedValues, string(jsonString)) fmt.Printf("Action: %s, ID: %d\n", action, id)
}
// Insert or update the record if action == "insert" {
id, action, err := database.InsertOrUpdateEstimatedCall(db, estimatedValues) recordedCallInsertCount++
if err != nil { //fmt.Printf("Action: %s, ID: %d\n", action, id)
fmt.Printf("Error inserting/updating estimated call: %v\n", err) } else if action == "update" {
} else { recordedCallUpdateCount++
mu.Lock() }
if action == "insert" {
estimatedCallInsertCount++
} else if action == "update" {
estimatedCallUpdateCount++
}
mu.Unlock()
}
}(call)
} }
} }
}
for _, recordedCall := range journey.RecordedCalls {
for _, call := range recordedCall.RecordedCall {
wg.Add(1)
go func(call data.RecordedCall) {
defer wg.Done()
var recordedValues []interface{}
//1 estimatedvehiclejourney
recordedValues = append(recordedValues, id)
//2 order
recordedValues = append(recordedValues, call.Order)
//3 stoppointref
recordedValues = append(recordedValues, call.StopPointRef)
//4 aimeddeparturetime
recordedValues = append(recordedValues, call.AimedDepartureTime)
//5 expecteddeparturetime
recordedValues = append(recordedValues, call.ExpectedDepartureTime)
//6 aimedarrivaltime
recordedValues = append(recordedValues, call.AimedArrivalTime)
//7 expectedarrivaltime
recordedValues = append(recordedValues, call.ExpectedArrivalTime)
//8 cancellation
recordedValues = append(recordedValues, call.Cancellation)
//9 actualdeparturetime
recordedValues = append(recordedValues, call.ActualDepartureTime)
//10 actualarrivaltime
recordedValues = append(recordedValues, call.ActualArrivalTime)
//11 recorded_data (JSON)
recordedJsonObject := make(map[string]interface{})
if call.StopPointName != "" {
recordedJsonObject["StopPointName"] = call.StopPointName
}
if call.ArrivalPlatformName != "" {
recordedJsonObject["ArrivalPlatformName"] = call.ArrivalPlatformName
}
if call.DeparturePlatformName != "" {
recordedJsonObject["DeparturePlatformName"] = call.DeparturePlatformName
}
if call.PredictionInaccurate != "" {
recordedJsonObject["PredictionInaccurate"] = call.PredictionInaccurate
}
if call.Occupancy != "" {
recordedJsonObject["Occupancy"] = call.Occupancy
}
// Convert the JSON object to a JSON string
jsonString, err := json.Marshal(recordedJsonObject)
if err != nil {
log.Fatal(err)
}
recordedValues = append(recordedValues, string(jsonString))
// Insert or update the record
id, action, err := database.InsertOrUpdateRecordedCall(db, recordedValues)
if err != nil {
fmt.Printf("Error inserting/updating recorded call: %v\n", err)
} else {
mu.Lock()
if action == "insert" {
recordedCallInsertCount++
} else if action == "update" {
recordedCallUpdateCount++
}
mu.Unlock()
}
}(call)
}
}
}(journey)
} }
wg.Wait()
fmt.Printf( fmt.Printf(
"DONE: Inserts: %d, Updates: %d, Total: %d; estimatedCalls = I: %d U: %d; recordedCalls = I: %d U: %d\n", "DONE: Inserts: %d, Updates: %d, Total: %d; estimatedCalls = I: %d U: %d; recordedCalls = I: %d U: %d\n",
insertCount, insertCount,
@@ -392,7 +396,6 @@ func DBData(data *data.Data) {
recordedCallInsertCount, recordedCallInsertCount,
recordedCallUpdateCount, recordedCallUpdateCount,
) )
// Create map to hold JSON // Create map to hold JSON
serviceDeliveryJsonObject := make(map[string]interface{}) serviceDeliveryJsonObject := make(map[string]interface{})
@@ -415,4 +418,4 @@ func DBData(data *data.Data) {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }