Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
champierre committed Sep 23, 2022
1 parent 1a8a509 commit 09673a4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 281,571 deletions.
22 changes: 13 additions & 9 deletions bin/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const turfCenter = require('@turf/center').default
const turfNearestPoint = require('@turf/nearest-point').default
const { featureCollection, point } = require('@turf/helpers')
const sqlite3 = require('sqlite3')
const db = new sqlite3.Database('./data/latest.db')
const { open } = require('sqlite')

const sleep = promisify(setTimeout)

Expand Down Expand Up @@ -678,12 +678,15 @@ const getAddressItems = async (
}

const main = async () => {
db.serialize(() => {
db.run('drop table if exists addresses_unsorted')
db.run('drop table if exists addresses')
db.run('create table addresses_unsorted(都道府県コード text, 都道府県名 text, 都道府県名カナ text, 都道府県名ローマ字 text, 市区町村コード text, 市区町村名 text, 市区町村名カナ text, 市区町村名ローマ字 text, 大字町丁目名 text, 大字町丁目名カナ text, 大字町丁目名ローマ字 text, 小字・通称名 text, 緯度 real, 経度 real)')
const db = await open({
filename: './data/latest.db',
driver: sqlite3.Database
})

await db.run('drop table if exists addresses_unsorted')
await db.run('drop table if exists addresses')
await db.run('create table addresses_unsorted(都道府県コード text, 都道府県名 text, 都道府県名カナ text, 都道府県名ローマ字 text, 市区町村コード text, 市区町村名 text, 市区町村名カナ text, 市区町村名ローマ字 text, 大字町丁目名 text, 大字町丁目名カナ text, 大字町丁目名ローマ字 text, 小字・通称名 text, 緯度 real, 経度 real)')

const t0 = performance.now()
process.stderr.write('郵便番号辞書のダウンロード中...')
const [
Expand Down Expand Up @@ -722,7 +725,7 @@ const main = async () => {
const gaiku_outfile = await fs.promises.open(path.join(dataDir, 'latest_gaiku.csv'), 'w')

const sqliteWriterQueue = async.queue(async array => {
db.run('insert into addresses_unsorted(都道府県コード, 都道府県名, 都道府県名カナ, 都道府県名ローマ字, 市区町村コード, 市区町村名, 市区町村名カナ, 市区町村名ローマ字, 大字町丁目名, 大字町丁目名カナ, 大字町丁目名ローマ字, 小字・通称名, 緯度, 経度) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', ...array)
await db.run('insert into addresses_unsorted(都道府県コード, 都道府県名, 都道府県名カナ, 都道府県名ローマ字, 市区町村コード, 市区町村名, 市区町村名カナ, 市区町村名ローマ字, 大字町丁目名, 大字町丁目名カナ, 大字町丁目名ローマ字, 小字・通称名, 緯度, 経度) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', ...array)
}, 1)
const gaiku_outfileWriterQueue = async.queue(async str => {
await gaiku_outfile.write(str)
Expand All @@ -738,7 +741,7 @@ const main = async () => {
].join(',') + '\n')

for (let i = 0; i < prefCodeArray.length; i++) {
const prefCode = toPrefCode(prefCodeArray[i])
const prefCode = toPrefCode(prefCodeArray[i])

const tp0 = performance.now()
const { towns, gaikuItems } = await getAddressItems(
Expand All @@ -760,8 +763,9 @@ const main = async () => {
const t1 = performance.now()
console.log('build.js took ' + (t1 - t0) + ' milliseconds.')

db.run('create table addresses as select * from addresses_unsorted order by 都道府県コード asc, 市区町村コード asc, 大字町丁目名カナ asc, 小字・通称名 asc')
db.close()
// db.run('create table addresses as select * from addresses_unsorted order by 都道府県コード asc, 市区町村コード asc, 大字町丁目名カナ asc, 小字・通称名 asc')
await db.run('create table addresses as select * from addresses_unsorted')
await db.close()
}

try {
Expand Down
Loading

0 comments on commit 09673a4

Please sign in to comment.