lets undo that?????
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"sync"
|
||||
"ti1/config"
|
||||
"ti1/data"
|
||||
"ti1/database"
|
||||
@@ -31,20 +30,14 @@ func DBData(data *data.Data) {
|
||||
// counters
|
||||
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 {
|
||||
wg.Add(1)
|
||||
go func(journey data.EstimatedVehicleJourney) {
|
||||
defer wg.Done()
|
||||
|
||||
var values []interface{}
|
||||
var datedVehicleJourneyRef, otherJson string
|
||||
|
||||
values = append(values, sid)
|
||||
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)
|
||||
|
||||
@@ -152,15 +145,18 @@ func DBData(data *data.Data) {
|
||||
if err != nil {
|
||||
fmt.Printf("Error inserting/updating estimated vehicle journey: %v\n", err)
|
||||
} else {
|
||||
mu.Lock()
|
||||
if 1 == 0 {
|
||||
fmt.Printf("Action: %s, ID: %d\n", action, id)
|
||||
}
|
||||
|
||||
if action == "insert" {
|
||||
insertCount++
|
||||
} else if action == "update" {
|
||||
updateCount++
|
||||
}
|
||||
totalCount = insertCount + updateCount
|
||||
mu.Unlock()
|
||||
|
||||
//fmt.Printf("Inserts: %d, Updates: %d, Total: %d\n", insertCount, updateCount, totalCount)
|
||||
if totalCount%1000 == 0 {
|
||||
fmt.Printf(
|
||||
"Inserts: %d, Updates: %d, Total: %d; estimatedCalls = I: %d U: %d; recordedCalls = I: %d U: %d\n",
|
||||
@@ -177,10 +173,6 @@ func DBData(data *data.Data) {
|
||||
|
||||
for _, estimatedCall := range journey.EstimatedCalls {
|
||||
for _, call := range estimatedCall.EstimatedCall {
|
||||
wg.Add(1)
|
||||
go func(call data.EstimatedCall) {
|
||||
defer wg.Done()
|
||||
|
||||
var estimatedValues []interface{}
|
||||
|
||||
//1 estimatedvehiclejourney
|
||||
@@ -202,7 +194,7 @@ func DBData(data *data.Data) {
|
||||
|
||||
//9 estimated_data (JSON)
|
||||
estimatedJsonObject := make(map[string]interface{})
|
||||
// data already logged
|
||||
// data allrady loged
|
||||
if call.ExpectedDepartureTime != "" {
|
||||
estimatedJsonObject["ExpectedDepartureTime"] = call.ExpectedDepartureTime
|
||||
}
|
||||
@@ -291,28 +283,32 @@ func DBData(data *data.Data) {
|
||||
estimatedValues = append(estimatedValues, string(jsonString))
|
||||
|
||||
// Insert or update the record
|
||||
id, action, err := database.InsertOrUpdateEstimatedCall(db, estimatedValues)
|
||||
stringValues := make([]string, len(estimatedValues))
|
||||
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 {
|
||||
mu.Lock()
|
||||
if 1 == 0 {
|
||||
fmt.Printf("Action: %s, ID: %d\n", action, id)
|
||||
}
|
||||
|
||||
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
|
||||
@@ -362,26 +358,34 @@ func DBData(data *data.Data) {
|
||||
recordedValues = append(recordedValues, string(jsonString))
|
||||
|
||||
// Insert or update the record
|
||||
id, action, err := database.InsertOrUpdateRecordedCall(db, recordedValues)
|
||||
stringValues := make([]string, len(recordedValues))
|
||||
for i, v := range recordedValues {
|
||||
stringValues[i] = fmt.Sprintf("%v", v)
|
||||
}
|
||||
interfaceValues := make([]interface{}, len(stringValues))
|
||||
for i, v := range stringValues {
|
||||
interfaceValues[i] = v
|
||||
}
|
||||
|
||||
id, action, err := database.InsertOrUpdateRecordedCall(db, interfaceValues)
|
||||
if err != nil {
|
||||
fmt.Printf("Error inserting/updating recorded call: %v\n", err)
|
||||
} else {
|
||||
mu.Lock()
|
||||
if 1 == 0 {
|
||||
fmt.Printf("Action: %s, ID: %d\n", action, id)
|
||||
}
|
||||
|
||||
if action == "insert" {
|
||||
recordedCallInsertCount++
|
||||
//fmt.Printf("Action: %s, ID: %d\n", action, id)
|
||||
} else if action == "update" {
|
||||
recordedCallUpdateCount++
|
||||
}
|
||||
mu.Unlock()
|
||||
}
|
||||
}(call)
|
||||
}
|
||||
}
|
||||
}(journey)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
}
|
||||
fmt.Printf(
|
||||
"DONE: Inserts: %d, Updates: %d, Total: %d; estimatedCalls = I: %d U: %d; recordedCalls = I: %d U: %d\n",
|
||||
insertCount,
|
||||
@@ -392,7 +396,6 @@ func DBData(data *data.Data) {
|
||||
recordedCallInsertCount,
|
||||
recordedCallUpdateCount,
|
||||
)
|
||||
|
||||
// Create map to hold JSON
|
||||
serviceDeliveryJsonObject := make(map[string]interface{})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user