progress things

This commit is contained in:
Peder Vatn Austad
2024-12-27 19:00:15 +01:00
parent 5fd16ff73c
commit af676eff6e
3 changed files with 27 additions and 1 deletions

View File

@@ -169,6 +169,7 @@ func FetchData() (*Data, error) {
}, },
} }
start := time.Now()
resp, err := client.Get("https://api.entur.io/realtime/v1/rest/et?useOriginalId=true&maxSize=100000&requestorId=ti1ASDASDDAAWdfs") resp, err := client.Get("https://api.entur.io/realtime/v1/rest/et?useOriginalId=true&maxSize=100000&requestorId=ti1ASDASDDAAWdfs")
if err != nil { if err != nil {
return nil, err return nil, err
@@ -182,5 +183,13 @@ func FetchData() (*Data, error) {
return nil, err return nil, err
} }
elapsed := time.Since(start)
contentLength := resp.ContentLength / (1024 * 1024) // Convert bytes to MB
if contentLength < 0 {
contentLength = 0 // If ContentLength is unknown, set to 0
}
println("Download took", elapsed.Seconds(), "seconds and downloaded", contentLength, "MB")
return data, nil return data, nil
} }

View File

@@ -14,6 +14,6 @@ func InsertServiceDelivery(db *sql.DB, responseTimestamp string, recordedAtTime
fmt.Println(err) fmt.Println(err)
return 0, err return 0, err
} }
fmt.Println("ServiceDelivery inserted successfully! (", id, ")") //fmt.Println("ServiceDelivery inserted successfully! (", id, ")")
return id, nil return id, nil
} }

View File

@@ -26,6 +26,9 @@ func DBData(data *data.Data) {
} }
fmt.Println("SID:", sid) fmt.Println("SID:", sid)
// counters
var insertCount, updateCount, totalCount int
for _, journey := range data.ServiceDelivery.EstimatedTimetableDelivery[0].EstimatedJourneyVersionFrame.EstimatedVehicleJourney { for _, journey := range data.ServiceDelivery.EstimatedTimetableDelivery[0].EstimatedJourneyVersionFrame.EstimatedVehicleJourney {
var values []interface{} var values []interface{}
var datedVehicleJourneyRef, otherJson string var datedVehicleJourneyRef, otherJson string
@@ -143,7 +146,20 @@ func DBData(data *data.Data) {
if 1 == 0 { if 1 == 0 {
fmt.Printf("Action: %s, ID: %d\n", action, id) fmt.Printf("Action: %s, ID: %d\n", action, id)
} }
if action == "insert" {
insertCount++
} else if action == "update" {
updateCount++
} }
totalCount = insertCount + updateCount
//fmt.Printf("Inserts: %d, Updates: %d, Total: %d\n", insertCount, updateCount, totalCount)
if totalCount%100 == 0 {
fmt.Printf("Inserts: %d, Updates: %d, Total: %d\n", insertCount, updateCount, totalCount)
}
}
for _, estimatedCall := range journey.EstimatedCalls { for _, estimatedCall := range journey.EstimatedCalls {
for _, call := range estimatedCall.EstimatedCall { for _, call := range estimatedCall.EstimatedCall {
var estimatedValues []interface{} var estimatedValues []interface{}
@@ -275,4 +291,5 @@ func DBData(data *data.Data) {
} }
} }
} }
fmt.Printf("Total: Inserts: %d, Updates: %d, Total: %d\n", insertCount, updateCount, totalCount)
} }