lets undo that?????
This commit is contained in:
@@ -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,20 +30,14 @@ 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)
|
|
||||||
go func(journey data.EstimatedVehicleJourney) {
|
|
||||||
defer wg.Done()
|
|
||||||
|
|
||||||
var values []interface{}
|
var values []interface{}
|
||||||
var datedVehicleJourneyRef, otherJson string
|
var datedVehicleJourneyRef, otherJson string
|
||||||
|
|
||||||
values = append(values, sid)
|
values = append(values, sid)
|
||||||
values = append(values, journey.RecordedAtTime)
|
values = append(values, journey.RecordedAtTime)
|
||||||
values = append(values, journey.LineRef)
|
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, strings.ToLower(journey.DirectionRef))
|
||||||
values = append(values, journey.DataSource)
|
values = append(values, journey.DataSource)
|
||||||
|
|
||||||
@@ -152,15 +145,18 @@ func DBData(data *data.Data) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error inserting/updating estimated vehicle journey: %v\n", err)
|
fmt.Printf("Error inserting/updating estimated vehicle journey: %v\n", err)
|
||||||
} else {
|
} else {
|
||||||
mu.Lock()
|
if 1 == 0 {
|
||||||
|
fmt.Printf("Action: %s, ID: %d\n", action, id)
|
||||||
|
}
|
||||||
|
|
||||||
if action == "insert" {
|
if action == "insert" {
|
||||||
insertCount++
|
insertCount++
|
||||||
} else if action == "update" {
|
} else if action == "update" {
|
||||||
updateCount++
|
updateCount++
|
||||||
}
|
}
|
||||||
totalCount = insertCount + updateCount
|
totalCount = insertCount + updateCount
|
||||||
mu.Unlock()
|
|
||||||
|
|
||||||
|
//fmt.Printf("Inserts: %d, Updates: %d, Total: %d\n", insertCount, updateCount, totalCount)
|
||||||
if totalCount%1000 == 0 {
|
if totalCount%1000 == 0 {
|
||||||
fmt.Printf(
|
fmt.Printf(
|
||||||
"Inserts: %d, Updates: %d, Total: %d; estimatedCalls = I: %d U: %d; recordedCalls = I: %d U: %d\n",
|
"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 _, estimatedCall := range journey.EstimatedCalls {
|
||||||
for _, call := range estimatedCall.EstimatedCall {
|
for _, call := range estimatedCall.EstimatedCall {
|
||||||
wg.Add(1)
|
|
||||||
go func(call data.EstimatedCall) {
|
|
||||||
defer wg.Done()
|
|
||||||
|
|
||||||
var estimatedValues []interface{}
|
var estimatedValues []interface{}
|
||||||
|
|
||||||
//1 estimatedvehiclejourney
|
//1 estimatedvehiclejourney
|
||||||
@@ -202,7 +194,7 @@ func DBData(data *data.Data) {
|
|||||||
|
|
||||||
//9 estimated_data (JSON)
|
//9 estimated_data (JSON)
|
||||||
estimatedJsonObject := make(map[string]interface{})
|
estimatedJsonObject := make(map[string]interface{})
|
||||||
// data already logged
|
// data allrady loged
|
||||||
if call.ExpectedDepartureTime != "" {
|
if call.ExpectedDepartureTime != "" {
|
||||||
estimatedJsonObject["ExpectedDepartureTime"] = call.ExpectedDepartureTime
|
estimatedJsonObject["ExpectedDepartureTime"] = call.ExpectedDepartureTime
|
||||||
}
|
}
|
||||||
@@ -291,28 +283,32 @@ func DBData(data *data.Data) {
|
|||||||
estimatedValues = append(estimatedValues, string(jsonString))
|
estimatedValues = append(estimatedValues, string(jsonString))
|
||||||
|
|
||||||
// Insert or update the record
|
// 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 {
|
if err != nil {
|
||||||
fmt.Printf("Error inserting/updating estimated call: %v\n", err)
|
fmt.Printf("Error inserting/updating estimated call: %v\n", err)
|
||||||
} else {
|
} else {
|
||||||
mu.Lock()
|
if 1 == 0 {
|
||||||
|
fmt.Printf("Action: %s, ID: %d\n", action, id)
|
||||||
|
}
|
||||||
|
|
||||||
if action == "insert" {
|
if action == "insert" {
|
||||||
estimatedCallInsertCount++
|
estimatedCallInsertCount++
|
||||||
} else if action == "update" {
|
} else if action == "update" {
|
||||||
estimatedCallUpdateCount++
|
estimatedCallUpdateCount++
|
||||||
}
|
}
|
||||||
mu.Unlock()
|
|
||||||
}
|
|
||||||
}(call)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for _, recordedCall := range journey.RecordedCalls {
|
for _, recordedCall := range journey.RecordedCalls {
|
||||||
for _, call := range recordedCall.RecordedCall {
|
for _, call := range recordedCall.RecordedCall {
|
||||||
wg.Add(1)
|
|
||||||
go func(call data.RecordedCall) {
|
|
||||||
defer wg.Done()
|
|
||||||
|
|
||||||
var recordedValues []interface{}
|
var recordedValues []interface{}
|
||||||
|
|
||||||
//1 estimatedvehiclejourney
|
//1 estimatedvehiclejourney
|
||||||
@@ -362,26 +358,34 @@ func DBData(data *data.Data) {
|
|||||||
recordedValues = append(recordedValues, string(jsonString))
|
recordedValues = append(recordedValues, string(jsonString))
|
||||||
|
|
||||||
// Insert or update the record
|
// 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 {
|
if err != nil {
|
||||||
fmt.Printf("Error inserting/updating recorded call: %v\n", err)
|
fmt.Printf("Error inserting/updating recorded call: %v\n", err)
|
||||||
} else {
|
} else {
|
||||||
mu.Lock()
|
if 1 == 0 {
|
||||||
|
fmt.Printf("Action: %s, ID: %d\n", action, id)
|
||||||
|
}
|
||||||
|
|
||||||
if action == "insert" {
|
if action == "insert" {
|
||||||
recordedCallInsertCount++
|
recordedCallInsertCount++
|
||||||
|
//fmt.Printf("Action: %s, ID: %d\n", action, id)
|
||||||
} else if action == "update" {
|
} else if action == "update" {
|
||||||
recordedCallUpdateCount++
|
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{})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user