set up override zoom if both lat and lng within delta

master
Bel LaPointe 2022-01-14 11:00:55 -05:00
parent 937f91bbf6
commit e660f2ef9f
5 changed files with 51 additions and 18 deletions

View File

@ -17,17 +17,23 @@
"UploadMethod": "POST" "UploadMethod": "POST"
}, },
"Maps": { "Maps": {
"DirectionsURIFormat": "https://maps.googleapis.com/maps/api/directions/json?origin=%s\u0026destination=%s\u0026mode=driving\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg",
"PathedURIFormat": "https://maps.googleapis.com/maps/api/staticmap?size=250x250\u0026path=%s\u0026format=jpeg\u0026maptype=roadmap\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg\u0026size=250x250\u0026markers=%s|%s\u0026zoom=5",
"URIFormat": "https://maps.googleapis.com/maps/api/staticmap?center=%s\u0026markers=label=A|%s\u0026zoom=5\u0026size=250x250\u0026scale=1\u0026format=jpeg\u0026maptype=roadmap\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg", "URIFormat": "https://maps.googleapis.com/maps/api/staticmap?center=%s\u0026markers=label=A|%s\u0026zoom=5\u0026size=250x250\u0026scale=1\u0026format=jpeg\u0026maptype=roadmap\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg",
"Pathed": false,
"Pickup": false, "Pickup": false,
"Dropoff": false "Dropoff": false,
"Pathed": {
"Enabled": true,
"DirectionsURIFormat": "https://maps.googleapis.com/maps/api/directions/json?origin=%s\u0026destination=%s\u0026mode=driving\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg",
"PathedURIFormat": "https://maps.googleapis.com/maps/api/staticmap?size=250x250\u0026path=%s\u0026format=jpeg\u0026maptype=roadmap\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg\u0026size=250x250\u0026markers=%s|%s",
"Zoom": {
"AcceptableLatLngDelta": 2,
"Override": 5
}
}
}, },
"Clients": { "Clients": {
"bel": { "bel": {
"States": [ "States": [
"OH" "NC"
], ],
"IDs": { "IDs": {
"Matrix": "@bel:m.bltrucks.top" "Matrix": "@bel:m.bltrucks.top"
@ -42,7 +48,7 @@
"Message": { "Message": {
"Matrix": { "Matrix": {
"ReceiveEnabled": true, "ReceiveEnabled": true,
"Mock": true, "Mock": false,
"Homeserver": "https://m.bltrucks.top", "Homeserver": "https://m.bltrucks.top",
"Username": "@bot.m.bltrucks.top", "Username": "@bot.m.bltrucks.top",
"Token": "mvDWB96KXMF8XhOam8EC5XVdQvSEw0CDeClcSWocBcYkwZX3FPNWZ5uOnQk2EmT1cjpzfeuD7gDYPPjOuyZlI3bE9TE35UjNOlZgi0Tugm25s91iVsbIF6kMZsCIhVMSmEf6w3jxX6wQYOWvmDZ4mu6f5c8wr221EMDcOpEzQV09d1zuBSWgKLBgjqAkYHJZ5dTRIWpEDpPgujhOFZa2ld1HiAOxrJKlIrlfDBN0CUsTlGOGplujDAr4VtpFzNRS", "Token": "mvDWB96KXMF8XhOam8EC5XVdQvSEw0CDeClcSWocBcYkwZX3FPNWZ5uOnQk2EmT1cjpzfeuD7gDYPPjOuyZlI3bE9TE35UjNOlZgi0Tugm25s91iVsbIF6kMZsCIhVMSmEf6w3jxX6wQYOWvmDZ4mu6f5c8wr221EMDcOpEzQV09d1zuBSWgKLBgjqAkYHJZ5dTRIWpEDpPgujhOFZa2ld1HiAOxrJKlIrlfDBN0CUsTlGOGplujDAr4VtpFzNRS",
@ -50,7 +56,7 @@
"Room": "!OYZqtInrBCn1cyz90D:m.bltrucks.top" "Room": "!OYZqtInrBCn1cyz90D:m.bltrucks.top"
} }
}, },
"Once": true, "Once": false,
"Brokers": { "Brokers": {
"NTG": { "NTG": {
"JobInfo": true, "JobInfo": true,

View File

@ -28,12 +28,18 @@ type Config struct {
UploadMethod string UploadMethod string
} }
Maps struct { Maps struct {
DirectionsURIFormat string
PathedURIFormat string
URIFormat string URIFormat string
Pathed bool
Pickup bool Pickup bool
Dropoff bool Dropoff bool
Pathed struct {
Enabled bool
DirectionsURIFormat string
PathedURIFormat string
Zoom struct {
AcceptableLatLngDelta float32
Override int
}
}
} }
Clients map[string]Client Clients map[string]Client
Storage []string Storage []string

26
main.go
View File

@ -337,8 +337,8 @@ func sendJob(job broker.Job) (bool, error) {
maps := config.Get().Maps maps := config.Get().Maps
pickup := fmt.Sprintf("%s,%s", url.QueryEscape(job.Pickup.City), job.Pickup.State) pickup := fmt.Sprintf("%s,%s", url.QueryEscape(job.Pickup.City), job.Pickup.State)
dropoff := fmt.Sprintf("%s,%s", url.QueryEscape(job.Dropoff.City), job.Dropoff.State) dropoff := fmt.Sprintf("%s,%s", url.QueryEscape(job.Dropoff.City), job.Dropoff.State)
if maps.Pathed { if maps.Pathed.Enabled {
directionsURI := fmt.Sprintf(maps.DirectionsURIFormat, pickup, dropoff) directionsURI := fmt.Sprintf(maps.Pathed.DirectionsURIFormat, pickup, dropoff)
resp, err := http.Get(directionsURI) resp, err := http.Get(directionsURI)
if err != nil { if err != nil {
return true, err return true, err
@ -365,11 +365,31 @@ func sendJob(job broker.Job) (bool, error) {
if len(directionsResp.Routes) < 1 || len(directionsResp.Routes[0].Legs) < 1 || len(directionsResp.Routes[0].Legs[0].Steps) < 1 { if len(directionsResp.Routes) < 1 || len(directionsResp.Routes[0].Legs) < 1 || len(directionsResp.Routes[0].Legs[0].Steps) < 1 {
} else { } else {
latLngPath := make([]string, 0) latLngPath := make([]string, 0)
minLat := directionsResp.Routes[0].Legs[0].Steps[0].StartLocation.Lat
maxLat := directionsResp.Routes[0].Legs[0].Steps[0].StartLocation.Lat
minLng := directionsResp.Routes[0].Legs[0].Steps[0].StartLocation.Lng
maxLng := directionsResp.Routes[0].Legs[0].Steps[0].StartLocation.Lng
for _, v := range directionsResp.Routes[0].Legs[0].Steps { for _, v := range directionsResp.Routes[0].Legs[0].Steps {
if v.StartLocation.Lng < minLng {
minLng = v.StartLocation.Lng
}
if v.StartLocation.Lng > maxLng {
maxLng = v.StartLocation.Lng
}
if v.StartLocation.Lat < minLat {
minLat = v.StartLocation.Lat
}
if v.StartLocation.Lat > maxLat {
maxLat = v.StartLocation.Lat
}
latLngPath = append(latLngPath, fmt.Sprintf("%.9f,%.9f", v.StartLocation.Lat, v.StartLocation.Lng)) latLngPath = append(latLngPath, fmt.Sprintf("%.9f,%.9f", v.StartLocation.Lat, v.StartLocation.Lng))
} }
pathQuery := strings.Join(latLngPath, "|") pathQuery := strings.Join(latLngPath, "|")
uri := fmt.Sprintf(maps.PathedURIFormat, pathQuery, pickup, dropoff) uri := fmt.Sprintf(maps.Pathed.PathedURIFormat, pathQuery, pickup, dropoff)
// if the bigger delta is <acceptable, override zoom
if maxLat-minLat <= maps.Pathed.Zoom.AcceptableLatLngDelta && maxLng-minLng <= maps.Pathed.Zoom.AcceptableLatLngDelta {
uri = fmt.Sprintf("%s&zoom=%d", uri, maps.Pathed.Zoom.Override)
}
log.Printf("sending pathed image: %s", uri) log.Printf("sending pathed image: %s", uri)
if err := sender.SendImage(uri); err != nil { if err := sender.SendImage(uri); err != nil {
return true, err return true, err

View File

@ -48,7 +48,7 @@ func (m *Matrix) Receive() ([]Message, error) {
log.Printf("matrix.Receive()") log.Printf("matrix.Receive()")
messages := make([]Message, 0) messages := make([]Message, 0)
for k := range config.Get().Clients { for k := range config.Get().Clients {
messages = append(messages, Message{Timestamp: time.Now(), Sender: k, Content: "!state OH"}) messages = append(messages, Message{Timestamp: time.Now(), Sender: k, Content: "!state nc"})
if k == "bel" { if k == "bel" {
messages = append(messages, Message{Timestamp: time.Now(), Sender: k, Content: "!help"}) messages = append(messages, Message{Timestamp: time.Now(), Sender: k, Content: "!help"})
} }

View File

@ -1,5 +1,5 @@
todo: todo:
- TEST its falling apart;; mock is nigh useless - TEST its falling apart
- figure out zoom on maps;; is there like an auto-zoom I can leverage? - figure out zoom on maps;; is there like an auto-zoom I can leverage?
- mark jobs no longer avail by modifying in matrix - mark jobs no longer avail by modifying in matrix
- write-as for clients so ma can write to pa by default - write-as for clients so ma can write to pa by default
@ -15,6 +15,7 @@ todo:
- banlist criteria like vendors, brokers, metadata - banlist criteria like vendors, brokers, metadata
- set up copy for caleb, broc - set up copy for caleb, broc
done: done:
- mock is nigh useless
- mark consumed;; save scroll id for matrix - mark consumed;; save scroll id for matrix
- todo: switch house to selfhosted for rate limit - todo: switch house to selfhosted for rate limit
tags: now tags: now