Skip to content

Instantly share code, notes, and snippets.

@bcho
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save bcho/24222f3f23cd14057092 to your computer and use it in GitHub Desktop.

Select an option

Save bcho/24222f3f23cd14057092 to your computer and use it in GitHub Desktop.
fs = require 'fs'
path = require 'path'
dataPath = './data'
fullPath = (name) -> path.join dataPath, name
evalFile = (name) -> eval fs.readFileSync(fullPath name).toString 'utf8'
files = fs.readdirSync dataPath
merged = []
merged = merged.concat.apply merged, files.map evalFile
fs.writeFileSync 'output.json', JSON.stringify merged
fs = require 'fs'
path = require 'path'
dataPath = './data'
fullPath = (name) -> path.join dataPath, name
evalFile = (name) -> JSON.parse fs.readFileSync(fullPath name).toString 'utf8'
files = fs.readdirSync dataPath
merged = files.map evalFile
fs.writeFileSync 'output.json', JSON.stringify merged
fs = require 'fs'
path = require 'path'
dataPath = './data'
fullPath = (name) -> path.join dataPath, name
gz_obtDatas = null # should catch by the closure
evalFile = (name) ->
console.log name
try
eval fs.readFileSync(fullPath name).toString 'utf8'
gz_obtDatas
catch e
console.log e
groupBy = (coll, f) ->
groups = {}
coll.forEach (c) ->
group = f(c)
groups[group] = [] unless groups[group]?
groups[group].push c
groups
files = fs.readdirSync dataPath
byMonths = groupBy files, (name) -> (new Date(name)).getMonth() + 1
byMonthsAndWeeks = {}
for month, files of byMonths
byMonthsAndWeeks[month] = groupBy files, (name) ->
(Math.round (new Date(name)).getDate() / 7) + 1
for month, byWeeks of byMonthsAndWeeks
for week, files of byWeeks
merged = (files.map evalFile).filter (x) -> x?
fs.writeFileSync "#{month}-#{week}.json", JSON.stringify merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment