Git Product home page Git Product logo

japan-train-data's Introduction

🚉 japan-train-data

Choo choo.

A circular object of train data for Japan including translations & station geocoding and a tool to generate it. Access train data by prefecture, by lines, or by stations.

Install

yarn add japan-train-data

Usage

import { prefectures, lines, stations } from 'japan-train-data'

console.log(prefectures.find(({ id }) => id === 13))

/*
{
  id: 13,
  name: { ja: '東京都', en: 'Tokyo' },
  lines: [
    {
      id: 11301,
      name: [Object],
      lat: 35.39507962341528,
      lng: 139.4302441326313,
      zoom: 10,
      stations: [Object],
      prefecture: [Circular],
    },
    ...
  ],
}
*/

console.log(lines.find(({ id }) => id === 11302))

/*
{
  id: 11302,
  name: {
    ja: 'JR山手線',
    en: 'JR Yamanote Line',
  },
  lat: 35.69302730762992,
  lng: 139.73522275686264,
  zoom: 12,
  stations: [
    {
      id: 1130201,
      name: [Object],
      location: [Object],
      lines: [Object],
      prefecture: [Object],
    },
    {
      id: 1130202,
      name: [Object],
      location: [Object],
      lines: [Object],
      prefecture: [Object],
    },
    ...
  ],
  prefecture: {
    id: 13,
    name: { ja: '東京都', en: 'Tokyo' },
    lines: [[Object], [Circular], [Object]],
  },
}
*/

console.log(stations.find(({ prefecture: { id } }) => id === 13))

/*
{
  id: 1130101,
  name: { ja: '東京', en: 'Tokyo' },
  location: {
    lat: 35.681391,
    lng: 139.766103,
    countryCode: { en: 'JP', ja: 'JP' },
    postalCode: {
      en: '100-0005',
      ja: '100-0005',
    },
    administrativeArea1: {
      en: 'Tōkyō-to',
      ja: '東京都',
    },
    locality1: {
      en: 'Chiyoda-ku',
      ja: '千代田区',
    },
    sublocality1: {
      en: 'Marunouchi',
      ja: '丸の内',
    },
    sublocality2: {
      en: '1 Chome',
      ja: '1丁目',
    },
    sublocality3: { en: '9', ja: '9' },
    sublocality4: { en: '1', ja: '1' },
  },
  lines: [
    { id: 11301, name: [Object] },
    { id: 11302, name: [Object] },
    { id: 11308, name: [Object] },
    ...
  ],
  prefecture: {
    id: 13,
    name: { ja: '東京都', en: 'Tokyo' },
    lines: [[Object], [Object], [Object]],
  },
}
*/

Just gimme the data

Sure. data/raw-data.json.

Generating the data

First clone the project:

git clone https://github.com/adieuadieu/japan-train-data.git

Set up your environment with Google Cloud keys. To generate the data you need API access to Google's Translation and Geocoding APIs.

echo GCP_PROJECT=your-gcp-project-id-here >> .env
GCP_API_KEY=your-google-maps-api-key-here >> .env
GCP_KEYFILE=./gcp-keyfile.json >> .env

Then to start generating data:

yarn generate

Known Issues

  1. Some of the translations are clearly crap.
  2. In many cases, transliteration would be better than translation, but there's no API? Suggestions?

Todo

  • npm package
  • unit tests
  • ci integrations

japan-train-data's People

Contributors

adieuadieu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

japan-train-data's Issues

Tameike Sanno wrong name

After importing the data to our db someone pointed out a mistake with the Tameike Sanno station name:

{
  _id: "tSRdiyXzHjMGPwQX4",
  id: NumberLong("2800114"),
  name: {
    ja: "溜池山王",
    en: "Tameike San"
  },
  location: {
    type: "Point",
    coordinates: [
      139.741419,
      35.673621
    ]
  },
  lines: [
    {
      id: NumberLong("28001"),
      name: {
        ja: "東京メトロ銀座線",
        en: "Tokyo Metro Ginza Line"
      }
    },
    {
      id: NumberLong("28009"),
      name: {
        ja: "東京メトロ南北線",
        en: "Tokyo Metro Namboku Line"
      }
    }
  ]
}

As you can see it's written as Tameike San. I guess there's a chance the mistake comes from our own import process but I don't really see how that would happen…?

Hot fix station/line name in English

Many English names are not correct since they are translated directly from Google translate API.
I have fixed many ones then should I create a pull request for raw-data.json file? just a hotfix at all but it seems to be good to another one.
I think it is good enough to get the response from google search with the first result of Wikipedia in English, maybe.
Btw, thank you so much for this repository.

Getting all stations for a given prefecture

In the example, console.log(stations.find(({ prefecture: { id } }) => id === 13)) seems to return a prefecture object?

I assume you can then iterate over that object's lines property to get the lines, and from there the stations? But is there a way to just get an array of stations right out of the box?

Hot fix some station/line names in English

I tried to fix and push new branch into this repository but access is denied.
Many English names are not correct since they are translated directly from Google translate API.
I have fixed many ones but cannot do anything to contribute.
I think it is good enough to get the response from google search with the first result of Wikipedia in English, maybe.
Btw, thank you so much for this repository.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.