-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb-script.coffee
68 lines (60 loc) · 1.77 KB
/
db-script.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#
# DB Setup
#
geohash = require('ngeohash')
cradle = require("cradle")
async = require('async')
cradle.setup
host: "localhost"
port: 5984
_createdb = (dbname) ->
db = cclient.database(dbname)
db.exists (err, exists) ->
db.create() unless exists
db
cradle_error = (err, res) ->
console.log err if err
cclient = new (cradle.Connection)
DB = _createdb("break")
#
# Update geohashes
#
update_geo = (db) ->
db.all (err, doc) ->
console.log(doc)
#async.until(
#-> i > doc.length + 1
#(a) ->
#type = doc[i].id.split("/")[1].slice(0, -1)
#if type is 'venue' and doc[i].id.indexOf("_design") is -1
#id = doc[i].id.replace(/\//g, "%2F")
#db.get id, (err, data) ->
#console.log(id)
#unless err
#if data.location isnt undefined and data.location isnt null
#console.log(data.location)
#data.location =
#lat: data.location[0]
#lon: data.location[1]
#if data.location.lat is null or data.location.lon is null then data.location.geohash = null
#else data.location.geohash = geohash.encode(data.location.lat, data.location.lon)
##id = data.id
##console.log('id',id)
##console.log('location',location)
##console.log('geohash',location.geohash)
##db.save(id, data, (err, d) ->
###console.log('id',id)
###console.log('err', err)
##console.log('result', d)
##)
#i++
#a()
#else
#console.log(i)
#i++
#a()
#, (err) ->
#console.log(err)
#console.log('finished')
#)
update_geo DB