<commit_before>#include "osm2nav.h"
#include <stdio.h>

#include <iostream>
#include <boost/lexical_cast.hpp>
#include "type/data.h"
#include "third_party/osmpbfreader/osmpbfreader.h"
#include "osm_tags_reader.h"
#include "georef/georef.h"

namespace navitia { namespace georef {
struct Node {
public:
    double lon() const {return static_cast<double>(this->lon_m) / precision;}
    double lat() const {return static_cast<double>(this->lat_m) / precision;}
    uint32_t uses;
    int32_t idx;

    Node(double lon = 0, double lat = 0) : uses(0), idx(-1), lon_m(lon * precision), lat_m(lat * precision){}
    bool increment_use(int idx){
        uses++;
        if(this->idx == -1 && uses > 1){
            this->idx = idx;
            return true;
        } else {
            return false;
        }
    }

private:
    int32_t lon_m;
    int32_t lat_m;
    static constexpr double precision = 10e6;
};

struct OSMWay {
    const static uint8_t CYCLE_FWD = 0;
    const static uint8_t CYCLE_BWD = 1;
    const static uint8_t CAR_FWD = 2;
    const static uint8_t CAR_BWD = 3;
    const static uint8_t FOOT_FWD = 4;
    const static uint8_t FOOT_BWD = 5;
    std::vector<uint64_t> refs;
    uint64_t id;
    std::bitset<8> properties;
    type::idx_t idx;
};

using namespace CanalTP;

struct Visitor{
    std::unordered_map<uint64_t, Node> nodes;
    int total_ways;
    std::vector<OSMWay> ways;
    georef::GeoRef & geo_ref;

    Visitor(GeoRef & to_fill) : total_ways(0), geo_ref(to_fill){}

    void node_callback(uint64_t osmid, double lon, double lat, const Tags &/*tags*/){
        this->nodes[osmid] = Node(lon, lat);
    }

    void way_callback(uint64_t osmid, const Tags &tags, const std::vector<uint64_t> &refs){
        total_ways++;
        std::bitset<8> properties = parse_way_tags(tags);
        if(properties.any()){
            OSMWay w;
            w.idx = ways.size();
            w.refs = refs;
            w.id = osmid;
            ways.push_back(w);

            georef::Way gr_way;
            gr_way.idx = w.idx;
            gr_way.city_idx = type::invalid_idx;
            if(tags.find("name") != tags.end())
                gr_way.name = tags.at("name");
            geo_ref.ways.push_back(gr_way);
        }
    }

    // Once all the ways and nodes are read, we count how many times a node is used to detect intersections
    void count_nodes_uses() {
        int count = 0;
        for(auto w : ways){

            for(uint64_t ref : w.refs){
                if(nodes[ref].increment_use(count)){
                    Vertex v;
                    count++;
                    v.coord = type::GeographicalCoord( nodes[ref].lon(), nodes[ref].lat());
                    boost::add_vertex(v, geo_ref.graph);<commit_msg>NaviMake : création d'un externalcode pour OSM<commit_after>#include "osm2nav.h"
#include <stdio.h>

#include <iostream>
#include <boost/lexical_cast.hpp>
#include "type/data.h"
#include "third_party/osmpbfreader/osmpbfreader.h"
#include "osm_tags_reader.h"
#include "georef/georef.h"

namespace navitia { namespace georef {
struct Node {
public:
    double lon() const {return static_cast<double>(this->lon_m) / precision;}
    double lat() const {return static_cast<double>(this->lat_m) / precision;}
    uint32_t uses;
    int32_t idx;

    Node(double lon = 0, double lat = 0) : uses(0), idx(-1), lon_m(lon * precision), lat_m(lat * precision){}
    bool increment_use(int idx){
        uses++;
        if(this->idx == -1 && uses > 1){
            this->idx = idx;
            return true;
        } else {
            return false;
        }
    }

private:
    int32_t lon_m;
    int32_t lat_m;
    static constexpr double precision = 10e6;
};

struct OSMWay {
    const static uint8_t CYCLE_FWD = 0;
    const static uint8_t CYCLE_BWD = 1;
    const static uint8_t CAR_FWD = 2;
    const static uint8_t CAR_BWD = 3;
    const static uint8_t FOOT_FWD = 4;
    const static uint8_t FOOT_BWD = 5;
    std::vector<uint64_t> refs;
    uint64_t id;
    std::bitset<8> properties;
    type::idx_t idx;
};

using namespace CanalTP;

struct Visitor{
    std::unordered_map<uint64_t, Node> nodes;
    int total_ways;
    std::vector<OSMWay> ways;
    georef::GeoRef & geo_ref;

    Visitor(GeoRef & to_fill) : total_ways(0), geo_ref(to_fill){}

    void node_callback(uint64_t osmid, double lon, double lat, const Tags &/*tags*/){
        this->nodes[osmid] = Node(lon, lat);
    }

    void way_callback(uint64_t osmid, const Tags &tags, const std::vector<uint64_t> &refs){
        total_ways++;
        std::bitset<8> properties = parse_way_tags(tags);
        if(properties.any()){
            OSMWay w;
            w.idx = ways.size();
            w.refs = refs;
            w.id = osmid;
            ways.push_back(w);

            georef::Way gr_way;
            gr_way.idx = w.idx;
            gr_way.external_code = std::to_string(w.idx);
            gr_way.city_idx = type::invalid_idx;
            if(tags.find("name") != tags.end())
                gr_way.name = tags.at("name");
            geo_ref.ways.push_back(gr_way);
        }
    }

    // Once all the ways and nodes are read, we count how many times a node is used to detect intersections
    void count_nodes_uses() {
        int count = 0;
        for(auto w : ways){

            for(uint64_t ref : w.refs){
                if(nodes[ref].increment_use(count)){
                    Vertex v;
                    count++;
                    v.coord = type::GeographicalCoord( nodes[ref].lon(), nodes[ref].lat());
                    boost::add_vertex(v, geo_ref.graph);
{'fraction_non_alphanumeric': 0.12421693216395203, 'fraction_numerical': 0.017182745659566852, 'mean_word_length': 2.354141656662665, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2856124', 'n_tokens_mistral': 2020, 'n_tokens_neox': 1902, 'n_words': 450}