First part of the todo done
This commit is contained in:
parent
26504b9e91
commit
e40cf53702
11
TODO.md
Normal file
11
TODO.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# TODO
|
||||||
|
|
||||||
|
## Data
|
||||||
|
[X] Get races and drivers
|
||||||
|
[] Get results by races linked to drivers
|
||||||
|
[] Get time by lap by driver by race
|
||||||
|
[] Get tyre strategy by race by driver
|
||||||
|
|
||||||
|
## Analyse
|
||||||
|
[] who is fatest in which race on which tyres
|
||||||
|
[] who improves with which tyres
|
|
@ -5,33 +5,38 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"framagit.org/pksl/paddockpass/db"
|
"framagit.org/pksl/paddockpass/db"
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Driver represents a structure of driver entry in the Eargast API.
|
||||||
type Driver struct {
|
type Driver struct {
|
||||||
FirstName string `json:"givenName"`
|
FirstName string `json:"givenName"`
|
||||||
LastName string `json:"familyName"`
|
LastName string `json:"familyName"`
|
||||||
DateOrBirth Date `json:"dateOfBirth"`
|
DateOrBirth Date `json:"dateOfBirth"`
|
||||||
Nationality string `json:nationality`
|
Nationality string `json:"nationality"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Drivers represents an array of driver in the Eargast API.
|
||||||
type Drivers struct {
|
type Drivers struct {
|
||||||
Drivers []Driver `json:"Drivers"`
|
Drivers []Driver `json:"Drivers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DriverTable reprensts a table of drivers in the Eargast API.
|
||||||
type DriverTable struct {
|
type DriverTable struct {
|
||||||
DriverTable Drivers `json:"DriverTable"`
|
DriverTable Drivers `json:"DriverTable"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MRDriverData is the wrapper for the datta in the Eargast API.
|
||||||
type MRDriverData struct {
|
type MRDriverData struct {
|
||||||
MRData DriverTable `json:"MRData"`
|
MRData DriverTable `json:"MRData"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDriversFromErgast gets the driver data from the API.
|
// GetDriversFromErgast gets the driver data from the API.
|
||||||
func GetDriversFromErgast() {
|
func GetDriversFromErgast(year string) {
|
||||||
resp, err := http.Get("http://ergast.com/api/f1/drivers.json")
|
resp, err := http.Get("http://ergast.com/api/f1/" + year + "/drivers.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -54,14 +59,18 @@ func GetDriversFromErgast() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
defer tx.Close()
|
|
||||||
for _, driver := range drivers {
|
for _, driver := range drivers {
|
||||||
|
fmt.Println(driver)
|
||||||
model := db.Driver{
|
model := db.Driver{
|
||||||
FirstName: driver.FirstName,
|
FirstName: driver.FirstName,
|
||||||
LastName: driver.LastName,
|
LastName: driver.LastName,
|
||||||
|
Nationality: driver.Nationality,
|
||||||
|
DoB: (driver.DateOrBirth).Format(time.RFC3339),
|
||||||
}
|
}
|
||||||
tx.Assign(model).FirstOrCreate(&model)
|
tx.Where(Driver{FirstName: driver.FirstName, LastName: driver.LastName}).Assign(model).FirstOrCreate(&model)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer tx.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// {
|
// {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
"framagit.org/pksl/paddockpass/db"
|
"framagit.org/pksl/paddockpass/db"
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Location represents the details of a circuit.
|
// Location represents the details of a circuit.
|
||||||
|
@ -89,7 +90,7 @@ func GetSeasonFromErgast(year string) {
|
||||||
var jsonData MRData
|
var jsonData MRData
|
||||||
err = json.Unmarshal(body, &jsonData)
|
err = json.Unmarshal(body, &jsonData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
races := jsonData.MRData.RaceTable.Races
|
races := jsonData.MRData.RaceTable.Races
|
||||||
|
|
|
@ -29,10 +29,10 @@ type Circuit struct {
|
||||||
// Driver describes a driver.
|
// Driver describes a driver.
|
||||||
type Driver struct {
|
type Driver struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
FirstName string
|
FirstName string
|
||||||
LastName string
|
LastName string
|
||||||
Number string
|
Nationality string
|
||||||
DoB time.Time
|
DoB string
|
||||||
}
|
}
|
||||||
|
|
||||||
// GORM DOC
|
// GORM DOC
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -5,4 +5,5 @@ go 1.12
|
||||||
require (
|
require (
|
||||||
github.com/go-sql-driver/mysql v1.4.1
|
github.com/go-sql-driver/mysql v1.4.1
|
||||||
github.com/jinzhu/gorm v1.9.11
|
github.com/jinzhu/gorm v1.9.11
|
||||||
|
github.com/sirupsen/logrus v1.2.0
|
||||||
)
|
)
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -72,6 +72,7 @@ github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8
|
||||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||||
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||||
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||||
|
github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo=
|
||||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
@ -103,6 +104,7 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5h
|
||||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
|
8
main.go
8
main.go
|
@ -2,6 +2,8 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"framagit.org/pksl/paddockpass/api"
|
"framagit.org/pksl/paddockpass/api"
|
||||||
"framagit.org/pksl/paddockpass/db"
|
"framagit.org/pksl/paddockpass/db"
|
||||||
|
@ -9,7 +11,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("Hello there!")
|
year := time.Now().Year()
|
||||||
|
fmt.Println("Hello there! It is", year)
|
||||||
db.InitDB()
|
db.InitDB()
|
||||||
api.GetSeasonFromErgast("2019")
|
api.GetSeasonFromErgast(strconv.Itoa(year))
|
||||||
|
api.GetDriversFromErgast(strconv.Itoa(year))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue