felipe-augusto / vazante

Back-end for vazante - the app that makes sure you get home safe
Other
0 stars 0 forks source link

Helpers #1

Open felipe-augusto opened 7 years ago

felipe-augusto commented 7 years ago

FINDING COMMON PATHS

https://stackoverflow.com/questions/32230611/how-to-find-the-overlap-of-polylines-in-order-to-draw-the-common-segment-as-shad https://jsfiddle.net/geocodezip/ko2gjrxp/5/

FORK: https://jsfiddle.net/pwg5gejm/

MAKING CUSTOM MAKERS

https://stackoverflow.com/questions/23965161/js-maps-v3-custom-marker-with-user-profile-picture http://jsfiddle.net/mfirdaus/DVKEj/

SUPRESS DEFAULT ROUTES MARKERS

https://stackoverflow.com/questions/26462222/changing-titles-of-endpoint-markers-in-a-google-maps-route

FACEBOOK AUTHENTICATION

https://auth0.com/authenticate/scala/facebook

SCALA + FIREBASE

https://medium.com/@RICEaaron/scala-firebase-da433df93bd2

felipe-augusto commented 7 years ago

https://jsfiddle.net/pwg5gejm/1/

var map;
var directionsService;
let main, first, second

function loadRoute1() {
    var request = {
        origin: '-23.643108, -46.529357',
        destination: 'rua holanda, 20, santo andré',
        travelMode: google.maps.TravelMode.DRIVING
    };

    directionsService.route(request, function (result, status) {
        if (status == google.maps.DirectionsStatus.OK) {
            result.draggable = true;
            var renderer = new google.maps.DirectionsRenderer({
                draggable: false, // true,
                polylineOptions: {
                    strokeColor: "#DD71D8",
                    strokeWeight: 1
                },
                map: map
            });

            console.log('loading my route')
            let arr = []
            result.routes[0].legs[0].steps.map(function(step) {
                step.path.map(function (path) {
                arr.push(path.lat() + '@@' + path.lng())
              })
            })

            main = arr

            renderer.setDirections(result);
        }
    });
}

function loadRoute2() {
    var request = {
        origin: '-23.643108, -46.529357',
        destination: 'rua aimbere, 85, santo andre',
        travelMode: google.maps.TravelMode.WALKING
    };

    directionsService.route(request, function (result, status) {
        if (status == google.maps.DirectionsStatus.OK) {
            result.draggable = true;
            var renderer = new google.maps.DirectionsRenderer({
                draggable: true, // true,
                polylineOptions: {
                    strokeColor: "#0000ff",
                    strokeWeight: 1
                },
                map: map
            });

            console.log('loading second route')
            let arr = []
            result.routes[0].legs[0].steps.map(function(step) {
                step.path.map(function (path) {
                arr.push(path.lat() + '@@' + path.lng())
              })
            })

            first = arr

            let test = main.filter(function(n) {
                return arr.includes(n);
            });

            console.log('intersection')
            console.log(test.length)

            let path = test.map(function(item, index) {
                let split = item.split('@@')
              return new google.maps.LatLng(split[0], split[1])
            })

            console.log(path)

            var polyline = new google.maps.Polyline({
                map: map,
                path: path,
                strokeWeight: 8,
                strokeColor: "#000000"
            });

            renderer.setDirections(result);
        }
    });
}

function loadRoute3() {
    var request = {
        origin: '-23.643108, -46.529357',
        destination: 'rua suica, 400, santo andre',
        travelMode: google.maps.TravelMode.WALKING
    };

    directionsService.route(request, function (result, status) {
        if (status == google.maps.DirectionsStatus.OK) {
            result.draggable = true;
            var renderer = new google.maps.DirectionsRenderer({
                draggable: true, // true,
                polylineOptions: {
                    strokeColor: "#0000ff",
                    strokeWeight: 1
                },
                map: map
            });

            console.log('loading third route')
            let arr = []
            result.routes[0].legs[0].steps.map(function(step) {
                step.path.map(function (path) {
                arr.push(path.lat() + '@@' + path.lng())
              })
            })

            second = arr
            let p = calculateIntersection(main, [first, second])
            console.log(p)
            renderer.setDirections(result);
        }
    });
}

function initialize() {

    var mapOptions = {
        zoom: 16,
        draggable: true,
        center: {
            lat: -23.644359,
            lng: -46.528339
        }
    };

    map = new google.maps.Map(document.getElementById('map'), mapOptions);
    directionsService = new google.maps.DirectionsService();

    loadRoute1();
    loadRoute2();
    loadRoute3();
}

function transformResultToHashable(result){
            let arr = []
            result.routes[0].legs[0].steps.map(function(step) {
                step.path.map(function (path) {
                  arr.push(path.lat() + '@@' + path.lng())
              })
            })
           return arr
}

function calculateIntersection(main, others) {
    let hash = {}

  main.forEach(function(path){
    hash[path] = true
  })

  return others.map(function(map) {
    return map.reduce(function(acc, item) {
        if(hash[item] != null) return acc + 1
      return acc
    }, 0) * 100 / main.length
  })
}

initialize();
felipe-augusto commented 7 years ago

https://www.youtube.com/watch?v=ML1f7uAf3L4

felipe-augusto commented 7 years ago

1 - TELA: LOGIN WITH FACEBOOK PEGAR SEXO, FOTO, NOME E E-MAIL

2 - TELA: CADASTRAR UM LOCAL (PODE PULAR SE QUISER) (NESTA TELA SERIA INTERESSANTE SE APARECESSE AS ROTAS POR ONDE MAIS PESSOAS VÃO) function getAllLocales(){} function pushNewLocale()

3 - TELA: DEFINIR UM PORTÃO DE SAÍDA DA UFABC UM HORÁRIO DE SAÍDA O LOCAL DE DESTINO https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-directions

DEPOIS QUE A QUERY FOR FEITA MOSTRA DUAS SEÇÕES: USUÁRIOS QUE SAEM NOS PRÓXIMO 15 MINUTOS, OPÇÃO DE MANDAR MENSAGEM USUÁRIO COM MAIOR COMPATIBILIDADE

COMO VAMOS MANTER ATUALIZADO TUDO ISSO?

felipe-augusto commented 7 years ago

DROP FIREBASE FOR MONGO: (livro scala cookbook)

http://alvinalexander.com/scala/how-to-connect-mongodb-database-insert-data-casbah-scala http://alvinalexander.com/scala/how-to-search-mongodb-collection-scala-casbah-findone-limit https://blog.knoldus.com/2012/08/02/working-with-play-framework-using-scala-and-mongodb/

GENERATES JWT https://github.com/pauldijou/jwt-scala

AUTHENTICATION MIDDLEWARE https://stackoverflow.com/questions/39466427/middleware-in-play-framework-java https://www.playframework.com/documentation/2.5.x/JavaActionsComposition

felipe-augusto commented 7 years ago

https://developers.google.com/maps/documentation/javascript/examples/directions-simple?hl=pt-br

https://www.experts-exchange.com/questions/26617895/Plotting-multiple-directions-using-Google-maps-API.html

Lembrar de restringir a chave de acesso!

felipe-augusto commented 7 years ago

FUTURES (mesma coisa que Promises, aonde usar?) -> TEORICAMENTE EM QUALQUER REQUISIÇÃO HTTP

http://docs.scala-lang.org/overviews/core/futures.html

PARALLEL COLLECTIONS

http://docs.scala-lang.org/overviews/parallel-collections/overview.html

felipe-augusto commented 7 years ago
val user_id = (json \ "user_id").as[JsString].value

implicit val coordsReader = Json.reads[Coordenate]
val coords = (json \ "coords").asOpt[List[Coordenates]].getOrElse(List())
coords.foreach(println)

// http://api.mongodb.com/scala/casbah/2.1.1/tutorial.html

// http://mongodb.github.io/casbah/3.1/reference/modules/

// https://www.playframework.com/documentation/2.0/api/scala/play/api/libs/json/package.html

// https://stackoverflow.com/questions/15643821/foreach-with-json-arrays-in-play2-and-scala

val new_preference = Preference(user_id, name, createCoords(coords))
Preference.save(new_preference)

//def createCoords(coords: List<Coordenates>) = {
//  coords.map((coord) => new Coordenate(coord.lat, coord.lgn))
//}

case class Coordenate(val lat: Float, val lgn: float) {}

case class Preference(user_id: String, name: String, coords: Array<Coordenate>)

object Preference {
    def build(preference: Preference): MongoDBObject {
        val builder = MongoDBObject.newBuilder
        builder += "user_id" -> user_id
        builder += "name" -> name
        builder += "coords" -> coords
        builder.result
    }

    def save(preference: Preference) = {
        val mongoObj = build(preference)
        MongoFactory.user.save(mongoObj)
    }

}